BadChanList_service.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 /// \brief Interface to the run-by-run list of bad channels
3 /// \author betancourt@physics.umn.edu
4 //////////////////////////////////////////////////////////////////////////
6 
7 #include <sys/stat.h>
8 #include <sstream>
9 
10 // NOvA includes
13 #include "Geometry/Geometry.h"
15 #include "SummaryData/RunData.h"
16 
17 //#include "NovaDatabase/Table.h"
18 #ifdef NOVACMAKE
19 #include "Database/cxx/include/Table.h"
20 #else
21 #include "Database/Table.h"
22 #endif
24 #include "Simulation/Simulation.h"
25 
26 // Framework includes
32 #include "cetlib/search_path.h"
33 #include "cetlib_except/exception.h"
35 
37 
38 #include "TString.h"
39 
40 namespace chaninfo {
41 
42  //------------------------------------------------------------
44  art::ActivityRegistry &reg) :
45  fNewCosmicEffTable(false)
46  {
47  fRandomBCMap.clear();
48  fNeedNewData = true;
50  fValidityTagFarDet = "";
51  fMCRunNumber = -1;
52  fMCSubrunNumber = -1;
53  fNBadSR = -1; // unknown yet
54  fIsPerfect = false;
55  fIsBadCacheValid = false;
56  fIsBadCache.reset();
57 
58  //treat every DCM as occupied at initialization.
59  for(int i = 0; i < 12; i++) { // re-initialize every event
60  for(int j = 0; j < 14; j++) { // just keep array sized 12 x 14; for ND we just won't use it all
61  fDCMHits[i][j] = 1;
62  }
63  }
64 
66  fFlatRand = std::unique_ptr<CLHEP::RandFlat>(new CLHEP::RandFlat(rle));
67 
68  this->reconfigure(pset);
69  reg.sPreBeginRun.watch(this, &BadChanList::preBeginRun);
72  }
73 
74  //----------------------------------------------------------
75 
77  {
78  }
79 
80  //----------------------------------------------------------
82  {
83  fRun = run.run();
84  if (fMCRunNumber > 0) {
86  }
87 
88  if (fRun >= 1000000)
89  fIsPerfect=true;
90  else if (fRun < 10000) {
92  LOG_DEBUG("BadChanList") <<"Bad Channels found a run number below 10000. This should never happen and is dangerous.";
93  std::abort();
94  }
95  else
96  fIsPerfect=true;
97  }
98  else
99  fIsPerfect=false;
100 
101  fNeedNewData = true;
102 
103  LOG_DEBUG("BadChanList")
104  << "Run in BCL is: " << fRun << " " << fNeedNewData;
105 
106  fNBadSR = -1;
107 
108  }
109 
110  //----------------------------------------------------------
112  {
114  if (rh->NSubruns() == 0) {
115  LOG_DEBUG("BadChanList") << "RunHistory thinks there are no subruns in this run.";
116  if (fAbortIfNoSubrun)
117  std::abort();
118  }
119 
120  int sr = subrun.subRun();
121 
122  if (fMCRunNumber > 0) {
123  sr = fMCSubrunNumber;
124  }
125 
126  fSubRun = sr;
127 
128  fNBadSR = -1;
129 
130  // As per Teresa Lackey on Slack #nova-offline, 2019-06-10, confirmed by
131  // Jon Paley, the badness status of a channel can only change at subrun
132  // boundaries, or perhaps even less often. Therefore invalidate the cache
133  // at subrun boundaries. Since most production jobs process only one subrun,
134  // trying to invalidate less often doesn't have much impact.
135  fIsBadCacheValid = false;
136  }
137 
138  //----------------------------------------------------------
139  template<class T> void BadChanList::CountDCMHits(const std::vector<T>& digitcol)
140  {
141  for(int i = 0; i < 12; i++) { // re-initialize every event
142  for(int j = 0; j < 14; j++) { // just keep array sized 12 x 14; for ND we just won't use it all
143  fDCMHits[i][j] = 0;
144  }
145  }
146  int dib, dcm;
149  for(const T& digit: digitcol){
150  // count the number of raw digit hits in each DCM
151  dcm = daqmap->getDCM(digit.DaqChannel());
152  dib = daqmap->getDiBlock(digit.DaqChannel());
153  fDCMHits[dcm-1][dib-1]++;
154  }
155  }
156 
157  //----------------------------------------------------------
159  {
160  if(fEventCheck) { // check for dropped DCMs every event
162  event.getByLabel(fRawDigitLabel, digitcol);
163 
164  // We prefer to use the raw digits, but if they've been dropped from the
165  // file we will try the CellHits instead.
166  if(digitcol.failedToGet()){
168  event.getByLabel(fCellHitLabel, chitcol);
169  if(!chitcol.failedToGet()){
170  CountDCMHits(*chitcol);
171  }
172  }
173  else{
174  CountDCMHits(*digitcol);
175  }
176  } // end looking for dropped DCMs
177 
178  if(!fIsBadCacheValid){
179  // turn off event checking here, turn it back on when we're done
180  // building cache
181  bool fEventCheck_save = fEventCheck;
182  fEventCheck = false;
183 
185  const unsigned int nplane = geom->NPlanes();
186 
187  LOG_INFO("BadChanList") << "Initializing bad cell cache for " << nplane << " planes";
188 
189  if(nplane > FD_NUM_PLANES)
190  LOG_ERROR("BadChanList") << "Too many planes " << nplane;
191 
192  for(unsigned int p = 0; p < nplane && p < FD_NUM_PLANES; p++){
193  const unsigned int ncell = geom->Plane(p)->Ncells();
194  if(ncell > FD_NUM_CELLS)
195  LOG_ERROR("BadChanList") << p << ", too many cells: " << ncell;
196 
197  for(unsigned int c = 0; c < ncell && c < FD_NUM_CELLS; c++)
198  fIsBadCache[p*FD_NUM_CELLS + c] = IsBadUncached(p, c);
199  }
200  fIsBadCacheValid = true;
201  fEventCheck = fEventCheck_save;
202  }
203  }
204 
205  //-----------------------------------------------------------
207  {
209 
210  if (isr > rh->NSubruns()) return 0;
211 
212  if (fNeedNewData) LoadNewData();
213 
215  int detId = geom->DetId();
217 
218  if(fNBadSR >= 0) return fNBadSR;
219 
220  // Otherwise, look up the answer
221  int nbad=0;
222  int fRun_save = fRun;
223  int fSubRun_save = fSubRun;
224  fRun = rh->RunNumber();
225  fSubRun = isr;
226 
227  // turn off event checking here, turn it back on when we're done
228  // counting bad channels
229  bool fEventCheck_save = fEventCheck;
230  fEventCheck = false;
231 
232  for (int idb=0; idb<rh->NDiBlocks(); ++idb) {
233  nova::dbi::RunHistory::DiBlock dblk = rh->GetDiBlock(idb,false);
234 
235  if (!rh->IsGoodDiBlock(dblk.num)) continue;
236 
237  for (unsigned int idcm=0; idcm<dblk.dcm.size(); ++idcm) {
238  for (unsigned int ifeb=0; ifeb<dblk.dcm[idcm].feb.size(); ++ifeb) {
239  if (dblk.dcm[idcm].feb[ifeb].hasAPD) {
240  for (int ipix=0; ipix<=31; ++ipix) {
241  //for (int ipix=1; ipix<=32; ++ipix) {
242  daqchannelmap::dchan daqChan = daqmap->encodeDChan(detId,
243  dblk.num,
244  idcm+1,
245  ifeb,
246  ipix);
247  daqchannelmap::lchan logChan = daqmap->encodeLChan(daqChan);
248 
249  int plane = daqmap->getPlane(logChan);
250  int cell = daqmap->getCell(logChan);
251  if (IsBad(plane,cell)) ++nbad;
252  } // end loop over pixels
253  } // end if hasAPD
254  } // end loop over FEBs
255  } // end loop over DCMs
256  } // end loop over DiBlocks
257 
258  fEventCheck = fEventCheck_save;
259  fNBadSR = nbad;
260 
261  fRun = fRun_save;
262  fSubRun = fSubRun_save;
263 
264  return fNBadSR;
265  }
266 
267  //-----------------------------------------------------------
269  {
270  if (!fRandomBCMap.empty()) return;
271 
272  LOG_ERROR("BadChanList")<< " RANDOM BAD CHANNELS at rate "
274 
275  fLowEfficiency.clear();
276 
278  for(unsigned int plane: geom->GetPlanesByView()){
279  const unsigned int nCells = geom->Plane(plane)->Ncells();
280 
281  for(unsigned int cell = 0; cell < nCells; ++cell){
283  if(fFlatRand->fire() < fRandomBadChannelFraction){
284  fRandomBCMap.insert(chan);
285  }
286  }
287  }
288  }
289 
290  //-----------------------------------------------------------
291  void BadChanList::LoadCosmicEff(int newrun, int newsubrun)
292  {
293  fLowEfficiency.clear();
294 
296  "/ChannelInfo/CosmicEffNew.xml" :
297  "/ChannelInfo/CosmicEff.xml");
298  tblEff.SetValidityRange("detector", "ndos");
299  tblEff.SetValiditySQL(TString::Format("(beginrun<%d or (beginrun=%d and beginsubrun<=%d)) and "
300  "(endrun>%d or (endrun=%d and endsubrun>=%d))",
301  newrun, newrun, newsubrun, newrun, newrun, newsubrun).Data());
302  // }
303 
304  // Only ask for the bad channels. We won't get any "good" ones back, so
305  // they won't go in the map, which is fine.
306  tblEff.SetValidityRange("good", false);
307 
308  tblEff.SetVerbosity(100);
309  const bool ok = tblEff.Load();
310  if(!ok){
311  // No safe way to handle this
312  LOG_DEBUG("BadChanList") << "Couldn't load efficiencies channels from DB. Aborting" << std::endl;
313  std::abort();
314  }
315  int planeIdx = tblEff.GetColIndex("plane");
316  int cellIdx = tblEff.GetColIndex("cell");
317  int goodIdx = tblEff.GetColIndex("good");
318 
319  for(int i = 0; i < tblEff.NRow(); ++i){
320  int plane, cell;
321  bool good;
322  bool ok = tblEff.GetRow(i)->Col(planeIdx).Get(plane);
323  ok = ok && tblEff.GetRow(i)->Col(cellIdx).Get(cell);
324  ok = ok && tblEff.GetRow(i)->Col(goodIdx).Get(good);
325  if(!ok) std::abort();
326  geo::OfflineChan chan(plane, cell);
327  if(!good) fLowEfficiency.insert(chan);
328  }
329  }
330 
331  //-----------------------------------------------------------
333  {
334  fApplyBadChan = pset.get<int>("ApplyBadChan");
335  fMCRunNumber = pset.get<int>("MCRunNumber");
336  fMCSubrunNumber = pset.get<int>("MCSubrunNumber");
337  fNewCosmicEffTable = pset.get<bool>("NewCosmicEffTable");
338  fRandomBadChannelFraction= pset.get<float>("RandomBadChannelFraction");
339  fBadChanCSVFile = pset.get<std::string>("BadChanCSVFile");
340  fValidityTagNearDet = pset.get<std::string>("ValidityTagNearDet");
341  fValidityTagFarDet = pset.get<std::string>("ValidityTagFarDet");
342  fAbortIfNoneFound = pset.get<bool>("AbortIfNoneFound");
343  fAbortOnSmallRunNum = pset.get<bool>("AbortOnSmallRunNum");
344  fAbortIfNoSubrun = pset.get<bool>("AbortIfNoSubrun");
345  fEventCheck = pset.get<bool>("EventCheck");
346  fRawDigitLabel = pset.get<std::string>("RawDigitLabel");
347  fCellHitLabel = pset.get<std::string>("CellHitLabel");
348  fApplyFEBDropout = pset.get<bool>("ApplyFEBDropout");
349  fFEBDropoutTag = pset.get<std::string>("FEBDropoutTag");
350  fVldRunGrouping = pset.get<int>("VldRunGrouping");
351  fPedestalThresholdLow = pset.get<int>("PedestalThresholdLow");
352  fPedestalThresholdHigh = pset.get<int>("PedestalThresholdHigh");
353 
354  bool applyKBC = pset.get<bool>("ApplyKnownBadChannels");
355 
356  if (!fValidityTagNearDet.empty()) {
357  float tagNum = atof(fValidityTagNearDet.substr(1).c_str());
358  if (tagNum < 9.0) {
359  LOG_ERROR("BadChanList")<<"This version of Bad Channels requires tag >= 9.0";
360  std::abort();
361  }
362  }
363 
364  if (!fValidityTagFarDet.empty()) {
365  float tagNum = atof(fValidityTagFarDet.substr(1).c_str());
366  if (tagNum < 9.0) {
367  LOG_ERROR("BadChanList")<<"This version of Bad Channels requires tag >= 9.0";
368  std::abort();
369  }
370  }
371 
372  fKBCList.clear();
373  if (applyKBC)
374  fKBCList = pset.get<std::vector<std::string> >("KnownBadChannels");
375 
376  }
377 
378  //----------------------------------------------------------
380  {
381  if (fIsPerfect) return;
382 
384 
385  if (!fKBCList.empty()) {
386 
387  fKnownBadChannels.clear();
389 
390  int idet = geom->DetId();
391  int db, dcm, feb, detId;
392  for (auto k : fKBCList) {
393  sscanf(k.c_str(),"%d-%02d-%02d-%02d",&detId,&db,&dcm,&feb);
394  if (detId == idet) {
395  LOG_DEBUG("BadChanList")<< k << " is known to be bad, all associated channels masked off.";
396  for (int ipix=0; ipix<32; ++ipix) {
397  daqchannelmap::dchan daqChan = cmap->Map()->encodeDChan(idet,db,dcm,feb,ipix);
398  daqchannelmap::dchan logChan = cmap->Map()->encodeLChan(daqChan);
399  int plane = cmap->Map()->getPlane(logChan);
400  int cell = cmap->Map()->getCell(logChan);
401  fKnownBadChannels.push_back(geo::OfflineChan(plane,cell));
402  }
403  }
404  }
405  }
406 
407  fBadChans.clear();
408  fDropOuts.clear();
409 
410  nova::dbi::Table BCTable("/ChannelInfo/ChanRateState.xml");
411  BCTable.SetVerbosity(100);
412  BCTable.SetDetector(geom->DetId());
413  if (geom->DetId() == novadaq::cnv::kNEARDET) {
414  if (fValidityTagNearDet != "")
415  BCTable.SetTag(fValidityTagNearDet);
416  }
417  else if (geom->DetId() == novadaq::cnv::kFARDET) {
418  if (fValidityTagFarDet != "")
419  BCTable.SetTag(fValidityTagFarDet);
420  }
421 
422 
423  const int stateIdx = BCTable.GetColIndex("state");
424 
425  nova::dbi::Table FEBDOTable("/ChannelInfo/FEBDropout.xml");
426  FEBDOTable.SetVerbosity(100);
427  FEBDOTable.SetDetector(geom->DetId());
428  if (fFEBDropoutTag != "")
429  FEBDOTable.SetTag(fFEBDropoutTag);
430  const int FEBStateIdx = FEBDOTable.GetColIndex("state");
431 
432  if (!fBadChanCSVFile.empty())
433  {
434  BCTable.LoadFromCSV(fBadChanCSVFile);
435  LOG_ERROR("BadChanList") << "Read " << BCTable.NRow()
436  << " BadChannel rows from "
437  << fBadChanCSVFile;
438  }
439  else
440  {
441  if (fMCRunNumber > 0)
442  {
444  fMinVldTime = rh.RunNumber()*10000 + 1;
445  fMaxVldTime = fMinVldTime + rh.NSubruns()*100;
446  }
447  else if (geom->DetId() == novadaq::cnv::kFARDET ||
448  geom->DetId() == novadaq::cnv::kNEARDET)
449  {
452  fMinVldTime = minrun*10000 + 1;
453  fMaxVldTime = fMinVldTime - 1 + fVldRunGrouping*10000;
454  }
455 
457  BCTable.SetMinTSVld(fMinVldTime);
458  BCTable.SetMaxTSVld(fMaxVldTime);
459 
460  if (!BCTable.Load()) {
461  LOG_ERROR("BadChanList") <<"Bad Channels table failed to load data!";
462  std::abort();
463  }
464  if (BCTable.NRow() == 0) {
465  LOG_ERROR("BadChanList") << "******** WARNING: BadChanList_service found no bad channels!";
466  if (fAbortIfNoneFound) {
467  LOG_ERROR("BadChanList") << "Bad Channels table is empty, this should never happen!";
468  std::abort();
469  }
470  }
471 
472  if (fApplyFEBDropout && (geom->DetId() == novadaq::cnv::kNEARDET)) {
473  FEBDOTable.SetMinTSVld(fMinVldTime-480);
474  FEBDOTable.SetMaxTSVld(fMaxVldTime+480);
475  FEBDOTable.Load();
476  if (FEBDOTable.NRow() == 0) {
477  LOG_WARNING("BadChanList") << "******** BadChanList_service found no FEB dropout data!";
478  }
479  }
480  }
481 
482  BCTable.FillChanRowMap();
483  FEBDOTable.FillChanRowMap();
484 
487  fBadChans.resize(rh->NSubruns());
488  fDropOuts.resize(rh->NSubruns());
489 
490  for(int subrun = 0; subrun < rh->NSubruns(); ++subrun){
491  const time_t evtTime = fRun*10000 + subrun*100 + 1;
492 
493  for(unsigned int plane = 0; plane < geom->NPlanes(); ++plane){
494  const geo::PlaneGeo* geoplane = geom->Plane(plane);
495  for(unsigned int cell = 0; cell < geoplane->Ncells(); ++cell){
497 
498  // get validity row for this timestamp
499  nova::dbi::Row* row = BCTable.GetVldRow(chan.ToDBValidityChan(),
500  evtTime);
501 
502  if(row){
503  // there is an entry for this timestamp (expected behavior), so
504  // make sure that the state is "ok" (==0)
505  int state;
506  const bool ok = row->Col(stateIdx).Get(state);
507  if(!ok) std::abort();
508  if(state != 0) {
510  }
511  } // end if row
512 
513  // Now the drop-out table
514 
515  // TODO - one could loop over all the FEBs more efficiently than
516  // this, but it doesn't really matter since this is once per run.
517 
518  daqchannelmap::lchan logChan = daqcmap->encodeLChan(geom->DetId(),
519  plane, cell);
520  daqchannelmap::dchan daqChan = daqcmap->encodeDChan(logChan);
521 
522  const int db = daqcmap->getDiBlock(daqChan);
523  const int dcm = daqcmap->getDCM(daqChan);
524  const int feb = daqcmap->getFEB(daqChan);
525 
526  const int tchan = db*1000+(dcm-1)*64+feb;
527 
528  row = FEBDOTable.GetVldRow(tchan, evtTime);
529 
530  if(row){
531  int state;
532  const bool ok = row->Col(FEBStateIdx).Get(state);
533  if(!ok) std::abort();
534  // a state of "1" means the FEB is live at this point
535  if(state != 1) fDropOuts[subrun].insert(tchan);
536  }
537  } // end for cell
538  } // end for plane
539  } // end for subrun
540 
541  auto info = LOG_INFO("BadChanList");
542  for(int sr = 0; sr < rh->NSubruns(); ++sr){
543  info << "Subrun " << sr << ": "
544  << fBadChans[sr].size() << " bad channels, "
545  << fDropOuts[sr].size() << " DCM dropouts.\n";
546  }
547 
548  fNeedNewData = false;
549  }
550 
551  //----------------------------------------------------------
553  {
554  if(InDroppedDCM(plane, cell)) return true;
555 
556  return fIsBadCache[plane*FD_NUM_CELLS + cell];
557  }
558 
559  //----------------------------------------------------------
561  {
562  if(!fEventCheck) return false;
563 
566  uint32_t dchan = daqmap->encodeDChan(daqmap->encodeLChan(geom->DetId(), plane, cell));
567  if(fDCMHits[daqmap->getDCM(dchan)-1][daqmap->getDiBlock(dchan)-1]==0) {
568  //***
569  LOG_DEBUG("BadChanList") << "Dropped DCM";
570  //***
571  return true;
572  }
573  return false;
574  }
575 
576  //----------------------------------------------------------
578  {
579  if(!fApplyBadChan) return false;
580  if (fIsPerfect) return false;
581 
582  geo::OfflineChan chan(plane,cell);
583 
584  for (auto kbc : fKnownBadChannels) {
585  if (kbc == chan) {
586  //***
587  LOG_DEBUG("BadChanList") << "BadChanList_service: known bad channel!";
588  //***
589  return true;
590  }
591  }
592 
595  return fRandomBCMap.count(chan);
596  }
597 
598  if (fNeedNewData) LoadNewData();
599 
602 
603  const int sr = fSubRun%rh->NSubruns();
604  const time_t evtTime = fRun*10000 + sr*100 + 1;
605 
606  // check if event time within validity range, i.e. sane
607  if ( fBadChanCSVFile.empty() && (evtTime < fMinVldTime || evtTime > fMaxVldTime)){
608  throw cet::exception("BadChanList")
609  << "Event time is outside the validity range of the database request. "
610  << fMinVldTime << " " << evtTime << " " << fMaxVldTime
611  << " Database request does not contain complete information, "
612  << "which could lead to unpredictable behavior.";
613  }
614 
615  if(InDroppedDCM(plane, cell)) return true;
616 
617  // check with RH whether this channel was instrumented, part of the partition, or masked
618  if (!rh->HasAPD(chan)) {
619  //***
620  LOG_DEBUG("BadChanList") << "Mmissing APD";
621  //***
622  return true;
623  }
624  // for now, just deal with dB tables for the FarDet and NearDet
625  if (geom->DetId() == novadaq::cnv::kFARDET ||
626  geom->DetId() == novadaq::cnv::kNEARDET) {
627 
628  assert((unsigned int)sr < fBadChans.size());
629  if(fBadChans[sr].count(chan)) return true;
630 
631  if (fApplyFEBDropout) {
633  daqchannelmap::lchan logChan = daqcmap->encodeLChan(geom->DetId(),plane,cell);
634  daqchannelmap::dchan daqChan = daqcmap->encodeDChan(logChan);
635 
636  int db = daqcmap->getDiBlock(daqChan);
637  int dcm = daqcmap->getDCM(daqChan);
638  int feb = daqcmap->getFEB(daqChan);
639 
640  int tchan = db*1000+(dcm-1)*64+feb;
641 
642  assert((unsigned int)sr < fDropOuts.size());
643  if(fDropOuts[sr].count(tchan)) return true;
644  }
645  }
646 
647  // check if we should mask off channels with too low or too high of a pedestal
648  if (fPedestalThresholdLow > 0) {
649  bool pedok;
650  int ped = rh->GetPedestal(chan,pedok);
651  if (pedok) {
652  if (ped < fPedestalThresholdLow ||
654  return true;
655  }
656  else {
657  LOG_WARNING("BadChanList") << "******** Failed to get a pedestal for found channel (" << plane << "," << cell << ")";
658  }
659  }
660  // If we can't find anything wrong with it then it must not be bad
661  return false;
662  }
663 
664  //----------------------------------------------------------
666  {
667  if(!fApplyBadChan) return false;
668 
669  const geo::OfflineChan chan(plane, cell);
670  return fLowEfficiency.count(chan);
671  }
672 
673  //--------------------------------------------------------
674 
676  {
678  int ch;
679  std::vector< art::Ptr<rawdata::RawDigit> > good;
680  for(unsigned int i=0; i<rd.size(); ++i) {
681  int plane = cmap->GetPlane(rd[i].get());
682  int cell = cmap->GetCell(rd[i].get());
683  if(!IsBad(plane,cell)) good.push_back(rd[i]);
684  }
685  rd.swap(good);
686  ch=rd.size();
687  return ch;
688  }
689 
690  //--------------------------------------------------------
691 
693  {
695  int ch;
697  for(unsigned int i=0; i<rd.size(); ++i) {
698  int plane = cmap->GetPlane(rd[i].get());
699  int cell = cmap->GetCell(rd[i].get());
700  if(!IsBad(plane,cell)) good.push_back(rd[i]);
701  }
702  rd.swap(good);
703  ch=rd.size();
704  return ch;
705  }
706 
707  //--------------------------------------------------------
708 
709  int BadChanList::Apply( std::vector<const rawdata::RawDigit*>& rd)
710  {
712  int ch;
713  std::vector<const rawdata::RawDigit*> good;
714  for(unsigned int i=0; i<rd.size(); ++i) {
715  int plane = cmap->GetPlane(rd[i]);
716  int cell = cmap->GetCell(rd[i]);
717  if(!IsBad(plane,cell)) good.push_back(rd[i]);
718  }
719  rd.swap(good);
720  ch=rd.size();
721  return ch;
722  }
723 
724 
725 
727 
728 }
729 ////////////////////////////////////////////////////////////////////////
void SetTag(std::string s)
Definition: Table.h:290
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const XML_Char XML_Encoding * info
Definition: expat.h:530
DEFINE_ART_SERVICE(BadChanList)
int LoadFromCSV(std::string fname, int offset=0, int limit=-1)
Definition: Table.cpp:1703
int NDiBlocks()
gives number of active diblocks only, may be less than 14
Definition: RunHistory.h:394
std::vector< std::string > fKBCList
Definition: BadChanList.h:137
void preBeginEvent(art::Event const &evt)
Column & Col(int i)
Find index of column with name. Suitable for passing to Col.
Definition: Row.h:63
std::string fValidityTagNearDet
Definition: BadChanList.h:127
int fDCMHits[12][14]
count hits in each DCM each event to look for dropped DCMs
Definition: BadChanList.h:135
std::string fBadChanCSVFile
Definition: BadChanList.h:103
TH2 * rh
Definition: drawXsec.C:5
const size_t FD_NUM_CELLS
Definition: BadChanList.h:34
SubRunNumber_t subRun() const
Definition: SubRun.h:44
Row *const GetRow(int i)
Definition: Table.cpp:492
void FillChanRowMap()
Definition: Table.cpp:2355
void swap(PtrVector &other)
Definition: PtrVector.h:522
std::unordered_set< geo::OfflineChan > fRandomBCMap
random bad channel map
Definition: BadChanList.h:101
const char * p
Definition: xmltok.h:285
DiBlock GetDiBlock(int i, bool loadAll=true)
get ith diblock is RH list (which only includes diblocks with activity), starting with i=0...
unsigned int Ncells() const
Number of cells in this plane.
Definition: PlaneGeo.h:43
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
GlobalSignal< detail::SignalResponseType::LIFO, void(SubRun const &)> sPostBeginSubRun
bool SetValidityRange(std::string cname, T start, T end)
Definition: Table.h:220
const PlaneGeo * Plane(unsigned int i) const
RunNumber_t run() const
Definition: Run.h:47
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
bool Get(T &val) const
Definition: Column.h:85
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
void CountDCMHits(const std::vector< T > &digitcol)
Definition: Run.h:31
bool fAbortIfNoneFound
Option to throw an exception if no channel rate state rows are returned from dB.
Definition: BadChanList.h:90
void SetValiditySQL(std::string cmd)
Definition: Table.h:206
std::string fValidityTagFarDet
Definition: BadChanList.h:128
std::vector< std::unordered_set< int > > fDropOuts
[subrun][tchan]
Definition: BadChanList.h:116
int ToDBValidityChan() const
Definition: OfflineChan.cxx:19
float fRandomBadChannelFraction
If >0, ignore DB and set this fraction bad at random.
Definition: BadChanList.h:112
BadChanList(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
Far Detector at Ash River, MN.
std::vector< geo::OfflineChan > fKnownBadChannels
Definition: BadChanList.h:138
int GetColIndex(std::string cname)
Definition: Table.cpp:952
std::bitset< FD_NUM_PLANES *FD_NUM_CELLS > fIsBadCache
Definition: BadChanList.h:145
bool fEventCheck
do we check each event for dropped DCMs?
Definition: BadChanList.h:105
void SetDataTypeMask(int mask)
Definition: Table.h:74
int GetPedestal(const geo::OfflineChan &, bool &)
Definition: RunHistory.cxx:632
bool fNewCosmicEffTable
Use new-style table?
Definition: BadChanList.h:110
static DAQChannelMap * getInstance(int detID)
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
void LoadCosmicEff(int newrun, int newsubrun)
void SetMinTSVld(time_t t)
Definition: Table.h:284
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::unordered_set< geo::OfflineChan > fLowEfficiency
set of low eff channels
Definition: BadChanList.h:100
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
std::string fRawDigitLabel
what is the name of the raw digits ART object
Definition: BadChanList.h:107
Geometry information for a single readout plane.
Definition: PlaneGeo.h:36
time_t fMaxVldTime
Maximum time used in database request.
Definition: BadChanList.h:123
bool SetDetector(std::string det)
Definition: Table.cpp:839
Near Detector in the NuMI cavern.
unsigned short GetPlane(const rawdata::RawDigit *dig)
Definition: CMap.cxx:285
caf::StandardRecord * sr
const double j
Definition: BetheBloch.cxx:29
void postBeginSubRun(art::SubRun const &subrun)
bool InDroppedDCM(int plane, int cell)
const size_t FD_NUM_PLANES
Definition: BadChanList.h:33
std::string fCellHitLabel
Definition: BadChanList.h:108
Definition: run.py:1
size_type size() const
Definition: PtrVector.h:308
int fMCRunNumber
Run number for the MC.
Definition: BadChanList.h:80
#define LOG_WARNING(category)
bool IsGoodDiBlock(int idb, int subrun=-1)
nova::dbi::Row * GetVldRow(unsigned long long channel, time_t t)
Definition: Table.cpp:2399
unsigned int GetRandomNumberSeed()
Definition: Simulation.cxx:13
std::vector< DCM > dcm
Definition: RunHistory.h:311
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void reconfigure(fhicl::ParameterSet p)
std::string fFEBDropoutTag
Definition: BadChanList.h:129
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
A (plane, cell) pair.
Definition: OfflineChan.h:17
void SetMaxTSVld(time_t t)
Definition: Table.h:285
bool HasAPD(const geo::OfflineChan &)
basic check for if a channel should be live. Used by BadChannels. Checks if channel has instrumented ...
time_t fMinVldTime
Minimum time used in database request.
Definition: BadChanList.h:121
const std::set< unsigned int > & GetPlanesByView(View_t v=kXorY) const
void geom(int which=0)
Definition: geom.C:163
int Apply(art::PtrVector< rawdata::RawDigit > &rd)
plane_t getPlane(lchan logicalchan) const
Decode the plane number from an lchan.
assert(nhit_max >=nhit_nbins)
Interface to the run-by-run list of bad channels.
Definition: BadChanList.h:31
unsigned short GetCell(const rawdata::RawDigit *dig)
Definition: CMap.cxx:327
int fMCSubrunNumber
Subrun number for the MC.
Definition: BadChanList.h:81
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
int fApplyBadChan
Option to activate the bad channels.
Definition: BadChanList.h:79
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
double T
Definition: Xdiff_gwt.C:5
void preBeginRun(art::Run const &run)
unsigned int NPlanes() const
#define LOG_INFO(stream)
Definition: Messenger.h:144
void SetVerbosity(int i)
Definition: Table.h:98
uint32_t dchan
< DAQ Channel Map Package
bool IsBad(int plane, int cell)
std::unique_ptr< CLHEP::RandFlat > fFlatRand
Definition: BadChanList.h:133
int NRow()
Definition: Table.h:101
std::vector< std::unordered_set< geo::OfflineChan > > fBadChans
Vector index is the subrun number, set contains all the bad channels.
Definition: BadChanList.h:115
Definition: fwd.h:28
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
int RunNumber() const
Definition: RunHistory.h:374
#define LOG_ERROR(stream)
Definition: Messenger.h:129
Encapsulate the geometry of one entire detector (near, far, ndos)
bool failedToGet() const
Definition: Handle.h:196
bool IsLowEfficiency(int plane, int cell)
bool IsBadUncached(int plane, int cell)
feb_t getFEB(dchan daqchan) const
Decode the feb id from a dchan.