CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DPGAnalysis/Skims/src/DetStatus.cc

Go to the documentation of this file.
00001 #include "DPGAnalysis/Skims/interface/DetStatus.h" 
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "DataFormats/Scalers/interface/DcsStatus.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include <iostream>
00007  
00008 using namespace std;
00009 
00010 //
00011 // -- Constructor
00012 //
00013 DetStatus::DetStatus( const edm::ParameterSet & pset ) {
00014    verbose_      = pset.getUntrackedParameter<bool>( "DebugOn", false );
00015    AndOr_      = pset.getParameter<bool>( "AndOr");
00016    applyfilter_      = pset.getParameter<bool>( "ApplyFilter");
00017    DetNames_ = pset.getParameter<std::vector<std::string> >( "DetectorType" );
00018 
00019   // build a map
00020   DetMap_=0;
00021   for (unsigned int detreq=0;detreq<DetNames_.size();detreq++)
00022     {
00023       for (unsigned int detlist=0;detlist<DcsStatus::nPartitions;detlist++)
00024         {
00025           
00026           if (DetNames_[detreq]==DcsStatus::partitionName[detlist])
00027             {
00028               DetMap_|=(1 << DcsStatus::partitionList[detlist]);
00029               if (verbose_)
00030                   std::cout << "DCSStatus filter: asked partition " << DcsStatus::partitionName[detlist] << " bit " << DcsStatus::partitionList[detlist] << std::endl; 
00031 
00032             }
00033         }
00034     }
00035 } 
00036 
00037 //
00038 // -- Destructor
00039 //
00040 DetStatus::~DetStatus() {
00041 }
00042  
00043 bool DetStatus::filter( edm::Event & evt, edm::EventSetup const& es) {
00044   
00045   bool accepted=false;
00046 
00047   edm::Handle<DcsStatusCollection> dcsStatus;
00048   evt.getByLabel("scalersRawToDigi", dcsStatus);
00049 
00050   if (dcsStatus.isValid()) 
00051     {
00052       if (dcsStatus->empty())
00053         {
00054           // Only complain in case it's real data. Accept in any case.
00055           if (evt.eventAuxiliary().isRealData())
00056             edm::LogError("DetStatus") << "Error! dcsStatus has size 0, accept in any case" ;
00057           accepted=true;
00058         }
00059       else 
00060         {
00061           unsigned int curr_dcs=(*dcsStatus)[0].ready();
00062           if (verbose_)
00063             std::cout << "curr_dcs = " << curr_dcs << std::endl;
00064           if(AndOr_)
00065             accepted=((DetMap_ & curr_dcs)== DetMap_);
00066           else
00067             accepted=((DetMap_ & curr_dcs)!= 0);
00068             
00069           if (verbose_)
00070 
00071             {
00072               std::cout << "DCSStatus filter: requested map: " << DetMap_ << " dcs in event: " <<curr_dcs << " filter: " << accepted << std::endl; 
00073               std::cout << "Partitions ON: " ;
00074               for (unsigned int detlist=0;detlist<DcsStatus::nPartitions;detlist++)
00075                 {
00076                   if ((*dcsStatus)[0].ready(DcsStatus::partitionList[detlist]))
00077                     {
00078                       std::cout << " " << DcsStatus::partitionName[detlist];
00079                     }
00080                 }
00081               std::cout << std::endl ;
00082             }
00083         }
00084     }
00085   else
00086     {
00087       edm::LogError("DetStatus") << "Error! can't get the product: scalersRawToDigi, accept in any case" ;
00088       accepted=true;
00089     }
00090 
00091   if (! applyfilter_) accepted=true;
00092   return accepted;
00093 }
00094 
00095 #include "FWCore/Framework/interface/MakerMacros.h"
00096 DEFINE_FWK_MODULE(DetStatus);
00097 
00098