Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  HistoDef.h
0005  *
0006  *    Description:  Histo Type Classes that are being used by EventProcessor
0007  *    to request histograms. 
0008  *
0009  *        Version:  1.0
0010  *        Created:  10/03/2008 11:54:31 AM
0011  *       Revision:  none
0012  *       Compiler:  gcc
0013  *
0014  *         Author:  Valdas Rapsevicius (VR), Valdas.Rapsevicius@cern.ch
0015  *        Company:  CERN, CH
0016  *
0017  * =====================================================================================
0018  */
0019 
0020 #ifndef CSCDQM_HistoDef_H
0021 #define CSCDQM_HistoDef_H
0022 
0023 #include <string>
0024 #include <iostream>
0025 
0026 #include "CSCDQM_Utility.h"
0027 #include "CSCDQM_Logger.h"
0028 
0029 namespace cscdqm {
0030 
0031   /** Type for histogram name constants */
0032   typedef std::string HistoName;
0033 
0034   /** Type for histogram id constants */
0035   typedef unsigned int HistoId;
0036 
0037   /** Type for detector component (HW) id parameters */
0038   typedef unsigned int HwId;
0039 
0040   namespace h {
0041     /** Histogram value that implies to skip the histogram */
0042     const HistoName HISTO_SKIP = "0";
0043   }  // namespace h
0044 
0045   /** DDU path pattern. Argument is FED ID */
0046   static const char PATH_FED[] = "FED_%03d";
0047 
0048   /** DDU path pattern. Argument is DDU ID */
0049   static const char PATH_DDU[] = "DDU_%02d";
0050 
0051   /** CSC path pattern. Arguments are Create ID and DMB ID */
0052   static const char PATH_CSC[] = "CSC_%03d_%02d";
0053 
0054   static const TPRegexp REGEXP_ONDEMAND("^.*%d.*$");
0055 
0056 #include "CSCDQM_HistoNames.icc"
0057 
0058   /**
0059    * @class HistoDef
0060    * @brief Abstract Base Histogram Definition
0061    */
0062   class HistoDef {
0063   private:
0064     /** Histogram Id */
0065     HistoId id;
0066 
0067   public:
0068     /**
0069        * @brief  Base constructor
0070        * @param  p_hname Raw histogram name by HistoName
0071        * @return 
0072        */
0073     HistoDef(const HistoId p_id) : id(p_id) {}
0074 
0075     /**
0076        * @brief  Base virtual destructor
0077        */
0078     virtual ~HistoDef() {}
0079 
0080     /**
0081        * @brief  Get Histogram ID
0082        * @return Histogram ID
0083        */
0084     const HistoId getId() const { return id; }
0085 
0086     /**
0087        * @brief  Get raw histogram name
0088        * @return Raw histogram name
0089        */
0090     const HistoName& getHistoName() const { return h::names[id]; }
0091 
0092     /**
0093        * @brief  Get processed histogram name. It can include additional
0094        * parameter in formated name. This Name is being constructed from raw
0095        * name and additional parameter. 
0096        * @return processed full name of the histogram
0097        */
0098     virtual const std::string getName() const { return getHistoName(); }
0099 
0100     /**
0101        * @brief  Get full path of the histogram. It is being constructed by
0102        * appending path and histogam name. 
0103        * @return full path name of the histogram (processed)
0104        */
0105     const std::string getFullPath() const {
0106       std::string path(getPath());
0107       if (!path.empty())
0108         path.append("/");
0109       path.append(getName());
0110       return path;
0111     }
0112 
0113     /**
0114        * @brief  Comparison (==) operator
0115        * @param  t Histogram to be compared to
0116        * @return true if HistoDefs match, false - otherwise
0117        */
0118     const bool operator==(const HistoDef& t) const {
0119       if (getId() != t.getId())
0120         return false;
0121       if (getFEDId() != t.getFEDId())
0122         return false;
0123       if (getDDUId() != t.getDDUId())
0124         return false;
0125       if (getCrateId() != t.getCrateId())
0126         return false;
0127       if (getDMBId() != t.getDMBId())
0128         return false;
0129       if (getAddId() != t.getAddId())
0130         return false;
0131       return true;
0132     }
0133 
0134     /**
0135        * @brief  Assignment (=) operator
0136        * @param  t Histogram to be taken data from
0137        * @return resulting histogram (this)
0138        */
0139     const HistoDef& operator=(const HistoDef& t) {
0140       id = t.getId();
0141       return *this;
0142     }
0143 
0144     /**
0145        * @brief  Less (<) operator
0146        * @param  t Histogram to be compared to
0147        * @return true if t is "more" than this
0148        */
0149     const bool operator<(const HistoDef& t) const {
0150       if (getId() < t.getId())
0151         return true;
0152       if (getFEDId() < t.getFEDId())
0153         return true;
0154       if (getDDUId() < t.getDDUId())
0155         return true;
0156       if (getCrateId() < t.getCrateId())
0157         return true;
0158       if (getDMBId() < t.getDMBId())
0159         return true;
0160       if (getAddId() < t.getAddId())
0161         return true;
0162       return false;
0163     }
0164 
0165     /**
0166        * @brief  Printing (<<) operator that prints hisotgram full path
0167        * @param  out output stream
0168        * @param  t Histogram type to be printed
0169        * @return output stream
0170        */
0171     friend std::ostream& operator<<(std::ostream& out, const HistoDef& t) { return out << t.getFullPath(); }
0172 
0173     /**
0174        * @brief  Get path part of the histogram (used only for DDUs and CSCs) 
0175        * @return path part of the histogram
0176        */
0177     virtual const std::string getPath() const { return ""; }
0178 
0179     /**
0180        * @brief  Get CSC Crate ID 
0181        * @return CSC Crate ID
0182        */
0183     virtual const HwId getCrateId() const { return 0; }
0184 
0185     /**
0186        * @brief  Get CSC DMB ID
0187        * @return CSC DMB ID
0188        */
0189     virtual const HwId getDMBId() const { return 0; }
0190 
0191     /**
0192        * @brief  Get CSC Additional ID (used to store Layer, CLCT, ALCT and
0193        * other identifiers.
0194        * @return CSC Additional ID
0195        */
0196     virtual const HwId getAddId() const { return 0; }
0197 
0198     /**
0199        * @brief  Get FED ID
0200        * @return FED ID
0201        */
0202     virtual const HwId getFEDId() const { return 0; }
0203 
0204     /**
0205        * @brief  Get DDU ID
0206        * @return DDU ID
0207        */
0208     virtual const HwId getDDUId() const { return 0; }
0209 
0210     /**
0211        * @brief  Process Title by Adding appropriate ID
0212        * @param  p_title Title to process
0213        * @return processed title
0214        */
0215     virtual const std::string processTitle(const std::string& p_title) const { return p_title; }
0216 
0217     /**
0218        * @brief  Get Histogram ID by name
0219        * @param  p_name Histogram name
0220        * @param  p_id Id to be filled in (return value)
0221        * @return true if ID was found, false - otherwise
0222        */
0223     static const bool getHistoIdByName(const std::string& p_name, HistoId& p_id) {
0224       for (HistoId i = 0; i < h::namesSize; i++) {
0225         if (p_name == h::names[i]) {
0226           p_id = i;
0227           return true;
0228         }
0229       }
0230       return false;
0231     }
0232 
0233     /**
0234        * @brief  Get Histogram key name by id
0235        * @param  p_id Histogram id
0236        * @return Histogram key name
0237        */
0238     static const std::string getHistoKeyById(const HistoId& p_id) { return h::keys[p_id]; }
0239 
0240     /**
0241        * @brief  Process name by applying ID to %d pattern (pattern is stored in REGEXP_ONDEMAND)
0242        * @param  p_name String value to process
0243        * @param  p_id ID to include
0244        * @return processed value
0245        */
0246     static const std::string processName(const HistoName& p_name, const HwId p_id) {
0247       if (Utility::regexMatch(REGEXP_ONDEMAND, p_name)) {
0248         return Form(p_name.c_str(), p_id);
0249       }
0250       return p_name;
0251     }
0252   };
0253 
0254   /**
0255    * @class EMUHistoDef
0256    * @brief EMU Level Histogram Definition
0257    */
0258   class EMUHistoDef : public HistoDef {
0259   public:
0260     /**
0261        * @brief  Constructor. It calls Base constructor inline
0262        * @param  p_id Histogram id (to be passed to Base class)
0263        * @return 
0264        */
0265     EMUHistoDef(const HistoId p_id) : HistoDef(p_id) {}
0266   };
0267 
0268   /**
0269    * @class FEDHistoDef
0270    * @brief FED Level Histogram Definition
0271    */
0272   class FEDHistoDef : public HistoDef {
0273   private:
0274     HwId fedId;
0275 
0276   public:
0277     /**
0278        * @brief  Constructor. It calls Base constructor inline
0279        * @param  p_id Histogram ID (to be passed to Base class)
0280        * @param  p_fedId FED ID
0281        * @return 
0282        */
0283     FEDHistoDef(const HistoId p_id, const HwId p_fedId) : HistoDef(p_id), fedId(p_fedId) {}
0284     const HwId getFEDId() const override { return fedId; }
0285     const std::string getPath() const override { return getPath(fedId); }
0286 
0287     /**
0288        * @brief  Static FED path formatter
0289        * @param  p_fedId FED ID
0290        * @return formatted FED path 
0291        */
0292     static const std::string getPath(const HwId p_fedId) { return Form(PATH_FED, p_fedId); }
0293 
0294     /**
0295        * @brief  Assignment (=) operator. Calls base assignment operator and
0296        * assigns FEd-related data
0297        * @param  t Histogram to be taken data from
0298        * @return resulting histogram (this)
0299        */
0300     const FEDHistoDef& operator=(const FEDHistoDef& t) {
0301       HistoDef* h1 = const_cast<FEDHistoDef*>(this);
0302       const HistoDef* h2 = &t;
0303       *h1 = *h2;
0304       fedId = t.getFEDId();
0305       return *this;
0306     }
0307 
0308     const std::string processTitle(const std::string& p_title) const override {
0309       return processName(p_title, getFEDId());
0310     }
0311   };
0312 
0313   /**
0314    * @class DDUHistoDef
0315    * @brief DDU Level Histogram Definition
0316    */
0317   class DDUHistoDef : public HistoDef {
0318   private:
0319     HwId dduId;
0320 
0321   public:
0322     /**
0323        * @brief  Constructor. It calls Base constructor inline
0324        * @param  p_id Histogram ID (to be passed to Base class)
0325        * @param  p_dduId DDU ID
0326        * @return 
0327        */
0328     DDUHistoDef(const HistoId p_id, const HwId p_dduId) : HistoDef(p_id), dduId(p_dduId) {}
0329     const HwId getDDUId() const override { return dduId; }
0330     const std::string getPath() const override { return getPath(dduId); }
0331 
0332     /**
0333        * @brief  Static DDU path formatter
0334        * @param  p_dduId DDU ID
0335        * @return formatted DDU path 
0336        */
0337     static const std::string getPath(const HwId p_dduId) { return Form(PATH_DDU, p_dduId); }
0338 
0339     /**
0340        * @brief  Assignment (=) operator. Calls base assignment operator and
0341        * assigns DDU-related data
0342        * @param  t Histogram to be taken data from
0343        * @return resulting histogram (this)
0344        */
0345     const DDUHistoDef& operator=(const DDUHistoDef& t) {
0346       HistoDef* h1 = const_cast<DDUHistoDef*>(this);
0347       const HistoDef* h2 = &t;
0348       *h1 = *h2;
0349       dduId = t.getDDUId();
0350       return *this;
0351     }
0352 
0353     const std::string processTitle(const std::string& p_title) const override {
0354       return processName(p_title, getDDUId());
0355     }
0356   };
0357 
0358   /**
0359    * @class CSCHistoDef
0360    * @brief CSC Level Histogram Type
0361    */
0362   class CSCHistoDef : public HistoDef {
0363   private:
0364     /** CSC Crate ID */
0365     HwId crateId;
0366     /** CSC DMB ID */
0367     HwId dmbId;
0368     /** CSC Additional ID */
0369     HwId addId;
0370 
0371   public:
0372     /**
0373        * @brief  Constructor. It calls Base constructor inline
0374        * @param  p_hname Histogram id (to be passed to Base class)
0375        * @param  p_crateId CSC Crate ID
0376        * @param  p_dmbId CSC DMB ID
0377        * @param  p_addId CSC Additional ID, used to store Layer ID, CFEB ID,
0378        * etc. Used to store processed name identifier. Optional.
0379        * @return 
0380        */
0381     CSCHistoDef(const HistoId p_id, const HwId p_crateId, const HwId p_dmbId, const HwId p_addId = 0)
0382         : HistoDef(p_id), crateId(p_crateId), dmbId(p_dmbId), addId(p_addId) {}
0383 
0384     const HwId getCrateId() const override { return crateId; }
0385     const HwId getDMBId() const override { return dmbId; }
0386     const HwId getAddId() const override { return addId; }
0387     const std::string getName() const override { return processName(getHistoName(), getAddId()); }
0388     const std::string getPath() const override { return getPath(crateId, dmbId); }
0389 
0390     /**
0391        * @brief  Static CSC path formatter
0392        * @param  p_crateId CSC Crate ID
0393        * @param  p_dmbId CSC DMB ID
0394        * @return formatted CSC path 
0395        */
0396     static const std::string getPath(const HwId p_crateId, const HwId p_dmbId) {
0397       return Form(PATH_CSC, p_crateId, p_dmbId);
0398     }
0399 
0400     /**
0401        * @brief  Assignment (=) operator. Calls base assignment operator and
0402        * assigns CSC-related data
0403        * @param  t Histogram to be taken data from
0404        * @return resulting histogram (this)
0405        */
0406     const CSCHistoDef& operator=(const CSCHistoDef& t) {
0407       HistoDef* h1 = const_cast<CSCHistoDef*>(this);
0408       const HistoDef* h2 = &t;
0409       *h1 = *h2;
0410       crateId = t.getCrateId();
0411       dmbId = t.getDMBId();
0412       addId = t.getAddId();
0413       return *this;
0414     }
0415 
0416     const std::string processTitle(const std::string& p_title) const override {
0417       return processName(p_title, getAddId());
0418     }
0419   };
0420 
0421   /**
0422    * @class ParHistoDef
0423    * @brief Parameter Histogram Definition
0424    */
0425   class ParHistoDef : public HistoDef {
0426   private:
0427     /**
0428        * @brief  Parameter name
0429        */
0430     HistoName name;
0431 
0432   public:
0433     /**
0434        * @brief  Constructor. It calls Base constructor inline
0435        * @param  p_name Histogram name, id will be constructed by using fastHash algorithm and then to be passed to Base class
0436        * @return 
0437        */
0438     ParHistoDef(const HistoName& p_name) : HistoDef(Utility::fastHash(p_name.c_str())), name(p_name) {}
0439 
0440     /**
0441        * @brief  Constructor. It calls Base constructor inline
0442        * @param  p_id Histogram id (to be passed to Base class)
0443        * @return 
0444        */
0445     ParHistoDef(const HistoId p_id) : HistoDef(p_id) { name = HistoDef::getHistoName(); }
0446 
0447     const HistoName& getHistoName() const { return name; }
0448   };
0449 
0450   static const std::type_info& EMUHistoDefT = typeid(cscdqm::EMUHistoDef);
0451   static const std::type_info& FEDHistoDefT = typeid(cscdqm::FEDHistoDef);
0452   static const std::type_info& DDUHistoDefT = typeid(cscdqm::DDUHistoDef);
0453   static const std::type_info& CSCHistoDefT = typeid(cscdqm::CSCHistoDef);
0454   static const std::type_info& ParHistoDefT = typeid(cscdqm::ParHistoDef);
0455 
0456 }  // namespace cscdqm
0457 
0458 #endif