Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:57

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