Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 /*
0003  * =====================================================================================
0004  *
0005  *       Filename:  CSCDQM_Dispatcher.h
0006  *
0007  *    Description:  CSCDQM Framework frontend and Histogram Cache controller
0008  *
0009  *        Version:  1.0
0010  *        Created:  10/03/2008 10:26:04 AM
0011  *       Revision:  none
0012  *       Compiler:  gcc
0013  *
0014  *         Author:  Valdas Rapsevicius, valdas.rapsevicius@cern.ch
0015  *        Company:  CERN, CH
0016  *
0017  * =====================================================================================
0018  */
0019 
0020 #ifndef CSCDQM_Dispatcher_H
0021 #define CSCDQM_Dispatcher_H
0022 
0023 #include <typeinfo>
0024 
0025 #ifdef DQMMT
0026 #include <boost/thread.hpp>
0027 #endif
0028 
0029 #include "CSCDQM_Configuration.h"
0030 #include "CSCDQM_EventProcessor.h"
0031 #include "CSCDQM_Collection.h"
0032 #include "CSCDQM_HistoDef.h"
0033 #include "CSCDQM_Cache.h"
0034 #include "CSCDQM_Logger.h"
0035 #include "CSCDQM_Lock.h"
0036 
0037 namespace cscdqm {
0038 
0039   /**
0040    * @class EventProcessorMutex
0041    * @brief Locking object (wrapper) that holds a separate EventProcessor. This
0042    * object can be used (theoretically) in separate thread.
0043    */
0044   class EventProcessorMutex : public Lock {
0045   private:
0046     /** Local (wrapped) event processor */
0047     EventProcessor processor;
0048 
0049     /** Global Configuration */
0050     Configuration* config;
0051 
0052     /** If full standby was already processed? */
0053     bool fullStandbyProcessed;
0054 
0055     /** Last standby value. To be checked for HV changes */
0056     HWStandbyType lastStandby;
0057 
0058   public:
0059     /**
0060        * @brief  Constructor.
0061        * @param  p_config Pointer to Global Configuration
0062        */
0063     EventProcessorMutex(Configuration* const p_config) : processor(p_config) {
0064       config = p_config;
0065       fullStandbyProcessed = false;
0066     }
0067 
0068     /**
0069        * @brief  Update Fraction and Efficiency histograms
0070        * @return 
0071        */
0072     void updateFractionAndEfficiencyHistos() {
0073       LockType lock(mutex);
0074       config->updateFraTimer(true);
0075       processor.updateFractionHistos();
0076       config->updateFraTimer(false);
0077       if (config->getPROCESS_EFF_HISTOS()) {
0078         config->updateEffTimer(true);
0079         processor.updateEfficiencyHistos();
0080         config->updateEffTimer(false);
0081       }
0082     }
0083 
0084     /**
0085         * @brief  Mask HW elements from the efficiency calculations. Can be applied on runtime!
0086         * @param  tokens String tokens of the HW elements
0087         * @return elements masked
0088         */
0089     unsigned int maskHWElements(std::vector<std::string>& tokens) { return processor.maskHWElements(tokens); }
0090 
0091     /**
0092        * @brief  Process standby information
0093        * @param  standby Standby information
0094        */
0095     void processStandby(HWStandbyType& standby) {
0096       if (lastStandby != standby) {
0097         processor.standbyEfficiencyHistos(standby);
0098         if (config->getIN_FULL_STANDBY()) {
0099           // Lets mark CSCs as BAD - have not ever ever been in !STANDBY
0100           if (!fullStandbyProcessed) {
0101             processor.standbyEfficiencyHistos(standby);
0102             processor.writeShifterHistograms();
0103             fullStandbyProcessed = true;
0104           }
0105         }
0106         lastStandby = standby;
0107       }
0108     }
0109   };
0110 
0111   /**
0112    * @class Dispatcher
0113    * @brief CSCDQM Framework frontend and Histogram Cache controller
0114    */
0115   class Dispatcher {
0116   public:
0117     Dispatcher(Configuration* const p_config, MonitorObjectProvider* const p_provider);
0118 
0119 #ifdef DQMGLOBAL
0120     Dispatcher(Configuration* const p_config,
0121                MonitorObjectProvider* const p_provider,
0122                const edm::InputTag& itag,
0123                edm::ConsumesCollector&& coco);
0124 #endif
0125 
0126     /**
0127        * @brief  Destructor. Joins and waits to complete all threads.
0128        */
0129     ~Dispatcher() {
0130 #ifdef DQMMT
0131       threads.join_all();
0132 #endif
0133     }
0134 
0135     void init();
0136     void book();
0137     void updateFractionAndEfficiencyHistos();
0138     const bool getHisto(const HistoDef& histoD, MonitorObject*& me);
0139     unsigned int maskHWElements(std::vector<std::string>& tokens);
0140     void processStandby(HWStandbyType& standby);
0141 
0142   private:
0143     // Old content of ctor into separate function so it can be called by both ctors
0144     void commonConstruct(Configuration* const p_config, MonitorObjectProvider* const p_provider);
0145 
0146     void updateFractionAndEfficiencyHistosAuto();
0147 
0148     /** Pointer to Global Configuration */
0149     Configuration* config;
0150 
0151     /** Pointer to MO provider */
0152     MonitorObjectProvider* provider;
0153 
0154     /** MO Collection object */
0155     Collection collection;
0156 
0157     /** Event Processor object */
0158     EventProcessor processor;
0159 
0160     /** MO Cache object */
0161     Cache cache;
0162 
0163     /** Lockable Fractional and Efficiency MO update object */
0164     EventProcessorMutex processorFract;
0165 
0166 #ifdef DQMMT
0167 
0168     /** Thread group to store all threads created by Dispatcher */
0169     boost::thread_group threads;
0170 
0171 #endif
0172 
0173 #ifdef DQMLOCAL
0174 
0175   public:
0176     void processEvent(const char* data, const int32_t dataSize, const uint32_t errorStat, const int32_t nodeNumber);
0177 
0178 #endif
0179 
0180 #ifdef DQMGLOBAL
0181 
0182   public:
0183     void processEvent(const edm::Event& e, const edm::InputTag& inputTag, HWStandbyType& standby);
0184 
0185 #endif
0186   };
0187 
0188 }  // namespace cscdqm
0189 
0190 #endif