Loaders.cxx
Go to the documentation of this file.
1 #include "CAFAna/Core/Loaders.h"
2 
5 
6 #include <cassert>
7 #include <iostream>
8 
9 namespace ana
10 {
11  //----------------------------------------------------------------------
13  : fSpillCut(0), fND(false)
14  {
15  }
16 
17  //----------------------------------------------------------------------
19  {
20  for(auto it: fLoaders) delete it.second;
21  if(fSpillCut) delete fSpillCut;
22  }
23 
24  //----------------------------------------------------------------------
27  DataMC datamc,
28  DataSource src,
30  {
31  assert(datamc == kMC || swap == kNonSwap);
32  if (!fND) assert(det == caf::kFARDET || swap == kNonSwap);
33  else assert(det == caf::kNEARDET || swap == kNonSwap);
34  assert(src == kBeam || swap == kNonSwap);
35 
36  const Key_t key(det, datamc, src, swap);
37 
38  // Clear out the old one if necessary
39  DisableLoader(det, datamc, src, swap);
40 
42  }
43 
44  //----------------------------------------------------------------------
45  void Loaders::SetLoaderFiles(const std::vector<std::string>& files,
47  DataMC datamc,
48  DataSource src,
50  {
51  assert(datamc == kMC || swap == kNonSwap);
52  if (!fND) assert(det == caf::kFARDET || swap == kNonSwap);
53  else assert(det == caf::kNEARDET || swap == kNonSwap);
54  assert(src == kBeam || swap == kNonSwap);
55 
56  const Key_t key(det, datamc, src, swap);
57 
58  // Clear out the old one if necessary
59  DisableLoader(det, datamc, src, swap);
60 
62  }
63 
64  //----------------------------------------------------------------------
66  DataMC datamc,
67  DataSource src,
69  {
70  assert(datamc == kMC || swap == kNonSwap);
71  if (!fND) assert(det == caf::kFARDET || swap == kNonSwap);
72  else assert(det == caf::kNEARDET || swap == kNonSwap);
73  assert(src == kBeam || swap == kNonSwap);
74 
75  const Key_t key(det, datamc, src, swap);
76 
77  // Clear out the current one if possible
78  auto it = fLoaders.find(key);
79  if(it != fLoaders.end()){
80  delete it->second;
81  fLoaders.erase(it);
82  }
83 
84  fLoaderPaths.erase(key);
85  fLoaderFiles.erase(key);
86  }
87 
88  //----------------------------------------------------------------------
90  DataMC datamc,
91  DataSource src,
92  SwappingConfig swap) const
93  {
94  assert(datamc == kMC || swap == kNonSwap);
95  if (!fND) assert(det == caf::kFARDET || swap == kNonSwap);
96  else assert(det == caf::kNEARDET || swap == kNonSwap);
97  assert(src == kBeam || swap == kNonSwap);
98 
99  const Key_t key(det, datamc, src, swap);
100 
101  return fLoaderPaths.at(key);
102  }
103 
104  //----------------------------------------------------------------------
105  std::vector<std::string> Loaders::GetLoaderFiles(caf::Det_t det,
106  DataMC datamc,
107  DataSource src,
108  SwappingConfig swap) const
109  {
110  assert(datamc == kMC || swap == kNonSwap);
111  if (!fND) assert(det == caf::kFARDET || swap == kNonSwap);
112  else assert(det == caf::kNEARDET || swap == kNonSwap);
113  assert(src == kBeam || swap == kNonSwap);
114 
115  const Key_t key(det, datamc, src, swap);
116 
117  return fLoaderFiles.at(key);
118  }
119 
120  //----------------------------------------------------------------------
122  {
123  for(auto it: fLoaders) it.second->SetSpillCut(cut);
124  if(fSpillCut) delete fSpillCut;
125  fSpillCut = new SpillCut(cut);
126  }
127 
128  //----------------------------------------------------------------------
130  DataMC datamc,
131  DataSource src,
133  {
134  assert(datamc == kMC || swap == kNonSwap);
135  if (!fND) assert(det == caf::kFARDET || swap == kNonSwap);
136  else assert(det == caf::kNEARDET || swap == kNonSwap);
137  assert(src == kBeam || swap == kNonSwap);
138 
139  const Key_t key(det, datamc, src, swap);
140 
141  // Look up and return. Use fNull if no loader is set for this config
142  auto itLoader = fLoaders.find(key);
143  if(itLoader != fLoaders.end()) return *itLoader->second;
144 
145  auto itPath = fLoaderPaths.find(key);
146  if(itPath != fLoaderPaths.end()){
147  fLoaders[key] = new SpectrumLoader(itPath->second);
148  if(fSpillCut) fLoaders[key]->SetSpillCut(*fSpillCut);
149  return *fLoaders[key];
150  }
151  auto itFiles = fLoaderFiles.find(key);
152  if(itFiles != fLoaderFiles.end()){
153  fLoaders[key] = new SpectrumLoader(itFiles->second);
154  if(fSpillCut) fLoaders[key]->SetSpillCut(*fSpillCut);
155  return *fLoaders[key];
156  }
157 
158  return fNull;
159  }
160 
161  //----------------------------------------------------------------------
162  void Loaders::Go()
163  {
164  for(auto it: fLoaders)
165  {
166  if (!it.second->Gone())
167  it.second->Go();
168  }
169  }
170 }
Near Detector underground.
Definition: SREnums.h:10
Det_t
Which NOvA detector?
Definition: SREnums.h:7
std::map< Key_t, std::string > fLoaderPaths
Definition: Loaders.h:81
const SpillCut * fSpillCut
Definition: Loaders.h:86
std::tuple< caf::Det_t, DataMC, DataSource, SwappingConfig > Key_t
Definition: Loaders.h:78
Far Detector at Ash River.
Definition: SREnums.h:11
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
set< int >::iterator it
std::vector< std::string > GetLoaderFiles(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap) const
Definition: Loaders.cxx:105
void DisableLoader(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Definition: Loaders.cxx:65
virtual ~Loaders()
Definition: Loaders.cxx:18
bool datamc
Definition: fnexvscaf.C:20
void Go()
Call Go() on all the loaders.
Definition: Loaders.cxx:162
std::string GetLoaderPath(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap) const
Definition: Loaders.cxx:89
void SetSpillCut(const SpillCut &cut)
Definition: Loaders.cxx:121
SpectrumLoaderBase & GetLoader(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Retrieve a specific loader.
Definition: Loaders.cxx:129
DataSource
Is this data-file representing beam spills or cosmic spills?
Definition: Loaders.h:14
NullLoader fNull
We give this back when a loader isn&#39;t set for some configuration.
Definition: Loaders.h:89
_Cut< caf::SRSpillProxy > SpillCut
Equivalent of Cut acting on caf::SRSpill. For use in spill-by-spill data quality cuts.
Definition: Cut.h:100
Base class for the various types of spectrum loader.
const std::string path
Definition: plot_BEN.C:43
void SetLoaderFiles(const std::vector< std::string > &files, caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Configure loader via explicit file list.
Definition: Loaders.cxx:45
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
assert(nhit_max >=nhit_nbins)
std::map< Key_t, std::vector< std::string > > fLoaderFiles
Definition: Loaders.h:82
Template for Cut and SpillCut.
Definition: Cut.h:15
Loaders()
No loaders initialized. Use SetLoaderPath to configure.
Definition: Loaders.cxx:12
std::map< Key_t, SpectrumLoader * > fLoaders
Definition: Loaders.h:84
void SetLoaderPath(const std::string &path, caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Configure loader via wildcard path.
Definition: Loaders.cxx:25
bool fND
Bool to set loader for near detector instead of far detector.
Definition: Loaders.h:91