CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/CSCMonitorModule/src/CSCDQM_Dispatcher.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  CSCDQM_Dispatcher.cc
00005  *
00006  *    Description:  CSCDQM Dispatcher implementation
00007  *
00008  *        Version:  1.0
00009  *        Created:  12/01/2008 10:32:38 AM
00010  *       Revision:  none
00011  *       Compiler:  gcc
00012  *
00013  *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
00014  *        Company:  CERN, CH
00015  *
00016  * =====================================================================================
00017  */
00018 
00019 #include "DQM/CSCMonitorModule/interface/CSCDQM_Dispatcher.h"
00020 
00021 namespace cscdqm {
00022 
00029   Dispatcher::Dispatcher(Configuration* const p_config, MonitorObjectProvider* p_provider) : 
00030   collection(p_config), processor(p_config), processorFract(p_config) {
00031 
00033     config = p_config;
00034     provider = p_provider;
00035 
00037     config->fnGetCacheEMUHisto = boost::bind(&Cache::getEMU, &cache, _1, _2);
00038     config->fnGetCacheDDUHisto = boost::bind(&Cache::getDDU, &cache, _1, _2, _3);
00039     config->fnGetCacheCSCHisto = boost::bind(&Cache::getCSC, &cache, _1, _2, _3, _4, _5);
00040     config->fnGetCacheParHisto = boost::bind(&Cache::getPar, &cache, _1, _2);
00041     config->fnPutHisto = boost::bind(&Cache::put, &cache, _1, _2);
00042     config->fnNextBookedCSC = boost::bind(&Cache::nextBookedCSC, &cache, _1, _2, _3);
00043     config->fnIsBookedCSC = boost::bind(&Cache::isBookedCSC, &cache, _1, _2);
00044     config->fnIsBookedDDU = boost::bind(&Cache::isBookedDDU, &cache, _1);
00045 
00047     config->fnGetHisto = boost::bind(&Dispatcher::getHisto, this, _1, _2);
00048 
00050     config->fnGetCSCDetId = boost::bind(&MonitorObjectProvider::getCSCDetId, provider, _1, _2, _3);
00051 
00053     config->fnBook = boost::bind(&MonitorObjectProvider::bookMonitorObject, provider, _1);
00054 
00055   }
00056 
00061   void Dispatcher::init() {
00062     collection.load();
00063     collection.bookEMUHistos();
00064     processor.init();
00065   }
00066 
00072   unsigned int Dispatcher::maskHWElements(std::vector<std::string>& tokens) {
00073     return processorFract.maskHWElements(tokens);
00074   }
00075 
00082   const bool Dispatcher::getHisto(const HistoDef& histoD, MonitorObject*& me) {
00083 
00085     if (typeid(histoD) == DDUHistoDefT && !cache.isBookedDDU(histoD.getDDUId())) {
00086       collection.bookDDUHistos(histoD.getDDUId());
00087       if (cache.get(histoD, me)) return true;
00088     }
00089 
00091     if (typeid(histoD) == CSCHistoDefT) {
00092       if (!cache.isBookedCSC(histoD.getCrateId(), histoD.getDMBId())) {
00093         collection.bookCSCHistos(histoD.getCrateId(), histoD.getDMBId());
00095       }
00096       if (collection.isOnDemand(histoD.getHistoName())) {
00097         collection.bookCSCHistos(histoD.getId(), histoD.getCrateId(), histoD.getDMBId(), histoD.getAddId());
00098       }
00099       if (cache.get(histoD, me)) return true;
00100     }
00101 
00103     if (typeid(histoD) == ParHistoDefT) {
00104       HistoBookRequest req(histoD, config->getFOLDER_PAR(), -1.0f);
00105       me = provider->bookMonitorObject(req);
00106       cache.put(histoD, me);
00107       return true;
00108     }
00109 
00111     cache.put(histoD, NULL);
00112 
00113     return false;
00114   }
00115 
00120   void Dispatcher::updateFractionAndEfficiencyHistosAuto() {
00121     if ( config->getFRAEFF_AUTO_UPDATE() &&
00122         (config->getNEventsCSC() >= config->getFRAEFF_AUTO_UPDATE_START()) &&
00123         (config->getNEventsCSC() % config->getFRAEFF_AUTO_UPDATE_FREQ()) == 0) {
00124       updateFractionAndEfficiencyHistos();
00125     }
00126   }
00127 
00132   void Dispatcher::updateFractionAndEfficiencyHistos() {
00133     LockType lock(processorFract.mutex);
00134     if (config->getFRAEFF_SEPARATE_THREAD()) { 
00135       boost::function<void ()> fnUpdate = boost::bind(&EventProcessorMutex::updateFractionAndEfficiencyHistos, &processorFract);
00136 #ifdef DQMMT
00137       threads.create_thread(boost::ref(fnUpdate));
00138 #else
00139       fnUpdate();
00140 #endif 
00141     } else {
00142       processorFract.updateFractionAndEfficiencyHistos();
00143     }
00144   }
00145 
00150   void Dispatcher::processStandby(HWStandbyType& standby) {
00151     LockType lock(processorFract.mutex);
00152     if (config->getFRAEFF_SEPARATE_THREAD()) { 
00153       boost::function<void (HWStandbyType&)> fnUpdate = boost::bind(&EventProcessorMutex::processStandby, &processorFract, _1);
00154 #ifdef DQMMT
00155       threads.create_thread(boost::ref(fnUpdate));
00156 #else
00157       fnUpdate(standby);
00158 #endif 
00159     } else {
00160       processorFract.processStandby(standby);
00161     }
00162   }
00163 
00164 #ifdef DQMLOCAL
00165 
00174   void Dispatcher::processEvent(const char* data, const int32_t dataSize, const uint32_t errorStat, const int32_t nodeNumber) {
00175     config->eventProcessTimer(true);
00176     processor.processEvent(data, dataSize, errorStat, nodeNumber);
00177     config->eventProcessTimer(false);
00178     updateFractionAndEfficiencyHistosAuto();
00179   }
00180 
00181 #endif      
00182 
00183 #ifdef DQMGLOBAL
00184 
00191   void Dispatcher::processEvent(const edm::Event& e, const edm::InputTag& inputTag, HWStandbyType& standby) {
00192     config->eventProcessTimer(true);
00193      
00194     // Consider standby information
00195     if (standby.process) {
00196 
00197       // Set in full standby once at the start. Afterwards - no!
00198       // i.e. if we ever in the run have gone off standby - this value is false 
00199       config->setIN_FULL_STANDBY(config->getIN_FULL_STANDBY() && standby.fullStandby());
00200 
00201       //std::cout << "standby.MeP = " << standby.MeP << "\n";
00202       //std::cout << "standby.MeM = " << standby.MeM << "\n";
00203       //std::cout << "standby.fullStandby() = " << standby.fullStandby() << "\n";
00204       //std::cout << "config->getIN_FULL_STANDBY = " << config->getIN_FULL_STANDBY() << "\n";
00205 
00206       processStandby(standby);
00207 
00208       // We do not fill histograms in full standby!
00209       if (standby.fullStandby()) {
00210         return;
00211       }
00212 
00213     }
00214 
00215     processor.processEvent(e, inputTag);
00216 
00217     config->eventProcessTimer(false);
00218 
00219     updateFractionAndEfficiencyHistosAuto();
00220 
00221   }
00222 
00223 #endif      
00224 
00225 }