CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/L1TriggerConfig/L1GtConfigProducers/src/L1GtPrescaleFactorsAlgoTrigConfigOnlineProd.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtPrescaleFactorsAlgoTrigConfigOnlineProd.h"
00019 
00020 // system include files
00021 #include <vector>
00022 
00023 #include "boost/lexical_cast.hpp"
00024 
00025 // user include files
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 
00028 // constructor
00029 L1GtPrescaleFactorsAlgoTrigConfigOnlineProd::L1GtPrescaleFactorsAlgoTrigConfigOnlineProd(
00030         const edm::ParameterSet& parSet) :
00031             L1ConfigOnlineProdBase<L1GtPrescaleFactorsAlgoTrigRcd, L1GtPrescaleFactors> (parSet),
00032             m_isDebugEnabled(edm::isDebugEnabled()) {
00033 
00034     // empty
00035 
00036 }
00037 
00038 // destructor
00039 L1GtPrescaleFactorsAlgoTrigConfigOnlineProd::~L1GtPrescaleFactorsAlgoTrigConfigOnlineProd() {
00040 
00041     // empty
00042 
00043 }
00044 
00045 // public methods
00046 
00047 boost::shared_ptr<L1GtPrescaleFactors> L1GtPrescaleFactorsAlgoTrigConfigOnlineProd::newObject(
00048         const std::string& objectKey) {
00049 
00050     // FIXME seems to not work anymore in constructor...
00051     m_isDebugEnabled = edm::isDebugEnabled();
00052 
00053     // shared pointer for L1GtPrescaleFactors
00054     boost::shared_ptr<L1GtPrescaleFactors> pL1GtPrescaleFactors =
00055             boost::shared_ptr<L1GtPrescaleFactors>(new L1GtPrescaleFactors());
00056 
00057     // Procedure:
00058     // objectKey received as input is GT_RUN_SETTINGS_FK
00059     //
00060     // get from GT_RUN_SETTINGS_PRESC_VIEW the PRESCALE_FACTORS_ALGO_FK and the index PRESCALE_INDEX
00061     // for the GT_RUN_SETTINGS_FK
00062     //
00063     // get the prescale factors for key PRESCALE_FACTORS_ALGO_FK
00064     // from GT_FDL_PRESCALE_FACTORS_ALGO table
00065 
00066     const std::string gtSchema = "CMS_GT";
00067 
00068     // select * from CMS_GT.GT_RUN_SETTINGS_PRESC_VIEW
00069     //     where GT_RUN_SETTINGS_PRESC_VIEW.ID = objectKey
00070 
00071     std::vector<std::string> columnsView;
00072     columnsView.push_back("PRESCALE_INDEX");
00073     columnsView.push_back("PRESCALE_FACTORS_ALGO_FK");
00074 
00075     l1t::OMDSReader::QueryResults resultsView = m_omdsReader.basicQueryView(
00076             columnsView, gtSchema, "GT_RUN_SETTINGS_PRESC_VIEW",
00077             "GT_RUN_SETTINGS_PRESC_VIEW.ID", m_omdsReader.singleAttribute(
00078                     objectKey));
00079 
00080     // check if query was successful
00081     if (resultsView.queryFailed()) {
00082         edm::LogError("L1-O2O")
00083                 << "Problem to get content of GT_RUN_SETTINGS_PRESC_VIEW "
00084                 << "for GT_RUN_SETTINGS_PRESC_VIEW.ID: " << objectKey;
00085         return pL1GtPrescaleFactors;
00086     }
00087 
00088     // retrieve PRESCALE_INDEX and PRESCALE_FACTORS_ALGO_FK for GT_RUN_SETTINGS_FK
00089 
00090     std::string objectKeyPrescaleFactorsSet = "WRONG_KEY_INITIAL";
00091     short prescaleFactorsSetIndex = 9999;
00092 
00093     int resultsViewRows = resultsView.numberRows();
00094     if (m_isDebugEnabled) {
00095         LogTrace("L1GtPrescaleFactorsAlgoTrigConfigOnlineProd") << "\nFound "
00096                 << resultsViewRows << " prescale factors sets for \n  "
00097                 << "GT_RUN_SETTINGS_PRESC_VIEW.ID = " << objectKey << "\n"
00098                 << std::endl;
00099     }
00100 
00101     // vector to be filled (resultsViewRows prescale factors sets)
00102     std::vector<std::vector<int> > pFactors;
00103     pFactors.reserve(resultsViewRows);
00104 
00105     int countSet = -1;
00106 
00107     for (int iRow = 0; iRow < resultsViewRows; ++iRow) {
00108 
00109         for (std::vector<std::string>::const_iterator constIt =
00110                 columnsView.begin(); constIt != columnsView.end(); ++constIt) {
00111 
00112             if ((*constIt) == "PRESCALE_INDEX") {
00113                 resultsView.fillVariableFromRow(*constIt, iRow,
00114                         prescaleFactorsSetIndex);
00115             } else if ((*constIt) == "PRESCALE_FACTORS_ALGO_FK") {
00116                 resultsView.fillVariableFromRow(*constIt, iRow,
00117                         objectKeyPrescaleFactorsSet);
00118             } else {
00119 
00120                 LogTrace("L1GtPrescaleFactorsAlgoTrigConfigOnlineProd")
00121                         << "\nUnknown field " << (*constIt)
00122                         << " requested for columns in GT_RUN_SETTINGS_PRESC_VIEW"
00123                         << std::endl;
00124 
00125             }
00126         }
00127 
00128         if (m_isDebugEnabled) {
00129             LogTrace("L1GtPrescaleFactorsAlgoTrigConfigOnlineProd")
00130                     << "\nFound prescale factors set: \n  index = "
00131                     << prescaleFactorsSetIndex
00132                     << "\n  PRESCALE_FACTORS_ALGO_FK = "
00133                     << objectKeyPrescaleFactorsSet << "\n" << std::endl;
00134         }
00135 
00136         // retrive now the prescale factors for PRESCALE_FACTORS_ALGO_FK
00137 
00138 
00139         // SQL query:
00140         //
00141         // select * from CMS_GT.GT_FDL_PRESCALE_FACTORS_ALGO
00142         //        WHERE GT_FDL_PRESCALE_FACTORS_ALGO.ID = objectKeyPrescaleFactorsSet
00143         const std::vector<std::string>& columns = m_omdsReader.columnNames(
00144                 gtSchema, "GT_FDL_PRESCALE_FACTORS_ALGO");
00145 
00146         if (m_isDebugEnabled) {
00147             LogTrace("L1GtPrescaleFactorsAlgoTrigConfigOnlineProd")
00148                     << "\nColumn names for GT_FDL_PRESCALE_FACTORS_ALGO"
00149                     << std::endl;
00150 
00151             for (std::vector<std::string>::const_iterator iter =
00152                     columns.begin(); iter != columns.end(); iter++) {
00153                 LogTrace("L1GtPrescaleFactorsAlgoTrigConfigOnlineProd")
00154                         << (*iter) << std::endl;
00155 
00156             }
00157         }
00158 
00159         l1t::OMDSReader::QueryResults results = m_omdsReader.basicQuery(
00160                 columns, gtSchema, "GT_FDL_PRESCALE_FACTORS_ALGO",
00161                 "GT_FDL_PRESCALE_FACTORS_ALGO.ID",
00162                 m_omdsReader.singleAttribute(objectKeyPrescaleFactorsSet));
00163 
00164         // check if query was successful
00165         if (results.queryFailed()) {
00166             edm::LogError("L1-O2O")
00167                     << "Problem with L1GtPrescaleFactorsAlgoTrigRcd key:"
00168                     << objectKeyPrescaleFactorsSet;
00169             return pL1GtPrescaleFactors;
00170         }
00171 
00172 
00173 
00174 
00175         // check if set indices are ordered, starting from 0 (initial value for countSet is -1)
00176         countSet++;
00177         if (prescaleFactorsSetIndex != countSet) {
00178             edm::LogError("L1-O2O")
00179                     << "L1GtPrescaleFactorsAlgoTrig has unordered sets PRESCALE_INDEX in DB for\n"
00180                     << " GT_RUN_SETTINGS_PRESC_VIEW.ID = " << objectKey << "\n"
00181                     << std::endl;
00182             return pL1GtPrescaleFactors;
00183 
00184         }
00185 
00186 
00187         // fill one set of prescale factors
00188         int pfSetSize = columns.size() - 1; // table ID is also in columns
00189         std::vector<int> pfSet(pfSetSize, 0);
00190 
00191         for (int i = 0; i < pfSetSize; i++) {
00192             results.fillVariable(columns[i + 1], pfSet[i]);
00193         }
00194 
00195         pFactors.push_back(pfSet);
00196 
00197     }
00198 
00199     // fill the record
00200 
00201     pL1GtPrescaleFactors->setGtPrescaleFactors(pFactors);
00202 
00203     if (m_isDebugEnabled) {
00204         std::ostringstream myCoutStream;
00205         pL1GtPrescaleFactors->print(myCoutStream);
00206         LogTrace("L1GtPrescaleFactorsAlgoTrigConfigOnlineProd")
00207                 << "\nThe following L1GtPrescaleFactorsAlgoTrigRcd record was read from OMDS: \n"
00208                 << myCoutStream.str() << "\n" << std::endl;
00209     }
00210 
00211     return pL1GtPrescaleFactors;
00212 }
00213 
00214 DEFINE_FWK_EVENTSETUP_MODULE( L1GtPrescaleFactorsAlgoTrigConfigOnlineProd);