AlgFilterDigitList Class Reference

#include <AlgFilterDigitList.h>

Inheritance diagram for AlgFilterDigitList:
AlgBase

List of all members.

Public Member Functions

 AlgFilterDigitList ()
virtual ~AlgFilterDigitList ()
virtual void RunAlg (AlgConfig &ac, CandHandle &ch, CandContext &cx)
virtual void Trace (const char *c) const

Private Member Functions

void MakeBadChannelMap (Detector::Detector_t det)
FilterBadChannelMapMakeBadChannelMapDB (const VldContext &vc)

Private Attributes

std::string fBadChannelFile
TFolder * fTFolder
 path and file holding bad channel info

Detailed Description

Definition at line 23 of file AlgFilterDigitList.h.


Constructor & Destructor Documentation

AlgFilterDigitList::AlgFilterDigitList (  ) 

Definition at line 58 of file AlgFilterDigitList.cxx.

00058                                        :
00059   fTFolder(0)
00060 {
00061 }

AlgFilterDigitList::~AlgFilterDigitList (  )  [virtual]

Definition at line 64 of file AlgFilterDigitList.cxx.

References fTFolder.

00065 {
00066   FilterBadChannelMap *badChannelMap;
00067   if (fTFolder && (badChannelMap = dynamic_cast<FilterBadChannelMap*>
00068                        (fTFolder->FindObject("FilterBadChannelMap")))) {
00069     fTFolder->Remove(badChannelMap);
00070     delete badChannelMap;
00071   }
00072 }


Member Function Documentation

void AlgFilterDigitList::MakeBadChannelMap ( Detector::Detector_t  det  )  [private]

Definition at line 299 of file AlgFilterDigitList.cxx.

References bfld::AsString(), RawChannelId::AsString(), RawChannelId::ClearModeBits(), fBadChannelFile, FilterBadChannelMap::fBadChannelMap, fTFolder, RawChannelId::GetEncoded(), Msg::kDebug, Msg::kError, Detector::kNear, ElecType::kQIE, and MSG.

Referenced by RunAlg().

00300 {
00301    MSG("AlgFilterDigitList",Msg::kDebug)
00302      << "MakeBadChannelMap called for " << Detector::AsString(det)
00303      << " using " << fBadChannelFile << endl;
00304 
00305    UInt_t prevEncoded = 0;
00306 
00307 // make the bad channel map object
00308    FilterBadChannelMap *badChMap = new FilterBadChannelMap();
00309 
00310 // open the bad channel file
00311    ifstream badChannels(fBadChannelFile.c_str());
00312 
00313    if (!badChannels.is_open()) {
00314      MSG("AlgFilterDigitList", Msg::kError)
00315                                   << "cannot open list of bad channels," 
00316                                                       << fBadChannelFile
00317                                     << " assume there are none" << endl;
00318 
00319 // Add the map to the white board. AlgFilterDigitList retains ownership!
00320      fTFolder->Add(badChMap);
00321      return;
00322    }
00323 
00324 // fill the map
00325    if (det==Detector::kNear) {
00326      UInt_t crate = 0;
00327      UInt_t geo = 0;
00328      UInt_t masterChannel = 0;
00329      UInt_t minderChannel = 0;
00330 
00331 // read in the list of bad channels
00332      while (!badChannels.eof()) {
00333        badChannels >> crate >> geo >> masterChannel >> minderChannel;
00334 
00335 // make a RawChannelId to get the encoded value
00336 #ifdef RAWCHANNELID_NEW_CTOR
00337        RawChannelId rawId(det,ElecType::kQIE, crate, geo,
00338                                           masterChannel, minderChannel);
00339 #else
00340        RawChannelId rawId(det,ElecType::kQIE, crate, geo,
00341                             masterChannel, minderChannel, false, false);
00342 #endif
00343        rawId.ClearModeBits();
00344        MSG("AlgFilterDigitList", Msg::kDebug)
00345                                       << "*******filter channel********"
00346                    << crate << " " << geo << " " << masterChannel << " " 
00347                                                  << minderChannel << " " 
00348                                         << rawId.AsString("ec") << endl;
00349 
00350 // if the channel is in the list it is a bad channel so the flag is true
00351        if (rawId.GetEncoded() != prevEncoded)
00352          badChMap->fBadChannelMap[rawId] = true;
00353 
00354      }                                       // end loop over input file
00355    }                                             // end if near detector
00356 
00357 // Add the map to the white board. AlgFilterDigitList retains ownership!
00358    fTFolder->Add(badChMap);
00359    return;
00360 }

