CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/L1TriggerConfig/L1GtConfigProducers/src/L1GtTriggerMenuConfigOnlineProd.cc

Go to the documentation of this file.
00001 
00017 // this class header
00018 #include "L1TriggerConfig/L1GtConfigProducers/interface/L1GtTriggerMenuConfigOnlineProd.h"
00019 
00020 // system include files
00021 #include <string>
00022 #include <vector>
00023 #include <map>
00024 #include <list>
00025 #include <utility>
00026 #include <algorithm>
00027 
00028 #include "boost/lexical_cast.hpp"
00029 
00030 // user include files
00031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00032 
00033 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenuFwd.h"
00034 #include "CondFormats/L1TObjects/interface/L1GtFwd.h"
00035 
00036 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00037 
00038 #include "CondFormats/L1TObjects/interface/L1GtCondition.h"
00039 #include "CondFormats/L1TObjects/interface/L1GtAlgorithm.h"
00040 
00041 
00042 // constructor
00043 L1GtTriggerMenuConfigOnlineProd::L1GtTriggerMenuConfigOnlineProd(const edm::ParameterSet& parSet) :
00044     L1ConfigOnlineProdBase<L1GtTriggerMenuRcd, L1GtTriggerMenu> (parSet), m_isDebugEnabled(
00045             edm::isDebugEnabled()) {
00046 
00047     // empty
00048 
00049 }
00050 
00051 // destructor
00052 L1GtTriggerMenuConfigOnlineProd::~L1GtTriggerMenuConfigOnlineProd() {
00053 
00054     // empty
00055 
00056 }
00057 
00058 // public methods
00059 
00060 // initialize the class (mainly reserve/resize)
00061 void L1GtTriggerMenuConfigOnlineProd::init(const int numberConditionChips) {
00062 
00063     // resize the vectors of condition maps
00064     // the number of condition chips should be correctly set
00065 
00066     m_vecMuonTemplate.resize(numberConditionChips);
00067     m_vecCaloTemplate.resize(numberConditionChips);
00068     m_vecEnergySumTemplate.resize(numberConditionChips);
00069     m_vecJetCountsTemplate.resize(numberConditionChips);
00070     m_vecCastorTemplate.resize(numberConditionChips);
00071     m_vecHfBitCountsTemplate.resize(numberConditionChips);
00072     m_vecHfRingEtSumsTemplate.resize(numberConditionChips);
00073     m_vecBptxTemplate.resize(numberConditionChips);
00074     m_vecExternalTemplate.resize(numberConditionChips);
00075 
00076     m_vecCorrelationTemplate.resize(numberConditionChips);
00077     m_corMuonTemplate.resize(numberConditionChips);
00078     m_corCaloTemplate.resize(numberConditionChips);
00079     m_corEnergySumTemplate.resize(numberConditionChips);
00080 
00081 
00082 }
00083 
00084 boost::shared_ptr<L1GtTriggerMenu> L1GtTriggerMenuConfigOnlineProd::newObject(
00085         const std::string& objectKey) {
00086 
00087     // FIXME seems to not work anymore in constructor...
00088     m_isDebugEnabled = edm::isDebugEnabled();
00089 
00090     // shared pointer for L1GtTriggerMenu - empty menu
00091     boost::shared_ptr<L1GtTriggerMenu> pL1GtTriggerMenuEmpty =
00092             boost::shared_ptr<L1GtTriggerMenu>(new L1GtTriggerMenu());
00093 
00094     // FIXME get it from L1GtStableParameters?
00095     //       initialize once, from outside
00096     const unsigned int numberConditionChips = 2;
00097     init(numberConditionChips);
00098 
00099     const std::string gtSchema = "CMS_GT";
00100 
00101     // l1GtTriggerMenu: parameters in table GTFE_SETUP_FK
00102     // the objectKey for the menu obtained from GT_SETUP is the L1T_MENU_IMPL key
00103 
00104     // SQL queries:
00105 
00106     // retrieve table with general menu parameters from DB, view L1T_MENU_GENERAL_VIEW
00107     if (!tableMenuGeneralFromDB(gtSchema, objectKey)) {
00108         return pL1GtTriggerMenuEmpty;
00109 
00110     }
00111 
00112     // build the menu name
00113     std::string menuName = m_tableMenuGeneral.menuInterface + "/" + m_tableMenuGeneral.scalesKey
00114             + "/" + m_tableMenuGeneral.algoImplTag;
00115 
00116 
00117     // retrieve table with physics algorithms from DB, view L1T_MENU_ALGO_VIEW
00118     if (!tableMenuAlgoFromDB(gtSchema, objectKey)) {
00119         return pL1GtTriggerMenuEmpty;
00120 
00121     }
00122 
00123     // retrieve table with conditions associated to physics algorithms from DB
00124     if (!tableMenuAlgoCondFromDB(gtSchema, objectKey)) {
00125         return pL1GtTriggerMenuEmpty;
00126 
00127     }
00128 
00129     // retrieve table with list of conditions in the menu
00130     if (!tableMenuCondFromDB(gtSchema, objectKey)) {
00131         return pL1GtTriggerMenuEmpty;
00132 
00133     }
00134 
00135 
00136     // retrieve table with object parameters from DB, view CMS_GT.L1T_MENU_OP_VIEW
00137     if (!tableMenuObjectParametersFromDB(gtSchema, objectKey)) {
00138         return pL1GtTriggerMenuEmpty;
00139 
00140     }
00141 
00142     // retrieve table with technical triggers from DB, view L1T_MENU_TECHTRIG_VIEW
00143     if (!tableMenuTechTrigFromDB(gtSchema, objectKey)) {
00144         return pL1GtTriggerMenuEmpty;
00145 
00146     }
00147 
00148     // build the algorithm map in the menu
00149     buildAlgorithmMap();
00150 
00151     // build the technical trigger map in the menu
00152     buildTechnicalTriggerMap();
00153 
00154     // add the conditions from a menu to the corresponding list
00155     addConditions();
00156 
00157     // fill the record
00158     boost::shared_ptr<L1GtTriggerMenu> pL1GtTriggerMenu = boost::shared_ptr<L1GtTriggerMenu>(
00159                 new L1GtTriggerMenu(menuName, numberConditionChips,
00160                         m_vecMuonTemplate,
00161                         m_vecCaloTemplate,
00162                         m_vecEnergySumTemplate,
00163                         m_vecJetCountsTemplate,
00164                         m_vecCastorTemplate,
00165                         m_vecHfBitCountsTemplate,
00166                         m_vecHfRingEtSumsTemplate,
00167                         m_vecBptxTemplate,
00168                         m_vecExternalTemplate,
00169                         m_vecCorrelationTemplate,
00170                         m_corMuonTemplate,
00171                         m_corCaloTemplate,
00172                         m_corEnergySumTemplate) );
00173 
00174     pL1GtTriggerMenu->setGtTriggerMenuInterface(m_tableMenuGeneral.menuInterface);
00175     pL1GtTriggerMenu->setGtTriggerMenuImplementation(m_tableMenuGeneral.menuImplementation);
00176     pL1GtTriggerMenu->setGtScaleDbKey(m_tableMenuGeneral.scalesKey);
00177 
00178     pL1GtTriggerMenu->setGtAlgorithmMap(m_algorithmMap);
00179     pL1GtTriggerMenu->setGtAlgorithmAliasMap(m_algorithmAliasMap);
00180     pL1GtTriggerMenu->setGtTechnicalTriggerMap(m_technicalTriggerMap);
00181 
00182 
00183     if (m_isDebugEnabled) {
00184         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00185             << "\nThe following L1GtTriggerMenu record was read from OMDS: \n"
00186             << std::endl;
00187 
00188         std::ostringstream myCoutStream;
00189         int verbosity = 0;
00190         pL1GtTriggerMenu->print(myCoutStream, verbosity);
00191         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n" << std::endl;
00192 
00193         verbosity = 2;
00194         pL1GtTriggerMenu->print(myCoutStream, verbosity);
00195         LogTrace("L1GtTriggerMenuConfigOnlineProd") << myCoutStream.str() << "\n" << std::endl;
00196 
00197     }
00198 
00199     return pL1GtTriggerMenu;
00200 }
00201 
00202 // retrieve table with general menu parameters from DB
00203 bool L1GtTriggerMenuConfigOnlineProd::tableMenuGeneralFromDB(
00204         const std::string& gtSchema, const std::string& objectKey) {
00205 
00206     // select * from CMS_GT.L1T_MENU_GENERAL_VIEW
00207     //     where L1T_MENU_GENERAL_VIEW.MENU_IMPLEMENTATION = objectKey
00208 
00209     const std::vector<std::string>& columns = m_omdsReader.columnNamesView(
00210             gtSchema, "L1T_MENU_GENERAL_VIEW");
00211 
00212     if (m_isDebugEnabled) {
00213         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00214                 << "\n List of columns in L1T_MENU_GENERAL_VIEW:\n" << std::endl;
00215         for (std::vector<std::string>::const_iterator iter = columns.begin(); iter != columns.end(); iter++) {
00216             LogTrace("L1GtTriggerMenuConfigOnlineProd") << ( *iter ) << std::endl;
00217 
00218         }
00219         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00220     }
00221 
00222     l1t::OMDSReader::QueryResults results = m_omdsReader.basicQueryView(
00223             columns, gtSchema, "L1T_MENU_GENERAL_VIEW",
00224             "L1T_MENU_GENERAL_VIEW.MENU_IMPLEMENTATION", m_omdsReader.singleAttribute(objectKey));
00225 
00226     // check if query was successful
00227     if (results.queryFailed()) {
00228         edm::LogError("L1-O2O")
00229                 << "Problem to get content of L1T_MENU_GENERAL_VIEW for L1GtTriggerMenu implementation key: "
00230                 << objectKey;
00231         return false;
00232     }
00233 
00234     // retrieve menu interface name, scales key, algorithm implementation tag
00235 
00236     for (std::vector<std::string>::const_iterator constIt = columns.begin(); constIt
00237             != columns.end(); ++constIt) {
00238 
00239         if ( ( *constIt ) == "MENU_IMPLEMENTATION") {
00240             results.fillVariable(*constIt, m_tableMenuGeneral.menuImplementation);
00241 
00242         } else if ( ( *constIt ) == "INTERFACE") {
00243             results.fillVariable(*constIt, m_tableMenuGeneral.menuInterface);
00244 
00245         } else if ( ( *constIt ) == "SCALES_KEY") {
00246             results.fillVariable(*constIt, m_tableMenuGeneral.scalesKey);
00247 
00248         } else if ( ( *constIt ) == "ALGO_IMPL_TAG") {
00249             results.fillVariable(*constIt, m_tableMenuGeneral.algoImplTag);
00250 
00251         } else {
00252             // do nothing
00253 
00254         }
00255 
00256     }
00257 
00258     // cross checks
00259     if (m_tableMenuGeneral.menuImplementation != objectKey)   {
00260 
00261         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00262                 << "\n L1 trigger menu implementation read from querying view not identical"
00263                 << "\n with menu key:"
00264                 << "\n   from view: " << m_tableMenuGeneral.menuImplementation
00265                 << "\n   from key:  " <<  objectKey
00266                 << "\n Menu implementation name set from key."
00267                 << std::endl;
00268         m_tableMenuGeneral.menuImplementation = objectKey;
00269     }
00270 
00271     //
00272     return true;
00273 
00274 }
00275 
00276 // retrieve table with physics algorithms from DB
00277 bool L1GtTriggerMenuConfigOnlineProd::tableMenuAlgoFromDB(
00278         const std::string& gtSchema, const std::string& objectKey) {
00279 
00280     // select * from CMS_GT.L1T_MENU_ALGO_VIEW
00281     //     where L1T_MENU_ALGO_VIEW.MENU_IMPLEMENTATION = objectKey
00282 
00283     const std::vector<std::string>& columnsMenuAlgo = m_omdsReader.columnNamesView(
00284             gtSchema, "L1T_MENU_ALGO_VIEW");
00285 
00286     if (m_isDebugEnabled) {
00287         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n List of columns in L1T_MENU_ALGO_VIEW:\n"
00288             << std::endl;
00289         for (std::vector<std::string>::const_iterator iter = columnsMenuAlgo.begin(); iter != columnsMenuAlgo.end(); iter++) {
00290             LogTrace("L1GtTriggerMenuConfigOnlineProd") << ( *iter ) << std::endl;
00291 
00292         }
00293         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00294     }
00295 
00296     l1t::OMDSReader::QueryResults resultsMenuAlgo = m_omdsReader.basicQueryView(
00297             columnsMenuAlgo, gtSchema, "L1T_MENU_ALGO_VIEW", "L1T_MENU_ALGO_VIEW.MENU_IMPLEMENTATION",
00298             m_omdsReader.singleAttribute(objectKey));
00299 
00300 
00301     // check if query was successful is based on size of returned list
00302     // BUT one can have menus w/o physics algorithms - no error for empty list, but a warning!
00303     if (resultsMenuAlgo.queryFailed()) {
00304         edm::LogWarning("L1-O2O")
00305                 << "Warning: Content of L1T_MENU_ALGO_VIEW for L1GtTriggerMenu implementation key: "
00306                 << "\n  " << objectKey << "\nis empty!"
00307                 << "\nNo physics algorithms are found for this menu.";
00308 
00309     }
00310 
00311     TableMenuAlgo menuAlgo;
00312     int resultsMenuAlgoRows = resultsMenuAlgo.numberRows();
00313 
00314     for (int iRow = 0; iRow < resultsMenuAlgoRows; ++iRow) {
00315 
00316         for (std::vector<std::string>::const_iterator constIt = columnsMenuAlgo.begin(); constIt
00317                 != columnsMenuAlgo.end(); ++constIt) {
00318 
00319             if ( ( *constIt ) == "ALGO_INDEX") {
00320                 resultsMenuAlgo.fillVariableFromRow(*constIt, iRow, menuAlgo.bitNumberSh);
00321 
00322             } else if ( ( *constIt ) == "NAME") {
00323                 resultsMenuAlgo.fillVariableFromRow(*constIt, iRow, menuAlgo.algName);
00324 
00325             } else if ( ( *constIt ) == "ALIAS") {
00326                 resultsMenuAlgo.fillVariableFromRow(*constIt, iRow, menuAlgo.algAlias);
00327 
00328             } else if ( ( *constIt ) == "LOGICEXPR") {
00329                 resultsMenuAlgo.fillVariableFromRow(*constIt, iRow, menuAlgo.logExpression);
00330 
00331             } else {
00332                 // do nothing
00333 
00334             }
00335 
00336         }
00337 
00338         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00339             << "Row  " << iRow << ": index = " << menuAlgo.bitNumberSh << " algName = " << menuAlgo.algName
00340             << " algAlias = " << menuAlgo.algAlias << " logExpression = '" << menuAlgo.logExpression << "'"
00341             << std::endl;
00342 
00343         m_tableMenuAlgo.push_back(menuAlgo);
00344 
00345 
00346     }
00347 
00348     if (m_isDebugEnabled) {
00349         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00350             << "\n Number of rows read from L1T_MENU_ALGO_VIEW: " << resultsMenuAlgoRows
00351             << std::endl;
00352 
00353     }
00354 
00355     return true;
00356 
00357 }
00358 
00359 // retrieve table with conditions associated to physics algorithms from DB
00360 bool L1GtTriggerMenuConfigOnlineProd::tableMenuAlgoCondFromDB(
00361         const std::string& gtSchema, const std::string& objectKey) {
00362 
00363     // get list of conditions associated with the algorithms
00364 
00365     // select * from CMS_GT.L1T_MENU_ALGO_COND_VIEW
00366     //     where L1T_MENU_ALGO_COND_VIEW.MENU_IMPLEMENTATION = objectKey
00367 
00368     const std::vector<std::string>& columnsMenuAlgoCond = m_omdsReader.columnNamesView(
00369             gtSchema, "L1T_MENU_ALGO_COND_VIEW");
00370 
00371     if (m_isDebugEnabled) {
00372         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00373                 << "\n List of columns in L1T_MENU_ALGO_COND_VIEW:\n" << std::endl;
00374         for (std::vector<std::string>::const_iterator iter = columnsMenuAlgoCond.begin(); iter
00375                 != columnsMenuAlgoCond.end(); iter++) {
00376             LogTrace("L1GtTriggerMenuConfigOnlineProd") << ( *iter ) << std::endl;
00377 
00378         }
00379         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00380     }
00381 
00382     l1t::OMDSReader::QueryResults resultsMenuAlgoCond = m_omdsReader.basicQueryView(
00383             columnsMenuAlgoCond, gtSchema, "L1T_MENU_ALGO_COND_VIEW",
00384             "L1T_MENU_ALGO_COND_VIEW.MENU_IMPLEMENTATION", m_omdsReader.singleAttribute(objectKey));
00385 
00386     // check if query was successful is based on size of returned list
00387     // BUT one can have menus w/o algorithms and conditions - no error for empty list, but a warning!
00388     if (resultsMenuAlgoCond.queryFailed()) {
00389         edm::LogWarning("L1-O2O")
00390                 << "Warning: Content of L1T_MENU_ALGO_COND_VIEW for L1GtTriggerMenu implementation key: "
00391                 << "\n  " << objectKey << "\nis empty!"
00392                 << "\nNo list of condition associated to each algorithm are found for this menu.";
00393 
00394     }
00395 
00396     //
00397     TableMenuAlgoCond menuAlgoCond;
00398     int resultsMenuAlgoCondRows = resultsMenuAlgoCond.numberRows();
00399 
00400     for (int iRow = 0; iRow < resultsMenuAlgoCondRows; ++iRow) {
00401 
00402         for (std::vector<std::string>::const_iterator constIt = columnsMenuAlgoCond.begin(); constIt
00403                 != columnsMenuAlgoCond.end(); ++constIt) {
00404 
00405             if ( ( *constIt ) == "ALGO_INDEX") {
00406                 resultsMenuAlgoCond.fillVariableFromRow(
00407                         *constIt, iRow, menuAlgoCond.bitNumberSh);
00408 
00409             } else if ( ( *constIt ) == "COND_INDEX") {
00410                 resultsMenuAlgoCond.fillVariableFromRow(
00411                         *constIt, iRow, menuAlgoCond.condIndexF);
00412 
00413             } else if ( ( *constIt ) == "COND_FK") {
00414                 resultsMenuAlgoCond.fillVariableFromRow(*constIt, iRow, menuAlgoCond.condFK);
00415 
00416             } else {
00417                 // do nothing
00418 
00419             }
00420 
00421         }
00422 
00423         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "Row  " << iRow << ": ALGO_INDEX = "
00424                 << menuAlgoCond.bitNumberSh << " COND_INDEX = " << menuAlgoCond.condIndexF
00425                 << " COND_FK = " << menuAlgoCond.condFK << std::endl;
00426 
00427         m_tableMenuAlgoCond.push_back(menuAlgoCond);
00428 
00429     }
00430 
00431     if (m_isDebugEnabled) {
00432         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00433                 << "\n Number of rows read from L1T_MENU_ALGO_COND_VIEW: "
00434                 << resultsMenuAlgoCondRows << std::endl;
00435     }
00436 
00437 
00438     return true;
00439 
00440 }
00441 
00442 // retrieve table with list of conditions in the menu
00443 bool L1GtTriggerMenuConfigOnlineProd::tableMenuCondFromDB(
00444         const std::string& gtSchema, const std::string& objectKey) {
00445 
00446     // select * from CMS_GT.L1T_MENU_COND_VIEW
00447     //     where L1T_MENU_COND_VIEW.MENU_IMPLEMENTATION = objectKey
00448 
00449     const std::vector<std::string>& columnsMenuCond = m_omdsReader.columnNamesView(
00450             gtSchema, "L1T_MENU_COND_VIEW");
00451 
00452     if (m_isDebugEnabled) {
00453         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00454                 << "\n List of columns in L1T_MENU_COND_VIEW:\n" << std::endl;
00455         for (std::vector<std::string>::const_iterator iter = columnsMenuCond.begin(); iter
00456                 != columnsMenuCond.end(); iter++) {
00457             LogTrace("L1GtTriggerMenuConfigOnlineProd") << ( *iter ) << std::endl;
00458 
00459         }
00460         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00461     }
00462 
00463     l1t::OMDSReader::QueryResults resultsMenuCond = m_omdsReader.basicQueryView(
00464             columnsMenuCond, gtSchema, "L1T_MENU_COND_VIEW",
00465             "L1T_MENU_COND_VIEW.MENU_IMPLEMENTATION", m_omdsReader.singleAttribute(objectKey));
00466 
00467     // check if query was successful is based on size of returned list
00468     // BUT one can have menus w/o conditions - no error for empty list, but a warning!
00469     if (resultsMenuCond.queryFailed()) {
00470         edm::LogWarning("L1-O2O")
00471                 << "Warning: Content of L1T_MENU_COND_VIEW for L1GtTriggerMenu implementation key: "
00472                 << "\n  " << objectKey << "\nis empty!"
00473                 << "\nNo conditions associated to menu are found for this menu.";
00474 
00475     }
00476 
00477     //
00478     TableMenuCond menuCond;
00479     int resultsMenuCondRows = resultsMenuCond.numberRows();
00480 
00481     for (int iRow = 0; iRow < resultsMenuCondRows; ++iRow) {
00482 
00483         for (std::vector<std::string>::const_iterator constIt = columnsMenuCond.begin(); constIt
00484                 != columnsMenuCond.end(); ++constIt) {
00485 
00486             if ( ( *constIt ) == "COND") {
00487                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.cond);
00488 
00489             } else if ( ( *constIt ) == "COND_CATEGORY") {
00490                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.condCategory);
00491 
00492             } else if ( ( *constIt ) == "COND_TYPE") {
00493                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.condType);
00494 
00495             } else if ( ( *constIt ) == "GT_OBJECT_1") {
00496                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.gtObject1);
00497 
00498             } else if ( ( *constIt ) == "GT_OBJECT_2") {
00499                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.gtObject2);
00500 
00501             } else if ( ( *constIt ) == "COND_GEQ") {
00502                 float condGEqFloat = -1;
00503                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, condGEqFloat);
00504                 menuCond.condGEq = (condGEqFloat > 0.5) ? true : false;
00505 
00506             } else if ( ( *constIt ) == "COUNT_INDEX") {
00507                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.countIndex);
00508 
00509             } else if ( ( *constIt ) == "COUNT_THRESHOLD") {
00510                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.countThreshold);
00511 
00512             } else if ( ( *constIt ) == "CHARGE_CORRELATION") {
00513                 resultsMenuCond.fillVariableFromRow(
00514                         *constIt, iRow, menuCond.chargeCorrelation);
00515 
00516             } else if ( ( *constIt ) == "OBJECT_PARAMETER_1_FK") {
00517                 resultsMenuCond.fillVariableFromRow(
00518                         *constIt, iRow, menuCond.objectParameter1FK);
00519 
00520             } else if ( ( *constIt ) == "OBJECT_PARAMETER_2_FK") {
00521                 resultsMenuCond.fillVariableFromRow(
00522                         *constIt, iRow, menuCond.objectParameter2FK);
00523 
00524             } else if ( ( *constIt ) == "OBJECT_PARAMETER_3_FK") {
00525                 resultsMenuCond.fillVariableFromRow(
00526                         *constIt, iRow, menuCond.objectParameter3FK);
00527 
00528             } else if ( ( *constIt ) == "OBJECT_PARAMETER_4_FK") {
00529                 resultsMenuCond.fillVariableFromRow(
00530                         *constIt, iRow, menuCond.objectParameter4FK);
00531 
00532             } else if ( ( *constIt ) == "DELTA_ETA_RANGE") {
00533                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.deltaEtaRange);
00534 
00535             } else if ( ( *constIt ) == "DELTA_PHI_RANGE") {
00536                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.deltaPhiRange);
00537 
00538             } else {
00539                 // do nothing
00540 
00541             }
00542 
00543         }
00544 
00545         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00546             << " COND " << menuCond.cond
00547             << " COND_CATEGORY " << menuCond.condCategory
00548             << " COND_TYPE " << menuCond.condType
00549             << " GT_OBJECT_1 " << menuCond.gtObject1
00550             << " GT_OBJECT_2 " << menuCond.gtObject2
00551             << " COND_GEQ " << menuCond.condGEq << "\n"
00552             << " COUNT_INDEX " << menuCond.countIndex
00553             << " COUNT_THRESHOLD " << menuCond.countThreshold << "\n"
00554             << " CHARGE_CORRELATION " << menuCond.chargeCorrelation << "\n"
00555             << " OBJECT_PARAMETER_1_FK " << menuCond.objectParameter1FK
00556             << " OBJECT_PARAMETER_2_FK " << menuCond.objectParameter2FK
00557             << " OBJECT_PARAMETER_3_FK " << menuCond.objectParameter3FK
00558             << " OBJECT_PARAMETER_4_FK " << menuCond.objectParameter4FK << "\n"
00559             << " DELTA_ETA_RANGE " << menuCond.deltaEtaRange
00560             << " DELTA_PHI_RANGE " << menuCond.deltaPhiRange;
00561 
00562         m_tableMenuCond.push_back(menuCond);
00563 
00564 
00565     }
00566 
00567     if (m_isDebugEnabled) {
00568         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00569             << "\n Number of rows read from L1T_MENU_COND_VIEW: " << resultsMenuCondRows
00570             << std::endl;
00571 
00572     }
00573 
00574     return true;
00575 
00576 }
00577 
00578 // retrieve table with object parameters from DB
00579 bool L1GtTriggerMenuConfigOnlineProd::tableMenuObjectParametersFromDB(
00580         const std::string& gtSchema, const std::string& objectKey) {
00581 
00582     // get the list of object parameters in the menu
00583 
00584     // select * from CMS_GT.L1T_MENU_OP_VIEW
00585     //     where L1T_MENU_OP_VIEW.MENU_IMPLEMENTATION = objectKey
00586 
00587     const std::vector<std::string>& columnsMenuOp = m_omdsReader.columnNamesView(
00588             gtSchema, "L1T_MENU_OP_VIEW");
00589 
00590     if (m_isDebugEnabled) {
00591         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n List of columns in L1T_MENU_OP_VIEW:\n"
00592                 << std::endl;
00593         for (std::vector<std::string>::const_iterator iter = columnsMenuOp.begin(); iter
00594                 != columnsMenuOp.end(); iter++) {
00595             LogTrace("L1GtTriggerMenuConfigOnlineProd") << ( *iter ) << std::endl;
00596 
00597         }
00598         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00599     }
00600 
00601     l1t::OMDSReader::QueryResults resultsMenuOp = m_omdsReader.basicQueryView(
00602             columnsMenuOp, gtSchema, "L1T_MENU_OP_VIEW", "L1T_MENU_OP_VIEW.MENU_IMPLEMENTATION",
00603             m_omdsReader.singleAttribute(objectKey));
00604 
00605     // check if query was successful is based on size of returned list
00606     // BUT one can have menus w/o object parameters - no error for empty list, but a warning!
00607     if (resultsMenuOp.queryFailed()) {
00608         edm::LogWarning("L1-O2O")
00609                 << "Warning: Content of L1T_MENU_OP_VIEW for L1GtTriggerMenu implementation key: "
00610                 << "\n  " << objectKey << "\nis empty!"
00611                 << "\nNo object parameters associated to menu are found for this menu.";
00612 
00613     }
00614 
00615     TableMenuObjectParameters menuObjectParameters;
00616     int resultsMenuOpRows = resultsMenuOp.numberRows();
00617 
00618     for (int iRow = 0; iRow < resultsMenuOpRows; ++iRow) {
00619 
00620         for (std::vector<std::string>::const_iterator constIt = columnsMenuOp.begin(); constIt
00621                 != columnsMenuOp.end(); ++constIt) {
00622 
00623             if ( ( *constIt ) == "ID") {
00624                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.opId);
00625 
00626             } else if ( ( *constIt ) == "PT_HIGH_THRESHOLD") {
00627                 resultsMenuOp.fillVariableFromRow(
00628                         *constIt, iRow, menuObjectParameters.ptHighThreshold);
00629 
00630             } else if ( ( *constIt ) == "PT_LOW_THRESHOLD") {
00631                 resultsMenuOp.fillVariableFromRow(
00632                         *constIt, iRow, menuObjectParameters.ptLowThreshold);
00633 
00634             } else if ( ( *constIt ) == "ENABLE_MIP") {
00635                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.enableMip);
00636 
00637             } else if ( ( *constIt ) == "ENABLE_ISO") {
00638                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.enableIso);
00639 
00640             } else if ( ( *constIt ) == "REQUEST_ISO") {
00641                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.requestIso);
00642 
00643             } else if ( ( *constIt ) == "ENERGY_OVERFLOW") {
00644                 resultsMenuOp.fillVariableFromRow(
00645                         *constIt, iRow, menuObjectParameters.energyOverflow);
00646 
00647             } else if ( ( *constIt ) == "ET_THRESHOLD") {
00648                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.etThreshold);
00649 
00650             } else if ( ( *constIt ) == "ETA_RANGE") {
00651                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.etaRange);
00652 
00653             } else if ( ( *constIt ) == "PHI_RANGE") {
00654                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.phiRange);
00655 
00656             } else if ( ( *constIt ) == "PHI_LOW") {
00657                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.phiLow);
00658 
00659             } else if ( ( *constIt ) == "PHI_HIGH") {
00660                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.phiHigh);
00661 
00662             } else if ( ( *constIt ) == "QUALITY_RANGE") {
00663                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.qualityRange);
00664 
00665             } else if ( ( *constIt ) == "CHARGE") {
00666                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.charge);
00667 
00668             } else {
00669                 // do nothing
00670 
00671             }
00672 
00673         }
00674 
00675         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00676             << " ID " << menuObjectParameters.opId
00677             << " PT_HIGH_THRESHOLD " << menuObjectParameters.ptHighThreshold
00678             << " PT_LOW_THRESHOLD " << menuObjectParameters.ptLowThreshold
00679             << " ENABLE_MIP " << menuObjectParameters.enableMip
00680             << " ENABLE_ISO " << menuObjectParameters.enableIso
00681             << " REQUEST_ISO " << menuObjectParameters.requestIso
00682             << " ENERGY_OVERFLOW " << menuObjectParameters.energyOverflow
00683             << " ET_THRESHOLD " << menuObjectParameters.etThreshold
00684             << " ETA_RANGE " << menuObjectParameters.etaRange
00685             << " PHI_RANGE " << menuObjectParameters.phiRange
00686             << " PHI_LOW " << menuObjectParameters.phiLow
00687             << " PHI_HIGH " << menuObjectParameters.phiHigh
00688             << " QUALITY_RANGE " << menuObjectParameters.qualityRange
00689             << " CHARGE " << menuObjectParameters.charge
00690             << std::endl;
00691 
00692         m_tableMenuObjectParameters.push_back(menuObjectParameters);
00693     }
00694 
00695     if (m_isDebugEnabled) {
00696         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00697                 << "\n Number of rows read from L1T_MENU_OP_VIEW: " << resultsMenuOpRows
00698                 << std::endl;
00699 
00700     }
00701 
00702     return true;
00703 
00704 }
00705 
00706 // retrieve table with technical triggers from DB
00707 bool L1GtTriggerMenuConfigOnlineProd::tableMenuTechTrigFromDB(
00708         const std::string& gtSchema, const std::string& objectKey) {
00709 
00710     // select * from CMS_GT.L1T_MENU_TECHTRIG_VIEW
00711     //     where L1T_MENU_TECHTRIG_VIEW.MENU_IMPLEMENTATION = objectKey
00712 
00713     const std::vector<std::string>& columnsMenuTechTrig =
00714             m_omdsReader.columnNamesView(gtSchema, "L1T_MENU_TECHTRIG_VIEW");
00715 
00716     if (m_isDebugEnabled) {
00717         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00718                 << "\n List of columns in L1T_MENU_TECHTRIG_VIEW:\n"
00719                 << std::endl;
00720         for (std::vector<std::string>::const_iterator iter =
00721                 columnsMenuTechTrig.begin(); iter != columnsMenuTechTrig.end(); iter++) {
00722             LogTrace("L1GtTriggerMenuConfigOnlineProd") << (*iter) << std::endl;
00723 
00724         }
00725         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00726     }
00727 
00728     l1t::OMDSReader::QueryResults resultsMenuTechTrig =
00729             m_omdsReader.basicQueryView(columnsMenuTechTrig, gtSchema,
00730                     "L1T_MENU_TECHTRIG_VIEW",
00731                     "L1T_MENU_TECHTRIG_VIEW.MENU_IMPLEMENTATION",
00732                     m_omdsReader.singleAttribute(objectKey));
00733 
00734     // check if query was successful is based on size of returned list
00735     // BUT one can have menus w/o technical triggers - no error for empty list, but a warning!
00736     if (resultsMenuTechTrig.queryFailed()) {
00737         edm::LogWarning("L1-O2O")
00738                 << "Warning: Content of L1T_MENU_TECHTRIG_VIEW for L1GtTriggerMenu implementation key: "
00739                 << "\n  " << objectKey << "\nis empty!"
00740                 << "\nNo technical triggers are found for this menu.";
00741 
00742     }
00743 
00744     TableMenuTechTrig menuTechTrig;
00745     int resultsMenuTechTrigRows = resultsMenuTechTrig.numberRows();
00746 
00747     for (int iRow = 0; iRow < resultsMenuTechTrigRows; ++iRow) {
00748 
00749         for (std::vector<std::string>::const_iterator constIt =
00750                 columnsMenuTechTrig.begin(); constIt
00751                 != columnsMenuTechTrig.end(); ++constIt) {
00752 
00753             if ((*constIt) == "TECHTRIG_INDEX") {
00754                 resultsMenuTechTrig.fillVariableFromRow(*constIt, iRow,
00755                         menuTechTrig.bitNumberSh);
00756 
00757             } else if ((*constIt) == "NAME") {
00758                 resultsMenuTechTrig.fillVariableFromRow(*constIt, iRow,
00759                         menuTechTrig.techName);
00760 
00761             } else {
00762                 // do nothing
00763 
00764             }
00765 
00766         }
00767 
00768         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "Row  " << iRow
00769                 << ": index = " << menuTechTrig.bitNumberSh << " techName = "
00770                 << menuTechTrig.techName << std::endl;
00771 
00772         m_tableMenuTechTrig.push_back(menuTechTrig);
00773 
00774     }
00775 
00776     if (m_isDebugEnabled) {
00777         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00778                 << "\n Number of rows read from L1T_MENU_TECHTRIG_VIEW: "
00779                 << resultsMenuTechTrigRows << std::endl;
00780 
00781     }
00782 
00783     return true;
00784 
00785 }
00786 
00787 // return for an algorithm with bitNr the mapping between the integer index in logical expression
00788 // and the condition name (FK)
00789 const std::map<int, std::string> L1GtTriggerMenuConfigOnlineProd::condIndexNameMap(
00790         const short bitNr) const {
00791 
00792     std::map<int, std::string> mapIndexName;
00793 
00794     for (std::vector<TableMenuAlgoCond>::const_iterator constIt = m_tableMenuAlgoCond.begin(); constIt
00795             != m_tableMenuAlgoCond.end(); ++constIt) {
00796 
00797         if (bitNr == (*constIt).bitNumberSh) {
00798             mapIndexName[static_cast<int>((*constIt).condIndexF)] = (*constIt).condFK;
00799         }
00800 
00801     }
00802 
00803     if (m_isDebugEnabled) {
00804 
00805         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Bit number : " << bitNr << std::endl;
00806 
00807         for (std::map<int, std::string>::const_iterator constIt = mapIndexName.begin(); constIt
00808                 != mapIndexName.end(); ++constIt) {
00809 
00810             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "  Condition index -> name: "
00811                     << ( ( *constIt ).first ) << " " << ( ( *constIt ).second ) << std::endl;
00812 
00813         }
00814 
00815     }
00816 
00817 
00818     return mapIndexName;
00819 
00820 }
00821 
00822 // convert a logical expression with indices to a logical expression with names
00823 std::string L1GtTriggerMenuConfigOnlineProd::convertLogicalExpression(
00824         const std::string& expressionIndices, const std::map<int, std::string>& mapCondIndexName) const {
00825 
00826     std::string expressionNames;
00827 
00828     L1GtLogicParser parserIndices = L1GtLogicParser(expressionIndices);
00829     parserIndices.convertIntToNameLogicalExpression(mapCondIndexName);
00830     expressionNames = parserIndices.logicalExpression();
00831 
00832     return expressionNames;
00833 
00834 }
00835 
00836 // return the chip number for an algorithm with index bitNumberSh
00837 int L1GtTriggerMenuConfigOnlineProd::chipNumber(short bitNumberSh) const {
00838 
00839     // FIXME get it from Event Setup
00840     const unsigned numberConditionChips = 2;
00841     const unsigned pinsOnConditionChip = 96;
00842     std::vector<int> orderConditionChip;
00843     orderConditionChip.push_back(2);
00844     orderConditionChip.push_back(1);
00845 
00846     int posChip = ( static_cast<unsigned> (bitNumberSh) / pinsOnConditionChip ) + 1;
00847     for (unsigned int iChip = 0; iChip < numberConditionChips; ++iChip) {
00848         if (posChip == orderConditionChip[iChip]) {
00849             return static_cast<int>(iChip);
00850         }
00851     }
00852 
00853     // chip number not found
00854     return -1;
00855 
00856 }
00857 
00858 // build the algorithm map in the menu
00859 void L1GtTriggerMenuConfigOnlineProd::buildAlgorithmMap() {
00860 
00861 
00862      // temporary value
00863     int bitNumber = -1;
00864     std::string logicalExpression;
00865 
00866     // loop over m_tableMenuAlgo
00867     for (std::vector<TableMenuAlgo>::const_iterator constIt = m_tableMenuAlgo.begin(); constIt
00868             != m_tableMenuAlgo.end(); constIt++) {
00869 
00870         bitNumber = static_cast<int> ((*constIt).bitNumberSh);
00871 
00872         const std::map<int, std::string>& condIndexName = condIndexNameMap((*constIt).bitNumberSh);
00873         logicalExpression = convertLogicalExpression((*constIt).logExpression, condIndexName);
00874 
00875         // create a new algorithm and insert it into algorithm map
00876         L1GtAlgorithm alg((*constIt).algName, logicalExpression, bitNumber);
00877         alg.setAlgoAlias((*constIt).algAlias);
00878 
00879         // set algorithm chip number:
00880         int algChipNr = chipNumber((*constIt).bitNumberSh);
00881         alg.setAlgoChipNumber(algChipNr);
00882 
00883         // insert algorithm
00884         m_algorithmMap[(*constIt).algName] = alg;
00885         m_algorithmAliasMap[(*constIt).algAlias] = alg;
00886 
00887     }
00888 
00889 }
00890 
00891 // build the technical trigger map in the menu
00892 void L1GtTriggerMenuConfigOnlineProd::buildTechnicalTriggerMap() {
00893 
00894     // temporary value
00895     int bitNumber = -1;
00896     std::string logicalExpression;
00897 
00898     // loop over m_tableMenuTechTrig
00899     for (std::vector<TableMenuTechTrig>::const_iterator constIt =
00900             m_tableMenuTechTrig.begin(); constIt != m_tableMenuTechTrig.end(); constIt++) {
00901 
00902         bitNumber = static_cast<int> ((*constIt).bitNumberSh);
00903 
00904         // create a new technical trigger and insert it into technical trigger map
00905         // technical triggers have L1GtAlgorithm class
00906         L1GtAlgorithm techTrig((*constIt).techName, logicalExpression, bitNumber);
00907 
00908         // chip number set in constructor to -1 - no meaning for technical triggers
00909 
00910         // insert technical trigger
00911         m_technicalTriggerMap[(*constIt).techName] = techTrig;
00912 
00913         // no alias is defined for technical triggers
00914     }
00915 
00916 }
00917 
00918 
00919 L1GtConditionCategory L1GtTriggerMenuConfigOnlineProd::strToEnumCondCategory(
00920         const std::string& strCategory) {
00921 
00922     if (strCategory == "CondMuon") {
00923         return CondMuon;
00924     } else if (strCategory == "CondCalo") {
00925         return CondCalo;
00926     } else if (strCategory == "CondEnergySum") {
00927         return CondEnergySum;
00928     } else if (strCategory == "CondJetCounts") {
00929         return CondJetCounts;
00930     } else if (strCategory == "CondCorrelation") {
00931         return CondCorrelation;
00932     } else if (strCategory == "CondCastor") {
00933         return CondCastor;
00934     } else if (strCategory == "CondHfBitCounts") {
00935         return CondHfBitCounts;
00936     } else if (strCategory == "CondHfRingEtSums") {
00937         return CondHfRingEtSums;
00938     } else if (strCategory == "CondBptx") {
00939         return CondBptx;
00940     } else if (strCategory == "CondExternal") {
00941         return CondExternal;
00942     } else if (strCategory == "CondNull") {
00943         return CondNull;
00944     } else {
00945         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
00946                 << "\n Warning: string " << strCategory
00947                 << " not defined. Returning CondNull.\n" << std::endl;
00948         return CondNull;
00949     }
00950 
00951     return CondNull;
00952 
00953 }
00954 
00955 // string to enum L1GtConditionType conversion
00956 L1GtConditionType L1GtTriggerMenuConfigOnlineProd::strToEnumCondType(const std::string& strType) {
00957 
00958     if (strType == "1s") {
00959         return Type1s;
00960     } else if (strType == "2s") {
00961         return Type2s;
00962     } else if (strType == "2wsc") {
00963         return Type2wsc;
00964     } else if (strType == "2cor") {
00965         return Type2cor;
00966     } else if (strType == "3s") {
00967         return Type3s;
00968     } else if (strType == "4s") {
00969         return Type4s;
00970     } else if (strType == "ETM") {
00971         return TypeETM;
00972     } else if (strType == "ETT") {
00973         return TypeETT;
00974     } else if (strType == "HTT") {
00975         return TypeHTT;
00976     } else if (strType == "HTM") {
00977         return TypeHTM;
00978     } else if (strType == "JetCounts") {
00979         return TypeJetCounts;
00980     } else if (strType == "Castor") {
00981         return TypeCastor;
00982     } else if (strType == "HfBitCounts") {
00983         return TypeHfBitCounts;
00984     } else if (strType == "HfRingEtSums") {
00985         return TypeHfRingEtSums;
00986     } else if (strType == "Bptx") {
00987         return TypeBptx;
00988     } else if (strType == "TypeExternal") {
00989         return TypeExternal;
00990     } else {
00991         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
00992                 << "\n Warning: string " << strType
00993                 << " not associated to any L1GtConditionType. Returning TypeNull.\n"
00994                 << std::endl;
00995         return TypeNull;
00996     }
00997 
00998     return TypeNull;
00999 
01000 }
01001 
01002 // string to enum L1GtObject conversion
01003 L1GtObject L1GtTriggerMenuConfigOnlineProd::strToEnumL1GtObject(const std::string& strObject) {
01004 
01005     if (strObject == "Mu") {
01006         return Mu;
01007     } else if (strObject == "NoIsoEG") {
01008         return NoIsoEG;
01009     } else if (strObject == "IsoEG") {
01010         return IsoEG;
01011     } else if (strObject == "CenJet") {
01012         return CenJet;
01013     } else if (strObject == "ForJet") {
01014         return ForJet;
01015     } else if (strObject == "TauJet") {
01016         return TauJet;
01017     } else if (strObject == "ETM") {
01018         return ETM;
01019     } else if (strObject == "ETT") {
01020         return ETT;
01021     } else if (strObject == "HTT") {
01022         return HTT;
01023     } else if (strObject == "HTM") {
01024         return HTM;
01025     } else if (strObject == "JetCounts") {
01026         return JetCounts;
01027     } else if (strObject == "HfBitCounts") {
01028         return HfBitCounts;
01029     } else if (strObject == "HfRingEtSums") {
01030         return HfRingEtSums;
01031     } else if (strObject == "TechTrig") {
01032         return TechTrig;
01033     } else if (strObject == "Castor") {
01034         return Castor;
01035     } else if (strObject == "BPTX") {
01036         return BPTX;
01037     } else if (strObject == "GtExternal") {
01038         return GtExternal;
01039     } else {
01040         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01041                 << "\n Warning: string " << strObject
01042                 << " not associated to any L1GtObject. Returning Mu (no Null type).\n"
01043                 << std::endl;
01044         return Mu;
01045     }
01046 
01047     // no null type, so returning Mu - should never arrive here
01048     return Mu;
01049 
01050 }
01051 
01052 void L1GtTriggerMenuConfigOnlineProd::splitHexStringInTwo64bitWords(
01053         const std::string& hexStr, std::string& hex0WordStr, std::string& hex1WordStr) {
01054 
01055     unsigned int lenHexStr = hexStr.length();
01056 
01057     if (lenHexStr < 3) {
01058         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Warning: string " << hexStr
01059                 << " has length less than 3." << "\n Not possible to split it in two 64-bit words."
01060                 << "\n Return two zero strings." << std::endl;
01061         hex0WordStr = "0x0";
01062         hex1WordStr = "0x0";
01063 
01064         return;
01065     }
01066 
01067     unsigned int lenHex = lenHexStr - 2;
01068     unsigned int len0Word = lenHex > 16 ? 16 : lenHex;
01069     unsigned int len1Word = lenHex - len0Word;
01070 
01071     unsigned int pos0Word = lenHexStr - len0Word;
01072     hex0WordStr = "0x" + hexStr.substr(pos0Word, len0Word);
01073 
01074     if (len1Word > 0) {
01075         unsigned int pos1Word = pos0Word - len1Word;
01076         hex1WordStr = "0x" + hexStr.substr(pos1Word, len1Word);
01077     } else {
01078         hex1WordStr = "0x0";
01079     }
01080 }
01081 
01082 // get a list of chip numbers from the m_tableMenuAlgoCond table for a condition
01083 std::list<int> L1GtTriggerMenuConfigOnlineProd::listChipNumber(const std::string& condFK) {
01084 
01085     std::list<int> chipList;
01086 
01087     // loop over m_tableMenuAlgoCond
01088     for (std::vector<TableMenuAlgoCond>::const_iterator constIt = m_tableMenuAlgoCond.begin(); constIt
01089             != m_tableMenuAlgoCond.end(); constIt++) {
01090 
01091         if (condFK == ( *constIt ).condFK) {
01092             int chipNr = chipNumber( ( *constIt ).bitNumberSh);
01093             chipList.push_back(chipNr);
01094         }
01095     }
01096 
01097     return chipList;
01098 
01099 }
01100 
01101 void L1GtTriggerMenuConfigOnlineProd::fillMuonObjectParameter(
01102         const std::string& opFK, L1GtMuonTemplate::ObjectParameter& objPar) {
01103 
01104     // loop over m_tableMenuCond
01105     for (std::vector<TableMenuObjectParameters>::const_iterator constIt =
01106             m_tableMenuObjectParameters.begin(); constIt != m_tableMenuObjectParameters.end(); constIt++) {
01107 
01108         if (opFK == ( *constIt ).opId) {
01109             objPar.ptHighThreshold = static_cast<unsigned int> ( ( *constIt ).ptHighThreshold);
01110             objPar.ptLowThreshold = static_cast<unsigned int> ( ( *constIt ).ptLowThreshold);
01111             objPar.enableMip = static_cast<bool> ( ( *constIt ).enableMip);
01112             objPar.enableIso = static_cast<bool> ( ( *constIt ).enableIso);
01113             objPar.requestIso = static_cast<bool> ( ( *constIt ).requestIso);
01114             objPar.etaRange = lexical_cast_from_hex<unsigned long long>( ( *constIt ).etaRange);
01115             objPar.phiHigh = static_cast<unsigned int> ( ( *constIt ).phiHigh);
01116             objPar.phiLow = static_cast<unsigned int> ( ( *constIt ).phiLow);
01117             objPar.qualityRange = lexical_cast_from_hex<unsigned int>( ( *constIt ).qualityRange);
01118             //objPar.charge = static_cast<unsigned int> ( ( *constIt ).charge);
01119 
01120             // can break after it is found - DB consistency
01121             break;
01122         }
01123     }
01124 
01125 }
01126 
01127 void L1GtTriggerMenuConfigOnlineProd::addMuonCondition(const TableMenuCond& condDB) {
01128 
01129 
01130     L1GtMuonTemplate muonCond(condDB.cond);
01131     muonCond.setCondType(strToEnumCondType(condDB.condType));
01132 
01133     // object types - all muons
01134     int nrObj = muonCond.nrObjects();
01135     std::vector<L1GtObject> objType(nrObj, Mu);
01136     muonCond.setObjectType(objType);
01137 
01138     muonCond.setCondGEq(condDB.condGEq);
01139 
01140     // temporary storage of the parameters
01141     std::vector<L1GtMuonTemplate::ObjectParameter> objParameter(nrObj);
01142 
01143     for (int iObj = 0; iObj < nrObj; ++iObj) {
01144         if (iObj == 0) {
01145             fillMuonObjectParameter(condDB.objectParameter1FK, objParameter[iObj]);
01146         } else if (iObj == 1) {
01147             fillMuonObjectParameter(condDB.objectParameter2FK, objParameter[iObj]);
01148         } else if (iObj == 2) {
01149             fillMuonObjectParameter(condDB.objectParameter3FK, objParameter[iObj]);
01150         } else if (iObj == 3) {
01151             fillMuonObjectParameter(condDB.objectParameter4FK, objParameter[iObj]);
01152         } else {
01153             LogTrace("L1GtTriggerMenuConfigOnlineProd")
01154                     << "\n Warning: number of objects requested " << nrObj
01155                     << " not available in DB." << "\n Maximum 4 object parameters implemented. \n"
01156                     << std::endl;
01157         }
01158     }
01159 
01160     L1GtMuonTemplate::CorrelationParameter corrParameter;
01161     corrParameter.chargeCorrelation = static_cast<unsigned int> (condDB.chargeCorrelation);
01162     if (muonCond.wsc()) {
01163         corrParameter.deltaEtaRange = lexical_cast_from_hex<unsigned long long> (
01164                 condDB.deltaEtaRange);
01165 
01166         std::string word0;
01167         std::string word1;
01168         splitHexStringInTwo64bitWords(condDB.deltaPhiRange, word0, word1);
01169 
01170         corrParameter.deltaPhiRange0Word = lexical_cast_from_hex<unsigned long long> (word0);
01171         corrParameter.deltaPhiRange1Word = lexical_cast_from_hex<unsigned long long> (word1);
01172 
01173         corrParameter.deltaPhiMaxbits = 0; // FIXME check correlations
01174     }
01175 
01176     muonCond.setConditionParameter(objParameter, corrParameter);
01177 
01178     // get chip number list
01179     std::list<int> chipList = listChipNumber(condDB.cond);
01180 
01181     // eliminate duplicates
01182     chipList.sort();
01183     chipList.unique();
01184 
01185     // add the same condition once to every chip where required
01186     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01187 
01188         muonCond.setCondChipNr(*itChip);
01189 
01190         // no check for uniqueness - done by DB
01191         ( m_vecMuonTemplate[*itChip] ).push_back(muonCond);
01192 
01193         if (m_isDebugEnabled) {
01194             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01195                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01196 
01197             LogTrace("L1GtTriggerMenuConfigOnlineProd") << muonCond << "\n" << std::endl;
01198         }
01199     }
01200 
01201 }
01202 
01203 void L1GtTriggerMenuConfigOnlineProd::fillCaloObjectParameter(
01204         const std::string& opFK, L1GtCaloTemplate::ObjectParameter& objPar) {
01205 
01206     // loop over m_tableMenuCond
01207     for (std::vector<TableMenuObjectParameters>::const_iterator constIt =
01208             m_tableMenuObjectParameters.begin(); constIt != m_tableMenuObjectParameters.end(); constIt++) {
01209 
01210         if (opFK == ( *constIt ).opId) {
01211             objPar.etThreshold = static_cast<unsigned int> ( ( *constIt ).etThreshold);
01212             objPar.etaRange = lexical_cast_from_hex<unsigned int> ( ( *constIt ).etaRange);
01213             objPar.phiRange = lexical_cast_from_hex<unsigned int> ( ( *constIt ).phiRange);
01214 
01215             // can break after it is found - DB consistency
01216             break;
01217         }
01218     }
01219 
01220 }
01221 
01222 void L1GtTriggerMenuConfigOnlineProd::addCaloCondition(const TableMenuCond& condDB) {
01223 
01224     L1GtCaloTemplate caloCond(condDB.cond);
01225     caloCond.setCondType(strToEnumCondType(condDB.condType));
01226 
01227     // object types - all have the same type, so reading it for first object is OK
01228     int nrObj = caloCond.nrObjects();
01229 
01230     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01231     std::vector<L1GtObject> objType(nrObj, obj);
01232     caloCond.setObjectType(objType);
01233 
01234     caloCond.setCondGEq(condDB.condGEq);
01235 
01236     // temporary storage of the parameters
01237     std::vector<L1GtCaloTemplate::ObjectParameter> objParameter(nrObj);
01238 
01239     for (int iObj = 0; iObj < nrObj; ++iObj) {
01240         if (iObj == 0) {
01241             fillCaloObjectParameter(condDB.objectParameter1FK, objParameter[iObj]);
01242         } else if (iObj == 1) {
01243             fillCaloObjectParameter(condDB.objectParameter2FK, objParameter[iObj]);
01244         } else if (iObj == 2) {
01245             fillCaloObjectParameter(condDB.objectParameter3FK, objParameter[iObj]);
01246         } else if (iObj == 3) {
01247             fillCaloObjectParameter(condDB.objectParameter4FK, objParameter[iObj]);
01248         } else {
01249             LogTrace("L1GtTriggerMenuConfigOnlineProd")
01250                     << "\n Warning: number of objects requested " << nrObj
01251                     << " not available in DB." << "\n Maximum 4 object parameters implemented. \n"
01252                     << std::endl;
01253         }
01254     }
01255 
01256     L1GtCaloTemplate::CorrelationParameter corrParameter;
01257     if (caloCond.wsc()) {
01258         corrParameter.deltaEtaRange = lexical_cast_from_hex<unsigned long long> (
01259                 condDB.deltaEtaRange);
01260 
01261         corrParameter.deltaPhiRange = lexical_cast_from_hex<unsigned long long> (
01262                 condDB.deltaPhiRange);
01263         corrParameter.deltaPhiMaxbits = 0; // FIXME check correlations
01264     }
01265 
01266     caloCond.setConditionParameter(objParameter, corrParameter);
01267 
01268     // get chip number list
01269     std::list<int> chipList = listChipNumber(condDB.cond);
01270 
01271     // eliminate duplicates
01272     chipList.sort();
01273     chipList.unique();
01274 
01275     // add the same condition once to every chip where required
01276     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01277 
01278         caloCond.setCondChipNr(*itChip);
01279 
01280         // no check for uniqueness - done by DB
01281         ( m_vecCaloTemplate[*itChip] ).push_back(caloCond);
01282 
01283         if (m_isDebugEnabled) {
01284             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01285                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01286 
01287             LogTrace("L1GtTriggerMenuConfigOnlineProd") << caloCond << "\n" << std::endl;
01288         }
01289     }
01290 
01291 }
01292 
01293 void L1GtTriggerMenuConfigOnlineProd::fillEnergySumObjectParameter(
01294         const std::string& opFK, L1GtEnergySumTemplate::ObjectParameter& objPar,
01295         const L1GtObject& obj) {
01296 
01297     // loop over m_tableMenuCond
01298     for (std::vector<TableMenuObjectParameters>::const_iterator constIt =
01299             m_tableMenuObjectParameters.begin(); constIt != m_tableMenuObjectParameters.end(); constIt++) {
01300 
01301         if (opFK == ( *constIt ).opId) {
01302             objPar.etThreshold = static_cast<unsigned int> ( ( *constIt ).etThreshold);
01303             objPar.energyOverflow = static_cast<bool> ( ( *constIt ).energyOverflow); // not used
01304 
01305             std::string word0;
01306             std::string word1;
01307             splitHexStringInTwo64bitWords( ( *constIt ).phiRange, word0, word1);
01308 
01309             if (obj == ETM) {
01310                 objPar.phiRange0Word = lexical_cast_from_hex<unsigned long long> (word0);
01311                 objPar.phiRange1Word = lexical_cast_from_hex<unsigned long long> (word1);
01312 
01313             } else if (obj == HTM) {
01314                 objPar.phiRange0Word = lexical_cast_from_hex<unsigned long long> (word0);
01315             }
01316 
01317             // can break after it is found - DB consistency
01318             break;
01319         }
01320     }
01321 
01322 }
01323 
01324 void L1GtTriggerMenuConfigOnlineProd::addEnergySumCondition(const TableMenuCond& condDB) {
01325 
01326     L1GtEnergySumTemplate esumCond(condDB.cond);
01327     esumCond.setCondType(strToEnumCondType(condDB.condType));
01328 
01329     // object types - all energy sums are global - so 1 object
01330     int nrObj = 1;
01331 
01332     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01333     std::vector<L1GtObject> objType(nrObj, obj);
01334     esumCond.setObjectType(objType);
01335 
01336     esumCond.setCondGEq(condDB.condGEq);
01337 
01338     // temporary storage of the parameters - no CorrelationParameter
01339     std::vector<L1GtEnergySumTemplate::ObjectParameter> objParameter(nrObj);
01340     fillEnergySumObjectParameter(condDB.objectParameter1FK, objParameter[0], objType[0]);
01341 
01342     esumCond.setConditionParameter(objParameter);
01343 
01344     // get chip number list
01345     std::list<int> chipList = listChipNumber(condDB.cond);
01346 
01347     // eliminate duplicates
01348     chipList.sort();
01349     chipList.unique();
01350 
01351     // add the same condition once to every chip where required
01352     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01353 
01354         esumCond.setCondChipNr(*itChip);
01355 
01356         // no check for uniqueness - done by DB
01357         ( m_vecEnergySumTemplate[*itChip] ).push_back(esumCond);
01358 
01359         if (m_isDebugEnabled) {
01360             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01361                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01362 
01363             LogTrace("L1GtTriggerMenuConfigOnlineProd") << esumCond << "\n" << std::endl;
01364         }
01365     }
01366 
01367 }
01368 
01369 
01370 void L1GtTriggerMenuConfigOnlineProd::addJetCountsCondition(const TableMenuCond& condDB) {
01371 
01372     L1GtJetCountsTemplate jcCond(condDB.cond);
01373     jcCond.setCondType(strToEnumCondType(condDB.condType));
01374 
01375     // object types - jet counts are "global"
01376     int nrObj = 1;
01377 
01378     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01379     std::vector<L1GtObject> objType(nrObj, obj);
01380     jcCond.setObjectType(objType);
01381 
01382     jcCond.setCondGEq(condDB.condGEq);
01383 
01384     // temporary storage of the parameters - no CorrelationParameter
01385     // for counts, the DB implementation is without OP, directly in TableMenuCond
01386     std::vector<L1GtJetCountsTemplate::ObjectParameter> objParameter(nrObj);
01387     objParameter.at(0).countIndex = static_cast<unsigned int>(condDB.countIndex);
01388     objParameter.at(0).countThreshold = static_cast<unsigned int>(condDB.countThreshold);
01389     objParameter.at(0).countOverflow = false ; // not used
01390 
01391     jcCond.setConditionParameter(objParameter);
01392 
01393     // get chip number list
01394     std::list<int> chipList = listChipNumber(condDB.cond);
01395 
01396     // eliminate duplicates
01397     chipList.sort();
01398     chipList.unique();
01399 
01400     // add the same condition once to every chip where required
01401     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01402 
01403         jcCond.setCondChipNr(*itChip);
01404 
01405         // no check for uniqueness - done by DB
01406         ( m_vecJetCountsTemplate[*itChip] ).push_back(jcCond);
01407 
01408         if (m_isDebugEnabled) {
01409             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01410                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01411 
01412             LogTrace("L1GtTriggerMenuConfigOnlineProd") << jcCond << "\n" << std::endl;
01413         }
01414     }
01415 
01416 }
01417 
01418 void L1GtTriggerMenuConfigOnlineProd::addHfBitCountsCondition(const TableMenuCond& condDB) {
01419 
01420     L1GtHfBitCountsTemplate countsCond(condDB.cond);
01421     countsCond.setCondType(strToEnumCondType(condDB.condType));
01422 
01423     // object types - HF bit counts are "global"
01424     int nrObj = 1;
01425 
01426     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01427     std::vector<L1GtObject> objType(nrObj, obj);
01428     countsCond.setObjectType(objType);
01429 
01430     countsCond.setCondGEq(condDB.condGEq);
01431 
01432     // temporary storage of the parameters - no CorrelationParameter
01433     // for counts, the DB implementation is without OP, directly in TableMenuCond
01434     std::vector<L1GtHfBitCountsTemplate::ObjectParameter> objParameter(nrObj);
01435     objParameter.at(0).countIndex = static_cast<unsigned int>(condDB.countIndex);
01436     objParameter.at(0).countThreshold = static_cast<unsigned int>(condDB.countThreshold);
01437 
01438     countsCond.setConditionParameter(objParameter);
01439 
01440     // get chip number list
01441     std::list<int> chipList = listChipNumber(condDB.cond);
01442 
01443     // eliminate duplicates
01444     chipList.sort();
01445     chipList.unique();
01446 
01447     // add the same condition once to every chip where required
01448     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01449 
01450         countsCond.setCondChipNr(*itChip);
01451 
01452         // no check for uniqueness - done by DB
01453         ( m_vecHfBitCountsTemplate[*itChip] ).push_back(countsCond);
01454 
01455         if (m_isDebugEnabled) {
01456             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01457                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01458 
01459             LogTrace("L1GtTriggerMenuConfigOnlineProd") << countsCond << "\n" << std::endl;
01460         }
01461     }
01462 
01463 }
01464 
01465 void L1GtTriggerMenuConfigOnlineProd::addHfRingEtSumsCondition(const TableMenuCond& condDB) {
01466 
01467     L1GtHfRingEtSumsTemplate esumCond(condDB.cond);
01468     esumCond.setCondType(strToEnumCondType(condDB.condType));
01469 
01470     // object types - HF energy sums are "global"
01471     int nrObj = 1;
01472 
01473     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01474     std::vector<L1GtObject> objType(nrObj, obj);
01475     esumCond.setObjectType(objType);
01476 
01477     esumCond.setCondGEq(condDB.condGEq);
01478 
01479     // temporary storage of the parameters - no CorrelationParameter
01480     // for HF energy sums, the DB implementation is without OP, directly in TableMenuCond
01481     std::vector<L1GtHfRingEtSumsTemplate::ObjectParameter> objParameter(nrObj);
01482     objParameter.at(0).etSumIndex = static_cast<unsigned int>(condDB.countIndex);
01483     objParameter.at(0).etSumThreshold = static_cast<unsigned int>(condDB.countThreshold);
01484 
01485     esumCond.setConditionParameter(objParameter);
01486 
01487     // get chip number list
01488     std::list<int> chipList = listChipNumber(condDB.cond);
01489 
01490     // eliminate duplicates
01491     chipList.sort();
01492     chipList.unique();
01493 
01494     // add the same condition once to every chip where required
01495     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01496 
01497         esumCond.setCondChipNr(*itChip);
01498 
01499         // no check for uniqueness - done by DB
01500         ( m_vecHfRingEtSumsTemplate[*itChip] ).push_back(esumCond);
01501 
01502         if (m_isDebugEnabled) {
01503             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01504                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01505 
01506             LogTrace("L1GtTriggerMenuConfigOnlineProd") << esumCond << "\n" << std::endl;
01507         }
01508     }
01509 
01510 }
01511 
01512 void L1GtTriggerMenuConfigOnlineProd::addCastorCondition(const TableMenuCond& condDB) {
01513 
01514     L1GtCastorTemplate castorCond(condDB.cond);
01515     castorCond.setCondType(strToEnumCondType(condDB.condType));
01516 
01517     // object types - logical conditions have no objects associated in GT
01518     // one put however a "Castor" object type
01519     int nrObj = 1;
01520 
01521     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01522     std::vector<L1GtObject> objType(nrObj, obj);
01523     castorCond.setObjectType(objType);
01524 
01525     // irrelevant, set to false for completeness
01526     castorCond.setCondGEq(false);
01527 
01528     // logical conditions have no ObjectParameter, no CorrelationParameter
01529 
01530     // get chip number list
01531     std::list<int> chipList = listChipNumber(condDB.cond);
01532 
01533     // eliminate duplicates
01534     chipList.sort();
01535     chipList.unique();
01536 
01537     // add the same condition once to every chip where required
01538     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01539 
01540         castorCond.setCondChipNr(*itChip);
01541 
01542         // no check for uniqueness - done by DB
01543         ( m_vecCastorTemplate[*itChip] ).push_back(castorCond);
01544 
01545         if (m_isDebugEnabled) {
01546             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01547                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01548 
01549             LogTrace("L1GtTriggerMenuConfigOnlineProd") << castorCond << "\n" << std::endl;
01550         }
01551     }
01552 
01553 }
01554 
01555 void L1GtTriggerMenuConfigOnlineProd::addBptxCondition(const TableMenuCond& condDB) {
01556 
01557     L1GtBptxTemplate bptxCond(condDB.cond);
01558     bptxCond.setCondType(strToEnumCondType(condDB.condType));
01559 
01560     // object types - logical conditions have no objects associated in GT
01561     // one put however a "Bptx" object type
01562     int nrObj = 1;
01563 
01564     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01565     std::vector<L1GtObject> objType(nrObj, obj);
01566     bptxCond.setObjectType(objType);
01567 
01568     // irrelevant, set to false for completeness
01569     bptxCond.setCondGEq(false);
01570 
01571     // logical conditions have no ObjectParameter, no CorrelationParameter
01572 
01573     // get chip number list
01574     std::list<int> chipList = listChipNumber(condDB.cond);
01575 
01576 
01577 
01578     // eliminate duplicates
01579     chipList.sort();
01580     chipList.unique();
01581 
01582     // add the same condition once to every chip where required
01583     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01584 
01585         bptxCond.setCondChipNr(*itChip);
01586 
01587         // no check for uniqueness - done by DB
01588         ( m_vecBptxTemplate[*itChip] ).push_back(bptxCond);
01589 
01590         if (m_isDebugEnabled) {
01591             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01592                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01593 
01594             LogTrace("L1GtTriggerMenuConfigOnlineProd") << bptxCond << "\n" << std::endl;
01595         }
01596     }
01597 
01598 }
01599 
01600 void L1GtTriggerMenuConfigOnlineProd::addExternalCondition(const TableMenuCond& condDB) {
01601 
01602     L1GtExternalTemplate externalCond(condDB.cond);
01603     externalCond.setCondType(strToEnumCondType(condDB.condType));
01604 
01605     // object types - logical conditions have no objects associated in GT
01606     // one put however a "External" object type
01607     int nrObj = 1;
01608 
01609     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01610     std::vector<L1GtObject> objType(nrObj, obj);
01611     externalCond.setObjectType(objType);
01612 
01613     // irrelevant, set to false for completeness
01614     externalCond.setCondGEq(false);
01615 
01616     // logical conditions have no ObjectParameter, no CorrelationParameter
01617 
01618     // get chip number list
01619     std::list<int> chipList = listChipNumber(condDB.cond);
01620 
01621 
01622 
01623     // eliminate duplicates
01624     chipList.sort();
01625     chipList.unique();
01626 
01627     // add the same condition once to every chip where required
01628     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01629 
01630         externalCond.setCondChipNr(*itChip);
01631 
01632         // no check for uniqueness - done by DB
01633         ( m_vecExternalTemplate[*itChip] ).push_back(externalCond);
01634 
01635         if (m_isDebugEnabled) {
01636             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01637                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01638 
01639             LogTrace("L1GtTriggerMenuConfigOnlineProd") << externalCond << "\n" << std::endl;
01640         }
01641     }
01642 
01643 }
01644 
01645 void L1GtTriggerMenuConfigOnlineProd::addCorrelationCondition(const TableMenuCond& condDB) {
01646 
01647     // create a new correlation condition
01648     L1GtCorrelationTemplate correlationCond(condDB.cond);
01649     correlationCond.setCondType(strToEnumCondType(condDB.condType));
01650 
01651     // two objects (for sure) - type taken from DB
01652     const int nrObj = 2;
01653 
01654     std::vector<L1GtObject> objType(nrObj);
01655     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01656     objType[0] = obj;
01657 
01658     obj = strToEnumL1GtObject(condDB.gtObject2);
01659     objType[1] = obj;
01660 
01661     correlationCond.setObjectType(objType);
01662 
01663     // irrelevant, it is set for each subcondition
01664     correlationCond.setCondGEq(condDB.condGEq);
01665 
01666     // get chip number list, eliminate duplicates
01667     std::list<int> chipList = listChipNumber(condDB.cond);
01668     chipList.sort();
01669     chipList.unique();
01670 
01671     // temporary vectors for sub-conditions
01672     std::vector<L1GtConditionCategory> subcondCategory(nrObj);
01673     std::vector<int> subcondIndex(nrObj);
01674 
01675     bool wrongSubcondition = false;
01676 
01677     for (int iObj = 0; iObj < nrObj; ++iObj) {
01678 
01679         L1GtObject gtObj = objType[iObj];
01680 
01681         // sub-conditions (all have the same condGEq as the correlation condition).
01682         switch (gtObj) {
01683             case Mu: {
01684                 subcondCategory[iObj] = CondMuon;
01685 
01686                 // temporary storage of the parameters
01687                 std::vector<L1GtMuonTemplate::ObjectParameter> objParameter(1);
01688 
01689                 std::string subcondName;
01690                 if (iObj == 0) {
01691                     fillMuonObjectParameter(condDB.objectParameter1FK, objParameter[0]);
01692                     subcondName = condDB.objectParameter1FK;
01693                 } else if (iObj == 1) {
01694                     subcondName = condDB.objectParameter2FK;
01695                     fillMuonObjectParameter(condDB.objectParameter2FK, objParameter[0]);
01696                 }
01697 
01698                 L1GtMuonTemplate::CorrelationParameter corrPar; //  dummy, not needed for correlation conditions
01699 
01700                 L1GtMuonTemplate subcond(subcondName, Type1s);
01701                 subcond.setCondGEq(condDB.condGEq);
01702                 subcond.setObjectType(std::vector<L1GtObject> (1, gtObj));
01703                 subcond.setConditionParameter(objParameter, corrPar);
01704 
01705                 // add the same sub-condition once to every chip where required
01706                 for (std::list<int>::const_iterator itChip = chipList.begin(); itChip
01707                         != chipList.end(); ++itChip) {
01708 
01709                     subcond.setCondChipNr(*itChip);
01710 
01711                     // no check for uniqueness - done by DB
01712                     ( m_corMuonTemplate[*itChip] ).push_back(subcond);
01713 
01714                     // index
01715                     subcondIndex[iObj] = ( m_corMuonTemplate[*itChip] ).size() - 1;
01716 
01717                     if (m_isDebugEnabled) {
01718                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition "
01719                                 << ( condDB.cond ) << " on chip " << ( *itChip ) << "\n "
01720                                 << std::endl;
01721 
01722                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << subcond << "\n" << std::endl;
01723                     }
01724                 }
01725 
01726             }
01727                 break;
01728 
01729             case IsoEG:
01730             case NoIsoEG:
01731             case CenJet:
01732             case ForJet:
01733             case TauJet: {
01734 
01735                 subcondCategory[iObj] = CondCalo;
01736 
01737                 // temporary storage of the parameters
01738                 std::vector<L1GtCaloTemplate::ObjectParameter> objParameter(1);
01739 
01740                 std::string subcondName;
01741                 if (iObj == 0) {
01742                     fillCaloObjectParameter(condDB.objectParameter1FK, objParameter[0]);
01743                     subcondName = condDB.objectParameter1FK;
01744                 } else if (iObj == 1) {
01745                     subcondName = condDB.objectParameter2FK;
01746                     fillCaloObjectParameter(condDB.objectParameter2FK, objParameter[0]);
01747                 }
01748 
01749                 L1GtCaloTemplate::CorrelationParameter corrPar; //  dummy
01750 
01751                 L1GtCaloTemplate subcond(subcondName, Type1s);
01752                 subcond.setCondGEq(condDB.condGEq);
01753                 subcond.setObjectType(std::vector<L1GtObject> (1, gtObj));
01754                 subcond.setConditionParameter(objParameter, corrPar);
01755 
01756                 // add the same sub-condition once to every chip where required
01757                 for (std::list<int>::const_iterator itChip = chipList.begin(); itChip
01758                         != chipList.end(); ++itChip) {
01759 
01760                     subcond.setCondChipNr(*itChip);
01761 
01762                     // no check for uniqueness - done by DB
01763                     ( m_corCaloTemplate[*itChip] ).push_back(subcond);
01764 
01765                     // index
01766                     subcondIndex[iObj] = ( m_corCaloTemplate[*itChip] ).size() - 1;
01767 
01768                     if (m_isDebugEnabled) {
01769                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition "
01770                                 << ( condDB.cond ) << " on chip " << ( *itChip ) << "\n "
01771                                 << std::endl;
01772 
01773                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << subcond << "\n" << std::endl;
01774                     }
01775                 }
01776             }
01777                 break;
01778 
01779             case ETM:
01780             case HTM: {
01781 
01782                 subcondCategory[iObj] = CondEnergySum;
01783 
01784                 // temporary storage of the parameters
01785                 std::vector<L1GtEnergySumTemplate::ObjectParameter> objParameter(1);
01786 
01787                 std::string subcondName;
01788                 if (iObj == 0) {
01789                     fillEnergySumObjectParameter(condDB.objectParameter1FK, objParameter[0], gtObj);
01790                     subcondName = condDB.objectParameter1FK;
01791                 } else if (iObj == 1) {
01792                     subcondName = condDB.objectParameter2FK;
01793                     fillEnergySumObjectParameter(condDB.objectParameter2FK, objParameter[0], gtObj);
01794                 }
01795 
01796                 L1GtConditionType condType;
01797 
01798                 switch (gtObj) {
01799                     case ETM: {
01800                         condType = TypeETM;
01801                     }
01802                         break;
01803                     case HTM: {
01804                         condType = TypeHTM;
01805                     }
01806                         break;
01807                     default: {
01808                         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01809                                 << "\n Warning: wrong L1GtConditionType "
01810                                 << gtObj << std::endl;
01811 
01812                     }
01813                         break;
01814                 }
01815 
01816                 L1GtEnergySumTemplate subcond(subcondName, condType);
01817                 subcond.setCondGEq(condDB.condGEq);
01818                 subcond.setObjectType(std::vector<L1GtObject> (1, gtObj));
01819                 subcond.setConditionParameter(objParameter);
01820 
01821                 // add the same sub-condition once to every chip where required
01822                 for (std::list<int>::const_iterator itChip = chipList.begin(); itChip
01823                         != chipList.end(); ++itChip) {
01824 
01825                     subcond.setCondChipNr(*itChip);
01826 
01827                     // no check for uniqueness - done by DB
01828                     ( m_corEnergySumTemplate[*itChip] ).push_back(subcond);
01829 
01830                     // index
01831                     subcondIndex[iObj] = ( m_corEnergySumTemplate[*itChip] ).size() - 1;
01832 
01833                     if (m_isDebugEnabled) {
01834                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition "
01835                                 << ( condDB.cond ) << " on chip " << ( *itChip ) << "\n "
01836                                 << std::endl;
01837 
01838                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << subcond << "\n" << std::endl;
01839                     }
01840                 }
01841             }
01842                 break;
01843             case ETT:
01844             case HTT:
01845             case JetCounts:
01846             case HfBitCounts:
01847             case HfRingEtSums:
01848             case Castor:
01849             case BPTX:
01850             case GtExternal:
01851             case TechTrig: {
01852                 wrongSubcondition = true;
01853                 edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01854                         << "\n Warning: correlation condition "
01855                         << (condDB.cond)
01856                         << " with invalid sub-condition object type " << gtObj
01857                         << "\n Condition ignored!" << std::endl;
01858             }
01859             default: {
01860                 wrongSubcondition = true;
01861                 edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01862                         << "\n Warning: correlation condition "
01863                         << (condDB.cond)
01864                         << " with invalid sub-condition object type " << gtObj
01865                         << "\n Condition ignored!" << std::endl;
01866 
01867                 //
01868 
01869             }
01870                 break;
01871         }
01872 
01873     }
01874 
01875     if (wrongSubcondition) {
01876         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01877                 << "\n Warning: wrong sub-condition for correlation condition "
01878                 << (condDB.cond)
01879                 << "\n Condition not inserted in menu. \n A sub-condition may be left in the menu"
01880                 << std::endl;
01881         return;
01882 
01883     }
01884 
01885     // get the correlation parameters for the correlation condition (std::string)
01886     L1GtCorrelationTemplate::CorrelationParameter corrParameter;
01887     corrParameter.deltaEtaRange = condDB.deltaEtaRange;
01888     corrParameter.deltaPhiRange = condDB.deltaPhiRange;
01889 
01890     // set condition categories
01891     correlationCond.setCond0Category(subcondCategory[0]);
01892     correlationCond.setCond1Category(subcondCategory[1]);
01893 
01894     // set condition indices in correlation vector
01895     correlationCond.setCond0Index(subcondIndex[0]);
01896     correlationCond.setCond1Index(subcondIndex[1]);
01897 
01898     // set correlation parameter
01899     corrParameter.deltaPhiMaxbits = 0; //  TODO
01900     correlationCond.setCorrelationParameter(corrParameter);
01901 
01902 
01903     // add the same condition once to every chip where required
01904     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01905 
01906         correlationCond.setCondChipNr(*itChip);
01907 
01908         // no check for uniqueness - done by DB
01909         ( m_vecCorrelationTemplate[*itChip] ).push_back(correlationCond);
01910 
01911         if (m_isDebugEnabled) {
01912             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01913                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01914 
01915             LogTrace("L1GtTriggerMenuConfigOnlineProd") << correlationCond << "\n" << std::endl;
01916         }
01917     }
01918 
01919 }
01920 
01921 
01922 
01923 // add the conditions from a menu to the corresponding list
01924 void L1GtTriggerMenuConfigOnlineProd::addConditions() {
01925 
01926     // loop over m_tableMenuCond
01927     for (std::vector<TableMenuCond>::const_iterator constIt = m_tableMenuCond.begin(); constIt
01928             != m_tableMenuCond.end(); constIt++) {
01929 
01930         L1GtConditionCategory conCategory = strToEnumCondCategory((*constIt).condCategory);
01931 
01932         switch (conCategory) {
01933             case CondMuon: {
01934 
01935                 addMuonCondition(*constIt);
01936 
01937             }
01938                 break;
01939             case CondCalo: {
01940 
01941                 addCaloCondition(*constIt);
01942 
01943             }
01944                 break;
01945             case CondEnergySum: {
01946 
01947                 addEnergySumCondition(*constIt);
01948 
01949             }
01950                 break;
01951             case CondJetCounts: {
01952                 addJetCountsCondition(*constIt);
01953 
01954             }
01955                 break;
01956             case CondHfBitCounts: {
01957                 addHfBitCountsCondition(*constIt);
01958 
01959             }
01960                 break;
01961             case CondHfRingEtSums: {
01962                 addHfRingEtSumsCondition(*constIt);
01963 
01964             }
01965                 break;
01966             case CondCastor: {
01967 
01968                 addCastorCondition(*constIt);
01969 
01970             }
01971                 break;
01972             case CondBptx: {
01973 
01974                 addBptxCondition(*constIt);
01975 
01976             }
01977                 break;
01978             case CondExternal: {
01979 
01980                 addExternalCondition(*constIt);
01981 
01982             }
01983                 break;
01984             case CondCorrelation: {
01985 
01986                 addCorrelationCondition(*constIt);
01987 
01988             }
01989                 break;
01990             case CondNull: {
01991 
01992                 // do nothing
01993 
01994             }
01995                 break;
01996             default: {
01997 
01998                 // do nothing
01999 
02000             }
02001                 break;
02002         }
02003 
02004     }
02005 
02006 }
02007 
02008 
02009 DEFINE_FWK_EVENTSETUP_MODULE( L1GtTriggerMenuConfigOnlineProd);