CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQM/RPCMonitorClient/src/RPCDqmClient.cc

Go to the documentation of this file.
00001 // Package:    RPCDqmClient
00002 // Original Author:  Anna Cimmino
00003 
00004 #include "DQM/RPCMonitorClient/interface/RPCDqmClient.h"
00005 #include "DQM/RPCMonitorDigi/interface/RPCBookFolderStructure.h"
00006 #include "DQM/RPCMonitorDigi/interface/utils.h"
00007 //include client headers
00008 #include  "DQM/RPCMonitorClient/interface/RPCDeadChannelTest.h"
00009 #include "DQM/RPCMonitorClient/interface/RPCMultiplicityTest.h"
00010 #include "DQM/RPCMonitorClient/interface/RPCClusterSizeTest.h"
00011 #include "DQM/RPCMonitorClient/interface/RPCOccupancyTest.h"
00012 #include "DQM/RPCMonitorClient/interface/RPCNoisyStripTest.h"
00013 //Geometry
00014 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00015 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00016 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00017 //Framework
00018 #include "FWCore/ServiceRegistry/interface/Service.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 
00021 RPCDqmClient::RPCDqmClient(const edm::ParameterSet& iConfig){
00022 
00023   edm::LogVerbatim ("rpcdqmclient") << "[RPCDqmClient]: Constructor";
00024 
00025   parameters_ = iConfig;
00026 
00027   offlineDQM_ = parameters_.getUntrackedParameter<bool> ("OfflineDQM",true); 
00028   useRollInfo_=  parameters_.getUntrackedParameter<bool>("UseRollInfo", false);
00029   //check enabling
00030   enableDQMClients_ =parameters_.getUntrackedParameter<bool> ("EnableRPCDqmClient",true); 
00031   minimumEvents_= parameters_.getUntrackedParameter<int>("MinimumRPCEvents", 10000);
00032 
00033   std::string subsystemFolder = parameters_.getUntrackedParameter<std::string>("RPCFolder", "RPC");
00034   std::string recHitTypeFolder= parameters_.getUntrackedParameter<std::string>("RecHitTypeFolder", "AllHits");
00035   std::string summaryFolder = parameters_.getUntrackedParameter<std::string>("SummaryFolder", "SummaryHistograms");
00036   
00037   prefixDir_ =   subsystemFolder+ "/"+ recHitTypeFolder;
00038   globalFolder_ = subsystemFolder + "/"+ recHitTypeFolder + "/"+ summaryFolder;
00039 
00040   //get prescale factor
00041   prescaleGlobalFactor_ = parameters_.getUntrackedParameter<int>("DiagnosticGlobalPrescale", 5);
00042 
00043  
00044 
00045   //make default client list  
00046   clientList_.push_back("RPCMultiplicityTest");
00047   clientList_.push_back("RPCDeadChannelTest");
00048   clientList_.push_back("RPCClusterSizeTest");
00049   clientList_= parameters_.getUntrackedParameter<std::vector<std::string> >("RPCDqmClientList",clientList_);
00050 
00051 
00052   //get all the possible RPC DQM clients 
00053   this->makeClientMap();
00054 }
00055 
00056 RPCDqmClient::~RPCDqmClient(){dbe_ = 0;}
00057 
00058 void RPCDqmClient::beginJob(){
00059 
00060   edm::LogVerbatim ("rpcdqmclient") << "[RPCDqmClient]: Begin Job";
00061   if (!enableDQMClients_) return;                 ;
00062 
00063   dbe_ = edm::Service<DQMStore>().operator->();
00064   dbe_->setVerbose(0);
00065   
00066 
00067   //Do whatever the begin jobs of all client modules do
00068   for(std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ )
00069     (*it)->beginJob(dbe_, globalFolder_);
00070   
00071 }
00072 
00073 
00074 void  RPCDqmClient::beginRun(const edm::Run& r, const edm::EventSetup& c){
00075 
00076   if (!enableDQMClients_) return;
00077 
00078   
00079   for ( std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ ){
00080     (*it)->beginRun(r,c);
00081   }
00082 
00083   if(!offlineDQM_) this->getMonitorElements(r, c);
00084   
00085   lumiCounter_ = prescaleGlobalFactor_;
00086   init_ = false;
00087 }
00088 
00089 
00090 
00091 void  RPCDqmClient::endRun(const edm::Run& r, const edm::EventSetup& c){
00092   edm::LogVerbatim ("rpcdqmclient") << "[RPCDqmClient]: End Run";
00093 
00094   if (!enableDQMClients_) return;
00095 
00096   if(offlineDQM_) this->getMonitorElements(r, c);
00097 
00098   float   rpcevents = minimumEvents_;
00099   if(RPCEvents_) rpcevents = RPCEvents_ ->getBinContent(1);
00100   
00101   if(rpcevents < minimumEvents_) return;
00102   
00103   for (std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ ){
00104     (*it)->clientOperation(c);
00105     (*it)->endRun(r,c);
00106   }
00107 }
00108 
00109 
00110 void  RPCDqmClient::getMonitorElements(const edm::Run& r, const edm::EventSetup& c){
00111  
00112   std::vector<MonitorElement *>  myMeVect;
00113   std::vector<RPCDetId>   myDetIds;
00114    
00115   edm::ESHandle<RPCGeometry> rpcGeo;
00116   c.get<MuonGeometryRecord>().get(rpcGeo);
00117   
00118   //dbe_->setCurrentFolder(prefixDir_);
00119   RPCBookFolderStructure *  folderStr = new RPCBookFolderStructure();
00120   MonitorElement * myMe = NULL;
00121   //loop on all geometry and get all histos
00122   for (TrackingGeometry::DetContainer::const_iterator it=rpcGeo->dets().begin();it<rpcGeo->dets().end();it++){
00123     if( dynamic_cast< RPCChamber* >( *it ) != 0 ){
00124        
00125        RPCChamber* ch = dynamic_cast< RPCChamber* >( *it ); 
00126        std::vector< const RPCRoll*> roles = (ch->rolls());
00127        //Loop on rolls in given chamber
00128        for(std::vector<const RPCRoll*>::const_iterator r = roles.begin();r != roles.end(); ++r){
00129          RPCDetId detId = (*r)->id();
00130          
00131          //Get Occupancy ME for roll
00132          RPCGeomServ RPCname(detId);       
00133          std::string rollName= "";
00134          //loop on clients
00135          for( unsigned int cl = 0; cl<clientModules_.size(); cl++ ){
00136            if(useRollInfo_) rollName =  RPCname.name();
00137            else     rollName =  RPCname.chambername();
00138              
00139            myMe = NULL;
00140            myMe = dbe_->get(prefixDir_ +"/"+ folderStr->folderStructure(detId)+"/"+clientHisto_[cl]+ "_"+rollName); 
00141 
00142           if (!myMe)continue;
00143 
00144           dbe_->tag(myMe, clientTag_[cl]);
00145 
00146           myMeVect.push_back(myMe);
00147           myDetIds.push_back(detId);
00148         }//end loop on clients
00149       }//end loop on roll in given chamber
00150     }
00151   }//end loop on all geometry and get all histos  
00152   
00153 
00154   RPCEvents_ = dbe_->get(prefixDir_ +"/RPCEvents");  
00155   
00156 
00157   for (std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ ){
00158     (*it)->getMonitorElements(myMeVect, myDetIds);
00159   }
00160 
00161   delete folderStr;
00162  
00163 }
00164  
00165 
00166 
00167 void RPCDqmClient::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& context) {
00168   if (!enableDQMClients_) return;
00169 
00170   for ( std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ )
00171     (*it)->beginLuminosityBlock(lumiSeg,context);
00172 }
00173 
00174 void RPCDqmClient::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){
00175 
00176  if (!enableDQMClients_) return;
00177 
00178  for ( std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ )
00179     (*it)->analyze( iEvent,iSetup);
00180 }
00181 
00182 
00183 void RPCDqmClient::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& c){
00184  
00185   if (!enableDQMClients_ ) return;
00186 
00187   if(offlineDQM_) return;
00188 
00189   edm::LogVerbatim ("rpcdqmclient") <<"[RPCDqmClient]: End of LS ";
00190 
00191   for (std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ )
00192     (*it)->endLuminosityBlock( lumiSeg, c);
00193   
00194   float   rpcevents = minimumEvents_;
00195   if(RPCEvents_) rpcevents = RPCEvents_ ->getBinContent(1);
00196   
00197   if( rpcevents < minimumEvents_) return;
00198 
00199   if( !init_ ){
00200 
00201     for (std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ ){
00202       (*it)->clientOperation(c);
00203     }
00204     init_ = true;
00205     return;
00206   }
00207 
00208   lumiCounter_++;
00209 
00210   if (lumiCounter_%prescaleGlobalFactor_ != 0) return;
00211 
00212 
00213   for (std::vector<RPCClient*>::iterator it = clientModules_.begin(); it!=clientModules_.end(); it++ ){
00214     (*it)->clientOperation(c);
00215   }
00216 
00217 }
00218 
00219 
00220 
00221 void RPCDqmClient::endJob() {
00222   if (!enableDQMClients_) return;
00223   
00224   for ( std::vector<RPCClient*>::iterator it= clientModules_.begin(); it!=clientModules_.end(); it++ )
00225     (*it)->endJob();
00226 }
00227 
00228 
00229 void RPCDqmClient::makeClientMap() {
00230 
00231   for(unsigned int i = 0; i<clientList_.size(); i++){
00232     
00233     if( clientList_[i] == "RPCMultiplicityTest" ) {
00234       clientHisto_.push_back("Multiplicity");
00235       clientTag_.push_back(rpcdqm::MULTIPLICITY);
00236       clientModules_.push_back( new RPCMultiplicityTest(parameters_));
00237     } else if ( clientList_[i] == "RPCDeadChannelTest" ){
00238       clientHisto_.push_back("Occupancy");
00239       clientModules_.push_back( new RPCDeadChannelTest(parameters_));
00240       clientTag_.push_back(rpcdqm::OCCUPANCY);
00241     } else if ( clientList_[i] == "RPCClusterSizeTest" ){
00242       clientHisto_.push_back("ClusterSize");
00243       clientModules_.push_back( new RPCClusterSizeTest(parameters_));
00244       clientTag_.push_back(rpcdqm::CLUSTERSIZE);
00245     } else if ( clientList_[i] == "RPCOccupancyTest" ){
00246       clientHisto_.push_back("Occupancy");
00247       clientModules_.push_back( new RPCOccupancyTest(parameters_));
00248       clientTag_.push_back(rpcdqm::OCCUPANCY);
00249     } else if ( clientList_[i] == "RPCNoisyStripTest" ){
00250       clientHisto_.push_back("Occupancy");
00251       clientModules_.push_back( new RPCNoisyStripTest(parameters_));
00252       clientTag_.push_back(rpcdqm::OCCUPANCY);
00253     }
00254   }
00255 
00256   return;
00257 
00258 }