FilterBadChannelMap * AlgFilterDigitList::MakeBadChannelMapDB ( const VldContext vc  )  [private]

Definition at line 364 of file AlgFilterDigitList.cxx.

References CandDigitBadChannels::cold, FilterBadChannelMap::fBadChannelMap, CandDigitBadChannels::GetBadnessReason(), CandDigitBadChannels::GetChAdd(), CandDigitBadChannels::GetCrate(), VldContext::GetDetector(), VldContext::GetSimFlag(), VldContext::GetTimeStamp(), Msg::kDebug, Detector::kNear, ElecType::kQIE, DbiSqlContext::kThroughout, ElecType::kVA, MAXMSG, and MSG.

Referenced by RunAlg().

00365 {
00366   //make the bad channel map object once
00367   static FilterBadChannelMap* badChMap=new FilterBadChannelMap();
00368 
00369   //clear out any channels that are already in the map
00370   badChMap->fBadChannelMap.clear();
00371   
00372   static Bool_t firstTime=true;
00373   if (firstTime) {
00374     firstTime=false;
00375     MAXMSG("AlgFilterDigitList",Msg::kDebug,200)
00376       <<"Running AlgFilterDigitList::MakeBadChannelMapDB for first time"
00377       <<endl;
00378     //vc.Print();
00379   }
00380   
00381   //now fill the map from the database
00382   //read in the list of bad channels
00383   Int_t task=0;
00384 
00385   // turn this into an extended db query
00386   // so that all db entries get returned
00387   DbiSqlContext evc(DbiSqlContext::kThroughout,
00388                     vc.GetTimeStamp(),vc.GetTimeStamp(),
00389                     vc.GetDetector(),vc.GetSimFlag());
00390   DbiResultPtr<CandDigitBadChannels> badChannelsPtr("CANDDIGITBADCHANNELS",evc,task);
00391   
00392   MAXMSG("AlgFilterDigitList",Msg::kDebug,100)
00393     <<"Num of CandDigitBadChannels rows="
00394     <<badChannelsPtr.GetNumRows()<<endl;
00395   
00396   //loop over all the bad channels and add to map
00397   for (UInt_t irow=0;irow<badChannelsPtr.GetNumRows();++irow) {
00398     
00399     //get bad channel
00400     const CandDigitBadChannels& badChannel=*(badChannelsPtr.GetRow(irow));
00401     
00402     MSG("AlgFilterDigitList",Msg::kDebug)
00403       <<"Crate="<<badChannel.GetCrate()
00404       <<", ChAdd="<<badChannel.GetChAdd()
00405       <<", badnessReason="<<badChannel.GetBadnessReason()
00406       //<<", parA="<<badChannel.GetParA()<<", parB="<<badChannel.GetParB()
00407       //<<", parC="<<badChannel.GetParC()
00408       <<endl;
00409     
00410     // skip over cold channels
00411     if( (badChannel.GetBadnessReason()&CandDigitBadChannels::cold)==CandDigitBadChannels::cold )
00412       continue;
00413 
00414     Int_t crate=badChannel.GetCrate();
00415     Int_t chadd=badChannel.GetChAdd();
00416   
00417     //deal with electronics type
00418     ElecType::Elec_t et=ElecType::kVA;
00419     if (vc.GetDetector()==Detector::kNear) et=ElecType::kQIE;
00420     
00421     //make a RawChannelId to get the encoded value
00422     RawChannelId rawId(vc.GetDetector(),et,crate,chadd);
00423     rawId.ClearModeBits();
00424     
00425     MAXMSG("AlgFilterDigitList",Msg::kDebug,200)
00426       << "*******filter channel********"
00427       <<rawId.AsString("ec")<<endl;
00428     
00429     //add channel to map
00430     //if channel is in the list it is a bad channel so set to true
00431     badChMap->fBadChannelMap[rawId]=true;
00432   }
00433   
00434   return badChMap;
00435 }

void AlgFilterDigitList::RunAlg ( AlgConfig ac,
CandHandle ch,
CandContext cx 
) [virtual]

Implements AlgBase.

