11 #include <CoralBase/Attribute.h>
12 #include <CoralBase/AttributeList.h>
14 #include "RelationalAccess/SchemaException.h"
15 #include "RelationalAccess/ITransaction.h"
16 #include "RelationalAccess/ITable.h"
17 #include "RelationalAccess/ISchema.h"
18 #include "RelationalAccess/ICursor.h"
19 #include "RelationalAccess/IQuery.h"
21 #include "boost/lexical_cast.hpp"
22 #include "boost/regex.hpp"
41 unique_ptr< coral::IQuery >
q( m_session.nominalSchema().newQuery() );
44 q->addToTableList (
"SUPER_MASTER_TABLE",
"SM" );
45 q->addToTableList (
"HLT_MASTER_TABLE",
"HM" );
49 bindList.extend<
int>(
"smid");
50 bindList[0].data<
int>() = SuperMasterKey;
53 string theCondition =
"SM.SMT_HLT_MASTER_TABLE_ID = HM.HMT_ID AND SM.SMT_ID = :smid";
55 q->setCondition( theCondition, bindList );
59 attList.extend<
int> (
"HM.HMT_ID" );
60 attList.extend<
int> (
"HM.HMT_TRIGGER_MENU_ID" );
62 attList.extend<
int> (
"HM.HMT_L2_SETUP_ID" );
63 attList.extend<
int> (
"HM.HMT_EF_SETUP_ID" );
65 attList.extend<
int> (
"HM.HMT_SETUP_ID" );
70 coral::ICursor&
cursor =
q->execute();
78 masterTableID =
row[
"HM.HMT_ID"].data<
int>();
79 triggerMenuID =
row[
"HM.HMT_TRIGGER_MENU_ID"].data<
int>();
81 l2SetupID =
row[
"HM.HMT_L2_SETUP_ID"].data<
int>();
82 efSetupID =
row[
"HM.HMT_EF_SETUP_ID"].data<
int>();
84 l2SetupID = efSetupID =
row[
"HM.HMT_SETUP_ID"].data<
int>();
93 unsigned int batchSize = 500;
94 set<int>::const_iterator
current = compIDsToLoad.begin();
95 vector< SplitParam > splitparams;
98 while(
current!=compIDsToLoad.end()) {
99 loadComponentNamesAndParameters(JOTable, compIDsToLoad, splitparams,
current, batchSize);
103 TRG_MSG_INFO(
"Split parameters => " << splitparams.size());
105 unsigned int countSplitParam = assembleSplitParameters2(JOTable, splitparams);
106 TRG_MSG_INFO(
"Assembled split parameters => " << countSplitParam);
113 const set<int>& compIDsToLoad,
114 vector<SplitParam>& splitparams,
115 set<int>::const_iterator &
current,
116 unsigned int batchSize) {
118 unique_ptr< coral::IQuery >
q( m_session.nominalSchema().newQuery() );
119 q->setRowCacheSize( 500 );
121 q->addToTableList (
"HLT_COMPONENT",
"CP" );
122 q->addToTableList (
"HLT_CP_TO_PA",
"CP2PA" );
123 q->addToTableList (
"HLT_PARAMETER",
"PA" );
129 std::string cond( buildCond_IN_(
"CP.HCP_ID", compIDsToLoad,
current, batchSize) );
130 cond +=
" AND CP2PA.HCP2PA_COMPONENT_ID = CP.HCP_ID";
131 cond +=
" AND CP2PA.HCP2PA_PARAMETER_ID = PA.HPA_ID";
132 q->setCondition( cond , bind );
136 attList.extend<std::string>(
"CP.HCP_ALIAS" );
137 attList.extend<std::string>(
"CP.HCP_TYPE" );
138 attList.extend<std::string>(
"PA.HPA_NAME" );
139 attList.extend<std::string>(
"PA.HPA_VALUE" );
142 coral::ICursor&
cursor =
q->execute();
148 string alias =
row[
"CP.HCP_ALIAS"].data<std::string>();
149 string type =
"type";
150 string name =
row[
"PA.HPA_NAME"].data<std::string>();
151 string value =
row[
"PA.HPA_VALUE"].data<std::string>();
156 if(
name.find(
"__IPC__",0) != string::npos){
170 std::set<int> compIDs;
172 std::unique_ptr< coral::IQuery >
q( m_session.nominalSchema().newQuery() );
173 q->setRowCacheSize( 1000 );
176 q->addToTableList (
"HLT_ST_TO_CP",
"ST2CP" );
180 bind.extend<
int>(
"setupid");
181 bind[0].data<
int>() = setup_id;
183 std::string cond(
"ST2CP.HST2CP_SETUP_ID = :setupid");
184 q->setCondition( cond , bind );
188 attList.extend<
int>(
"ST2CP.HST2CP_COMPONENT_ID" );
192 coral::ICursor&
cursor =
q->execute();
195 int id =
row[
"ST2CP.HST2CP_COMPONENT_ID"].data<
int>();
199 TRG_MSG_INFO(
"Loaded I-Components => " << compIDs.size());
208 std::set<int> compIDs;
210 std::unique_ptr< coral::IQuery >
q( m_session.nominalSchema().newQuery() );
211 q->setRowCacheSize( 1000 );
213 q->addToTableList(
"HLT_TM_TO_TC",
"TM2TC" );
214 q->addToTableList(
"HLT_TRIGGER_CHAIN",
"TC" );
215 q->addToTableList(
"HLT_TC_TO_TS",
"TC2TS" );
216 q->addToTableList(
"HLT_TS_TO_TE",
"TS2TE" );
217 q->addToTableList(
"HLT_TE_TO_CP",
"TE2CP" );
221 bind.extend<
int>(
"menuid");
222 bind[0].data<
int>() = menu_id;
226 std::string cond(
"TM2TC.HTM2TC_TRIGGER_MENU_ID = :menuid");
227 cond +=
" AND TM2TC.HTM2TC_TRIGGER_CHAIN_ID = TC.HTC_ID";
228 cond +=
" AND TM2TC.HTM2TC_TRIGGER_CHAIN_ID = TC2TS.HTC2TS_TRIGGER_CHAIN_ID";
229 cond +=
" AND TC2TS.HTC2TS_TRIGGER_SIGNATURE_ID = TS2TE.HTS2TE_TRIGGER_SIGNATURE_ID";
230 cond +=
" AND TS2TE.HTS2TE_TRIGGER_ELEMENT_ID = TE2CP.HTE2CP_TRIGGER_ELEMENT_ID";
233 if(triggerLevel!=2) {
234 cond +=
" AND TC.HTC_L2_OR_EF = ";
235 cond += ( triggerLevel==0 ?
"'L2'" :
"'EF'" );
238 q->setCondition( cond , bind );
242 attList.extend<
int>(
"TE2CP.HTE2CP_COMPONENT_ID" );
246 coral::ICursor&
cursor =
q->execute();
249 int id =
row[
"TE2CP.HTE2CP_COMPONENT_ID"].data<
int>();
253 TRG_MSG_INFO(
"Loaded M-Components => " << compIDs.size());
270 std::stringstream
ss;
273 unsigned int count(0), totalCount(0);
279 ss <<
") OR " <<
field <<
" IN (";
292 vector<int> createSortedVector(
const set<int>& compIDs) {
293 vector<int> sortedVector(compIDs.size());
294 copy(compIDs.begin(), compIDs.end(), sortedVector.begin());
295 sort(sortedVector.begin(),sortedVector.end());
299 vector<string> concatAndSplit(
const vector<int>&
v,
uint maxStringSize) {
302 vector<string>
split;
304 string s(
"");
s.reserve(8000);
312 if(
count<1000 &&
s.size()<maxStringSize )
337 std::set<int> childCompIDs;
341 vector<int> sortedParentIDs = createSortedVector(compIDs);
343 vector<string> splitParentIDs = concatAndSplit(sortedParentIDs, 7500);
345 for(
const string& idList : splitParentIDs) {
348 string cond =
"HCP2CP_PARENT_COMP_ID IN (" + idList +
")";
350 coral::ITable&
table = m_session.nominalSchema().tableHandle(
"HLT_CP_TO_CP");
351 std::unique_ptr< coral::IQuery >
q(
table.newQuery() );
354 q->setCondition( cond, bind );
358 attList.extend<
int>(
"HCP2CP_CHILD_COMP_ID" );
365 coral::ICursor&
cursor =
q->execute();
370 int id =
row[
"HCP2CP_CHILD_COMP_ID"].data<
int>();
371 childCompIDs.insert(
id);
377 if(childCompIDs.size()==0)
381 set<int> allSubChildrenIDs = getChildCompIDs(childCompIDs);
384 childCompIDs.insert(allSubChildrenIDs.begin(),allSubChildrenIDs.end());
413 unsigned int paramCount = 0;
416 std::string mergedvalue =
"";
417 std::string aliasname =
"";
418 std::string paraname =
"";
422 vector< SplitParam > alreadymatched_v;
424 for (
unsigned int sit=0; sit<splitparams.size(); sit++) {
426 const SplitParam & splitpar = splitparams.at(sit);
433 for (
unsigned int mit=0; mit<alreadymatched_v.size(); mit++){
434 SplitParam matchtemp = alreadymatched_v.at(mit);
442 if( paraname!=actualname || aliasname!=splitpar.
alias ){
446 JobOption jo( aliasname, paraname,
"type",
"set", mergedvalue);
450 aliasname = splitpar.
alias;
451 paraname = actualname;
455 alreadymatched_v.push_back( splitpar );
456 mergedvalue = splitpar.
value;
459 for (
unsigned int sit2=sit+1; sit2<splitparams.size(); sit2++){
460 const SplitParam& newtemp2 = splitparams.at(sit2);
461 std::string actualname2 = newtemp2.
actualname;
463 if(actualname2==actualname && splitpar.
alias==newtemp2.
alias ){
464 mergedvalue+= newtemp2.
value;
475 JobOption jo( aliasname, paraname,
"type",
"set", mergedvalue);
487 AssembledPar(
const std::string& compalias,
const std::string&
parname) :
488 comp_alias(compalias),
491 std::string comp_alias;
492 std::string par_name;
496 bool operator()(
const AssembledPar&
p1,
const AssembledPar&
p2)
const {
497 int alias_cmp =
p1.comp_alias.compare(
p2.comp_alias);
498 if(alias_cmp>0)
return false;
499 if(alias_cmp<0)
return true;
500 return p1.par_name.compare(
p2.par_name)<0;
508 std::map<AssembledPar, std::vector<std::string>, APlessthan > assembled_params;
511 boost::cmatch matches;
514 for(
const SplitParam & splitpar: splitparams ) {
517 if(boost::regex_match(splitpar.name.c_str(), matches, pname_exp)) {
519 const std::string& comp_alias = splitpar.alias;
520 std::string par_name(matches[1].
first, matches[1].
second);
521 unsigned int pos = boost::lexical_cast<unsigned int,std::string>(
string(matches[2].
first, matches[2].
second)) - 1;
523 std::vector<std::string>&
values = assembled_params[ AssembledPar(comp_alias, par_name) ];
529 std::cout <<
"ERROR, can't parse " << splitpar.name << std::endl;
534 for(
auto par: assembled_params) {
536 const string& comp_alias =
par.first.comp_alias;
537 const string& par_name =
par.first.par_name;
544 return assembled_params.size();
556 triggerDBSchemaVersion();
562 int masterTableID(0);
563 int triggerMenuID(0);
566 if( ! loadHLTMasterTable( jot.
smk(),
579 if(l2SetupID==efSetupID) {
587 if( l2SetupID == efSetupID ||
588 (l2SetupID != 0 && efSetupID==0) )
591 int setupId = (
level==0 ||
level==2) ? l2SetupID : efSetupID;
593 std::set<int> compIDsToLoad = loadComponentIDsFromSetup(setupId);
596 TRG_MSG_INFO(
"Direct components => " << compIDsToLoad.size());
598 std::set<int> childCompIDs = getChildCompIDs( compIDsToLoad );
600 TRG_MSG_INFO(
"All children => " << childCompIDs.size());
602 compIDsToLoad.insert(childCompIDs.begin(), childCompIDs.end());
604 TRG_MSG_INFO(
"All components => " << compIDsToLoad.size());
606 loadComponentNamesAndParameters(jot, compIDsToLoad);