Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:01

0001 #include "OnlineDB/EcalCondDB/interface/LMFDefFabric.h"
0002 #include "OnlineDB/EcalCondDB/interface/LMFColor.h"
0003 #include "OnlineDB/EcalCondDB/interface/LMFTrigType.h"
0004 #include "OnlineDB/EcalCondDB/interface/LMFRunTag.h"
0005 #include "OnlineDB/EcalCondDB/interface/LMFPrimVers.h"
0006 #include "OnlineDB/EcalCondDB/interface/LMFSeqVers.h"
0007 
0008 #include <iostream>
0009 
0010 LMFDefFabric::LMFDefFabric() { noDebug(); }
0011 
0012 LMFDefFabric::LMFDefFabric(oracle::occi::Environment *env, oracle::occi::Connection *conn) {
0013   noDebug();
0014   setConnection(env, conn);
0015   initialize();
0016 }
0017 
0018 LMFDefFabric::LMFDefFabric(EcalDBConnection *c) {
0019   noDebug();
0020   setConnection(c->getEnv(), c->getConn());
0021   initialize();
0022 }
0023 
0024 LMFDefFabric::~LMFDefFabric() {}
0025 
0026 void LMFDefFabric::debug() { _debug = true; }
0027 
0028 void LMFDefFabric::noDebug() { _debug = false; }
0029 
0030 std::list<LMFColor> LMFDefFabric::getColors() const { return _lmfColors; }
0031 
0032 std::list<LMFTrigType> LMFDefFabric::getTriggerTypes() const { return _lmfTrigTypes; }
0033 
0034 std::list<LMFRunTag> LMFDefFabric::getRunTags() const { return _lmfRunTags; }
0035 
0036 LMFColor LMFDefFabric::getColor(std::string name) const {
0037   std::list<LMFColor>::const_iterator i = _lmfColors.begin();
0038   std::list<LMFColor>::const_iterator e = _lmfColors.end();
0039   LMFColor ret;
0040   bool loop = true;
0041   while ((loop) && (i != e)) {
0042     if (i->getShortName() == name) {
0043       ret = *i;
0044       loop = false;
0045     }
0046     i++;
0047   }
0048   return ret;
0049 }
0050 
0051 LMFColor LMFDefFabric::getColorFromID(int id) const {
0052   std::list<LMFColor>::const_iterator i = _lmfColors.begin();
0053   std::list<LMFColor>::const_iterator e = _lmfColors.end();
0054   LMFColor ret;
0055   bool loop = true;
0056   while ((loop) && (i != e)) {
0057     if (i->getID() == id) {
0058       ret = *i;
0059       loop = false;
0060     }
0061     i++;
0062   }
0063   return ret;
0064 }
0065 
0066 LMFColor LMFDefFabric::getColor(int index) const {
0067   std::list<LMFColor>::const_iterator i = _lmfColors.begin();
0068   std::list<LMFColor>::const_iterator e = _lmfColors.end();
0069   LMFColor ret;
0070   bool loop = true;
0071   while ((loop) && (i != e)) {
0072     if (i->getColorIndex() == index) {
0073       ret = *i;
0074       loop = false;
0075     }
0076     i++;
0077   }
0078   return ret;
0079 }
0080 
0081 int LMFDefFabric::getColorID(std::string sname) const { return getColor(sname).getID(); }
0082 
0083 int LMFDefFabric::getColorID(int index) const { return getColor(index).getID(); }
0084 
0085 int LMFDefFabric::getTrigTypeID(std::string sname) const { return getTrigType(sname).getID(); }
0086 
0087 LMFTrigType LMFDefFabric::getTrigType(std::string sname) const {
0088   std::list<LMFTrigType>::const_iterator i = _lmfTrigTypes.begin();
0089   std::list<LMFTrigType>::const_iterator e = _lmfTrigTypes.end();
0090   LMFTrigType tt;
0091   bool loop = true;
0092   while ((loop) && (i != e)) {
0093     if (i->getShortName() == sname) {
0094       tt = *i;
0095       loop = false;
0096     }
0097     i++;
0098   }
0099   return tt;
0100 }
0101 
0102 LMFTrigType LMFDefFabric::getTrigTypeFromID(int id) const {
0103   std::list<LMFTrigType>::const_iterator i = _lmfTrigTypes.begin();
0104   std::list<LMFTrigType>::const_iterator e = _lmfTrigTypes.end();
0105   LMFTrigType tt;
0106   bool loop = true;
0107   while ((loop) && (i != e)) {
0108     if (i->getID() == id) {
0109       tt = *i;
0110       loop = false;
0111     }
0112     i++;
0113   }
0114   return tt;
0115 }
0116 
0117 LMFRunTag LMFDefFabric::getRunTag(std::string tag, int version) const {
0118   std::list<LMFRunTag>::const_iterator i = _lmfRunTags.begin();
0119   std::list<LMFRunTag>::const_iterator e = _lmfRunTags.end();
0120   LMFRunTag rt;
0121   bool loop = true;
0122   while ((loop) && (i != e)) {
0123     if ((i->getGeneralTag()) == tag && (i->getVersion() == version)) {
0124       rt = *i;
0125     }
0126     i++;
0127   }
0128   return rt;
0129 }
0130 
0131 LMFRunTag LMFDefFabric::getRunTagFromID(int id) const {
0132   std::list<LMFRunTag>::const_iterator i = _lmfRunTags.begin();
0133   std::list<LMFRunTag>::const_iterator e = _lmfRunTags.end();
0134   LMFRunTag rt;
0135   bool loop = true;
0136   while ((loop) && (i != e)) {
0137     if (i->getID() == id) {
0138       rt = *i;
0139     }
0140     i++;
0141   }
0142   return rt;
0143 }
0144 
0145 int LMFDefFabric::getRunTagID(std::string tag, int version) const { return getRunTag(tag, version).getID(); }
0146 
0147 template <typename T, typename U>
0148 inline T &unique_static_cast(U &i) {
0149   return *(static_cast<T *>(i.get()));
0150 }
0151 
0152 void LMFDefFabric::initialize() noexcept(false) {
0153   _lmfColors.clear();
0154   _lmfTrigTypes.clear();
0155   _lmfRunTags.clear();
0156   _lmfPrimVersions.clear();
0157   _lmfSeqVersions.clear();
0158   _lmfCorrVersions.clear();
0159   if ((m_env != nullptr) && (m_conn != nullptr)) {
0160     auto listOfObjects = LMFColor(m_env, m_conn).fetchAll();
0161     auto i = listOfObjects.begin();
0162     auto e = listOfObjects.end();
0163 
0164     while (i != e) {
0165       const LMFColor &c = unique_static_cast<const LMFColor>(*i);
0166       _lmfColors.push_back(c);
0167       i++;
0168     }
0169     listOfObjects.clear();
0170     listOfObjects = LMFTrigType(m_env, m_conn).fetchAll();
0171     i = listOfObjects.begin();
0172     e = listOfObjects.end();
0173     while (i != e) {
0174       const LMFTrigType &c = unique_static_cast<const LMFTrigType>(*i);
0175       _lmfTrigTypes.push_back(c);
0176       i++;
0177     }
0178     listOfObjects.clear();
0179     listOfObjects = LMFRunTag(m_env, m_conn).fetchAll();
0180     i = listOfObjects.begin();
0181     e = listOfObjects.end();
0182     while (i != e) {
0183       const LMFRunTag &c = unique_static_cast<const LMFRunTag>(*i);
0184       _lmfRunTags.push_back(c);
0185       i++;
0186     }
0187     listOfObjects.clear();
0188     listOfObjects = LMFPrimVers(m_env, m_conn).fetchAll();
0189     i = listOfObjects.begin();
0190     e = listOfObjects.end();
0191     while (i != e) {
0192       const LMFPrimVers &c = unique_static_cast<const LMFPrimVers>(*i);
0193       _lmfPrimVersions.push_back(c);
0194       i++;
0195     }
0196     listOfObjects.clear();
0197     listOfObjects = LMFCorrVers(m_env, m_conn).fetchAll();
0198     i = listOfObjects.begin();
0199     e = listOfObjects.end();
0200     while (i != e) {
0201       const LMFCorrVers &c = unique_static_cast<const LMFCorrVers>(*i);
0202       _lmfCorrVersions.push_back(c);
0203       i++;
0204     }
0205     listOfObjects.clear();
0206     listOfObjects = LMFSeqVers(m_env, m_conn).fetchAll();
0207     i = listOfObjects.begin();
0208     e = listOfObjects.end();
0209     while (i != e) {
0210       const LMFSeqVers &c = unique_static_cast<const LMFSeqVers>(*i);
0211       _lmfSeqVersions.push_back(c);
0212       i++;
0213     }
0214     listOfObjects.clear();
0215     _lmfColors.sort();
0216     _lmfTrigTypes.sort();
0217     _lmfRunTags.sort();
0218     _lmfPrimVersions.sort();
0219     _lmfSeqVersions.sort();
0220     _lmfCorrVersions.sort();
0221   } else {
0222     throw(
0223         std::runtime_error("LMFDefFabric: cannot initialize since connection not"
0224                            "set"));
0225   }
0226 }
0227 
0228 void LMFDefFabric::dump() {
0229   std::cout << "========= Fabric dump @ address " << this << " ============" << std::endl;
0230   std::list<LMFColor>::const_iterator i1 = _lmfColors.begin();
0231   std::list<LMFTrigType>::const_iterator i2 = _lmfTrigTypes.begin();
0232   std::list<LMFRunTag>::const_iterator i3 = _lmfRunTags.begin();
0233   std::list<LMFPrimVers>::const_iterator i4 = _lmfPrimVersions.begin();
0234   std::list<LMFSeqVers>::const_iterator i5 = _lmfSeqVersions.begin();
0235   std::list<LMFCorrVers>::const_iterator i6 = _lmfCorrVersions.begin();
0236   std::list<LMFColor>::const_iterator e1 = _lmfColors.end();
0237   std::list<LMFTrigType>::const_iterator e2 = _lmfTrigTypes.end();
0238   std::list<LMFRunTag>::const_iterator e3 = _lmfRunTags.end();
0239   std::list<LMFPrimVers>::const_iterator e4 = _lmfPrimVersions.end();
0240   std::list<LMFSeqVers>::const_iterator e5 = _lmfSeqVersions.end();
0241   std::list<LMFCorrVers>::const_iterator e6 = _lmfCorrVersions.end();
0242   std::cout << "=== Colors" << std::endl;
0243   while (i1 != e1) {
0244     i1++->dump();
0245   }
0246   std::cout << "=== Trigger Types" << std::endl;
0247   while (i2 != e2) {
0248     i2++->dump();
0249   }
0250   std::cout << "=== Run Tags" << std::endl;
0251   while (i3 != e3) {
0252     i3++->dump();
0253   }
0254   std::cout << "=== Prim. Vers." << std::endl;
0255   while (i4 != e4) {
0256     i4++->dump();
0257   }
0258   std::cout << "=== Seq. Vers." << std::endl;
0259   while (i5 != e5) {
0260     i5++->dump();
0261   }
0262   std::cout << "=== Corr. Vers." << std::endl;
0263   while (i6 != e6) {
0264     i6++->dump();
0265   }
0266 }