SumRunsCalib_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file SumRunsCalib_module.cc
3 // \brief Sum up AttenProfilesMap objects
4 // \author Christopher Backhouse - bckhouse@caltech.edu
5 ////////////////////////////////////////////////////////////////////////
6 
7 #include <sstream>
8 
9 // Framework includes
15 
16 // NOvAsoft includes
18 
19 namespace calib
20 {
21  /// Sum up AttenProfilesMap objects
23  {
24  public:
25  explicit SumRunsCalib(const fhicl::ParameterSet& pset);
26  ~SumRunsCalib();
27 
28  void reconfigure(const fhicl::ParameterSet& pset);
29  virtual bool filter(art::Event& evt) {return false;}
30  virtual bool endRun(art::Run& run);
31 
32  protected:
33  std::list<std::pair<art::InputTag, int> > fInputTags;
34  int fMinBlock;
35  int fMaxBlock;
36  unsigned int fLastRun;
37 
38  std::map<int, std::unique_ptr<caldp::AttenProfilesMap>> fChannelMapProf;
39  };
40 
41  //......................................................................
43  {
44  reconfigure(pset);
45 
46  for(auto tag : fInputTags){
47  produces<caldp::AttenProfilesMap, art::InRun>(tag.first.instance());
48  }
49  }
50 
51  //......................................................................
53  {
54  }
55 
56  //......................................................................
58  {
59  fMinBlock = pset.get<int >("MinBlock");
60  fMaxBlock = pset.get<int >("MaxBlock");
61  fLastRun = pset.get<unsigned int>("LastRun" );
62 
63  assert(fMinBlock >= 0);
64  assert(fMaxBlock < 0 || fMaxBlock >= fMinBlock);
65 
66  // I don't think we can determine the detector in time
67  if(fMaxBlock < 0) fMaxBlock = 27;
68 
69  // make the input tags
70  fInputTags.clear();
71  auto histsMapLabel = pset.get<std::string>("AttenHistsMapLabel");
72 
73  for(int block = fMinBlock; block < fMaxBlock + 1; ++block){
74  std::ostringstream blockLabel;
75  blockLabel << "block" << block;
76  fInputTags.push_back(std::make_pair(art::InputTag(histsMapLabel, blockLabel.str()),
77  block));
78  }
79 
80  }
81 
82  //......................................................................
84  {
85  for(auto tag : fInputTags){
87 
88  LOG_VERBATIM("SumRunsCalib")
89  << run.run() << " " << tag.first.label() << " " << tag.first.instance();
90 
91  run.getByLabel(tag.first, profsmap);
92 
93  if(profsmap.failedToGet()) continue;
94 
95  if(!fChannelMapProf[tag.second]) fChannelMapProf[tag.second] = std::unique_ptr<caldp::AttenProfilesMap>(new caldp::AttenProfilesMap(profsmap->MinW(), profsmap->MaxW()));
96 
97  *fChannelMapProf[tag.second] += *profsmap;
98 
99  // No one else will ever want this. Save the memory
100  run.removeCachedProduct(profsmap);
101  }
102 
103  if(run.run() == fLastRun){
104  for(auto& it: fChannelMapProf){
105  std::ostringstream blockLabel;
106  blockLabel << "block" << it.first;
107 
108  run.put(std::move(it.second), blockLabel.str());
109  }
110 
111  fChannelMapProf.clear();
112 
113  return true;
114  }
115 
116  return false;
117  }
118 
120 
121 } // namespace
double MinW() const
std::list< std::pair< art::InputTag, int > > fInputTags
set< int >::iterator it
Sum up AttenProfilesMap objects.
virtual bool filter(art::Event &evt)
AttenProfiles for many channels.
Definition: AttenProfiles.h:89
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:149
DEFINE_ART_MODULE(TestTMapFile)
RunNumber_t run() const
Definition: Run.h:47
Definition: Run.h:31
CDPStorage service.
block
print "ROW IS " print row
Definition: elec2geo.py:31
T get(std::string const &key) const
Definition: ParameterSet.h:231
int evt
Definition: run.py:1
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void reconfigure(const fhicl::ParameterSet &pset)
SumRunsCalib(const fhicl::ParameterSet &pset)
assert(nhit_max >=nhit_nbins)
virtual bool endRun(art::Run &run)
std::map< int, std::unique_ptr< caldp::AttenProfilesMap > > fChannelMapProf
bool removeCachedProduct(Handle< PROD > &h) const
Definition: DataViewImpl.h:551
#define LOG_VERBATIM(category)
bool failedToGet() const
Definition: Handle.h:196
double MaxW() const
enum BeamMode string