CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/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->fnGetCacheFEDHisto = boost::bind(&Cache::getFED, &cache, _1, _2, _3);
00039     config->fnGetCacheDDUHisto = boost::bind(&Cache::getDDU, &cache, _1, _2, _3);
00040     config->fnGetCacheCSCHisto = boost::bind(&Cache::getCSC, &cache, _1, _2, _3, _4, _5);
00041     config->fnGetCacheParHisto = boost::bind(&Cache::getPar, &cache, _1, _2);
00042     config->fnPutHisto = boost::bind(&Cache::put, &cache, _1, _2);
00043     config->fnNextBookedCSC = boost::bind(&Cache::nextBookedCSC, &cache, _1, _2, _3);
00044     config->fnIsBookedCSC = boost::bind(&Cache::isBookedCSC, &cache, _1, _2);
00045     config->fnIsBookedDDU = boost::bind(&Cache::isBookedDDU, &cache, _1);
00046     config->fnIsBookedFED = boost::bind(&Cache::isBookedFED, &cache, _1);
00047 
00049     config->fnGetHisto = boost::bind(&Dispatcher::getHisto, this, _1, _2);
00050 
00052     config->fnGetCSCDetId = boost::bind(&MonitorObjectProvider::getCSCDetId, provider, _1, _2, _3);
00053 
00055     config->fnBook = boost::bind(&MonitorObjectProvider::bookMonitorObject, provider, _1);
00056 
00057   }
00058 
00063   void Dispatcher::init() {
00064     collection.load();
00065     collection.bookEMUHistos();
00066     processor.init();
00067   }
00068 
00074   unsigned int Dispatcher::maskHWElements(std::vector<std::string>& tokens) {
00075     return processorFract.maskHWElements(tokens);
00076   }
00077 
00084   const bool Dispatcher::getHisto(const HistoDef& histoD, MonitorObject*& me) {
00085 
00087     if (typeid(histoD) == FEDHistoDefT && !cache.isBookedFED(histoD.getFEDId())) {
00088       collection.bookFEDHistos(histoD.getFEDId());
00089       if (cache.get(histoD, me)) return true;
00090     }
00091 
00093     if (typeid(histoD) == DDUHistoDefT && !cache.isBookedDDU(histoD.getDDUId())) {
00094       collection.bookDDUHistos(histoD.getDDUId());
00095       if (cache.get(histoD, me)) return true;
00096     }
00097 
00099     if (typeid(histoD) == CSCHistoDefT) {
00100       if (!cache.isBookedCSC(histoD.getCrateId(), histoD.getDMBId())) {
00101         collection.bookCSCHistos(histoD.getCrateId(), histoD.getDMBId());
00103       }
00104       if (collection.isOnDemand(histoD.getHistoName())) {
00105         collection.bookCSCHistos(histoD.getId(), histoD.getCrateId(), histoD.getDMBId(), histoD.getAddId());
00106       }
00107       if (cache.get(histoD, me)) return true;
00108     }
00109 
00111     if (typeid(histoD) == ParHistoDefT) {
00112       HistoBookRequest req(histoD, config->getFOLDER_PAR(), -1.0f);
00113       me = provider->bookMonitorObject(req);
00114       cache.put(histoD, me);
00115       return true;
00116     }
00117 
00119     cache.put(histoD, NULL);
00120 
00121     return false;
00122   }
00123 
00128   void Dispatcher::updateFractionAndEfficiencyHistosAuto() {
00129     if ( config->getFRAEFF_AUTO_UPDATE() &&
00130         (config->getNEventsCSC() >= config->getFRAEFF_AUTO_UPDATE_START()) &&
00131         (config->getNEventsCSC() % config->getFRAEFF_AUTO_UPDATE_FREQ()) == 0) {
00132       updateFractionAndEfficiencyHistos();
00133     }
00134   }
00135 
00140   void Dispatcher::updateFractionAndEfficiencyHistos() {
00141     LockType lock(processorFract.mutex);
00142     if (config->getFRAEFF_SEPARATE_THREAD()) { 
00143       boost::function<void ()> fnUpdate = boost::bind(&EventProcessorMutex::updateFractionAndEfficiencyHistos, &processorFract);
00144 #ifdef DQMMT
00145       threads.create_thread(boost::ref(fnUpdate));
00146 #else
00147       fnUpdate();
00148 #endif 
00149     } else {
00150       processorFract.updateFractionAndEfficiencyHistos();
00151     }
00152   }
00153 
00158   void Dispatcher::processStandby(HWStandbyType& standby) {
00159     LockType lock(processorFract.mutex);
00160     if (config->getFRAEFF_SEPARATE_THREAD()) { 
00161       boost::function<void (HWStandbyType&)> fnUpdate = boost::bind(&EventProcessorMutex::processStandby, &processorFract, _1);
00162 #ifdef DQMMT
00163       threads.create_thread(boost::ref(fnUpdate));
00164 #else
00165       fnUpdate(standby);
00166 #endif 
00167     } else {
00168       processorFract.processStandby(standby);
00169     }
00170   }
00171 
00172 #ifdef DQMLOCAL
00173 
00182   void Dispatcher::processEvent(const char* data, const int32_t dataSize, const uint32_t errorStat, const int32_t nodeNumber) {
00183     config->eventProcessTimer(true);
00184     processor.processEvent(data, dataSize, errorStat, nodeNumber);
00185     config->eventProcessTimer(false);
00186     updateFractionAndEfficiencyHistosAuto();
00187   }
00188 
00189 #endif      
00190 
00191 #ifdef DQMGLOBAL
00192 
00199   void Dispatcher::processEvent(const edm::Event& e, const edm::InputTag& inputTag, HWStandbyType& standby) {
00200     config->eventProcessTimer(true);
00201      
00202     // Consider standby information
00203     if (standby.process) {
00204 
00205       // Set in full standby once at the start. Afterwards - no!
00206       // i.e. if we ever in the run have gone off standby - this value is false 
00207       config->setIN_FULL_STANDBY(config->getIN_FULL_STANDBY() && standby.fullStandby());
00208 
00209       //std::cout << "standby.MeP = " << standby.MeP << "\n";
00210       //std::cout << "standby.MeM = " << standby.MeM << "\n";
00211       //std::cout << "standby.fullStandby() = " << standby.fullStandby() << "\n";
00212       //std::cout << "config->getIN_FULL_STANDBY = " << config->getIN_FULL_STANDBY() << "\n";
00213 
00214       processStandby(standby);
00215 
00216       // We do not fill histograms in full standby!
00217       if (standby.fullStandby()) {
00218         return;
00219       }
00220 
00221     }
00222 
00223     processor.processEvent(e, inputTag);
00224 
00225     config->eventProcessTimer(false);
00226 
00227     updateFractionAndEfficiencyHistosAuto();
00228 
00229   }
00230 
00231 #endif      
00232 
00233 }