Definition at line 75 of file AlgFilterDigitList.cxx.

References CandHandle::AddDaughterLink(), RawChannelId::AsString(), RawChannelId::ClearModeBits(), fBadChannelFile, FilterBadChannelMap::fBadChannelMap, fTFolder, Registry::Get(), CandDigitHandle::GetChannelId(), CandDigitHandle::GetCharge(), RawChannelId::GetCrate(), CandContext::GetDataIn(), VldContext::GetDetector(), RawChannelId::GetGeographicAddress(), RawChannelId::GetMasterChannel(), RawChannelId::GetMinderChannel(), CandDigitHandle::GetQieErrorBits(), CandDigitHandle::GetSubtractedTime(), CandDigitHandle::GetVaErrorBits(), CandHandle::GetVldContext(), Msg::kDebug, Msg::kFatal, Msg::kInfo, Msg::kVerbose, MakeBadChannelMap(), MakeBadChannelMapDB(), MAXMSG, MSG, CandDigitListHandle::SetAbsTime(), CandHandle::SetCandRecord(), and CandDigitListHandle::SetIsSparse().

00077 {
00078    MSG("AlgFilterDigitList", Msg::kDebug)
00079                      << "Starting AlgFilterDigitList::RunAlg()" << endl;
00080 
00081 // Check for input CandDigitListHandle in CandContext
00082    assert(cx.GetDataIn());
00083 
00084 // Obtain CandContext's CandDigitList as input
00085    const CandDigitListHandle *cdlh =
00086              dynamic_cast<const CandDigitListHandle *> (cx.GetDataIn());
00087    assert(cdlh);   // Check for input CandDigitListHandle in CandContext
00088 
00089 // Obtain filtering parameters from AlgConfig
00090    Int_t    filterstrategy = 0;
00091    Float_t  chargeMin = -FLT_MAX;
00092    Double_t timeMin   = -FLT_MAX;
00093    Int_t    errorBitsMaskVA  = 0;
00094    Int_t    errorBitsMaskQIE = 0;
00095 
00096    Int_t tmpi = 0;
00097    Double_t tmpd = 0;
00098    const char* tmps;
00099    if (ac.Get("FilterStrategy", tmpi))   filterstrategy   = tmpi;
00100    if (ac.Get("ChargeMin",tmpd))         chargeMin        = tmpd;
00101    if (ac.Get("SubtractedTimeMin",tmpd)) timeMin          = tmpd;
00102    if (ac.Get("ErrorBitsMaskVA",tmpi))   errorBitsMaskVA  = tmpi;
00103    if (ac.Get("ErrorBitsMaskQIE",tmpi))  errorBitsMaskQIE = tmpi;
00104    if (ac.Get("BadChannelFile", tmps))   fBadChannelFile  = tmps;
00105 
00106    MSG("AlgFilterDigitList", Msg::kDebug) << "file = "
00107                                     << fBadChannelFile << " strategy = " 
00108                                               << filterstrategy << endl;
00109 
00110 // Set CandRecord pointer in new CandDigitList to that of CandDigitList
00111    ch.SetCandRecord((cdlh->GetCandRecord())); //Sub-algorithms need this
00112 
00113 // Copy member variables from orig CandDigitList to new CandDigitList
00114    CandDigitListHandle &cddlh = dynamic_cast<CandDigitListHandle &>(ch);
00115    cddlh.SetAbsTime(cdlh->GetAbsTime());
00116    cddlh.SetIsSparse(cdlh->GetIsSparse());
00117 
00118 // Iterate over CandContext's CandDigitList to find CandDigitHandles.
00119    TIter cdhiter = cdlh->GetDaughterIterator();
00120    TObject *tob;
00121    while ((tob = cdhiter())) {
00122      CandDigitHandle *cdh = dynamic_cast<CandDigitHandle *>(tob);
00123      if (cdh == 0) continue;   // Skip daughter if not a CandDigitHandle
00124 
00125 // Filter unwanted digits here
00126 // if (DontWantThisDigit(filterstrategy)) continue;
00127 
00128 // Strategy 1:  filter away digits that have error codes
00129 //              or are below the sparsification threshold
00130      if (1==filterstrategy) {
00131        if ( cdh->GetCharge()         < chargeMin ) continue;
00132        if ( cdh->GetSubtractedTime() < timeMin   ) continue;
00133        if ( cdh->GetVaErrorBits()    & errorBitsMaskVA  ) continue;
00134        if ( cdh->GetQieErrorBits()   & errorBitsMaskQIE ) continue;
00135      }                                          // End Filter Strategy 1
00136 
00137 // Strategy 2:  Strategy 1 + filter away digits from known bad channels
00138      if(filterstrategy==2){
00139        MSG("AlgFilterDigitList", Msg::kDebug)
00140                                           << "using strategy 2" << endl;
00141 
00142 // Look for the FilterBadChannelMap object on the TFolder white board.
00143        if (fTFolder==0) {
00144          TFolder *lf = dynamic_cast<TFolder*>
00145                            (gROOT->GetRootFolder()->FindObject("Loon"));
00146          if (lf==0) {
00147            MSG("AlgFilterDigitList", Msg::kDebug)
00148                                      << "Creating Loon TFolder" << endl;
00149            lf = gROOT->GetRootFolder()->AddFolder("Loon",
00150                                                        "Loon analysis");
00151            gROOT->GetListOfBrowsables()->Add(lf, "Loon");
00152          }
00153          fTFolder = dynamic_cast<TFolder*>(lf->FindObject("CandDigit"));
00154          if (fTFolder==0) {
00155            MSG("AlgFilterDigitList", Msg::kDebug)
00156                            << "Creating Loon/CandDigit TFolder" << endl;
00157            fTFolder =
00158                     lf->AddFolder("CandDigit", "CandDigit diagnostics");
00159          }
00160        }         
00161 
00162        FilterBadChannelMap *badChannelMap =
00163                                       dynamic_cast<FilterBadChannelMap*>
00164                           (fTFolder->FindObject("FilterBadChannelMap"));
00165        if (badChannelMap==0) {
00166          MAXMSG("AlgFilterDigitList", Msg::kInfo,2)
00167             << "Creating Loon/CandDigit/FilterBadChannelMap" << endl;
00168          MakeBadChannelMap(cdh->GetVldContext()->GetDetector());
00169          badChannelMap = dynamic_cast<FilterBadChannelMap*>
00170                           (fTFolder->FindObject("FilterBadChannelMap"));
00171 
00172          if ( !badChannelMap ) MSG("AlgFilterDigitList", Msg::kFatal)
00173             << "still no Loon/CandDigit/FilterBadChannelMap" << endl;
00174        }
00175 
00176 // grab the RawChannelId and copy it to a local thing
00177        RawChannelId theChannel = cdh->GetChannelId();
00178        theChannel.ClearModeBits();
00179 
00180        MSG("AlgFilterDigitList", Msg::kDebug) << "encoded value = "
00181                                    << theChannel.AsString("ec") << endl;
00182 
00183 // check to see if the channel for this digit is in the bad channel map
00184        map<RawChannelId, bool>& theMap = badChannelMap->fBadChannelMap;
00185        if (theMap.find(theChannel) != theMap.end()) {
00186          MSG("AlgFilterDigitList", Msg::kDebug)
00187                 << "filtering " << cdh->GetChannelId().GetCrate() << "-"
00188                     << cdh->GetChannelId().GetGeographicAddress() << "-"
00189                         << cdh->GetChannelId().GetMasterChannel() << "-"
00190                       << cdh->GetChannelId().GetMinderChannel() << endl;
00191          continue;
00192        }
00193 
00194        if ( cdh->GetCharge()         < chargeMin ) continue;
00195        if ( cdh->GetSubtractedTime() < timeMin   ) continue;
00196        if ( cdh->GetVaErrorBits()    & errorBitsMaskVA  ) continue;
00197        if ( cdh->GetQieErrorBits()   & errorBitsMaskQIE ) continue;
00198               
00199      }                                                 // end strategy 2
00200      
00202      //Strategy 3:  Strategy 1 + filter away digits from BADCHANNELS db
00203      //This uses the database so is more flexible
00205      else if(filterstrategy==3){
00206        MSG("AlgFilterDigitList",Msg::kVerbose)
00207          <<"Using filterstrategy 3"<<endl;
00208        
00209        //do filter strategy 1 first
00210        if ( cdh->GetCharge()         < chargeMin ) continue;
00211        if ( cdh->GetSubtractedTime() < timeMin   ) continue;
00212        if ( cdh->GetVaErrorBits()    & errorBitsMaskVA  ) continue;
00213        if ( cdh->GetQieErrorBits()   & errorBitsMaskQIE ) continue;
00214 
00216        //now do the additional filter strategy
00218        
00219        //create the bad channel map pointer
00220        static FilterBadChannelMap* badChannelMap=0;
00221        
00222        //only create a bad channel map once per validity context
00223        static VldContext lastvc;
00224        if (*cdh->GetVldContext()!=lastvc) {
00225          MAXMSG("AlgFilterDigitList",Msg::kDebug,3)
00226            <<"AlgFilterDigitList: found new VldContext..."<<endl;
00227          //get the map of bad channels
00228          badChannelMap=this->MakeBadChannelMapDB(*cdh->GetVldContext());
00229 
00230          if ( !badChannelMap ) MSG("AlgFilterDigitList", Msg::kFatal)
00231             << "failed to get anything from MakeBadChannelMapDB" << endl;
00232          else {
00233            // RWH 2008-11-12 print the whole list once, just for the record
00234            // under the assumption that the list is short
00235            static int ndumps = 1;
00236            if ( ndumps > 0 ) {
00237              --ndumps;
00238              size_t nbad = badChannelMap->fBadChannelMap.size();
00239              MSG("AlgFilterDigitList", Msg::kInfo)
00240                << "AlgFilterDigitList strategy " << filterstrategy 
00241                << ", BadChannelMap has " << nbad << " entries" << endl;
00242              std::map<RawChannelId, bool>::const_iterator bcitr = 
00243                badChannelMap->fBadChannelMap.begin();
00244              std::map<RawChannelId, bool>::const_iterator bcitr_end = 
00245                badChannelMap->fBadChannelMap.end();
00246              size_t indx = 0;
00247              while ( bcitr != bcitr_end ) {
00248                MSG("AlgFilterDigitList", Msg::kInfo)
00249                  << "  [" << std::setw(3) << indx << "] "
00250                  << bcitr->first << " " << ((bcitr->second)?"true":"false")
00251                  << endl;
00252                indx++; bcitr++;
00253              }
00254            }
00255          }
00256        }
00257        assert(badChannelMap);
00258        //store the vc for next iteration of loop
00259        lastvc=*cdh->GetVldContext();
00260 
00261        //check that there is actually something in the map
00262        if (badChannelMap->fBadChannelMap.size()>0) {
00263          //cache the RawChannelId
00264          RawChannelId theChannel=cdh->GetChannelId();
00265          theChannel.ClearModeBits();
00266          
00267          MSG("AlgFilterDigitList",Msg::kDebug) 
00268            <<"Encoded value = "<<theChannel.AsString("ec")<<endl;
00269          
00270          //check to see if channel for this digit is in bad channel map
00271          map<RawChannelId, bool>& theMap = badChannelMap->fBadChannelMap;
00272          if (theMap.find(theChannel)!=theMap.end()) {
00273            MAXMSG("AlgFilterDigitList",Msg::kInfo,3)
00274              <<"AlgFilterDigitList::Filtering bad channel: "<<theChannel.AsString("ec")
00275              <<endl;
00276            continue;
00277          }
00278        }
00279        else {
00280          MAXMSG("AlgFilterDigitList",Msg::kInfo,1)
00281            <<"AlgFilterDigitList: No CandDigitBadChannels found in map"
00282            <<", skipping this filter step"<<endl;
00283        }
00284      }
00285 
00286      //Effect copy of wanted digits from orig CandDigitList to daughter list
00287      CandDigitHandle cddh(*cdh);
00288      ch.AddDaughterLink(cddh, kFALSE);           // Don't check for dups
00289    }
00290 }

void AlgFilterDigitList::Trace ( const char *  c  )  const [virtual]

Reimplemented from AlgBase.

Definition at line 293 of file AlgFilterDigitList.cxx.

00294 {
00295 }


Member Data Documentation

std::string AlgFilterDigitList::fBadChannelFile [private]

Definition at line 36 of file AlgFilterDigitList.h.

Referenced by MakeBadChannelMap(), and RunAlg().

TFolder* AlgFilterDigitList::fTFolder [private]

path and file holding bad channel info

Definition at line 37 of file AlgFilterDigitList.h.

Referenced by MakeBadChannelMap(), RunAlg(), and ~AlgFilterDigitList().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1