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/regex.hpp"
40 unique_ptr< coral::IQuery > q(
m_session.nominalSchema().newQuery() );
43 q->addToTableList (
"SUPER_MASTER_TABLE",
"SM" );
44 q->addToTableList (
"HLT_MASTER_TABLE",
"HM" );
47 coral::AttributeList bindList;
48 bindList.extend<
int>(
"smid");
49 bindList[0].data<
int>() = SuperMasterKey;
52 string theCondition =
"SM.SMT_HLT_MASTER_TABLE_ID = HM.HMT_ID AND SM.SMT_ID = :smid";
54 q->setCondition( theCondition, bindList );
57 coral::AttributeList attList;
58 attList.extend<
int> (
"HM.HMT_ID" );
59 attList.extend<
int> (
"HM.HMT_TRIGGER_MENU_ID" );
61 attList.extend<
int> (
"HM.HMT_L2_SETUP_ID" );
62 attList.extend<
int> (
"HM.HMT_EF_SETUP_ID" );
64 attList.extend<
int> (
"HM.HMT_SETUP_ID" );
69 coral::ICursor& cursor = q->execute();
75 const coral::AttributeList& row = cursor.currentRow();
77 masterTableID = row[
"HM.HMT_ID"].data<
int>();
78 triggerMenuID = row[
"HM.HMT_TRIGGER_MENU_ID"].data<
int>();
80 l2SetupID = row[
"HM.HMT_L2_SETUP_ID"].data<
int>();
81 efSetupID = row[
"HM.HMT_EF_SETUP_ID"].data<
int>();
83 l2SetupID = efSetupID = row[
"HM.HMT_SETUP_ID"].data<
int>();
92 unsigned int batchSize = 500;
94 vector< SplitParam > splitparams;
97 while(current!=compIDsToLoad.end()) {
102 TRG_MSG_INFO(
"Split parameters => " << splitparams.size());
105 TRG_MSG_INFO(
"Assembled split parameters => " << countSplitParam);
112 const set<int>& compIDsToLoad,
113 vector<SplitParam>& splitparams,
115 unsigned int batchSize) {
117 unique_ptr< coral::IQuery > q(
m_session.nominalSchema().newQuery() );
118 q->setRowCacheSize( 500 );
120 q->addToTableList (
"HLT_COMPONENT",
"CP" );
121 q->addToTableList (
"HLT_CP_TO_PA",
"CP2PA" );
122 q->addToTableList (
"HLT_PARAMETER",
"PA" );
126 coral::AttributeList bind;
128 std::string cond(
buildCond_IN_(
"CP.HCP_ID", compIDsToLoad, current, batchSize) );
129 cond +=
" AND CP2PA.HCP2PA_COMPONENT_ID = CP.HCP_ID";
130 cond +=
" AND CP2PA.HCP2PA_PARAMETER_ID = PA.HPA_ID";
131 q->setCondition( cond , bind );
134 coral::AttributeList attList;
135 attList.extend<std::string>(
"CP.HCP_ALIAS" );
136 attList.extend<std::string>(
"CP.HCP_TYPE" );
137 attList.extend<std::string>(
"PA.HPA_NAME" );
138 attList.extend<std::string>(
"PA.HPA_VALUE" );
141 coral::ICursor& cursor = q->execute();
143 while( cursor.next() ) {
145 const coral::AttributeList& row = cursor.currentRow();
147 string alias = row[
"CP.HCP_ALIAS"].data<std::string>();
148 string type =
"type";
149 string name = row[
"PA.HPA_NAME"].data<std::string>();
150 string value = row[
"PA.HPA_VALUE"].data<std::string>();
152 if( value ==
"~" ) value =
"";
155 if(
name.find(
"__IPC__",0) != string::npos){
156 splitparams.push_back( SplitParam(alias,
name,
type,
"set", value) );
169 std::set<int> compIDs;
171 std::unique_ptr< coral::IQuery > q(
m_session.nominalSchema().newQuery() );
172 q->setRowCacheSize( 1000 );
175 q->addToTableList (
"HLT_ST_TO_CP",
"ST2CP" );
178 coral::AttributeList bind;
179 bind.extend<
int>(
"setupid");
180 bind[0].data<
int>() = setup_id;
182 std::string cond(
"ST2CP.HST2CP_SETUP_ID = :setupid");
183 q->setCondition( cond , bind );
186 coral::AttributeList attList;
187 attList.extend<
int>(
"ST2CP.HST2CP_COMPONENT_ID" );
191 coral::ICursor& cursor = q->execute();
192 while( cursor.next() ) {
193 const coral::AttributeList& row = cursor.currentRow();
194 int id = row[
"ST2CP.HST2CP_COMPONENT_ID"].data<
int>();
198 TRG_MSG_INFO(
"Loaded I-Components => " << compIDs.size());
207 std::set<int> compIDs;
209 std::unique_ptr< coral::IQuery > q(
m_session.nominalSchema().newQuery() );
210 q->setRowCacheSize( 1000 );
212 q->addToTableList(
"HLT_TM_TO_TC",
"TM2TC" );
213 q->addToTableList(
"HLT_TRIGGER_CHAIN",
"TC" );
214 q->addToTableList(
"HLT_TC_TO_TS",
"TC2TS" );
215 q->addToTableList(
"HLT_TS_TO_TE",
"TS2TE" );
216 q->addToTableList(
"HLT_TE_TO_CP",
"TE2CP" );
219 coral::AttributeList bind;
220 bind.extend<
int>(
"menuid");
221 bind[0].data<
int>() = menu_id;
225 std::string cond(
"TM2TC.HTM2TC_TRIGGER_MENU_ID = :menuid");
226 cond +=
" AND TM2TC.HTM2TC_TRIGGER_CHAIN_ID = TC.HTC_ID";
227 cond +=
" AND TM2TC.HTM2TC_TRIGGER_CHAIN_ID = TC2TS.HTC2TS_TRIGGER_CHAIN_ID";
228 cond +=
" AND TC2TS.HTC2TS_TRIGGER_SIGNATURE_ID = TS2TE.HTS2TE_TRIGGER_SIGNATURE_ID";
229 cond +=
" AND TS2TE.HTS2TE_TRIGGER_ELEMENT_ID = TE2CP.HTE2CP_TRIGGER_ELEMENT_ID";
232 if(triggerLevel!=2) {
233 cond +=
" AND TC.HTC_L2_OR_EF = ";
234 cond += ( triggerLevel==0 ?
"'L2'" :
"'EF'" );
237 q->setCondition( cond , bind );
240 coral::AttributeList attList;
241 attList.extend<
int>(
"TE2CP.HTE2CP_COMPONENT_ID" );
245 coral::ICursor& cursor = q->execute();
246 while( cursor.next() ) {
247 const coral::AttributeList& row = cursor.currentRow();
248 int id = row[
"TE2CP.HTE2CP_COMPONENT_ID"].data<
int>();
252 TRG_MSG_INFO(
"Loaded M-Components => " << compIDs.size());
269 std::stringstream
ss;
270 ss <<
"(" << field <<
" IN (";
272 unsigned int count(0), totalCount(0);
274 for(; current!=last && totalCount!=batchSize-1; ++current) {
278 ss <<
") OR " << field <<
" IN (";
284 ss << *current++ <<
"))";
291 vector<int> createSortedVector(
const set<int>& compIDs) {
292 vector<int> sortedVector(compIDs.size());
293 copy(compIDs.begin(), compIDs.end(), sortedVector.begin());
294 sort(sortedVector.begin(),sortedVector.end());
298 vector<string> concatAndSplit(
const vector<int>& v,
uint maxStringSize) {
301 vector<string>
split;
303 string s(
"");s.reserve(8000);
311 if(
count<1000 && s.size()<maxStringSize )
316 split.push_back( s );
325 split.push_back( std::move(s) );
336 std::set<int> childCompIDs;
340 vector<int> sortedParentIDs = createSortedVector(compIDs);
342 vector<string> splitParentIDs = concatAndSplit(sortedParentIDs, 7500);
344 for(
const string& idList : splitParentIDs) {
347 string cond =
"HCP2CP_PARENT_COMP_ID IN (" + idList +
")";
349 coral::ITable& table =
m_session.nominalSchema().tableHandle(
"HLT_CP_TO_CP");
350 std::unique_ptr< coral::IQuery > q( table.newQuery() );
352 coral::AttributeList bind;
353 q->setCondition( cond, bind );
356 coral::AttributeList attList;
357 attList.extend<
int>(
"HCP2CP_CHILD_COMP_ID" );
364 coral::ICursor& cursor = q->execute();
367 while( cursor.next() ) {
368 const coral::AttributeList& row = cursor.currentRow();
369 int id = row[
"HCP2CP_CHILD_COMP_ID"].data<
int>();
370 childCompIDs.insert(
id);
376 if(childCompIDs.size()==0)
383 childCompIDs.insert(allSubChildrenIDs.begin(),allSubChildrenIDs.end());
396 catch(
const std::exception& e ) {
412 unsigned int paramCount = 0;
415 std::string mergedvalue =
"";
416 std::string aliasname =
"";
417 std::string paraname =
"";
421 vector< SplitParam > alreadymatched_v;
423 for (
unsigned int sit=0; sit<splitparams.size(); sit++) {
425 const SplitParam & splitpar = splitparams.at(sit);
431 bool matched =
false;
432 for (
unsigned int mit=0; mit<alreadymatched_v.size(); mit++){
433 SplitParam matchtemp = alreadymatched_v.at(mit);
441 if( paraname!=actualname || aliasname!=splitpar.
alias ){
445 JobOption jo( aliasname, paraname,
"type",
"set", mergedvalue);
449 aliasname = splitpar.
alias;
450 paraname = actualname;
454 alreadymatched_v.push_back( splitpar );
455 mergedvalue = splitpar.
value;
458 for (
unsigned int sit2=sit+1; sit2<splitparams.size(); sit2++){
459 const SplitParam& newtemp2 = splitparams.at(sit2);
460 std::string actualname2 = newtemp2.
actualname;
462 if(actualname2==actualname && splitpar.
alias==newtemp2.
alias ){
463 mergedvalue+= newtemp2.
value;
474 JobOption jo( aliasname, paraname,
"type",
"set", mergedvalue);
486 AssembledPar(
const std::string& compalias,
const std::string& parname) :
487 comp_alias(compalias),
490 std::string comp_alias;
491 std::string par_name;
495 bool operator()(
const AssembledPar& p1,
const AssembledPar& p2)
const {
496 int alias_cmp =
p1.comp_alias.compare(
p2.comp_alias);
497 if(alias_cmp>0)
return false;
498 if(alias_cmp<0)
return true;
499 return p1.par_name.compare(
p2.par_name)<0;
507 std::map<AssembledPar, std::vector<std::string>, APlessthan > assembled_params;
509 boost::regex pname_exp(
"(.*)__IPC__(\\d+)");
510 boost::cmatch matches;
513 for(
const SplitParam & splitpar: splitparams ) {
516 if(boost::regex_match(splitpar.name.c_str(), matches, pname_exp)) {
518 const std::string& comp_alias = splitpar.alias;
519 std::string par_name(matches[1].first, matches[1].second);
520 unsigned int pos =
static_cast<unsigned int>(std::stoul(std::string(matches[2].first, matches[2].second))) - 1;
522 std::vector<std::string>& values = assembled_params[ AssembledPar(comp_alias, par_name) ];
524 if(values.size()<=pos) values.resize(pos+1);
525 values[pos]= splitpar.value;
528 std::cout <<
"ERROR, can't parse " << splitpar.name << std::endl;
533 for(
auto par: assembled_params) {
535 const string& comp_alias = par.first.comp_alias;
536 const string& par_name = par.first.par_name;
537 vector<string>& values = par.second;
539 copy(values.begin(), values.end(), std::ostream_iterator<std::string>(
ss));
543 return assembled_params.size();
561 int masterTableID(0);
562 int triggerMenuID(0);
578 if(l2SetupID==efSetupID) {
586 if( l2SetupID == efSetupID ||
587 (l2SetupID != 0 && efSetupID==0) )
590 int setupId = (level==0 || level==2) ? l2SetupID : efSetupID;
595 TRG_MSG_INFO(
"Direct components => " << compIDsToLoad.size());
599 TRG_MSG_INFO(
"All children => " << childCompIDs.size());
601 compIDsToLoad.insert(childCompIDs.begin(), childCompIDs.end());
603 TRG_MSG_INFO(
"All components => " << compIDsToLoad.size());
char data[hepevt_bytes_allocation_ATLAS]
#define TRG_MSG_VERBOSE(x)
void commitSession()
commit session if not already done
coral::ISessionProxy & m_session
CORAL interface to database session.
unsigned int triggerDBSchemaVersion()
void startSession()
start session if not already active
std::string buildCond_IN_(const std::string &field, const std::set< int > &IDs, std::set< int >::const_iterator ¤t, unsigned int batchSize)
virtual bool load(TrigConfData &data)
bool loadComponentNamesAndParameters(TrigConf::JobOptionTable &JOTable, const std::set< int > &compIDsToLoad)
std::set< int > loadComponentIDsFromMenu(const int menu_id, int triggerLevel)
std::set< int > loadComponentIDsFromSetup(const int setup_id)
bool loadHLTMasterTable(int SuperMasterKey, int &masterTableID, int &triggerMenuID, int &l2SetupID, int &efSetupID)
std::set< int > getChildCompIDs(const std::set< int > &compIDs)
unsigned int assembleSplitParameters(JobOptionTable &jot, const std::vector< SplitParam > &splitparams)
unsigned int assembleSplitParameters2(JobOptionTable &jot, const std::vector< SplitParam > &splitparams)
table to hold the complete list of JobOption entries for a single configuration, from which the JobOp...
void setHltMasterTableId(int id)
setter of the HLT master table configuration key
void addJobOption(const JobOption &jo)
adds a job option to the table
int triggerLevel() const
accessor to the trigger level
std::vector< JobOption > & jobOptionVector()
accessor to the vector of job options
void sort()
sort alphabetically by component and property name
int hltMasterTableId() const
accessor to the HLT master table configuration key
hold a single job option (parameter and value)
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Forward iterator to traverse the main components of the trigger configuration.
void fillQuery(coral::IQuery *q, coral::AttributeList &attList)
std::vector< std::string > split(const std::string &line, const std::string &del=" ")
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.