Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:09:28

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  CSCDQM_Dispatcher.cc
0005  *
0006  *    Description:  CSCDQM Dispatcher implementation
0007  *
0008  *        Version:  1.0
0009  *        Created:  12/01/2008 10:32:38 AM
0010  *       Revision:  none
0011  *       Compiler:  gcc
0012  *
0013  *         Author:  Valdas Rapsevicius (VR), valdas.rapsevicius@cern.ch
0014  *        Company:  CERN, CH
0015  *
0016  * =====================================================================================
0017  */
0018 
0019 #include "CSCDQM_Dispatcher.h"
0020 
0021 namespace cscdqm {
0022 
0023   /**
0024  * @brief  Constructor.
0025  * @param  p_config Pointer to Global Configuration
0026  * @param  p_provider Pointer to MonitorObjectProvider
0027  * @return
0028  */
0029   Dispatcher::Dispatcher(Configuration* const p_config, MonitorObjectProvider* p_provider)
0030       : collection(p_config), processor(p_config), processorFract(p_config) {
0031     commonConstruct(p_config, p_provider);
0032   }
0033 
0034 #ifdef DQMGLOBAL
0035 
0036   /**
0037  * @brief  Constructor.
0038  * @param  p_config Pointer to Global Configuration
0039  * @param  p_provider Pointer to MonitorObjectProvider
0040  * @param  itag InputTag to raw data - to be passed down
0041  * @param  coco rvalue to ConsumesCollector - to be passed down
0042  * @return
0043  */
0044   Dispatcher::Dispatcher(Configuration* const p_config,
0045                          MonitorObjectProvider* p_provider,
0046                          const edm::InputTag& itag,
0047                          edm::ConsumesCollector&& coco)
0048       : collection(p_config), processor(p_config, itag, coco), processorFract(p_config) {
0049     commonConstruct(p_config, p_provider);
0050   }
0051 
0052 #endif
0053 
0054   void Dispatcher::commonConstruct(Configuration* const p_config, MonitorObjectProvider* p_provider) {
0055     /** Save pointers to class properties */
0056     config = p_config;
0057     provider = p_provider;
0058 
0059     /** Link/share Cache methods to function pointers in configuration */
0060     config->fnGetCacheEMUHisto = std::bind(&Cache::getEMU, &cache, std::placeholders::_1, std::placeholders::_2);
0061     config->fnGetCacheFEDHisto =
0062         std::bind(&Cache::getFED, &cache, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
0063     config->fnGetCacheDDUHisto =
0064         std::bind(&Cache::getDDU, &cache, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
0065     config->fnGetCacheCSCHisto = std::bind(&Cache::getCSC,
0066                                            &cache,
0067                                            std::placeholders::_1,
0068                                            std::placeholders::_2,
0069                                            std::placeholders::_3,
0070                                            std::placeholders::_4,
0071                                            std::placeholders::_5);
0072     config->fnGetCacheParHisto = std::bind(&Cache::getPar, &cache, std::placeholders::_1, std::placeholders::_2);
0073     config->fnPutHisto = std::bind(&Cache::put, &cache, std::placeholders::_1, std::placeholders::_2);
0074     config->fnNextBookedCSC =
0075         std::bind(&Cache::nextBookedCSC, &cache, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
0076     config->fnIsBookedCSC = std::bind(&Cache::isBookedCSC, &cache, std::placeholders::_1, std::placeholders::_2);
0077     config->fnIsBookedDDU = std::bind(&Cache::isBookedDDU, &cache, std::placeholders::_1);
0078     config->fnIsBookedFED = std::bind(&Cache::isBookedFED, &cache, std::placeholders::_1);
0079 
0080     /** Link/share local functions */
0081     config->fnGetHisto = std::bind(&Dispatcher::getHisto, this, std::placeholders::_1, std::placeholders::_2);
0082 
0083     /** Link/share getCSCDetId function */
0084     config->fnGetCSCDetId = std::bind(&MonitorObjectProvider::getCSCDetId,
0085                                       provider,
0086                                       std::placeholders::_1,
0087                                       std::placeholders::_2,
0088                                       std::placeholders::_3);
0089 
0090     /** Link/share booking function */
0091     config->fnBook = std::bind(&MonitorObjectProvider::bookMonitorObject, provider, std::placeholders::_1);
0092   }
0093 
0094   /**
0095  * @brief  Initialize Dispatcher: book histograms, init processor, etc.
0096  * @return
0097  */
0098   void Dispatcher::init() {
0099     collection.load();
0100     // collection.bookEMUHistos();
0101     // processor.init();
0102   }
0103 
0104   void Dispatcher::book() {
0105     collection.bookEMUHistos();
0106 
0107     /*** FOr multi-threading pre-book all FED, DDU, CSC histograms ***/
0108     if (config->getPREBOOK_ALL_HISTOS()) {
0109       /** For the first FED - book general */
0110       for (HwId FEDId = 750; FEDId < 758; FEDId++) {
0111         if (!cache.isBookedFED(FEDId)) {
0112           collection.bookFEDHistos(FEDId);
0113         }
0114       }
0115 
0116       if (config->getPROCESS_DDU()) {
0117         /** For the first DDU - book general */
0118         for (HwId DDUId = 1; DDUId <= 36; DDUId++) {
0119           if (!cache.isBookedDDU(DDUId)) {
0120             collection.bookDDUHistos(DDUId);
0121           }
0122         }
0123       }
0124 
0125       if (config->getPROCESS_CSC()) {
0126         /** For the first and specific CSCs - book general and specific */
0127         for (HwId CrateId = 1; CrateId <= 60; CrateId++) {
0128           for (HwId DMBId = 1; DMBId <= 10; DMBId++) {
0129             if (DMBId == 6)
0130               continue;  /// No DMB in slot 6
0131             if (!cache.isBookedCSC(CrateId, DMBId)) {
0132               collection.bookCSCHistos(CrateId, DMBId);
0133             }
0134           }
0135         }
0136       }
0137 
0138       if (config->getPROCESS_EFF_PARAMETERS()) {
0139         /** For the Parameters - book parameter histograms */
0140 
0141         std::vector<HistoId> parameters;
0142         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION01_RING01);
0143         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION01_RING02);
0144         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION01_RING03);
0145         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION01);
0146         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION02_RING01);
0147         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION02_RING02);
0148         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION02);
0149         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION03_RING01);
0150         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION03_RING02);
0151         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION03);
0152         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION04_RING01);
0153         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION04_RING02);
0154         parameters.push_back(h::PAR_CSC_SIDEPLUS_STATION04);
0155         parameters.push_back(h::PAR_CSC_SIDEPLUS);
0156         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION01_RING01);
0157         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION01_RING02);
0158         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION01_RING03);
0159         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION01);
0160         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION02_RING01);
0161         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION02_RING02);
0162         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION02);
0163         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION03_RING01);
0164         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION03_RING02);
0165         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION03);
0166         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION04_RING01);
0167         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION04_RING02);
0168         parameters.push_back(h::PAR_CSC_SIDEMINUS_STATION04);
0169         parameters.push_back(h::PAR_CSC_SIDEMINUS);
0170         parameters.push_back(h::PAR_REPORT_SUMMARY);
0171 
0172         for (size_t i = 0; i < parameters.size(); i++) {
0173           ParHistoDef histoD(parameters[i]);
0174           auto histodef = HistoDef(parameters[i]);
0175           HistoBookRequest req(histodef, config->getFOLDER_PAR(), -1.0f);
0176           MonitorObject* me = provider->bookMonitorObject(req);
0177           cache.put(histoD, me);
0178         }
0179       }
0180     }
0181 
0182     processor.init();
0183   }
0184 
0185   /**
0186  * @brief  Mask HW elements from the efficiency calculations. Can be applied on runtime!
0187  * @param  tokens String tokens of the HW elements
0188  * @return elements masked
0189  */
0190   unsigned int Dispatcher::maskHWElements(std::vector<std::string>& tokens) {
0191     return processorFract.maskHWElements(tokens);
0192   }
0193 
0194   /**
0195  * @brief  Global get MO function. If request has reached this function it means that histo is not in cache!
0196  * @param  histoD Histogram Definition to get
0197  * @param  me MO to return
0198  * @return true if me found and filled, false - otherwise
0199  */
0200   const bool Dispatcher::getHisto(const HistoDef& histoD, MonitorObject*& me) {
0201     /** For the first FED - book general */
0202     if (typeid(histoD) == FEDHistoDefT && !cache.isBookedFED(histoD.getFEDId())) {
0203       collection.bookFEDHistos(histoD.getFEDId());
0204       if (cache.get(histoD, me))
0205         return true;
0206     }
0207 
0208     /** For the first DDU - book general */
0209     if (typeid(histoD) == DDUHistoDefT && !cache.isBookedDDU(histoD.getDDUId())) {
0210       collection.bookDDUHistos(histoD.getDDUId());
0211       if (cache.get(histoD, me))
0212         return true;
0213     }
0214 
0215     /** For the first and specific CSCs - book general and specific */
0216     if (typeid(histoD) == CSCHistoDefT) {
0217       if (!cache.isBookedCSC(histoD.getCrateId(), histoD.getDMBId())) {
0218         collection.bookCSCHistos(histoD.getCrateId(), histoD.getDMBId());
0219         /** cache.printContent(); */
0220       }
0221       if (collection.isOnDemand(histoD.getHistoName())) {
0222         collection.bookCSCHistos(histoD.getId(), histoD.getCrateId(), histoD.getDMBId(), histoD.getAddId());
0223       }
0224       if (cache.get(histoD, me))
0225         return true;
0226     }
0227 
0228     /** For the Parameters - book parameter histogram */
0229     if (typeid(histoD) == ParHistoDefT) {
0230       HistoBookRequest req(histoD, config->getFOLDER_PAR(), -1.0f);
0231       me = provider->bookMonitorObject(req);
0232       cache.put(histoD, me);
0233       return true;
0234     }
0235 
0236     /** If not found after booking - mark it as not existent */
0237     cache.put(histoD, nullptr);
0238 
0239     return false;
0240   }
0241 
0242   /**
0243  * @brief  Automatically called fraction and efficiency MOs update function
0244  * @return
0245  */
0246   void Dispatcher::updateFractionAndEfficiencyHistosAuto() {
0247     if (config->getFRAEFF_AUTO_UPDATE() && (config->getNEventsCSC() >= config->getFRAEFF_AUTO_UPDATE_START()) &&
0248         (config->getNEventsCSC() % config->getFRAEFF_AUTO_UPDATE_FREQ()) == 0) {
0249       updateFractionAndEfficiencyHistos();
0250     }
0251   }
0252 
0253   /**
0254  * @brief  On demand update fraction and efficiency MOs
0255  * @return
0256  */
0257   void Dispatcher::updateFractionAndEfficiencyHistos() {
0258     LockType lock(processorFract.mutex);
0259     if (config->getFRAEFF_SEPARATE_THREAD()) {
0260       std::function<void()> fnUpdate =
0261           std::bind(&EventProcessorMutex::updateFractionAndEfficiencyHistos, &processorFract);
0262 #ifdef DQMMT
0263       threads.create_thread(std::ref(fnUpdate));
0264 #else
0265       fnUpdate();
0266 #endif
0267     } else {
0268       processorFract.updateFractionAndEfficiencyHistos();
0269     }
0270   }
0271 
0272   /**
0273  * @brief  Set HW Standby modes
0274  * @return
0275  */
0276   void Dispatcher::processStandby(HWStandbyType& standby) {
0277     LockType lock(processorFract.mutex);
0278     if (config->getFRAEFF_SEPARATE_THREAD()) {
0279       std::function<void(HWStandbyType&)> fnUpdate =
0280           std::bind(&EventProcessorMutex::processStandby, &processorFract, std::placeholders::_1);
0281 #ifdef DQMMT
0282       threads.create_thread(std::ref(fnUpdate));
0283 #else
0284       fnUpdate(standby);
0285 #endif
0286     } else {
0287       processorFract.processStandby(standby);
0288     }
0289   }
0290 
0291 #ifdef DQMLOCAL
0292 
0293   /**
0294  * @brief  Process event (Local DQM)
0295  * @param  data Event Data buffer
0296  * @param  dataSize Event Data buffer size
0297  * @param  errorStat Error status received by reading DAQ buffer
0298  * @param  nodeNumber DAQ node number
0299  * @return
0300  */
0301   void Dispatcher::processEvent(const char* data,
0302                                 const int32_t dataSize,
0303                                 const uint32_t errorStat,
0304                                 const int32_t nodeNumber) {
0305     config->eventProcessTimer(true);
0306     processor.processEvent(data, dataSize, errorStat, nodeNumber);
0307     config->eventProcessTimer(false);
0308     updateFractionAndEfficiencyHistosAuto();
0309   }
0310 
0311 #endif
0312 
0313 #ifdef DQMGLOBAL
0314 
0315   /**
0316  * @brief  Process event (Global DQM)
0317  * @param  e Event object
0318  * @param  inputTag Tag to search Event Data in
0319  * @return
0320  */
0321   void Dispatcher::processEvent(const edm::Event& e, const edm::InputTag& inputTag, HWStandbyType& standby) {
0322     config->eventProcessTimer(true);
0323 
0324     // Consider standby information
0325     if (standby.process) {
0326       // Set in full standby once at the start. Afterwards - no!
0327       // i.e. if we ever in the run have gone off standby - this value is false
0328       config->setIN_FULL_STANDBY(config->getIN_FULL_STANDBY() && standby.fullStandby());
0329 
0330       //std::cout << "standby.MeP = " << standby.MeP << "\n";
0331       //std::cout << "standby.MeM = " << standby.MeM << "\n";
0332       //std::cout << "standby.fullStandby() = " << standby.fullStandby() << "\n";
0333       //std::cout << "config->getIN_FULL_STANDBY = " << config->getIN_FULL_STANDBY() << "\n";
0334 
0335       processStandby(standby);
0336 
0337       // We do not fill histograms in full standby!
0338       if (standby.fullStandby()) {
0339         return;
0340       }
0341     }
0342 
0343     processor.processEvent(e, inputTag);
0344 
0345     config->eventProcessTimer(false);
0346 
0347     updateFractionAndEfficiencyHistosAuto();
0348   }
0349 
0350 #endif
0351 
0352 }  // namespace cscdqm