RunHistory_service.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 /// \brief Simple service to provide a RunHistory configured to the right run
3 /// \author Christopher Backhouse - bckhouse@caltech.edu
4 //////////////////////////////////////////////////////////////////////////
5 
6 // NOvA includes
8 #ifdef NOVACMAKE
9 #include "Database/cxx/include/Table.h"
10 #else
11 #include "Database/Table.h"
12 #endif
13 
15 
16 // Framework includes
20 
21 // ROOT includes
22 #include "TTimeStamp.h"
23 
24 namespace nova
25 {
26 namespace dbi
27 {
28 
29  //------------------------------------------------------------
32  {
33  reconfigure(pset);
36  }
37 
38  //----------------------------------------------------------
39 
41  {
42  }
43 
44  //-----------------------------------------------------------
46  {
47  fCalHitLabel = pset.get< std::string >("CalHitLabel");
48  fFakeRunNumber = pset.get< int >("FakeRunNumber", 0);
49  fTimeQueries = pset.get< bool >("TimeQueries", false);
50  fUseMasking = pset.get< bool >("UseMasking", false);
51  fAnalysisDiBlockMasking = pset.get< bool >("AnalysisDiBlockMasking", false);
52  fCustomMasking = pset.get< bool >("CustomMasking", false);
53  fCustomMask = pset.get< std::vector<int> >("CustomMask");
54  fAbort = pset.get< bool >("AbortIfNoMask", false);
55  fAbortIfMissingRunInDB = pset.get< bool >("AbortIfMissingRunInDB", true);
56  this->_getDiBlockMaskFromCondb = pset.get< bool >("GetDiBlockMaskFromCondb", false);
57  this->_dbMaskTag = pset.get< std::string >("DiBlockMaskTag");
58  this->SetGainSettingTag(pset.get< std::string >("DetGainTag"));
59  this->SetVerbosity(pset.get< int >("Verbosity"));
60  this->SetNDRHCRunStart(pset.get<std::vector<int> >("NDRHCRunStart"));
61  this->SetNDRHCRunStop(pset.get<std::vector<int> >("NDRHCRunStop"));
62  this->SetFDRHCRunStart(pset.get<std::vector<int> >("FDRHCRunStart"));
63  this->SetFDRHCRunStop(pset.get<std::vector<int> >("FDRHCRunStop"));
64 
65  }
66 
67  //----------------------------------------------------------
69  {
72  int runNumber = (fFakeRunNumber == 0) ? run.run() : fFakeRunNumber;
73 
74  RunHistory::SetRunNumber(runNumber);
75 
81  this->SetAbort(fAbort);
83  this->SetCurrentSubrun(0);
84 
85  // determine whether we are dealing with MC, data, or a mixture of the two
86  // for now just test on the date of the file. MC has a timestamp before 2010
87  art::Timestamp ts = run.beginTime();
88 
89  // make it into a TTimeStamp
90  TTimeStamp tts(ts.timeHigh(), ts.timeLow());
91 
92  // Get the year of the timestamp from YYYYMMDD format
93  uint32_t year = tts.GetDate()/10000;
94 
96  if(year < 2010) this->SetDataType(nova::dbi::kMCOnly);
98 
99  if (runNumber > 1000000 || runNumber < 10000) {
101  this->SetIfAnyMasking(false);
102  }
103 
104  // get detector diblock masks
105 
107  this->SetIfAnyMasking(false);
108  }
109 
110  if (novadaq::cnv::DetInfo::GetId(RunHistory::Detector()) == novadaq::cnv::kFARDET) { // only worry about masking for FD
111  std::vector<bool> cmask; // let people put 1s and 0s into fcl instead of trues and falses
112 
113  for(unsigned int i = 0; i < 14; i++) {
114  if(fCustomMask[i] == 1) cmask.push_back(true);
115  else cmask.push_back(false);
116  }
117  this->SetCustomMask(cmask);
118 
120  run.getByLabel(fCalHitLabel,mask);
121 
122  if(mask.failedToGet()) {
123  if(fCustomMasking) {
124  LOG_WARNING("RunHistoryService") << "RunHistory: No mask in file. Custom mask requested." << std::endl;
126  }
127  else if(runNumber >= 1000000 || runNumber < 10000) { // clear MC that can't access DB
128  LOG_INFO("RunHistoryService") << __PRETTY_FUNCTION__
129  << ": this looks like ideal conditions MC. No mask applied: "
132  }
133  else {
134  if(fAbort) {
135  if (!(RunHistory::GoodDiBlockMask()!=(1<<16)-1))
136  // running in mode that absolutely requires a mask, and there was not one
137  std::abort();
138  }
139 
141  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__
142  << ": did not find mask in file, using current fcl settings of: detector fully masked off! "
144  else
145  LOG_DEBUG("RunHistoryService") << __PRETTY_FUNCTION__
146  << ": did not find mask in file, using current fcl settings of: "
148  << std::endl;
149  }
150  }
151  else { // got mask from file
152  // running in mode that absolutely requires a mask, and there was not one
153  if(fAbort && runNumber < 1000000 && runNumber > 10000) {if(!(*mask!= (1<<16)-1)) std::abort();}
154 
156  if(*mask==0) {
157  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__
158  << ": found mask in file: detector fully masked off! "
160  << std::endl;
161  }
162  else if(*mask==(1<<16)-1) {
163  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__
164  << ": no run was found in good runs DB when this file was processed, "
165  << "so we assume perfect. LiveGeometry should still catch any empty "
166  << "regions, but check badboxes in the event display to be sure."
167  << std::endl;
168  }
169  else if(*mask==(1<<17)-1) {
170  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__
171  << ": masking was turned off when file was processed, so apply no mask. "
173  << std::endl;
174  }
175  else {
176  LOG_INFO("RunHistoryService") << __PRETTY_FUNCTION__
177  << ": found mask in file: "
179  }
180  }
181  }
182 
183  return;
184  }
185 
186  //----------------------------------------------------------
188  {
189  if (novadaq::cnv::DetInfo::GetId(RunHistory::Detector()) != novadaq::cnv::kFARDET) // only worry about masking for FD
190  return;
191 
192  // don't do anything if we're not using subrun-by-subrun diblock masks
193  if (!this->_getDiBlockMaskFromCondb) return;
194 
195  int isr = subrun.subRun();
196  int runNumber = this->RunNumber();
197 
198  LOG_DEBUG("RunHistory")
199  << "runNumber = " << runNumber;
200 
201  // use a realistic subrun number for ideal conditions
202  if (runNumber >= 1000000) {
203  isr = isr%64;
204  }
205 
206  this->SetCurrentSubrun(isr);
207 
209  subrun.getByLabel(fCalHitLabel,mask);
210 
211  if(mask.failedToGet()) {
212  if(fCustomMasking) {
213  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__
214  << ": No mask in file. Custom mask requested." << std::endl;
216  }
217  else if(runNumber >= 1000000 || runNumber < 10000) { // clear MC that can't access DB
218  LOG_INFO("RunHistoryService") << __PRETTY_FUNCTION__ << ": this looks like ideal conditions MC. No mask applied: "
221  }
222  else {
223  // running in mode that absolutely requires a mask, and there was not one
224  if(fAbort) {
225  if (!(RunHistory::GoodDiBlockMask()!=(1<<16)-1)) {
226  // running in mode that absolutely requires a mask, and there was not one
227  LOG_ERROR("RunHistoryService") << __PRETTY_FUNCTION__ << ": failed to get subrun diblock mask, aborting." << std::endl;
228  std::abort();
229  }
230  else
231  LOG_DEBUG("RunHistoryService") << __PRETTY_FUNCTION__ << ": did not find subrun mask in file, using mask: "
233  }
234  }
235  }
236  else { // got mask from file
237 
238  if(fAbort && runNumber < 1000000 && runNumber > 10000) {
239  if (!(*mask!= (1<<16)-1))
240  // running in mode that absolutely requires a mask, and there was not one
241  std::abort();
242  }
243 
245  if(*mask==0) {
246  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__ << ": found subrun diblock mask in file: detector fully masked off! "
248  }
249  else if(*mask==(1<<16)-1) {
250  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__ << ": no run was found in good runs DB when this file was processed, "
251  << "so we assume perfect. LiveGeometry should still catch any empty regions, but check badboxes in "
252  << "the event display to be sure." << std::endl;
253  }
254  else if(*mask==(1<<17)-1) {
255  LOG_WARNING("RunHistoryService") << __PRETTY_FUNCTION__ << ": masking was turned off when file was processed, so apply no mask. "
257  }
258  else {
259  LOG_INFO("RunHistoryService") << __PRETTY_FUNCTION__ << ": subrun diblock found mask in file: "
261  }
262  }
263 
264  return;
265  }
266 
268 
269 }
270 }
271 ////////////////////////////////////////////////////////////////////////
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
novadaq::cnv::DetId DetId() const
What detector are we in?
void SetTimeQueries(bool f)
Definition: RunHistory.h:361
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:30
std::vector< int > fCustomMask
void SetAbort(bool abort)
Definition: RunHistory.h:449
SubRunNumber_t subRun() const
Definition: SubRun.h:44
void SetDetector(novadaq::cnv::DetId det)
Definition: RunHistory.cxx:325
#define DEFINE_ART_SERVICE(svc)
Definition: ServiceMacros.h:93
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:35
void SetIfCustomMasking(bool f)
set from fcl: do we want to use a custom mask?
Definition: RunHistory.h:365
void preBeginSubrun(const art::SubRun &subrun)
RunNumber_t run() const
Definition: Run.h:47
void preBeginRun(const art::Run &run)
void SetRunNumber(int run)
Definition: RunHistory.cxx:317
Definition: Run.h:31
void SetAbortIfMissingRunInDB(bool abort)
Definition: RunHistory.h:450
Far Detector at Ash River, MN.
std::string DiBlockMaskToString(const int mask) const
T get(std::string const &key) const
Definition: ParameterSet.h:231
void SetDataType(nova::dbi::DataType dt)
Definition: RunHistory.h:448
Near Detector in the NuMI cavern.
void SetGainSettingTag(std::string tag)
Definition: RunHistory.h:473
void SetCustomMask(std::vector< bool > f)
set from fcl: what is our custom mask?
Definition: RunHistory.h:366
void SetNDRHCRunStart(std::vector< int > r)
Definition: RunHistory.h:356
void SetCurrentSubrun(int isr)
Definition: RunHistory.h:481
Hold drift constants from current run.
Definition: DriftCache.h:17
A very simple service to remember what detector we&#39;re working in.
void SetNDRHCRunStop(std::vector< int > r)
Definition: RunHistory.h:357
Definition: run.py:1
#define LOG_WARNING(category)
void SetSubrunDiBlockMask(int isr, int m)
Definition: RunHistory.h:370
static int GetId(std::string name)
void SetTimeParsing(bool f)
Definition: RunHistory.h:362
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
RunHistoryService(const fhicl::ParameterSet &pset, art::ActivityRegistry &reg)
void SetFDRHCRunStop(std::vector< int > r)
Definition: RunHistory.h:359
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Simple service to provide a RunHistory configured to the right run.
void reconfigure(const fhicl::ParameterSet &pset)
GlobalSignal< detail::SignalResponseType::FIFO, void(SubRun const &)> sPreBeginSubRun
void SetVerbosity(int i)
Definition: RunHistory.h:478
Timestamp const & beginTime() const
Definition: Run.h:52
void SetGoodDiBlockMask(int newmask)
Definition: RunHistory.h:408
#define LOG_INFO(stream)
Definition: Messenger.h:144
int GoodDiBlockMask(int subrun=-1, bool reload=false)
void SetFDRHCRunStart(std::vector< int > r)
Definition: RunHistory.h:358
void SetAnalysisDiBlockMasking(bool f)
set from fcl: do we want to use the analysis rules when we mask (not for custom masking)?
Definition: RunHistory.h:364
int RunNumber() const
Definition: RunHistory.h:374
#define LOG_ERROR(stream)
Definition: Messenger.h:129
bool failedToGet() const
Definition: Handle.h:196
std::string Detector() const
Definition: RunHistory.h:376
void SetIfAnyMasking(bool f)
set from fcl: do we want to use any masking at all? If no, other masking options irrelevant ...
Definition: RunHistory.h:363
std::string _dbMaskTag
Definition: RunHistory.h:488
static constexpr Double_t year
Definition: Munits.h:185
enum BeamMode string