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.cc
0005  *
0006  *    Description:  MonitorObject cache implementation
0007  *
0008  *        Version:  1.0
0009  *        Created:  12/01/2008 11:36:11 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_Cache.h"
0020 
0021 namespace cscdqm {
0022 
0023   /**
0024    * @brief  Get Monitoring Object on Histogram Definition
0025    * @param  histo Histogram definition
0026    * @param  mo Monitoring Object to return
0027    * @return true if MO was found in cache and false otherwise
0028    */
0029   const bool Cache::get(const HistoDef& histo, MonitorObject*& mo) {
0030     if (typeid(histo) == EMUHistoDefT) {
0031       return getEMU(histo.getId(), mo);
0032     } else if (typeid(histo) == FEDHistoDefT) {
0033       return getFED(histo.getId(), histo.getFEDId(), mo);
0034     } else if (typeid(histo) == DDUHistoDefT) {
0035       return getDDU(histo.getId(), histo.getDDUId(), mo);
0036     } else if (typeid(histo) == CSCHistoDefT) {
0037       return getCSC(histo.getId(), histo.getCrateId(), histo.getDMBId(), histo.getAddId(), mo);
0038     } else if (typeid(histo) == ParHistoDefT) {
0039       return getPar(histo.getId(), mo);
0040     }
0041 
0042     return false;
0043   }
0044 
0045   /**
0046    * @brief  Get EMU MO on Histogram Id
0047    * @param  id Histogram identifier
0048    * @param  mo Monitoring Object to return
0049    * @return true if MO was found in cache and false otherwise
0050    */
0051   const bool Cache::getEMU(const HistoId& id, MonitorObject*& mo) {
0052     if (data[id]) {
0053       mo = data[id];
0054       return true;
0055     }
0056     return false;
0057   }
0058 
0059   /**
0060    * @brief  Get FED MO on Histogram Id and FED Id
0061    * @param  id Histogram identifier
0062    * @param  fedId FED identifier
0063    * @param  mo Monitoring Object to return
0064    * @return true if MO was found in cache and false otherwise
0065    */
0066   const bool Cache::getFED(const HistoId& id, const HwId& fedId, MonitorObject*& mo) {
0067     /** If not cached (last FED) - find FED */
0068     if (fedPointerValue != fedId) {
0069       fedPointer = fedData.find(fedId);
0070       if (fedPointer == fedData.end()) {
0071         fedPointerValue = 0;
0072         return false;
0073       }
0074       fedPointerValue = fedId;
0075     }
0076 
0077     /** Get MO from static array */
0078     if (fedPointer->second[id]) {
0079       mo = fedPointer->second[id];
0080       return true;
0081     }
0082     return false;
0083   }
0084 
0085   /**
0086    * @brief  Get DDU MO on Histogram Id and DDU Id
0087    * @param  id Histogram identifier
0088    * @param  dduId DDU identifier
0089    * @param  mo Monitoring Object to return
0090    * @return true if MO was found in cache and false otherwise
0091    */
0092   const bool Cache::getDDU(const HistoId& id, const HwId& dduId, MonitorObject*& mo) {
0093     /** If not cached (last DDU) - find DDU */
0094     if (dduPointerValue != dduId) {
0095       dduPointer = dduData.find(dduId);
0096       if (dduPointer == dduData.end()) {
0097         dduPointerValue = 0;
0098         return false;
0099       }
0100       dduPointerValue = dduId;
0101     }
0102 
0103     /** Get MO from static array */
0104     if (dduPointer->second[id]) {
0105       mo = dduPointer->second[id];
0106       return true;
0107     }
0108     return false;
0109   }
0110 
0111   /**
0112    * @brief  Get CSC MO on Histogram Id and CSC Crate and DMB Ids
0113    * @param  id Histogram identifier
0114    * @param  crateId CSC Crate identifier
0115    * @param  dmbId CSC DMB identifier
0116    * @param  mo Monitoring Object to return
0117    * @return true if MO was found in cache and false otherwise
0118    */
0119   const bool Cache::getCSC(
0120       const HistoId& id, const HwId& crateId, const HwId& dmbId, const HwId& addId, MonitorObject*& mo) {
0121     /** If not cached (last CSC) - find CSC */
0122     if (cscPointer == cscData.end() || cscPointer->crateId != crateId || cscPointer->dmbId != dmbId) {
0123       cscPointer = cscData.find(boost::make_tuple(crateId, dmbId));
0124     }
0125 
0126     /** Get Monitor object from multi_index List */
0127     if (cscPointer != cscData.end()) {
0128       CSCHistoMapType::const_iterator hit = cscPointer->mos.find(boost::make_tuple(id, addId));
0129       if (hit != cscPointer->mos.end()) {
0130         mo = const_cast<MonitorObject*>(hit->mo);
0131         return true;
0132       }
0133     }
0134     return false;
0135   }
0136 
0137   /**
0138    * @brief  Get Parameter MO on Histogram Id
0139    * @param  id Histogram identifier
0140    * @param  mo Monitoring Object to return
0141    * @return true if MO was found in cache and false otherwise
0142    */
0143   const bool Cache::getPar(const HistoId& id, MonitorObject*& mo) {
0144     if (data[id]) {
0145       mo = data[id];
0146       return true;
0147     }
0148     return false;
0149   }
0150 
0151   /**
0152    * @brief  Put Monitoring Object into cache
0153    * @param  histo Histogram Definition
0154    * @param  mo Monitoring Object to put
0155    * @return
0156    */
0157   void Cache::put(const HistoDef& histo, MonitorObject* mo) {
0158     HistoId id = histo.getId();
0159 
0160     /** EMU MO */
0161     if (typeid(histo) == EMUHistoDefT) {
0162       data[id] = mo;
0163     } else
0164 
0165       /** FED MO */
0166       if (typeid(histo) == FEDHistoDefT) {
0167         HwId fedId = histo.getFEDId();
0168 
0169         if (fedPointerValue != fedId) {
0170           fedPointer = fedData.find(fedId);
0171         }
0172 
0173         if (fedPointer == fedData.end()) {
0174           MonitorObject** mos = new MonitorObject*[h::namesSize];
0175           for (unsigned int i = 0; i < h::namesSize; i++)
0176             mos[i] = nullptr;
0177           fedPointer = fedData.insert(fedData.end(), std::make_pair(fedId, mos));
0178         }
0179 
0180         fedPointer->second[id] = mo;
0181         fedPointerValue = fedId;
0182 
0183       } else
0184 
0185         /** DDU MO */
0186         if (typeid(histo) == DDUHistoDefT) {
0187           HwId dduId = histo.getDDUId();
0188 
0189           if (dduPointerValue != dduId) {
0190             dduPointer = dduData.find(dduId);
0191           }
0192 
0193           if (dduPointer == dduData.end()) {
0194             MonitorObject** mos = new MonitorObject*[h::namesSize];
0195             for (unsigned int i = 0; i < h::namesSize; i++)
0196               mos[i] = nullptr;
0197             dduPointer = dduData.insert(dduData.end(), std::make_pair(dduId, mos));
0198           }
0199 
0200           dduPointer->second[id] = mo;
0201           dduPointerValue = dduId;
0202 
0203         } else
0204 
0205           /** CSC MO */
0206           if (typeid(histo) == CSCHistoDefT) {
0207             HwId crateId = histo.getCrateId();
0208             HwId dmbId = histo.getDMBId();
0209             HwId addId = histo.getAddId();
0210 
0211             CSCHistoKeyType histoKey(id, addId, mo);
0212 
0213             if (cscPointer == cscData.end() || cscPointer->crateId != crateId || cscPointer->dmbId != dmbId) {
0214               cscPointer = cscData.find(boost::make_tuple(crateId, dmbId));
0215             }
0216 
0217             if (cscPointer == cscData.end()) {
0218               CSCKeyType cscKey(crateId, dmbId);
0219               cscPointer = cscData.insert(cscData.end(), cscKey);
0220             }
0221             CSCHistoMapType* mos = const_cast<CSCHistoMapType*>(&cscPointer->mos);
0222             mos->insert(histoKey);
0223 
0224           } else
0225 
0226             /** Parameter MO */
0227             if (typeid(histo) == ParHistoDefT) {
0228               data[id] = mo;
0229             }
0230 
0231     /** Add histo (if mo is not null!) into lookup list */
0232     if (mo) {
0233       lookupData.insert(lookupData.end(), LookupKeyType(histo, mo));
0234     }
0235   }
0236 
0237   /**
0238    * @brief  Iterator to get booked CSC identifiers on enumerator
0239    * @param  n iterator (0 and up)
0240    * @param  crateId CSC Crate Id returned
0241    * @param  dmbId CSC DMB Id returned
0242    * @return true if CSC on n found, false - otherwise
0243    */
0244   const bool Cache::nextBookedCSC(unsigned int& n, unsigned int& crateId, unsigned int& dmbId) const {
0245     if (n < cscData.size()) {
0246       CSCMapType::const_iterator iter = cscData.begin();
0247       for (unsigned int i = n; i > 0; i--)
0248         iter++;
0249       crateId = iter->crateId;
0250       dmbId = iter->dmbId;
0251       n++;
0252       return true;
0253     }
0254     return false;
0255   }
0256 
0257   /**
0258    * @brief  Iterator to get booked FED identifier on enumerator
0259    * @param  n iterator (0 and up)
0260    * @param  fedId FED Id returned
0261    * @return true if FED on n found, false - otherwise
0262    */
0263   const bool Cache::nextBookedFED(unsigned int& n, unsigned int& fedId) const {
0264     if (n < fedData.size()) {
0265       FEDMapType::const_iterator iter = fedData.begin();
0266       for (unsigned int i = n; i > 0; i--)
0267         iter++;
0268       fedId = iter->first;
0269       n++;
0270       return true;
0271     }
0272     return false;
0273   }
0274 
0275   /**
0276    * @brief  Iterator to get booked DDU identifier on enumerator
0277    * @param  n iterator (0 and up)
0278    * @param  dduId DDU Id returned
0279    * @return true if DDU on n found, false - otherwise
0280    */
0281   const bool Cache::nextBookedDDU(unsigned int& n, unsigned int& dduId) const {
0282     if (n < dduData.size()) {
0283       DDUMapType::const_iterator iter = dduData.begin();
0284       for (unsigned int i = n; i > 0; i--)
0285         iter++;
0286       dduId = iter->first;
0287       n++;
0288       return true;
0289     }
0290     return false;
0291   }
0292 
0293   /**
0294    * @brief  Check if CSC was booked on given identifiers 
0295    * @param  crateId CSC Crate Id
0296    * @param  dmbId CSC DMB Id
0297    * @return true if CSC was booked, false - otherwise
0298    */
0299   const bool Cache::isBookedCSC(const HwId& crateId, const HwId& dmbId) const {
0300     CSCMapType::const_iterator it = cscData.find(boost::make_tuple(crateId, dmbId));
0301     if (it != cscData.end()) {
0302       return true;
0303     }
0304     return false;
0305   }
0306 
0307   /**
0308    * @brief  Check if FED was booked on given identifier 
0309    * @param  fedId FED Id
0310    * @return true if FED was booked, false - otherwise
0311    */
0312   const bool Cache::isBookedFED(const HwId& fedId) const {
0313     FEDMapType::const_iterator iter = fedData.find(fedId);
0314     return (iter != fedData.end());
0315   }
0316 
0317   /**
0318    * @brief  Check if DDU was booked on given identifier 
0319    * @param  dduId DDU Id
0320    * @return true if DDU was booked, false - otherwise
0321    */
0322   const bool Cache::isBookedDDU(const HwId& dduId) const {
0323     DDUMapType::const_iterator iter = dduData.find(dduId);
0324     return (iter != dduData.end());
0325   }
0326 
0327 }  // namespace cscdqm