19 #include "Database/cxx/include/Table.h" 33 #include "cetlib_except/exception.h" 45 fNewCosmicEffTable(false)
59 for(
int i = 0;
i < 12;
i++) {
60 for(
int j = 0;
j < 14;
j++) {
90 else if (
fRun < 10000) {
92 LOG_DEBUG(
"BadChanList") <<
"Bad Channels found a run number below 10000. This should never happen and is dangerous.";
115 LOG_DEBUG(
"BadChanList") <<
"RunHistory thinks there are no subruns in this run.";
141 for(
int i = 0;
i < 12;
i++) {
142 for(
int j = 0;
j < 14;
j++) {
149 for(
const T& digit: digitcol){
151 dcm = daqmap->
getDCM(digit.DaqChannel());
185 const unsigned int nplane = geom->
NPlanes();
187 LOG_INFO(
"BadChanList") <<
"Initializing bad cell cache for " << nplane <<
" planes";
190 LOG_ERROR(
"BadChanList") <<
"Too many planes " << nplane;
195 LOG_ERROR(
"BadChanList") <<
p <<
", too many cells: " << ncell;
222 int fRun_save =
fRun;
232 for (
int idb=0; idb<rh->
NDiBlocks(); ++idb) {
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) {
251 if (
IsBad(plane,cell)) ++nbad;
272 LOG_ERROR(
"BadChanList")<<
" RANDOM BAD CHANNELS at rate " 296 "/ChannelInfo/CosmicEffNew.xml" :
297 "/ChannelInfo/CosmicEff.xml");
300 "(endrun>%d or (endrun=%d and endsubrun>=%d))",
301 newrun, newrun, newsubrun, newrun, newrun, newsubrun).Data());
309 const bool ok = tblEff.
Load();
312 LOG_DEBUG(
"BadChanList") <<
"Couldn't load efficiencies channels from DB. Aborting" <<
std::endl;
319 for(
int i = 0;
i < tblEff.
NRow(); ++
i){
325 if(!ok) std::abort();
354 bool applyKBC = pset.
get<
bool>(
"ApplyKnownBadChannels");
356 if (!fValidityTagNearDet.empty()) {
357 float tagNum = atof(fValidityTagNearDet.substr(1).c_str());
359 LOG_ERROR(
"BadChanList")<<
"This version of Bad Channels requires tag >= 9.0";
364 if (!fValidityTagFarDet.empty()) {
365 float tagNum = atof(fValidityTagFarDet.substr(1).c_str());
367 LOG_ERROR(
"BadChanList")<<
"This version of Bad Channels requires tag >= 9.0";
374 fKBCList = pset.
get<std::vector<std::string> >(
"KnownBadChannels");
390 int idet = geom->
DetId();
395 LOG_DEBUG(
"BadChanList")<< k <<
" is known to be bad, all associated channels masked off.";
396 for (
int ipix=0; ipix<32; ++ipix) {
430 const int FEBStateIdx = FEBDOTable.
GetColIndex(
"state");
436 <<
" BadChannel rows from " 460 if (!BCTable.
Load()) {
461 LOG_ERROR(
"BadChanList") <<
"Bad Channels table failed to load data!";
464 if (BCTable.
NRow() == 0) {
465 LOG_ERROR(
"BadChanList") <<
"******** WARNING: BadChanList_service found no bad channels!";
467 LOG_ERROR(
"BadChanList") <<
"Bad Channels table is empty, this should never happen!";
476 if (FEBDOTable.
NRow() == 0) {
477 LOG_WARNING(
"BadChanList") <<
"******** BadChanList_service found no FEB dropout data!";
491 const time_t evtTime =
fRun*10000 +
subrun*100 + 1;
506 const bool ok = row->
Col(stateIdx).
Get(state);
507 if(!ok) std::abort();
523 const int dcm = daqcmap->
getDCM(daqChan);
524 const int feb = daqcmap->
getFEB(daqChan);
526 const int tchan = db*1000+(dcm-1)*64+feb;
528 row = FEBDOTable.
GetVldRow(tchan, evtTime);
532 const bool ok = row->Col(FEBStateIdx).Get(state);
533 if(!ok) std::abort();
543 info <<
"Subrun " <<
sr <<
": " 569 LOG_DEBUG(
"BadChanList") <<
"Dropped DCM";
587 LOG_DEBUG(
"BadChanList") <<
"BadChanList_service: known bad channel!";
604 const time_t evtTime =
fRun*10000 + sr*100 + 1;
609 <<
"Event time is outside the validity range of the database request. " 611 <<
" Database request does not contain complete information, " 612 <<
"which could lead to unpredictable behavior.";
620 LOG_DEBUG(
"BadChanList") <<
"Mmissing APD";
640 int tchan = db*1000+(dcm-1)*64+feb;
657 LOG_WARNING(
"BadChanList") <<
"******** Failed to get a pedestal for found channel (" << plane <<
"," << cell <<
")";
679 std::vector< art::Ptr<rawdata::RawDigit> >
good;
680 for(
unsigned int i=0;
i<rd.size(); ++
i) {
683 if(!
IsBad(plane,cell)) good.push_back(rd[
i]);
697 for(
unsigned int i=0;
i<rd.
size(); ++
i) {
713 std::vector<const rawdata::RawDigit*>
good;
714 for(
unsigned int i=0;
i<rd.size(); ++
i) {
717 if(!
IsBad(plane,cell)) good.push_back(rd[i]);
int fPedestalThresholdHigh
void SetTag(std::string s)
#define LOG_DEBUG(stream)
const XML_Char XML_Encoding * info
DEFINE_ART_SERVICE(BadChanList)
int LoadFromCSV(std::string fname, int offset=0, int limit=-1)
int NDiBlocks()
gives number of active diblocks only, may be less than 14
std::vector< std::string > fKBCList
void preBeginEvent(art::Event const &evt)
Column & Col(int i)
Find index of column with name. Suitable for passing to Col.
std::string fValidityTagNearDet
int fDCMHits[12][14]
count hits in each DCM each event to look for dropped DCMs
std::string fBadChanCSVFile
void SetRandomBadChannels()
const size_t FD_NUM_CELLS
SubRunNumber_t subRun() const
void swap(PtrVector &other)
std::unordered_set< geo::OfflineChan > fRandomBCMap
random bad channel map
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.
const daqchannelmap::DAQChannelMap * Map() const
::xsd::cxx::tree::exception< char > exception
GlobalSignal< detail::SignalResponseType::LIFO, void(SubRun const &)> sPostBeginSubRun
bool SetValidityRange(std::string cname, T start, T end)
const PlaneGeo * Plane(unsigned int i) const
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
void CountDCMHits(const std::vector< T > &digitcol)
bool fAbortIfNoneFound
Option to throw an exception if no channel rate state rows are returned from dB.
void SetValiditySQL(std::string cmd)
std::string fValidityTagFarDet
std::vector< std::unordered_set< int > > fDropOuts
[subrun][tchan]
int ToDBValidityChan() const
float fRandomBadChannelFraction
If >0, ignore DB and set this fraction bad at random.
BadChanList(fhicl::ParameterSet const &pset, art::ActivityRegistry ®)
Far Detector at Ash River, MN.
std::vector< geo::OfflineChan > fKnownBadChannels
int GetColIndex(std::string cname)
std::bitset< FD_NUM_PLANES *FD_NUM_CELLS > fIsBadCache
bool fEventCheck
do we check each event for dropped DCMs?
void SetDataTypeMask(int mask)
int GetPedestal(const geo::OfflineChan &, bool &)
bool fNewCosmicEffTable
Use new-style table?
static DAQChannelMap * getInstance(int detID)
void push_back(Ptr< U > const &p)
void LoadCosmicEff(int newrun, int newsubrun)
void SetMinTSVld(time_t t)
T get(std::string const &key) const
std::unordered_set< geo::OfflineChan > fLowEfficiency
set of low eff channels
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
std::string fRawDigitLabel
what is the name of the raw digits ART object
Geometry information for a single readout plane.
time_t fMaxVldTime
Maximum time used in database request.
bool SetDetector(std::string det)
Near Detector in the NuMI cavern.
unsigned short GetPlane(const rawdata::RawDigit *dig)
void postBeginSubRun(art::SubRun const &subrun)
bool InDroppedDCM(int plane, int cell)
const size_t FD_NUM_PLANES
std::string fCellHitLabel
int fMCRunNumber
Run number for the MC.
#define LOG_WARNING(category)
bool IsGoodDiBlock(int idb, int subrun=-1)
int fPedestalThresholdLow
nova::dbi::Row * GetVldRow(unsigned long long channel, time_t t)
unsigned int GetRandomNumberSeed()
GlobalSignal< detail::SignalResponseType::FIFO, void(Run const &)> sPreBeginRun
void reconfigure(fhicl::ParameterSet p)
std::string fFEBDropoutTag
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &)> sPreProcessEvent
void SetMaxTSVld(time_t t)
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.
const std::set< unsigned int > & GetPlanesByView(View_t v=kXorY) const
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.
unsigned short GetCell(const rawdata::RawDigit *dig)
int fMCSubrunNumber
Subrun number for the MC.
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
int fApplyBadChan
Option to activate the bad channels.
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
void preBeginRun(art::Run const &run)
unsigned int NPlanes() const
uint32_t dchan
< DAQ Channel Map Package
bool IsBad(int plane, int cell)
std::unique_ptr< CLHEP::RandFlat > fFlatRand
std::vector< std::unordered_set< geo::OfflineChan > > fBadChans
Vector index is the subrun number, set contains all the bad channels.
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
#define LOG_ERROR(stream)
Encapsulate the geometry of one entire detector (near, far, ndos)
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.