CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_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                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.condGEq);
00506 
00507             } else if ( ( *constIt ) == "COUNT_INDEX") {
00508                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.countIndex);
00509 
00510             } else if ( ( *constIt ) == "COUNT_THRESHOLD") {
00511                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.countThreshold);
00512 
00513             } else if ( ( *constIt ) == "CHARGE_CORRELATION") {
00514                 resultsMenuCond.fillVariableFromRow(
00515                         *constIt, iRow, menuCond.chargeCorrelation);
00516 
00517             } else if ( ( *constIt ) == "OBJECT_PARAMETER_1_FK") {
00518                 resultsMenuCond.fillVariableFromRow(
00519                         *constIt, iRow, menuCond.objectParameter1FK);
00520 
00521             } else if ( ( *constIt ) == "OBJECT_PARAMETER_2_FK") {
00522                 resultsMenuCond.fillVariableFromRow(
00523                         *constIt, iRow, menuCond.objectParameter2FK);
00524 
00525             } else if ( ( *constIt ) == "OBJECT_PARAMETER_3_FK") {
00526                 resultsMenuCond.fillVariableFromRow(
00527                         *constIt, iRow, menuCond.objectParameter3FK);
00528 
00529             } else if ( ( *constIt ) == "OBJECT_PARAMETER_4_FK") {
00530                 resultsMenuCond.fillVariableFromRow(
00531                         *constIt, iRow, menuCond.objectParameter4FK);
00532 
00533             } else if ( ( *constIt ) == "DELTA_ETA_RANGE") {
00534                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.deltaEtaRange);
00535 
00536             } else if ( ( *constIt ) == "DELTA_PHI_RANGE") {
00537                 resultsMenuCond.fillVariableFromRow(*constIt, iRow, menuCond.deltaPhiRange);
00538 
00539             } else {
00540                 // do nothing
00541 
00542             }
00543 
00544         }
00545 
00546         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00547             << " COND " << menuCond.cond
00548             << " COND_CATEGORY " << menuCond.condCategory
00549             << " COND_TYPE " << menuCond.condType
00550             << " GT_OBJECT_1 " << menuCond.gtObject1
00551             << " GT_OBJECT_2 " << menuCond.gtObject2
00552             << " COND_GEQ " << menuCond.condGEq << "\n"
00553             << " COUNT_INDEX " << menuCond.countIndex
00554             << " COUNT_THRESHOLD " << menuCond.countThreshold << "\n"
00555             << " CHARGE_CORRELATION " << menuCond.chargeCorrelation << "\n"
00556             << " OBJECT_PARAMETER_1_FK " << menuCond.objectParameter1FK
00557             << " OBJECT_PARAMETER_2_FK " << menuCond.objectParameter2FK
00558             << " OBJECT_PARAMETER_3_FK " << menuCond.objectParameter3FK
00559             << " OBJECT_PARAMETER_4_FK " << menuCond.objectParameter4FK << "\n"
00560             << " DELTA_ETA_RANGE " << menuCond.deltaEtaRange
00561             << " DELTA_PHI_RANGE " << menuCond.deltaPhiRange;
00562 
00563         m_tableMenuCond.push_back(menuCond);
00564 
00565 
00566     }
00567 
00568     if (m_isDebugEnabled) {
00569         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00570             << "\n Number of rows read from L1T_MENU_COND_VIEW: " << resultsMenuCondRows
00571             << std::endl;
00572 
00573     }
00574 
00575     return true;
00576 
00577 }
00578 
00579 // retrieve table with object parameters from DB
00580 bool L1GtTriggerMenuConfigOnlineProd::tableMenuObjectParametersFromDB(
00581         const std::string& gtSchema, const std::string& objectKey) {
00582 
00583     // get the list of object parameters in the menu
00584 
00585     // select * from CMS_GT.L1T_MENU_OP_VIEW
00586     //     where L1T_MENU_OP_VIEW.MENU_IMPLEMENTATION = objectKey
00587 
00588     const std::vector<std::string>& columnsMenuOp = m_omdsReader.columnNamesView(
00589             gtSchema, "L1T_MENU_OP_VIEW");
00590 
00591     if (m_isDebugEnabled) {
00592         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n List of columns in L1T_MENU_OP_VIEW:\n"
00593                 << std::endl;
00594         for (std::vector<std::string>::const_iterator iter = columnsMenuOp.begin(); iter
00595                 != columnsMenuOp.end(); iter++) {
00596             LogTrace("L1GtTriggerMenuConfigOnlineProd") << ( *iter ) << std::endl;
00597 
00598         }
00599         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00600     }
00601 
00602     l1t::OMDSReader::QueryResults resultsMenuOp = m_omdsReader.basicQueryView(
00603             columnsMenuOp, gtSchema, "L1T_MENU_OP_VIEW", "L1T_MENU_OP_VIEW.MENU_IMPLEMENTATION",
00604             m_omdsReader.singleAttribute(objectKey));
00605 
00606     // check if query was successful is based on size of returned list
00607     // BUT one can have menus w/o object parameters - no error for empty list, but a warning!
00608     if (resultsMenuOp.queryFailed()) {
00609         edm::LogWarning("L1-O2O")
00610                 << "Warning: Content of L1T_MENU_OP_VIEW for L1GtTriggerMenu implementation key: "
00611                 << "\n  " << objectKey << "\nis empty!"
00612                 << "\nNo object parameters associated to menu are found for this menu.";
00613 
00614     }
00615 
00616     TableMenuObjectParameters menuObjectParameters;
00617     int resultsMenuOpRows = resultsMenuOp.numberRows();
00618 
00619     for (int iRow = 0; iRow < resultsMenuOpRows; ++iRow) {
00620 
00621         for (std::vector<std::string>::const_iterator constIt = columnsMenuOp.begin(); constIt
00622                 != columnsMenuOp.end(); ++constIt) {
00623 
00624             if ( ( *constIt ) == "ID") {
00625                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.opId);
00626 
00627             } else if ( ( *constIt ) == "PT_HIGH_THRESHOLD") {
00628                 resultsMenuOp.fillVariableFromRow(
00629                         *constIt, iRow, menuObjectParameters.ptHighThreshold);
00630 
00631             } else if ( ( *constIt ) == "PT_LOW_THRESHOLD") {
00632                 resultsMenuOp.fillVariableFromRow(
00633                         *constIt, iRow, menuObjectParameters.ptLowThreshold);
00634 
00635             } else if ( ( *constIt ) == "ENABLE_MIP") {
00636                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.enableMip);
00637 
00638             } else if ( ( *constIt ) == "ENABLE_ISO") {
00639                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.enableIso);
00640 
00641             } else if ( ( *constIt ) == "REQUEST_ISO") {
00642                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.requestIso);
00643 
00644             } else if ( ( *constIt ) == "ENERGY_OVERFLOW") {
00645                 resultsMenuOp.fillVariableFromRow(
00646                         *constIt, iRow, menuObjectParameters.energyOverflow);
00647 
00648             } else if ( ( *constIt ) == "ET_THRESHOLD") {
00649                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.etThreshold);
00650 
00651             } else if ( ( *constIt ) == "ETA_RANGE") {
00652                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.etaRange);
00653 
00654             } else if ( ( *constIt ) == "PHI_RANGE") {
00655                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.phiRange);
00656 
00657             } else if ( ( *constIt ) == "PHI_LOW") {
00658                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.phiLow);
00659 
00660             } else if ( ( *constIt ) == "PHI_HIGH") {
00661                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.phiHigh);
00662 
00663             } else if ( ( *constIt ) == "QUALITY_RANGE") {
00664                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.qualityRange);
00665 
00666             } else if ( ( *constIt ) == "CHARGE") {
00667                 resultsMenuOp.fillVariableFromRow(*constIt, iRow, menuObjectParameters.charge);
00668 
00669             } else {
00670                 // do nothing
00671 
00672             }
00673 
00674         }
00675 
00676         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00677             << " ID " << menuObjectParameters.opId
00678             << " PT_HIGH_THRESHOLD " << menuObjectParameters.ptHighThreshold
00679             << " PT_LOW_THRESHOLD " << menuObjectParameters.ptLowThreshold
00680             << " ENABLE_MIP " << menuObjectParameters.enableMip
00681             << " ENABLE_ISO " << menuObjectParameters.enableIso
00682             << " REQUEST_ISO " << menuObjectParameters.requestIso
00683             << " ENERGY_OVERFLOW " << menuObjectParameters.energyOverflow
00684             << " ET_THRESHOLD " << menuObjectParameters.etThreshold
00685             << " ETA_RANGE " << menuObjectParameters.etaRange
00686             << " PHI_RANGE " << menuObjectParameters.phiRange
00687             << " PHI_LOW " << menuObjectParameters.phiLow
00688             << " PHI_HIGH " << menuObjectParameters.phiHigh
00689             << " QUALITY_RANGE " << menuObjectParameters.qualityRange
00690             << " CHARGE " << menuObjectParameters.charge
00691             << std::endl;
00692 
00693         m_tableMenuObjectParameters.push_back(menuObjectParameters);
00694     }
00695 
00696     if (m_isDebugEnabled) {
00697         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00698                 << "\n Number of rows read from L1T_MENU_OP_VIEW: " << resultsMenuOpRows
00699                 << std::endl;
00700 
00701     }
00702 
00703     return true;
00704 
00705 }
00706 
00707 // retrieve table with technical triggers from DB
00708 bool L1GtTriggerMenuConfigOnlineProd::tableMenuTechTrigFromDB(
00709         const std::string& gtSchema, const std::string& objectKey) {
00710 
00711     // select * from CMS_GT.L1T_MENU_TECHTRIG_VIEW
00712     //     where L1T_MENU_TECHTRIG_VIEW.MENU_IMPLEMENTATION = objectKey
00713 
00714     const std::vector<std::string>& columnsMenuTechTrig =
00715             m_omdsReader.columnNamesView(gtSchema, "L1T_MENU_TECHTRIG_VIEW");
00716 
00717     if (m_isDebugEnabled) {
00718         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00719                 << "\n List of columns in L1T_MENU_TECHTRIG_VIEW:\n"
00720                 << std::endl;
00721         for (std::vector<std::string>::const_iterator iter =
00722                 columnsMenuTechTrig.begin(); iter != columnsMenuTechTrig.end(); iter++) {
00723             LogTrace("L1GtTriggerMenuConfigOnlineProd") << (*iter) << std::endl;
00724 
00725         }
00726         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n\n" << std::endl;
00727     }
00728 
00729     l1t::OMDSReader::QueryResults resultsMenuTechTrig =
00730             m_omdsReader.basicQueryView(columnsMenuTechTrig, gtSchema,
00731                     "L1T_MENU_TECHTRIG_VIEW",
00732                     "L1T_MENU_TECHTRIG_VIEW.MENU_IMPLEMENTATION",
00733                     m_omdsReader.singleAttribute(objectKey));
00734 
00735     // check if query was successful is based on size of returned list
00736     // BUT one can have menus w/o technical triggers - no error for empty list, but a warning!
00737     if (resultsMenuTechTrig.queryFailed()) {
00738         edm::LogWarning("L1-O2O")
00739                 << "Warning: Content of L1T_MENU_TECHTRIG_VIEW for L1GtTriggerMenu implementation key: "
00740                 << "\n  " << objectKey << "\nis empty!"
00741                 << "\nNo technical triggers are found for this menu.";
00742 
00743     }
00744 
00745     TableMenuTechTrig menuTechTrig;
00746     int resultsMenuTechTrigRows = resultsMenuTechTrig.numberRows();
00747 
00748     for (int iRow = 0; iRow < resultsMenuTechTrigRows; ++iRow) {
00749 
00750         for (std::vector<std::string>::const_iterator constIt =
00751                 columnsMenuTechTrig.begin(); constIt
00752                 != columnsMenuTechTrig.end(); ++constIt) {
00753 
00754             if ((*constIt) == "TECHTRIG_INDEX") {
00755                 resultsMenuTechTrig.fillVariableFromRow(*constIt, iRow,
00756                         menuTechTrig.bitNumberSh);
00757 
00758             } else if ((*constIt) == "NAME") {
00759                 resultsMenuTechTrig.fillVariableFromRow(*constIt, iRow,
00760                         menuTechTrig.techName);
00761 
00762             } else {
00763                 // do nothing
00764 
00765             }
00766 
00767         }
00768 
00769         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "Row  " << iRow
00770                 << ": index = " << menuTechTrig.bitNumberSh << " techName = "
00771                 << menuTechTrig.techName << std::endl;
00772 
00773         m_tableMenuTechTrig.push_back(menuTechTrig);
00774 
00775     }
00776 
00777     if (m_isDebugEnabled) {
00778         LogTrace("L1GtTriggerMenuConfigOnlineProd")
00779                 << "\n Number of rows read from L1T_MENU_TECHTRIG_VIEW: "
00780                 << resultsMenuTechTrigRows << std::endl;
00781 
00782     }
00783 
00784     return true;
00785 
00786 }
00787 
00788 // return for an algorithm with bitNr the mapping between the integer index in logical expression
00789 // and the condition name (FK)
00790 const std::map<int, std::string> L1GtTriggerMenuConfigOnlineProd::condIndexNameMap(
00791         const short bitNr) const {
00792 
00793     std::map<int, std::string> mapIndexName;
00794 
00795     for (std::vector<TableMenuAlgoCond>::const_iterator constIt = m_tableMenuAlgoCond.begin(); constIt
00796             != m_tableMenuAlgoCond.end(); ++constIt) {
00797 
00798         if (bitNr == (*constIt).bitNumberSh) {
00799             mapIndexName[static_cast<int>((*constIt).condIndexF)] = (*constIt).condFK;
00800         }
00801 
00802     }
00803 
00804     if (m_isDebugEnabled) {
00805 
00806         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Bit number : " << bitNr << std::endl;
00807 
00808         for (std::map<int, std::string>::const_iterator constIt = mapIndexName.begin(); constIt
00809                 != mapIndexName.end(); ++constIt) {
00810 
00811             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "  Condition index -> name: "
00812                     << ( ( *constIt ).first ) << " " << ( ( *constIt ).second ) << std::endl;
00813 
00814         }
00815 
00816     }
00817 
00818 
00819     return mapIndexName;
00820 
00821 }
00822 
00823 // convert a logical expression with indices to a logical expression with names
00824 std::string L1GtTriggerMenuConfigOnlineProd::convertLogicalExpression(
00825         const std::string& expressionIndices, const std::map<int, std::string>& mapCondIndexName) const {
00826 
00827     std::string expressionNames;
00828 
00829     L1GtLogicParser parserIndices = L1GtLogicParser(expressionIndices);
00830     parserIndices.convertIntToNameLogicalExpression(mapCondIndexName);
00831     expressionNames = parserIndices.logicalExpression();
00832 
00833     return expressionNames;
00834 
00835 }
00836 
00837 // return the chip number for an algorithm with index bitNumberSh
00838 int L1GtTriggerMenuConfigOnlineProd::chipNumber(short bitNumberSh) const {
00839 
00840     // FIXME get it from Event Setup
00841     const unsigned numberConditionChips = 2;
00842     const unsigned pinsOnConditionChip = 96;
00843     std::vector<int> orderConditionChip;
00844     orderConditionChip.push_back(2);
00845     orderConditionChip.push_back(1);
00846 
00847     int posChip = ( static_cast<unsigned> (bitNumberSh) / pinsOnConditionChip ) + 1;
00848     for (unsigned int iChip = 0; iChip < numberConditionChips; ++iChip) {
00849         if (posChip == orderConditionChip[iChip]) {
00850             return static_cast<int>(iChip);
00851         }
00852     }
00853 
00854     // chip number not found
00855     return -1;
00856 
00857 }
00858 
00859 // build the algorithm map in the menu
00860 void L1GtTriggerMenuConfigOnlineProd::buildAlgorithmMap() {
00861 
00862 
00863      // temporary value
00864     int bitNumber = -1;
00865     std::string logicalExpression;
00866 
00867     // loop over m_tableMenuAlgo
00868     for (std::vector<TableMenuAlgo>::const_iterator constIt = m_tableMenuAlgo.begin(); constIt
00869             != m_tableMenuAlgo.end(); constIt++) {
00870 
00871         bitNumber = static_cast<int> ((*constIt).bitNumberSh);
00872 
00873         const std::map<int, std::string>& condIndexName = condIndexNameMap((*constIt).bitNumberSh);
00874         logicalExpression = convertLogicalExpression((*constIt).logExpression, condIndexName);
00875 
00876         // create a new algorithm and insert it into algorithm map
00877         L1GtAlgorithm alg((*constIt).algName, logicalExpression, bitNumber);
00878         alg.setAlgoAlias((*constIt).algAlias);
00879 
00880         // set algorithm chip number:
00881         int algChipNr = chipNumber((*constIt).bitNumberSh);
00882         alg.setAlgoChipNumber(algChipNr);
00883 
00884         // insert algorithm
00885         m_algorithmMap[(*constIt).algName] = alg;
00886         m_algorithmAliasMap[(*constIt).algAlias] = alg;
00887 
00888     }
00889 
00890 }
00891 
00892 // build the technical trigger map in the menu
00893 void L1GtTriggerMenuConfigOnlineProd::buildTechnicalTriggerMap() {
00894 
00895     // temporary value
00896     int bitNumber = -1;
00897     std::string logicalExpression;
00898 
00899     // loop over m_tableMenuTechTrig
00900     for (std::vector<TableMenuTechTrig>::const_iterator constIt =
00901             m_tableMenuTechTrig.begin(); constIt != m_tableMenuTechTrig.end(); constIt++) {
00902 
00903         bitNumber = static_cast<int> ((*constIt).bitNumberSh);
00904 
00905         // create a new technical trigger and insert it into technical trigger map
00906         // technical triggers have L1GtAlgorithm class
00907         L1GtAlgorithm techTrig((*constIt).techName, logicalExpression, bitNumber);
00908 
00909         // chip number set in constructor to -1 - no meaning for technical triggers
00910 
00911         // insert technical trigger
00912         m_technicalTriggerMap[(*constIt).techName] = techTrig;
00913 
00914         // no alias is defined for technical triggers
00915     }
00916 
00917 }
00918 
00919 
00920 L1GtConditionCategory L1GtTriggerMenuConfigOnlineProd::strToEnumCondCategory(
00921         const std::string& strCategory) {
00922 
00923     if (strCategory == "CondMuon") {
00924         return CondMuon;
00925     } else if (strCategory == "CondCalo") {
00926         return CondCalo;
00927     } else if (strCategory == "CondEnergySum") {
00928         return CondEnergySum;
00929     } else if (strCategory == "CondJetCounts") {
00930         return CondJetCounts;
00931     } else if (strCategory == "CondCorrelation") {
00932         return CondCorrelation;
00933     } else if (strCategory == "CondCastor") {
00934         return CondCastor;
00935     } else if (strCategory == "CondHfBitCounts") {
00936         return CondHfBitCounts;
00937     } else if (strCategory == "CondHfRingEtSums") {
00938         return CondHfRingEtSums;
00939     } else if (strCategory == "CondBptx") {
00940         return CondBptx;
00941     } else if (strCategory == "CondExternal") {
00942         return CondExternal;
00943     } else if (strCategory == "CondNull") {
00944         return CondNull;
00945     } else {
00946         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
00947                 << "\n Warning: string " << strCategory
00948                 << " not defined. Returning CondNull.\n" << std::endl;
00949         return CondNull;
00950     }
00951 
00952     return CondNull;
00953 
00954 }
00955 
00956 // string to enum L1GtConditionType conversion
00957 L1GtConditionType L1GtTriggerMenuConfigOnlineProd::strToEnumCondType(const std::string& strType) {
00958 
00959     if (strType == "1s") {
00960         return Type1s;
00961     } else if (strType == "2s") {
00962         return Type2s;
00963     } else if (strType == "2wsc") {
00964         return Type2wsc;
00965     } else if (strType == "2cor") {
00966         return Type2cor;
00967     } else if (strType == "3s") {
00968         return Type3s;
00969     } else if (strType == "4s") {
00970         return Type4s;
00971     } else if (strType == "ETM") {
00972         return TypeETM;
00973     } else if (strType == "ETT") {
00974         return TypeETT;
00975     } else if (strType == "HTT") {
00976         return TypeHTT;
00977     } else if (strType == "HTM") {
00978         return TypeHTM;
00979     } else if (strType == "JetCounts") {
00980         return TypeJetCounts;
00981     } else if (strType == "Castor") {
00982         return TypeCastor;
00983     } else if (strType == "HfBitCounts") {
00984         return TypeHfBitCounts;
00985     } else if (strType == "HfRingEtSums") {
00986         return TypeHfRingEtSums;
00987     } else if (strType == "Bptx") {
00988         return TypeBptx;
00989     } else if (strType == "TypeExternal") {
00990         return TypeExternal;
00991     } else {
00992         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
00993                 << "\n Warning: string " << strType
00994                 << " not associated to any L1GtConditionType. Returning TypeNull.\n"
00995                 << std::endl;
00996         return TypeNull;
00997     }
00998 
00999     return TypeNull;
01000 
01001 }
01002 
01003 // string to enum L1GtObject conversion
01004 L1GtObject L1GtTriggerMenuConfigOnlineProd::strToEnumL1GtObject(const std::string& strObject) {
01005 
01006     if (strObject == "Mu") {
01007         return Mu;
01008     } else if (strObject == "NoIsoEG") {
01009         return NoIsoEG;
01010     } else if (strObject == "IsoEG") {
01011         return IsoEG;
01012     } else if (strObject == "CenJet") {
01013         return CenJet;
01014     } else if (strObject == "ForJet") {
01015         return ForJet;
01016     } else if (strObject == "TauJet") {
01017         return TauJet;
01018     } else if (strObject == "ETM") {
01019         return ETM;
01020     } else if (strObject == "ETT") {
01021         return ETT;
01022     } else if (strObject == "HTT") {
01023         return HTT;
01024     } else if (strObject == "HTM") {
01025         return HTM;
01026     } else if (strObject == "JetCounts") {
01027         return JetCounts;
01028     } else if (strObject == "HfBitCounts") {
01029         return HfBitCounts;
01030     } else if (strObject == "HfRingEtSums") {
01031         return HfRingEtSums;
01032     } else if (strObject == "TechTrig") {
01033         return TechTrig;
01034     } else if (strObject == "Castor") {
01035         return Castor;
01036     } else if (strObject == "BPTX") {
01037         return BPTX;
01038     } else if (strObject == "GtExternal") {
01039         return GtExternal;
01040     } else {
01041         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01042                 << "\n Warning: string " << strObject
01043                 << " not associated to any L1GtObject. Returning Mu (no Null type).\n"
01044                 << std::endl;
01045         return Mu;
01046     }
01047 
01048     // no null type, so returning Mu - should never arrive here
01049     return Mu;
01050 
01051 }
01052 
01053 void L1GtTriggerMenuConfigOnlineProd::splitHexStringInTwo64bitWords(
01054         const std::string& hexStr, std::string& hex0WordStr, std::string& hex1WordStr) {
01055 
01056     unsigned int lenHexStr = hexStr.length();
01057 
01058     if (lenHexStr < 3) {
01059         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Warning: string " << hexStr
01060                 << " has length less than 3." << "\n Not possible to split it in two 64-bit words."
01061                 << "\n Return two zero strings." << std::endl;
01062         hex0WordStr = "0x0";
01063         hex1WordStr = "0x0";
01064 
01065         return;
01066     }
01067 
01068     unsigned int lenHex = lenHexStr - 2;
01069     unsigned int len0Word = lenHex > 16 ? 16 : lenHex;
01070     unsigned int len1Word = lenHex - len0Word;
01071 
01072     unsigned int pos0Word = lenHexStr - len0Word;
01073     hex0WordStr = "0x" + hexStr.substr(pos0Word, len0Word);
01074 
01075     if (len1Word > 0) {
01076         unsigned int pos1Word = pos0Word - len1Word;
01077         hex1WordStr = "0x" + hexStr.substr(pos1Word, len1Word);
01078     } else {
01079         hex1WordStr = "0x0";
01080     }
01081 }
01082 
01083 // get a list of chip numbers from the m_tableMenuAlgoCond table for a condition
01084 std::list<int> L1GtTriggerMenuConfigOnlineProd::listChipNumber(const std::string& condFK) {
01085 
01086     std::list<int> chipList;
01087 
01088     // loop over m_tableMenuAlgoCond
01089     for (std::vector<TableMenuAlgoCond>::const_iterator constIt = m_tableMenuAlgoCond.begin(); constIt
01090             != m_tableMenuAlgoCond.end(); constIt++) {
01091 
01092         if (condFK == ( *constIt ).condFK) {
01093             int chipNr = chipNumber( ( *constIt ).bitNumberSh);
01094             chipList.push_back(chipNr);
01095         }
01096     }
01097 
01098     return chipList;
01099 
01100 }
01101 
01102 void L1GtTriggerMenuConfigOnlineProd::fillMuonObjectParameter(
01103         const std::string& opFK, L1GtMuonTemplate::ObjectParameter& objPar) {
01104 
01105     // loop over m_tableMenuCond
01106     for (std::vector<TableMenuObjectParameters>::const_iterator constIt =
01107             m_tableMenuObjectParameters.begin(); constIt != m_tableMenuObjectParameters.end(); constIt++) {
01108 
01109         if (opFK == ( *constIt ).opId) {
01110             objPar.ptHighThreshold = static_cast<unsigned int> ( ( *constIt ).ptHighThreshold);
01111             objPar.ptLowThreshold = static_cast<unsigned int> ( ( *constIt ).ptLowThreshold);
01112             objPar.enableMip = static_cast<bool> ( ( *constIt ).enableMip);
01113             objPar.enableIso = static_cast<bool> ( ( *constIt ).enableIso);
01114             objPar.requestIso = static_cast<bool> ( ( *constIt ).requestIso);
01115             objPar.etaRange = lexical_cast_from_hex<unsigned long long>( ( *constIt ).etaRange);
01116             objPar.phiHigh = static_cast<unsigned int> ( ( *constIt ).phiHigh);
01117             objPar.phiLow = static_cast<unsigned int> ( ( *constIt ).phiLow);
01118             objPar.qualityRange = lexical_cast_from_hex<unsigned int>( ( *constIt ).qualityRange);
01119             //objPar.charge = static_cast<unsigned int> ( ( *constIt ).charge);
01120 
01121             // can break after it is found - DB consistency
01122             break;
01123         }
01124     }
01125 
01126 }
01127 
01128 void L1GtTriggerMenuConfigOnlineProd::addMuonCondition(const TableMenuCond& condDB) {
01129 
01130 
01131     L1GtMuonTemplate muonCond(condDB.cond);
01132     muonCond.setCondType(strToEnumCondType(condDB.condType));
01133 
01134     // object types - all muons
01135     int nrObj = muonCond.nrObjects();
01136     std::vector<L1GtObject> objType(nrObj, Mu);
01137     muonCond.setObjectType(objType);
01138 
01139     muonCond.setCondGEq(condDB.condGEq);
01140 
01141     // temporary storage of the parameters
01142     std::vector<L1GtMuonTemplate::ObjectParameter> objParameter(nrObj);
01143 
01144     for (int iObj = 0; iObj < nrObj; ++iObj) {
01145         if (iObj == 0) {
01146             fillMuonObjectParameter(condDB.objectParameter1FK, objParameter[iObj]);
01147         } else if (iObj == 1) {
01148             fillMuonObjectParameter(condDB.objectParameter2FK, objParameter[iObj]);
01149         } else if (iObj == 2) {
01150             fillMuonObjectParameter(condDB.objectParameter3FK, objParameter[iObj]);
01151         } else if (iObj == 3) {
01152             fillMuonObjectParameter(condDB.objectParameter4FK, objParameter[iObj]);
01153         } else {
01154             LogTrace("L1GtTriggerMenuConfigOnlineProd")
01155                     << "\n Warning: number of objects requested " << nrObj
01156                     << " not available in DB." << "\n Maximum 4 object parameters implemented. \n"
01157                     << std::endl;
01158         }
01159     }
01160 
01161     L1GtMuonTemplate::CorrelationParameter corrParameter;
01162     // FIXME
01163     // put it back from OMDS when fixing the bool problem
01164     // now, put it hardcoded to 1 - we never used another value up to now
01165     //corrParameter.chargeCorrelation = static_cast<unsigned int> (condDB.chargeCorrelation);
01166     corrParameter.chargeCorrelation = 1;
01167     if (muonCond.wsc()) {
01168         corrParameter.deltaEtaRange = lexical_cast_from_hex<unsigned long long> (
01169                 condDB.deltaEtaRange);
01170 
01171         std::string word0;
01172         std::string word1;
01173         splitHexStringInTwo64bitWords(condDB.deltaPhiRange, word0, word1);
01174 
01175         corrParameter.deltaPhiRange0Word = lexical_cast_from_hex<unsigned long long> (word0);
01176         corrParameter.deltaPhiRange1Word = lexical_cast_from_hex<unsigned long long> (word1);
01177 
01178         corrParameter.deltaPhiMaxbits = 0; // FIXME check correlations
01179     }
01180 
01181     muonCond.setConditionParameter(objParameter, corrParameter);
01182 
01183     // get chip number list
01184     std::list<int> chipList = listChipNumber(condDB.cond);
01185 
01186     // eliminate duplicates
01187     chipList.sort();
01188     chipList.unique();
01189 
01190     // add the same condition once to every chip where required
01191     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01192 
01193         muonCond.setCondChipNr(*itChip);
01194 
01195         // no check for uniqueness - done by DB
01196         ( m_vecMuonTemplate[*itChip] ).push_back(muonCond);
01197 
01198         if (m_isDebugEnabled) {
01199             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01200                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01201 
01202             LogTrace("L1GtTriggerMenuConfigOnlineProd") << muonCond << "\n" << std::endl;
01203         }
01204     }
01205 
01206 }
01207 
01208 void L1GtTriggerMenuConfigOnlineProd::fillCaloObjectParameter(
01209         const std::string& opFK, L1GtCaloTemplate::ObjectParameter& objPar) {
01210 
01211     // loop over m_tableMenuCond
01212     for (std::vector<TableMenuObjectParameters>::const_iterator constIt =
01213             m_tableMenuObjectParameters.begin(); constIt != m_tableMenuObjectParameters.end(); constIt++) {
01214 
01215         if (opFK == ( *constIt ).opId) {
01216             objPar.etThreshold = static_cast<unsigned int> ( ( *constIt ).etThreshold);
01217             objPar.etaRange = lexical_cast_from_hex<unsigned int> ( ( *constIt ).etaRange);
01218             objPar.phiRange = lexical_cast_from_hex<unsigned int> ( ( *constIt ).phiRange);
01219 
01220             // can break after it is found - DB consistency
01221             break;
01222         }
01223     }
01224 
01225 }
01226 
01227 void L1GtTriggerMenuConfigOnlineProd::addCaloCondition(const TableMenuCond& condDB) {
01228 
01229     L1GtCaloTemplate caloCond(condDB.cond);
01230     caloCond.setCondType(strToEnumCondType(condDB.condType));
01231 
01232     // object types - all have the same type, so reading it for first object is OK
01233     int nrObj = caloCond.nrObjects();
01234 
01235     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01236     std::vector<L1GtObject> objType(nrObj, obj);
01237     caloCond.setObjectType(objType);
01238 
01239     caloCond.setCondGEq(condDB.condGEq);
01240 
01241     // temporary storage of the parameters
01242     std::vector<L1GtCaloTemplate::ObjectParameter> objParameter(nrObj);
01243 
01244     for (int iObj = 0; iObj < nrObj; ++iObj) {
01245         if (iObj == 0) {
01246             fillCaloObjectParameter(condDB.objectParameter1FK, objParameter[iObj]);
01247         } else if (iObj == 1) {
01248             fillCaloObjectParameter(condDB.objectParameter2FK, objParameter[iObj]);
01249         } else if (iObj == 2) {
01250             fillCaloObjectParameter(condDB.objectParameter3FK, objParameter[iObj]);
01251         } else if (iObj == 3) {
01252             fillCaloObjectParameter(condDB.objectParameter4FK, objParameter[iObj]);
01253         } else {
01254             LogTrace("L1GtTriggerMenuConfigOnlineProd")
01255                     << "\n Warning: number of objects requested " << nrObj
01256                     << " not available in DB." << "\n Maximum 4 object parameters implemented. \n"
01257                     << std::endl;
01258         }
01259     }
01260 
01261     L1GtCaloTemplate::CorrelationParameter corrParameter;
01262     if (caloCond.wsc()) {
01263         corrParameter.deltaEtaRange = lexical_cast_from_hex<unsigned long long> (
01264                 condDB.deltaEtaRange);
01265 
01266         corrParameter.deltaPhiRange = lexical_cast_from_hex<unsigned long long> (
01267                 condDB.deltaPhiRange);
01268         corrParameter.deltaPhiMaxbits = 0; // FIXME check correlations
01269     }
01270 
01271     caloCond.setConditionParameter(objParameter, corrParameter);
01272 
01273     // get chip number list
01274     std::list<int> chipList = listChipNumber(condDB.cond);
01275 
01276     // eliminate duplicates
01277     chipList.sort();
01278     chipList.unique();
01279 
01280     // add the same condition once to every chip where required
01281     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01282 
01283         caloCond.setCondChipNr(*itChip);
01284 
01285         // no check for uniqueness - done by DB
01286         ( m_vecCaloTemplate[*itChip] ).push_back(caloCond);
01287 
01288         if (m_isDebugEnabled) {
01289             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01290                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01291 
01292             LogTrace("L1GtTriggerMenuConfigOnlineProd") << caloCond << "\n" << std::endl;
01293         }
01294     }
01295 
01296 }
01297 
01298 void L1GtTriggerMenuConfigOnlineProd::fillEnergySumObjectParameter(
01299         const std::string& opFK, L1GtEnergySumTemplate::ObjectParameter& objPar,
01300         const L1GtObject& obj) {
01301 
01302     // loop over m_tableMenuCond
01303     for (std::vector<TableMenuObjectParameters>::const_iterator constIt =
01304             m_tableMenuObjectParameters.begin(); constIt != m_tableMenuObjectParameters.end(); constIt++) {
01305 
01306         if (opFK == ( *constIt ).opId) {
01307             objPar.etThreshold = static_cast<unsigned int> ( ( *constIt ).etThreshold);
01308             objPar.energyOverflow = static_cast<bool> ( ( *constIt ).energyOverflow); // not used
01309 
01310             std::string word0;
01311             std::string word1;
01312             splitHexStringInTwo64bitWords( ( *constIt ).phiRange, word0, word1);
01313 
01314             if (obj == ETM) {
01315                 objPar.phiRange0Word = lexical_cast_from_hex<unsigned long long> (word0);
01316                 objPar.phiRange1Word = lexical_cast_from_hex<unsigned long long> (word1);
01317 
01318             } else if (obj == HTM) {
01319                 objPar.phiRange0Word = lexical_cast_from_hex<unsigned long long> (word0);
01320             }
01321 
01322             // can break after it is found - DB consistency
01323             break;
01324         }
01325     }
01326 
01327 }
01328 
01329 void L1GtTriggerMenuConfigOnlineProd::addEnergySumCondition(const TableMenuCond& condDB) {
01330 
01331     L1GtEnergySumTemplate esumCond(condDB.cond);
01332     esumCond.setCondType(strToEnumCondType(condDB.condType));
01333 
01334     // object types - all energy sums are global - so 1 object
01335     int nrObj = 1;
01336 
01337     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01338     std::vector<L1GtObject> objType(nrObj, obj);
01339     esumCond.setObjectType(objType);
01340 
01341     esumCond.setCondGEq(condDB.condGEq);
01342 
01343     // temporary storage of the parameters - no CorrelationParameter
01344     std::vector<L1GtEnergySumTemplate::ObjectParameter> objParameter(nrObj);
01345     fillEnergySumObjectParameter(condDB.objectParameter1FK, objParameter[0], objType[0]);
01346 
01347     esumCond.setConditionParameter(objParameter);
01348 
01349     // get chip number list
01350     std::list<int> chipList = listChipNumber(condDB.cond);
01351 
01352     // eliminate duplicates
01353     chipList.sort();
01354     chipList.unique();
01355 
01356     // add the same condition once to every chip where required
01357     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01358 
01359         esumCond.setCondChipNr(*itChip);
01360 
01361         // no check for uniqueness - done by DB
01362         ( m_vecEnergySumTemplate[*itChip] ).push_back(esumCond);
01363 
01364         if (m_isDebugEnabled) {
01365             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01366                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01367 
01368             LogTrace("L1GtTriggerMenuConfigOnlineProd") << esumCond << "\n" << std::endl;
01369         }
01370     }
01371 
01372 }
01373 
01374 
01375 void L1GtTriggerMenuConfigOnlineProd::addJetCountsCondition(const TableMenuCond& condDB) {
01376 
01377     L1GtJetCountsTemplate jcCond(condDB.cond);
01378     jcCond.setCondType(strToEnumCondType(condDB.condType));
01379 
01380     // object types - jet counts are "global"
01381     int nrObj = 1;
01382 
01383     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01384     std::vector<L1GtObject> objType(nrObj, obj);
01385     jcCond.setObjectType(objType);
01386 
01387     jcCond.setCondGEq(condDB.condGEq);
01388 
01389     // temporary storage of the parameters - no CorrelationParameter
01390     // for counts, the DB implementation is without OP, directly in TableMenuCond
01391     std::vector<L1GtJetCountsTemplate::ObjectParameter> objParameter(nrObj);
01392     objParameter.at(0).countIndex = static_cast<unsigned int>(condDB.countIndex);
01393     objParameter.at(0).countThreshold = static_cast<unsigned int>(condDB.countThreshold);
01394     objParameter.at(0).countOverflow = false ; // not used
01395 
01396     jcCond.setConditionParameter(objParameter);
01397 
01398     // get chip number list
01399     std::list<int> chipList = listChipNumber(condDB.cond);
01400 
01401     // eliminate duplicates
01402     chipList.sort();
01403     chipList.unique();
01404 
01405     // add the same condition once to every chip where required
01406     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01407 
01408         jcCond.setCondChipNr(*itChip);
01409 
01410         // no check for uniqueness - done by DB
01411         ( m_vecJetCountsTemplate[*itChip] ).push_back(jcCond);
01412 
01413         if (m_isDebugEnabled) {
01414             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01415                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01416 
01417             LogTrace("L1GtTriggerMenuConfigOnlineProd") << jcCond << "\n" << std::endl;
01418         }
01419     }
01420 
01421 }
01422 
01423 void L1GtTriggerMenuConfigOnlineProd::addHfBitCountsCondition(const TableMenuCond& condDB) {
01424 
01425     L1GtHfBitCountsTemplate countsCond(condDB.cond);
01426     countsCond.setCondType(strToEnumCondType(condDB.condType));
01427 
01428     // object types - HF bit counts are "global"
01429     int nrObj = 1;
01430 
01431     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01432     std::vector<L1GtObject> objType(nrObj, obj);
01433     countsCond.setObjectType(objType);
01434 
01435     countsCond.setCondGEq(condDB.condGEq);
01436 
01437     // temporary storage of the parameters - no CorrelationParameter
01438     // for counts, the DB implementation is without OP, directly in TableMenuCond
01439     std::vector<L1GtHfBitCountsTemplate::ObjectParameter> objParameter(nrObj);
01440     objParameter.at(0).countIndex = static_cast<unsigned int>(condDB.countIndex);
01441     objParameter.at(0).countThreshold = static_cast<unsigned int>(condDB.countThreshold);
01442 
01443     countsCond.setConditionParameter(objParameter);
01444 
01445     // get chip number list
01446     std::list<int> chipList = listChipNumber(condDB.cond);
01447 
01448     // eliminate duplicates
01449     chipList.sort();
01450     chipList.unique();
01451 
01452     // add the same condition once to every chip where required
01453     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01454 
01455         countsCond.setCondChipNr(*itChip);
01456 
01457         // no check for uniqueness - done by DB
01458         ( m_vecHfBitCountsTemplate[*itChip] ).push_back(countsCond);
01459 
01460         if (m_isDebugEnabled) {
01461             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01462                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01463 
01464             LogTrace("L1GtTriggerMenuConfigOnlineProd") << countsCond << "\n" << std::endl;
01465         }
01466     }
01467 
01468 }
01469 
01470 void L1GtTriggerMenuConfigOnlineProd::addHfRingEtSumsCondition(const TableMenuCond& condDB) {
01471 
01472     L1GtHfRingEtSumsTemplate esumCond(condDB.cond);
01473     esumCond.setCondType(strToEnumCondType(condDB.condType));
01474 
01475     // object types - HF energy sums are "global"
01476     int nrObj = 1;
01477 
01478     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01479     std::vector<L1GtObject> objType(nrObj, obj);
01480     esumCond.setObjectType(objType);
01481 
01482     esumCond.setCondGEq(condDB.condGEq);
01483 
01484     // temporary storage of the parameters - no CorrelationParameter
01485     // for HF energy sums, the DB implementation is without OP, directly in TableMenuCond
01486     std::vector<L1GtHfRingEtSumsTemplate::ObjectParameter> objParameter(nrObj);
01487     objParameter.at(0).etSumIndex = static_cast<unsigned int>(condDB.countIndex);
01488     objParameter.at(0).etSumThreshold = static_cast<unsigned int>(condDB.countThreshold);
01489 
01490     esumCond.setConditionParameter(objParameter);
01491 
01492     // get chip number list
01493     std::list<int> chipList = listChipNumber(condDB.cond);
01494 
01495     // eliminate duplicates
01496     chipList.sort();
01497     chipList.unique();
01498 
01499     // add the same condition once to every chip where required
01500     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01501 
01502         esumCond.setCondChipNr(*itChip);
01503 
01504         // no check for uniqueness - done by DB
01505         ( m_vecHfRingEtSumsTemplate[*itChip] ).push_back(esumCond);
01506 
01507         if (m_isDebugEnabled) {
01508             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01509                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01510 
01511             LogTrace("L1GtTriggerMenuConfigOnlineProd") << esumCond << "\n" << std::endl;
01512         }
01513     }
01514 
01515 }
01516 
01517 void L1GtTriggerMenuConfigOnlineProd::addCastorCondition(const TableMenuCond& condDB) {
01518 
01519     L1GtCastorTemplate castorCond(condDB.cond);
01520     castorCond.setCondType(strToEnumCondType(condDB.condType));
01521 
01522     // object types - logical conditions have no objects associated in GT
01523     // one put however a "Castor" object type
01524     int nrObj = 1;
01525 
01526     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01527     std::vector<L1GtObject> objType(nrObj, obj);
01528     castorCond.setObjectType(objType);
01529 
01530     // irrelevant, set to false for completeness
01531     castorCond.setCondGEq(false);
01532 
01533     // logical conditions have no ObjectParameter, no CorrelationParameter
01534 
01535     // get chip number list
01536     std::list<int> chipList = listChipNumber(condDB.cond);
01537 
01538     // eliminate duplicates
01539     chipList.sort();
01540     chipList.unique();
01541 
01542     // add the same condition once to every chip where required
01543     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01544 
01545         castorCond.setCondChipNr(*itChip);
01546 
01547         // no check for uniqueness - done by DB
01548         ( m_vecCastorTemplate[*itChip] ).push_back(castorCond);
01549 
01550         if (m_isDebugEnabled) {
01551             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01552                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01553 
01554             LogTrace("L1GtTriggerMenuConfigOnlineProd") << castorCond << "\n" << std::endl;
01555         }
01556     }
01557 
01558 }
01559 
01560 void L1GtTriggerMenuConfigOnlineProd::addBptxCondition(const TableMenuCond& condDB) {
01561 
01562     L1GtBptxTemplate bptxCond(condDB.cond);
01563     bptxCond.setCondType(strToEnumCondType(condDB.condType));
01564 
01565     // object types - logical conditions have no objects associated in GT
01566     // one put however a "Bptx" object type
01567     int nrObj = 1;
01568 
01569     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01570     std::vector<L1GtObject> objType(nrObj, obj);
01571     bptxCond.setObjectType(objType);
01572 
01573     // irrelevant, set to false for completeness
01574     bptxCond.setCondGEq(false);
01575 
01576     // logical conditions have no ObjectParameter, no CorrelationParameter
01577 
01578     // get chip number list
01579     std::list<int> chipList = listChipNumber(condDB.cond);
01580 
01581 
01582 
01583     // eliminate duplicates
01584     chipList.sort();
01585     chipList.unique();
01586 
01587     // add the same condition once to every chip where required
01588     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01589 
01590         bptxCond.setCondChipNr(*itChip);
01591 
01592         // no check for uniqueness - done by DB
01593         ( m_vecBptxTemplate[*itChip] ).push_back(bptxCond);
01594 
01595         if (m_isDebugEnabled) {
01596             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01597                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01598 
01599             LogTrace("L1GtTriggerMenuConfigOnlineProd") << bptxCond << "\n" << std::endl;
01600         }
01601     }
01602 
01603 }
01604 
01605 void L1GtTriggerMenuConfigOnlineProd::addExternalCondition(const TableMenuCond& condDB) {
01606 
01607     L1GtExternalTemplate externalCond(condDB.cond);
01608     externalCond.setCondType(strToEnumCondType(condDB.condType));
01609 
01610     // object types - logical conditions have no objects associated in GT
01611     // one put however a "External" object type
01612     int nrObj = 1;
01613 
01614     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01615     std::vector<L1GtObject> objType(nrObj, obj);
01616     externalCond.setObjectType(objType);
01617 
01618     // irrelevant, set to false for completeness
01619     externalCond.setCondGEq(false);
01620 
01621     // logical conditions have no ObjectParameter, no CorrelationParameter
01622 
01623     // get chip number list
01624     std::list<int> chipList = listChipNumber(condDB.cond);
01625 
01626 
01627 
01628     // eliminate duplicates
01629     chipList.sort();
01630     chipList.unique();
01631 
01632     // add the same condition once to every chip where required
01633     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01634 
01635         externalCond.setCondChipNr(*itChip);
01636 
01637         // no check for uniqueness - done by DB
01638         ( m_vecExternalTemplate[*itChip] ).push_back(externalCond);
01639 
01640         if (m_isDebugEnabled) {
01641             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01642                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01643 
01644             LogTrace("L1GtTriggerMenuConfigOnlineProd") << externalCond << "\n" << std::endl;
01645         }
01646     }
01647 
01648 }
01649 
01650 void L1GtTriggerMenuConfigOnlineProd::addCorrelationCondition(const TableMenuCond& condDB) {
01651 
01652     // create a new correlation condition
01653     L1GtCorrelationTemplate correlationCond(condDB.cond);
01654     correlationCond.setCondType(strToEnumCondType(condDB.condType));
01655 
01656     // two objects (for sure) - type taken from DB
01657     const int nrObj = 2;
01658 
01659     std::vector<L1GtObject> objType(nrObj);
01660     L1GtObject obj = strToEnumL1GtObject(condDB.gtObject1);
01661     objType[0] = obj;
01662 
01663     obj = strToEnumL1GtObject(condDB.gtObject2);
01664     objType[1] = obj;
01665 
01666     correlationCond.setObjectType(objType);
01667 
01668     // irrelevant, it is set for each subcondition
01669     correlationCond.setCondGEq(condDB.condGEq);
01670 
01671     // get chip number list, eliminate duplicates
01672     std::list<int> chipList = listChipNumber(condDB.cond);
01673     chipList.sort();
01674     chipList.unique();
01675 
01676     // temporary vectors for sub-conditions
01677     std::vector<L1GtConditionCategory> subcondCategory(nrObj);
01678     std::vector<int> subcondIndex(nrObj);
01679 
01680     bool wrongSubcondition = false;
01681 
01682     for (int iObj = 0; iObj < nrObj; ++iObj) {
01683 
01684         L1GtObject gtObj = objType[iObj];
01685 
01686         // sub-conditions (all have the same condGEq as the correlation condition).
01687         switch (gtObj) {
01688             case Mu: {
01689                 subcondCategory[iObj] = CondMuon;
01690 
01691                 // temporary storage of the parameters
01692                 std::vector<L1GtMuonTemplate::ObjectParameter> objParameter(1);
01693 
01694                 std::string subcondName;
01695                 if (iObj == 0) {
01696                     fillMuonObjectParameter(condDB.objectParameter1FK, objParameter[0]);
01697                     subcondName = condDB.objectParameter1FK;
01698                 } else if (iObj == 1) {
01699                     subcondName = condDB.objectParameter2FK;
01700                     fillMuonObjectParameter(condDB.objectParameter2FK, objParameter[0]);
01701                 }
01702 
01703                 //  chargeCorrelation must be set for muons
01704                 // FIXME check with the hardware if the charge for muons can be used
01705                 //       till then, put it to ignore
01706                 L1GtMuonTemplate::CorrelationParameter corrPar;
01707                 corrPar.chargeCorrelation = 1;
01708 
01709                 L1GtMuonTemplate subcond(subcondName, Type1s);
01710                 subcond.setCondGEq(condDB.condGEq);
01711                 subcond.setObjectType(std::vector<L1GtObject> (1, gtObj));
01712                 subcond.setConditionParameter(objParameter, corrPar);
01713 
01714                 // add the same sub-condition once to every chip where required
01715                 for (std::list<int>::const_iterator itChip = chipList.begin(); itChip
01716                         != chipList.end(); ++itChip) {
01717 
01718                     subcond.setCondChipNr(*itChip);
01719 
01720                     // no check for uniqueness - done by DB
01721                     ( m_corMuonTemplate[*itChip] ).push_back(subcond);
01722 
01723                     // index
01724                     subcondIndex[iObj] = ( m_corMuonTemplate[*itChip] ).size() - 1;
01725 
01726                     if (m_isDebugEnabled) {
01727                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition "
01728                                 << ( condDB.cond ) << " on chip " << ( *itChip ) << "\n "
01729                                 << std::endl;
01730 
01731                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << subcond << "\n" << std::endl;
01732                     }
01733                 }
01734 
01735             }
01736                 break;
01737 
01738             case IsoEG:
01739             case NoIsoEG:
01740             case CenJet:
01741             case ForJet:
01742             case TauJet: {
01743 
01744                 subcondCategory[iObj] = CondCalo;
01745 
01746                 // temporary storage of the parameters
01747                 std::vector<L1GtCaloTemplate::ObjectParameter> objParameter(1);
01748 
01749                 std::string subcondName;
01750                 if (iObj == 0) {
01751                     fillCaloObjectParameter(condDB.objectParameter1FK, objParameter[0]);
01752                     subcondName = condDB.objectParameter1FK;
01753                 } else if (iObj == 1) {
01754                     subcondName = condDB.objectParameter2FK;
01755                     fillCaloObjectParameter(condDB.objectParameter2FK, objParameter[0]);
01756                 }
01757 
01758                 L1GtCaloTemplate::CorrelationParameter corrPar; //  dummy
01759 
01760                 L1GtCaloTemplate subcond(subcondName, Type1s);
01761                 subcond.setCondGEq(condDB.condGEq);
01762                 subcond.setObjectType(std::vector<L1GtObject> (1, gtObj));
01763                 subcond.setConditionParameter(objParameter, corrPar);
01764 
01765                 // add the same sub-condition once to every chip where required
01766                 for (std::list<int>::const_iterator itChip = chipList.begin(); itChip
01767                         != chipList.end(); ++itChip) {
01768 
01769                     subcond.setCondChipNr(*itChip);
01770 
01771                     // no check for uniqueness - done by DB
01772                     ( m_corCaloTemplate[*itChip] ).push_back(subcond);
01773 
01774                     // index
01775                     subcondIndex[iObj] = ( m_corCaloTemplate[*itChip] ).size() - 1;
01776 
01777                     if (m_isDebugEnabled) {
01778                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition "
01779                                 << ( condDB.cond ) << " on chip " << ( *itChip ) << "\n "
01780                                 << std::endl;
01781 
01782                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << subcond << "\n" << std::endl;
01783                     }
01784                 }
01785             }
01786                 break;
01787 
01788             case ETM:
01789             case HTM: {
01790 
01791                 subcondCategory[iObj] = CondEnergySum;
01792 
01793                 // temporary storage of the parameters
01794                 std::vector<L1GtEnergySumTemplate::ObjectParameter> objParameter(1);
01795 
01796                 std::string subcondName;
01797                 if (iObj == 0) {
01798                     fillEnergySumObjectParameter(condDB.objectParameter1FK, objParameter[0], gtObj);
01799                     subcondName = condDB.objectParameter1FK;
01800                 } else if (iObj == 1) {
01801                     subcondName = condDB.objectParameter2FK;
01802                     fillEnergySumObjectParameter(condDB.objectParameter2FK, objParameter[0], gtObj);
01803                 }
01804 
01805                 L1GtConditionType condType;
01806 
01807                 switch (gtObj) {
01808                     case ETM: {
01809                         condType = TypeETM;
01810                     }
01811                         break;
01812                     case HTM: {
01813                         condType = TypeHTM;
01814                     }
01815                         break;
01816                     default: {
01817                         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01818                                 << "\n Warning: wrong L1GtConditionType "
01819                                 << gtObj << std::endl;
01820 
01821                     }
01822                         break;
01823                 }
01824 
01825                 L1GtEnergySumTemplate subcond(subcondName, condType);
01826                 subcond.setCondGEq(condDB.condGEq);
01827                 subcond.setObjectType(std::vector<L1GtObject> (1, gtObj));
01828                 subcond.setConditionParameter(objParameter);
01829 
01830                 // add the same sub-condition once to every chip where required
01831                 for (std::list<int>::const_iterator itChip = chipList.begin(); itChip
01832                         != chipList.end(); ++itChip) {
01833 
01834                     subcond.setCondChipNr(*itChip);
01835 
01836                     // no check for uniqueness - done by DB
01837                     ( m_corEnergySumTemplate[*itChip] ).push_back(subcond);
01838 
01839                     // index
01840                     subcondIndex[iObj] = ( m_corEnergySumTemplate[*itChip] ).size() - 1;
01841 
01842                     if (m_isDebugEnabled) {
01843                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition "
01844                                 << ( condDB.cond ) << " on chip " << ( *itChip ) << "\n "
01845                                 << std::endl;
01846 
01847                         LogTrace("L1GtTriggerMenuConfigOnlineProd") << subcond << "\n" << std::endl;
01848                     }
01849                 }
01850             }
01851                 break;
01852             case ETT:
01853             case HTT:
01854             case JetCounts:
01855             case HfBitCounts:
01856             case HfRingEtSums:
01857             case Castor:
01858             case BPTX:
01859             case GtExternal:
01860             case TechTrig: {
01861                 wrongSubcondition = true;
01862                 edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01863                         << "\n Warning: correlation condition "
01864                         << (condDB.cond)
01865                         << " with invalid sub-condition object type " << gtObj
01866                         << "\n Condition ignored!" << std::endl;
01867             }
01868             default: {
01869                 wrongSubcondition = true;
01870                 edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01871                         << "\n Warning: correlation condition "
01872                         << (condDB.cond)
01873                         << " with invalid sub-condition object type " << gtObj
01874                         << "\n Condition ignored!" << std::endl;
01875 
01876                 //
01877 
01878             }
01879                 break;
01880         }
01881 
01882     }
01883 
01884     if (wrongSubcondition) {
01885         edm::LogWarning("L1GtTriggerMenuConfigOnlineProd")
01886                 << "\n Warning: wrong sub-condition for correlation condition "
01887                 << (condDB.cond)
01888                 << "\n Condition not inserted in menu. \n A sub-condition may be left in the menu"
01889                 << std::endl;
01890         return;
01891 
01892     }
01893 
01894     // get the correlation parameters for the correlation condition (std::string)
01895     L1GtCorrelationTemplate::CorrelationParameter corrParameter;
01896     corrParameter.deltaEtaRange = condDB.deltaEtaRange;
01897     corrParameter.deltaPhiRange = condDB.deltaPhiRange;
01898 
01899     // set condition categories
01900     correlationCond.setCond0Category(subcondCategory[0]);
01901     correlationCond.setCond1Category(subcondCategory[1]);
01902 
01903     // set condition indices in correlation vector
01904     correlationCond.setCond0Index(subcondIndex[0]);
01905     correlationCond.setCond1Index(subcondIndex[1]);
01906 
01907     // set correlation parameter
01908     corrParameter.deltaPhiMaxbits = 0; //  TODO
01909     correlationCond.setCorrelationParameter(corrParameter);
01910 
01911 
01912     // add the same condition once to every chip where required
01913     for (std::list<int>::const_iterator itChip = chipList.begin(); itChip != chipList.end(); ++itChip) {
01914 
01915         correlationCond.setCondChipNr(*itChip);
01916 
01917         // no check for uniqueness - done by DB
01918         ( m_vecCorrelationTemplate[*itChip] ).push_back(correlationCond);
01919 
01920         if (m_isDebugEnabled) {
01921             LogTrace("L1GtTriggerMenuConfigOnlineProd") << "\n Adding condition " << ( condDB.cond )
01922                     << " on chip " << ( *itChip ) << "\n " << std::endl;
01923 
01924             LogTrace("L1GtTriggerMenuConfigOnlineProd") << correlationCond << "\n" << std::endl;
01925         }
01926     }
01927 
01928 }
01929 
01930 
01931 
01932 // add the conditions from a menu to the corresponding list
01933 void L1GtTriggerMenuConfigOnlineProd::addConditions() {
01934 
01935     // loop over m_tableMenuCond
01936     for (std::vector<TableMenuCond>::const_iterator constIt = m_tableMenuCond.begin(); constIt
01937             != m_tableMenuCond.end(); constIt++) {
01938 
01939         L1GtConditionCategory conCategory = strToEnumCondCategory((*constIt).condCategory);
01940 
01941         switch (conCategory) {
01942             case CondMuon: {
01943 
01944                 addMuonCondition(*constIt);
01945 
01946             }
01947                 break;
01948             case CondCalo: {
01949 
01950                 addCaloCondition(*constIt);
01951 
01952             }
01953                 break;
01954             case CondEnergySum: {
01955 
01956                 addEnergySumCondition(*constIt);
01957 
01958             }
01959                 break;
01960             case CondJetCounts: {
01961                 addJetCountsCondition(*constIt);
01962 
01963             }
01964                 break;
01965             case CondHfBitCounts: {
01966                 addHfBitCountsCondition(*constIt);
01967 
01968             }
01969                 break;
01970             case CondHfRingEtSums: {
01971                 addHfRingEtSumsCondition(*constIt);
01972 
01973             }
01974                 break;
01975             case CondCastor: {
01976 
01977                 addCastorCondition(*constIt);
01978 
01979             }
01980                 break;
01981             case CondBptx: {
01982 
01983                 addBptxCondition(*constIt);
01984 
01985             }
01986                 break;
01987             case CondExternal: {
01988 
01989                 addExternalCondition(*constIt);
01990 
01991             }
01992                 break;
01993             case CondCorrelation: {
01994 
01995                 addCorrelationCondition(*constIt);
01996 
01997             }
01998                 break;
01999             case CondNull: {
02000 
02001                 // do nothing
02002 
02003             }
02004                 break;
02005             default: {
02006 
02007                 // do nothing
02008 
02009             }
02010                 break;
02011         }
02012 
02013     }
02014 
02015 }
02016 
02017 
02018 DEFINE_FWK_EVENTSETUP_MODULE( L1GtTriggerMenuConfigOnlineProd);