All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Loaders.cxx
Go to the documentation of this file.
2 
5 
6 #include <cassert>
7 #include <iostream>
8 
9 namespace ana
10 {
11  //----------------------------------------------------------------------
13  {
14  }
15 
16  //----------------------------------------------------------------------
18  {
19  // for(auto it: fLoaders) delete it.second;
20  }
21 
22  //----------------------------------------------------------------------
23  void Loaders::SetLoaderPath(const std::string& path,
24  DataMC datamc,
25  DataSource src,
26  SwappingConfig swap)
27  {
28  assert(datamc == kMC || swap == kNonSwap);
29  assert(src == kBeam || swap == kNonSwap);
30 
31  const Key_t key(datamc, src, swap);
32 
33  // Clear out the old one if necessary
34  DisableLoader(datamc, src, swap);
35 
36  fLoaderPaths[key] = path;
37  }
38 
39  //----------------------------------------------------------------------
40  void Loaders::SetLoaderFiles(const std::vector<std::string>& files,
41  DataMC datamc,
42  DataSource src,
43  SwappingConfig swap)
44  {
45  assert(datamc == kMC || swap == kNonSwap);
46  assert(src == kBeam || swap == kNonSwap);
47 
48  const Key_t key(datamc, src, swap);
49 
50  // Clear out the old one if necessary
51  DisableLoader(datamc, src, swap);
52 
53  fLoaderFiles[key] = files;
54  }
55 
56  //----------------------------------------------------------------------
58  DataMC datamc,
59  DataSource src,
60  SwappingConfig swap)
61  {
62  assert(datamc == kMC || swap == kNonSwap);
63  assert(src == kBeam || swap == kNonSwap);
64 
65  const Key_t key(datamc, src, swap);
66 
67  // Clear out the old one if necessary
68  DisableLoader(datamc, src, swap);
69 
70  fLoaders[key] = file;
71  }
72 
73  //----------------------------------------------------------------------
75  DataSource src,
76  SwappingConfig swap)
77  {
78  assert(datamc == kMC || swap == kNonSwap);
79  assert(src == kBeam || swap == kNonSwap);
80 
81  const Key_t key(datamc, src, swap);
82 
83  // Clear out the current one if possible
84  auto it = fLoaders.find(key);
85  if(it != fLoaders.end()){
86  delete it->second;
87  fLoaders.erase(it);
88  }
89 
90  fLoaderPaths.erase(key);
91  fLoaderFiles.erase(key);
92  }
93 
94  //----------------------------------------------------------------------
96  DataSource src,
97  SwappingConfig swap)
98  {
99  assert(datamc == kMC || swap == kNonSwap);
100  assert(src == kBeam || swap == kNonSwap);
101 
102  const Key_t key(datamc, src, swap);
103 
104  // Look up and return. Use fNull if no loader is set for this config
105  auto itLoader = fLoaders.find(key);
106  if(itLoader != fLoaders.end()) return *itLoader->second;
107 
108  auto itPath = fLoaderPaths.find(key);
109  if(itPath != fLoaderPaths.end()){
110  fLoaders[key] = new SpectrumLoader(itPath->second, src);
111  return *fLoaders[key];
112  }
113  auto itFiles = fLoaderFiles.find(key);
114  if(itFiles != fLoaderFiles.end()){
115  fLoaders[key] = new SpectrumLoader(itFiles->second, src);
116  return *fLoaders[key];
117  }
118 
119  return fNull;
120  }
121 
122  //----------------------------------------------------------------------
123  void Loaders::Go()
124  {
125  for(auto it: fLoaders) it.second->Go();
126  }
127 }
void AddLoader(SpectrumLoaderBase *, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Definition: Loaders.cxx:57
std::map< Key_t, std::string > fLoaderPaths
Definition: Loaders.h:55
void SetLoaderFiles(const std::vector< std::string > &files, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Configure loader via explicit file list.
Definition: Loaders.cxx:40
void DisableLoader(DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Definition: Loaders.cxx:74
void SetLoaderPath(const std::string &path, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Configure loader via wildcard path.
Definition: Loaders.cxx:23
* file
Definition: file_to_url.sh:69
process_name opflashCryoW ana
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:123
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
SpectrumLoaderBase & GetLoader(DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Retrieve a specific loader.
Definition: Loaders.cxx:95
DataSource
Is this data-file representing beam spills or cosmic spills?
NullLoader fNull
We give this back when a loader isn&#39;t set for some configuration.
Definition: Loaders.h:61
Base class for the various types of spectrum loader.
std::map< Key_t, SpectrumLoaderBase * > fLoaders
Definition: Loaders.h:58
std::tuple< DataMC, DataSource, SwappingConfig > Key_t
Definition: Loaders.h:52
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
std::map< Key_t, std::vector< std::string > > fLoaderFiles
Definition: Loaders.h:56
Loaders()
No loaders initialized. Use SetLoaderPath to configure.
Definition: Loaders.cxx:12