Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:55:26

0001 #include "DQM/L1TMonitor/interface/L1TOMDSHelper.h"
0002 
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/Run.h"
0005 
0006 using namespace std;
0007 
0008 //_____________________________________________________________________
0009 L1TOMDSHelper::L1TOMDSHelper() { m_omdsReader = nullptr; }
0010 
0011 //_____________________________________________________________________
0012 L1TOMDSHelper::~L1TOMDSHelper() { delete m_omdsReader; }
0013 
0014 //_____________________________________________________________________
0015 bool L1TOMDSHelper::connect(string iOracleDB, string iPathCondDB, int &error) {
0016   // Handeling inputs
0017   m_oracleDB = iOracleDB;
0018   m_pathCondDB = iPathCondDB;
0019   error = NO_ERROR;
0020 
0021   // Initializing variables
0022   bool SessionOpen = false;
0023   bool out = false;
0024 
0025   m_omdsReader = new l1t::OMDSReader();
0026   m_omdsReader->connect(m_oracleDB, m_pathCondDB);
0027 
0028   // Testing session
0029   if (!m_omdsReader->dbSession().connectionString().empty()) {
0030     SessionOpen = true;
0031   }
0032 
0033   // Defining output and error message if needed
0034   if (SessionOpen) {
0035     out = true;
0036   } else {
0037     error = WARNING_DB_CONN_FAILED;
0038   }
0039 
0040   return out;
0041 }
0042 
0043 //_____________________________________________________________________
0044 map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMTriggerXsecFits(string iTable, int &error) {
0045   map<string, WbMTriggerXSecFit> out;
0046   const l1t::OMDSReader::QueryResults qresults;
0047   error = NO_ERROR;
0048 
0049   // Parameters
0050   string qSchema = "CMS_WBM";
0051 
0052   // Fields to retrive in the query
0053   vector<string> qStrings;
0054   qStrings.push_back("BIT");
0055   qStrings.push_back("NAME");
0056   qStrings.push_back("PM1");  //Inverse
0057   qStrings.push_back("P0");   //Constant
0058   qStrings.push_back("P1");   //Linear
0059   qStrings.push_back("P2");   //Quadratic
0060 
0061   l1t::OMDSReader::QueryResults paramResults = m_omdsReader->basicQuery(qStrings, qSchema, iTable, "", qresults);
0062 
0063   if (paramResults.queryFailed()) {
0064     error = WARNING_DB_QUERY_FAILED;
0065   } else {
0066     for (int i = 0; i < paramResults.numberRows(); ++i) {
0067       WbMTriggerXSecFit tFit;
0068       tFit.fitFunction = "[0]/x+[1]+[2]*x+[3]*x*x";  // Fitting function hardcoded for now
0069 
0070       string tBitName;
0071 
0072       paramResults.fillVariableFromRow("BIT", i, tFit.bitNumber);
0073       paramResults.fillVariableFromRow("NAME", i, tBitName);
0074       paramResults.fillVariableFromRow("PM1", i, tFit.pm1);
0075       paramResults.fillVariableFromRow("P0", i, tFit.p0);
0076       paramResults.fillVariableFromRow("P1", i, tFit.p1);
0077       paramResults.fillVariableFromRow("P2", i, tFit.p2);
0078 
0079       tFit.bitName = tBitName;
0080 
0081       out[tBitName] = tFit;
0082     }
0083   }
0084 
0085   return out;
0086 }
0087 
0088 //_____________________________________________________________________
0089 map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMAlgoXsecFits(int &error) {
0090   return getWbMTriggerXsecFits("LEVEL1_ALGO_CROSS_SECTION", error);
0091 }
0092 
0093 //_____________________________________________________________________
0094 map<string, WbMTriggerXSecFit> L1TOMDSHelper::getWbMTechXsecFits(int &error) {
0095   return getWbMTriggerXsecFits("LEVEL1_TECH_CROSS_SECTION", error);
0096 }
0097 
0098 //_____________________________________________________________________
0099 int L1TOMDSHelper::getNumberCollidingBunches(int lhcFillNumber, int &error) {
0100   int nCollidingBunches = 0;
0101   error = NO_ERROR;
0102 
0103   // Parameters
0104   string rtlSchema = "CMS_RUNTIME_LOGGER";
0105   string table = "FILL_INITLUMIPERBUNCH";
0106   string atribute1 = "LHCFILL";
0107 
0108   // Fields to retrive in the query
0109   vector<std::string> qStrings;
0110   qStrings.push_back("BUNCH");
0111   qStrings.push_back("BEAM1CONFIG");
0112   qStrings.push_back("BEAM2CONFIG");
0113 
0114   l1t::OMDSReader::QueryResults qResults =
0115       m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
0116 
0117   // Check query successful
0118   if (qResults.queryFailed()) {
0119     error = WARNING_DB_QUERY_FAILED;
0120   } else {
0121     if (qResults.numberRows() != 3564) {
0122       error = WARNING_DB_INCORRECT_NBUNCHES;
0123     } else {
0124       // Now we count the number of bunches with both beam 1 and 2 configured
0125       for (int i = 0; i < qResults.numberRows(); ++i) {
0126         int bunch;
0127         bool beam1config, beam2config;
0128         qResults.fillVariableFromRow("BUNCH", i, bunch);
0129         qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
0130         qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
0131 
0132         if (beam1config && beam2config) {
0133           nCollidingBunches++;
0134         }
0135       }
0136     }
0137   }
0138 
0139   return nCollidingBunches;
0140 }
0141 
0142 //_____________________________________________________________________
0143 BeamConfiguration L1TOMDSHelper::getBeamConfiguration(int lhcFillNumber, int &error) {
0144   BeamConfiguration bConfig;
0145   error = NO_ERROR;
0146 
0147   // Fields to retrive in the query
0148   string rtlSchema = "CMS_RUNTIME_LOGGER";
0149   string table = "FILL_INITLUMIPERBUNCH";
0150   string atribute1 = "LHCFILL";
0151 
0152   // Setting the strings we want to recover from OMDS
0153   vector<std::string> qStrings;
0154   qStrings.push_back("BUNCH");
0155   qStrings.push_back("BEAM1CONFIG");
0156   qStrings.push_back("BEAM2CONFIG");
0157 
0158   l1t::OMDSReader::QueryResults qResults =
0159       m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
0160 
0161   if (qResults.queryFailed()) {
0162     error = WARNING_DB_QUERY_FAILED;
0163   } else {
0164     if (qResults.numberRows() != 3564) {
0165       error = WARNING_DB_INCORRECT_NBUNCHES;
0166     } else {
0167       bConfig.m_valid = true;
0168 
0169       int nCollidingBunches = 0;
0170 
0171       for (int i = 0; i < qResults.numberRows(); ++i) {
0172         int bunch;
0173         bool beam1config, beam2config;
0174         qResults.fillVariableFromRow("BUNCH", i, bunch);
0175         qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
0176         qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
0177 
0178         if (beam1config) {
0179           bConfig.beam1.push_back(true);
0180         } else {
0181           bConfig.beam1.push_back(false);
0182         }
0183 
0184         if (beam2config) {
0185           bConfig.beam2.push_back(true);
0186         } else {
0187           bConfig.beam2.push_back(false);
0188         }
0189 
0190         if (beam1config && beam2config) {
0191           nCollidingBunches++;
0192         }
0193       }
0194 
0195       bConfig.nCollidingBunches = nCollidingBunches;
0196     }
0197   }
0198 
0199   return bConfig;
0200 }
0201 
0202 //_____________________________________________________________________
0203 vector<bool> L1TOMDSHelper::getBunchStructure(int lhcFillNumber, int &error) {
0204   vector<bool> BunchStructure;
0205   error = NO_ERROR;
0206 
0207   // Fields to retrive in the query
0208   string rtlSchema = "CMS_RUNTIME_LOGGER";
0209   string table = "FILL_INITLUMIPERBUNCH";
0210   string atribute1 = "LHCFILL";
0211 
0212   // Setting the strings we want to recover from OMDS
0213   vector<std::string> qStrings;
0214   qStrings.push_back("BUNCH");
0215   qStrings.push_back("BEAM1CONFIG");
0216   qStrings.push_back("BEAM2CONFIG");
0217 
0218   l1t::OMDSReader::QueryResults qResults =
0219       m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
0220 
0221   if (qResults.queryFailed()) {
0222     error = WARNING_DB_QUERY_FAILED;
0223   } else {
0224     if (qResults.numberRows() != 3564) {
0225       error = WARNING_DB_INCORRECT_NBUNCHES;
0226     } else {
0227       for (int i = 0; i < qResults.numberRows(); ++i) {
0228         int bunch;
0229         bool beam1config, beam2config;
0230         qResults.fillVariableFromRow("BUNCH", i, bunch);
0231         qResults.fillVariableFromRow("BEAM1CONFIG", i, beam1config);
0232         qResults.fillVariableFromRow("BEAM2CONFIG", i, beam2config);
0233 
0234         if (beam1config && beam2config) {
0235           BunchStructure.push_back(true);
0236         } else {
0237           BunchStructure.push_back(false);
0238         }
0239       }
0240     }
0241   }
0242 
0243   return BunchStructure;
0244 }
0245 
0246 //_____________________________________________________________________
0247 vector<float> L1TOMDSHelper::getInitBunchLumi(int lhcFillNumber, int &error) {
0248   vector<float> InitBunchLumi;
0249   error = NO_ERROR;
0250 
0251   // Fields to retrive in the query
0252   string rtlSchema = "CMS_RUNTIME_LOGGER";
0253   string table = "FILL_INITLUMIPERBUNCH";
0254   string atribute1 = "LHCFILL";
0255 
0256   // Setting the strings we want to recover from OMDS
0257   vector<std::string> qStrings;
0258   qStrings.push_back("BUNCH");
0259   qStrings.push_back("INITBUNCHLUMI");
0260 
0261   l1t::OMDSReader::QueryResults qResults =
0262       m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
0263 
0264   if (qResults.queryFailed()) {
0265     error = WARNING_DB_QUERY_FAILED;
0266   } else {
0267     if (qResults.numberRows() != 3564) {
0268       error = WARNING_DB_INCORRECT_NBUNCHES;
0269     } else {
0270       for (int i = 0; i < qResults.numberRows(); ++i) {
0271         int bunch;
0272         float initbunchlumi;
0273         qResults.fillVariableFromRow("BUNCH", i, bunch);
0274         qResults.fillVariableFromRow("INITBUNCHLUMI", i, initbunchlumi);
0275 
0276         InitBunchLumi.push_back(initbunchlumi);
0277       }
0278     }
0279   }
0280 
0281   return InitBunchLumi;
0282 }
0283 
0284 //_____________________________________________________________________
0285 vector<double> L1TOMDSHelper::getRelativeBunchLumi(int lhcFillNumber, int &error) {
0286   vector<double> RelativeBunchLumi;
0287   error = NO_ERROR;
0288 
0289   // Fields to retrive in the query
0290   string rtlSchema = "CMS_RUNTIME_LOGGER";
0291   string table = "FILL_INITLUMIPERBUNCH";
0292   string atribute1 = "LHCFILL";
0293 
0294   // Setting the strings we want to recover from OMDS
0295   vector<std::string> qStrings;
0296   qStrings.push_back("BUNCH");
0297   qStrings.push_back("INITBUNCHLUMI");
0298 
0299   l1t::OMDSReader::QueryResults qResults =
0300       m_omdsReader->basicQuery(qStrings, rtlSchema, table, atribute1, m_omdsReader->singleAttribute(lhcFillNumber));
0301 
0302   if (qResults.queryFailed()) {
0303     error = WARNING_DB_QUERY_FAILED;
0304   } else {
0305     if (qResults.numberRows() != 3564) {
0306       error = WARNING_DB_INCORRECT_NBUNCHES;
0307     } else {
0308       //-> Get the inicial bunch luminosity add calculate the total luminosity of the fill
0309       double InitTotalLumi = 0;
0310       vector<float> InitBunchLumi;
0311 
0312       for (int i = 0; i < qResults.numberRows(); ++i) {
0313         int bunch;
0314         float initbunchlumi;
0315         qResults.fillVariableFromRow("BUNCH", i, bunch);
0316         qResults.fillVariableFromRow("INITBUNCHLUMI", i, initbunchlumi);
0317 
0318         InitTotalLumi += initbunchlumi;
0319         InitBunchLumi.push_back(initbunchlumi);
0320       }
0321 
0322       //-> We calculate the relative luminosity for each bunch
0323       for (unsigned int i = 0; i < InitBunchLumi.size(); i++) {
0324         RelativeBunchLumi.push_back(InitBunchLumi[i] / InitTotalLumi);
0325       }
0326     }
0327   }
0328 
0329   return RelativeBunchLumi;
0330 }
0331 
0332 //_____________________________________________________________________
0333 string L1TOMDSHelper::enumToStringError(int iObject) {
0334   string out;
0335 
0336   switch (iObject) {
0337     case NO_ERROR:
0338       out = "NO_ERROR";
0339       break;
0340     case WARNING_DB_CONN_FAILED:
0341       out = "WARNING_DB_CONN_FAILED";
0342       break;
0343     case WARNING_DB_QUERY_FAILED:
0344       out = "WARNING_DB_QUERY_FAILED";
0345       break;
0346     case WARNING_DB_INCORRECT_NBUNCHES:
0347       out = "WARNING_DB_INCORRECT_NBUNCHES";
0348       break;
0349     default:
0350       out = "UNKNOWN";
0351       break;
0352   };
0353 
0354   return out;
0355 }