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