CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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).size()==0)
00053         {
00054           // it's probably a MC event, accepet it in any case
00055           edm::LogError("DetStatus") << "Error! dcsStatus has size 0, accept in any case" ;
00056           accepted=true;
00057         }
00058       else 
00059         {
00060           unsigned int curr_dcs=(*dcsStatus)[0].ready();
00061           if (verbose_)
00062             std::cout << "curr_dcs = " << curr_dcs << std::endl;
00063           if(AndOr_)
00064             accepted=((DetMap_ & curr_dcs)== DetMap_);
00065           else
00066             accepted=((DetMap_ & curr_dcs)!= 0);
00067             
00068           if (verbose_)
00069 
00070             {
00071               std::cout << "DCSStatus filter: requested map: " << DetMap_ << " dcs in event: " <<curr_dcs << " filter: " << accepted << std::endl; 
00072               std::cout << "Partitions ON: " ;
00073               for (unsigned int detlist=0;detlist<DcsStatus::nPartitions;detlist++)
00074                 {
00075                   if ((*dcsStatus)[0].ready(DcsStatus::partitionList[detlist]))
00076                     {
00077                       std::cout << " " << DcsStatus::partitionName[detlist];
00078                     }
00079                 }
00080               std::cout << std::endl ;
00081             }
00082         }
00083     }
00084   else
00085     {
00086       edm::LogError("DetStatus") << "Error! can't get the product: scalersRawToDigi, accept in any case" ;
00087       accepted=true;
00088     }
00089 
00090   if (! applyfilter_) accepted=true;
00091   return accepted;
00092 }
00093 
00094 #include "FWCore/Framework/interface/MakerMacros.h"
00095 DEFINE_FWK_MODULE(DetStatus);
00096 
00097