Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  * =====================================================================================
0003  *
0004  *       Filename:  CSCDQM_Cache.h
0005  *
0006  *    Description:  Efficiently manages lists of MonitorObject's for internal
0007  *    MO cache.
0008  *
0009  *        Version:  1.0
0010  *        Created:  11/27/2008 10:05:00 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_Cache_H
0021 #define CSCDQM_Cache_H
0022 
0023 #include <map>
0024 #include <boost/multi_index_container.hpp>
0025 #include <boost/multi_index/member.hpp>
0026 #include <boost/multi_index/composite_key.hpp>
0027 #include <boost/multi_index/ordered_index.hpp>
0028 #include "boost/tuple/tuple.hpp"
0029 
0030 #include "CSCDQM_Logger.h"
0031 #include "CSCDQM_HistoDef.h"
0032 #include "CSCDQM_MonitorObject.h"
0033 #include "CSCDQM_Utility.h"
0034 
0035 namespace cscdqm {
0036 
0037   /** @brief Chamber MO List object definition */
0038   struct CSCHistoKeyType {
0039     HistoId id;
0040     HwId addId;
0041     const MonitorObject* mo;
0042     CSCHistoKeyType(const HistoId& id_, const HwId& addId_, const MonitorObject* mo_)
0043         : id(id_), addId(addId_), mo(mo_) {}
0044   };
0045 
0046   /** Chamber MO List definition */
0047   typedef boost::multi_index_container<
0048       CSCHistoKeyType,
0049       boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::composite_key<
0050           CSCHistoKeyType,
0051           boost::multi_index::member<CSCHistoKeyType, HistoId, &CSCHistoKeyType::id>,
0052           boost::multi_index::member<CSCHistoKeyType, HwId, &CSCHistoKeyType::addId> > > > >
0053       CSCHistoMapType;
0054 
0055   /** @brief Chamber List object definition */
0056   struct CSCKeyType {
0057     HwId crateId;
0058     HwId dmbId;
0059     CSCHistoMapType mos;
0060     CSCKeyType(const HwId& crateId_, const HwId& dmbId_) : crateId(crateId_), dmbId(dmbId_) {}
0061   };
0062 
0063   /** Chamber List definition */
0064   typedef boost::multi_index_container<
0065       CSCKeyType,
0066       boost::multi_index::indexed_by<boost::multi_index::ordered_unique<
0067           boost::multi_index::composite_key<CSCKeyType,
0068                                             boost::multi_index::member<CSCKeyType, HwId, &CSCKeyType::crateId>,
0069                                             boost::multi_index::member<CSCKeyType, HwId, &CSCKeyType::dmbId> > > > >
0070       CSCMapType;
0071 
0072   /** FED List definition (static MO list) */
0073   typedef std::map<HwId, MonitorObject**> FEDMapType;
0074 
0075   /** DDU List definition (static MO list) */
0076   typedef std::map<HwId, MonitorObject**> DDUMapType;
0077 
0078   /** @brief MO Lookup List object definition */
0079   struct LookupKeyType {
0080     HistoDef histo;
0081     std::string path;
0082     MonitorObject* mo;
0083     LookupKeyType(const HistoDef& histo_, MonitorObject*& mo_) : histo(histo_), mo(mo_) { path = histo.getPath(); }
0084   };
0085 
0086   /** MO Lookup List definition */
0087   typedef boost::multi_index_container<
0088       LookupKeyType,
0089       boost::multi_index::indexed_by<
0090           boost::multi_index::ordered_unique<boost::multi_index::member<LookupKeyType, HistoDef, &LookupKeyType::histo> >,
0091           boost::multi_index::ordered_non_unique<
0092               boost::multi_index::member<LookupKeyType, std::string, &LookupKeyType::path> > > >
0093       LookupMapType;
0094 
0095   /**
0096    * @class Cache
0097    * @brief MonitorObject cache - list objects and routines to manage cache
0098    */
0099   class Cache {
0100   private:
0101     /** EMU and PAR MO static List */
0102     MonitorObject* data[h::namesSize];
0103 
0104     /** FED MO List */
0105     FEDMapType fedData;
0106     /** Pointer to the Last FED object used (cached) */
0107     FEDMapType::const_iterator fedPointer;
0108     /** Last FED id used (cached) */
0109     HwId fedPointerValue;
0110 
0111     /** DDU MO List */
0112     DDUMapType dduData;
0113     /** Pointer to the Last DDU object used (cached) */
0114     DDUMapType::const_iterator dduPointer;
0115     /** Last DDU id used (cached) */
0116     HwId dduPointerValue;
0117 
0118     /** Chamber MO List */
0119     CSCMapType cscData;
0120     /** Pointer to the Last Chamber object used (cached) */
0121     CSCMapType::const_iterator cscPointer;
0122 
0123     /** MO Lookup List */
0124     LookupMapType lookupData;
0125 
0126   public:
0127     /** Cache Constructor */
0128     Cache() {
0129       /** Initialize EMU and PAR static array with zero's */
0130       for (unsigned int i = 0; i < h::namesSize; i++)
0131         data[i] = nullptr;
0132 
0133       /** Initialize FED cached pointers */
0134       fedPointer = fedData.end();
0135       fedPointerValue = 0;
0136 
0137       /** Initialize DDU and CSC cached pointers */
0138       dduPointer = dduData.end();
0139       dduPointerValue = 0;
0140       cscPointer = cscData.end();
0141     }
0142 
0143     /** Destructor */
0144     ~Cache() {
0145       /** Clear FED MO static arrays */
0146       while (fedData.begin() != fedData.end()) {
0147         if (fedData.begin()->second) {
0148           delete[] fedData.begin()->second;
0149         }
0150         fedData.erase(fedData.begin());
0151       }
0152 
0153       /** Clear DDU MO static arrays */
0154       while (dduData.begin() != dduData.end()) {
0155         if (dduData.begin()->second) {
0156           delete[] dduData.begin()->second;
0157         }
0158         dduData.erase(dduData.begin());
0159       }
0160     }
0161 
0162     /** Native Cache methods */
0163 
0164     const bool get(const HistoDef& histo, MonitorObject*& mo);
0165     const bool getEMU(const HistoId& id, MonitorObject*& mo);
0166     const bool getFED(const HistoId& id, const HwId& fedId, MonitorObject*& mo);
0167     const bool getDDU(const HistoId& id, const HwId& dduId, MonitorObject*& mo);
0168     const bool getCSC(const HistoId& id, const HwId& crateId, const HwId& dmbId, const HwId& addId, MonitorObject*& mo);
0169     const bool getPar(const HistoId& id, MonitorObject*& mo);
0170     void put(const HistoDef& histo, MonitorObject* mo);
0171 
0172     /** Utility methods */
0173 
0174     const bool nextBookedFED(unsigned int& n, unsigned int& fedId) const;
0175     const bool nextBookedDDU(unsigned int& n, unsigned int& dduId) const;
0176     const bool nextBookedCSC(unsigned int& n, unsigned int& crateId, unsigned int& dmbId) const;
0177     const bool isBookedCSC(const HwId& crateId, const HwId& dmbId) const;
0178     const bool isBookedDDU(const HwId& dduId) const;
0179     const bool isBookedFED(const HwId& fedId) const;
0180   };
0181 
0182 }  // namespace cscdqm
0183 
0184 #endif