5 #include <unordered_map> 8 #include "tmEventSetup/tmEventSetup.hh" 9 #include "tmEventSetup/esTriggerMenu.hh" 10 #include "tmEventSetup/esAlgorithm.hh" 11 #include "tmEventSetup/esCondition.hh" 12 #include "tmEventSetup/esObject.hh" 13 #include "tmEventSetup/esCut.hh" 14 #include "tmEventSetup/esScale.hh" 15 #include "tmGrammar/Algorithm.hh" 45 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Producing L1TGlobalPrescalesVetos with TSC:RS key = " << objectKey ;
47 if( objectKey.empty() ){
49 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
51 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
52 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
56 unsigned int m_numberPhysTriggers = 512;
59 std::unordered_map<std::string, int, std::hash<std::string>> algoName2bit;
61 std::string uGTtscKey = objectKey.substr(0, objectKey.find(
":"));
62 std::string uGTrsKey = objectKey.substr(objectKey.find(
":")+1, std::string::npos);
67 std::vector< std::string > queryStrings ;
68 queryStrings.push_back(
"L1_MENU" ) ;
80 edm::LogError(
"L1-O2O" ) <<
"Cannot get UGT_KEYS.L1_MENU for ID = " << uGTtscKey <<
" " ;
82 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
84 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
85 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
89 if( !queryResult.
fillVariable(
"L1_MENU", l1_menu_key) ) l1_menu_key =
"";
91 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Producing L1TUtmTriggerMenu with key =" << l1_menu_key;
93 if( uGTtscKey.empty() ){
94 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"TSC key is empty, returning";
96 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
98 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
99 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
103 std::vector< std::string > queryColumns;
104 queryColumns.push_back(
"CONF" ) ;
115 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_L1_MENU.CONF for ID = " << l1_menu_key;
117 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
119 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
120 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
127 std::istringstream iss(l1Menu);
129 std::shared_ptr<L1TUtmTriggerMenu> pMenu(
130 const_cast<L1TUtmTriggerMenu*>(
131 reinterpret_cast<const L1TUtmTriggerMenu*>(tmeventsetup::getTriggerMenu(iss))
135 for(
auto algo : pMenu->getAlgorithmMap())
136 algoName2bit[
algo.first] =
algo.second.getIndex();
142 queryColumns.clear();
143 queryColumns.push_back(
"ALGOBX_MASK" ) ;
144 queryColumns.push_back(
"ALGO_FINOR_MASK" ) ;
145 queryColumns.push_back(
"ALGO_FINOR_VETO" ) ;
146 queryColumns.push_back(
"ALGO_PRESCALE" ) ;
148 std::string prescale_key, bxmask_key, mask_key, vetomask_key;
149 std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
152 prescale_key = subKeys[
"ALGO_PRESCALE"];
153 bxmask_key = subKeys[
"ALGOBX_MASK"];
154 mask_key = subKeys[
"ALGO_FINOR_MASK"];
155 vetomask_key = subKeys[
"ALGO_FINOR_VETO"];
160 }
catch ( std::runtime_error &
e ) {
161 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << e.what();
163 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
165 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
166 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
172 std::ofstream output1(
std::string(
"/tmp/").
append(prescale_key.substr(0,prescale_key.find(
"/"))).append(
".xml"));
173 output1<<xmlPayload_prescale;
175 std::ofstream output2(
std::string(
"/tmp/").
append(mask_key.substr(0,mask_key.find(
"/"))).append(
".xml"));
176 output2<<xmlPayload_mask_finor;
178 std::ofstream output3(
std::string(
"/tmp/").
append(bxmask_key.substr(0,bxmask_key.find(
"/"))).append(
".xml"));
179 output3<<xmlPayload_mask_algobx;
181 std::ofstream output4(
std::string(
"/tmp/").
append(vetomask_key.substr(0,vetomask_key.find(
"/"))).append(
".xml"));
182 output4<<xmlPayload_mask_veto;
187 std::vector<std::vector<int> > prescales;
188 std::vector<unsigned int> triggerMasks;
189 std::vector<int> triggerVetoMasks;
190 std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
196 ts_prescale.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
203 const std::map<std::string, l1t::Parameter> &settings_prescale = ts_prescale.
getParameters(
"uGtProcessor");
204 std::map<std::string,unsigned int> prescaleColumns = settings_prescale.at(
"prescales").getColumnIndices();
206 unsigned int numColumns_prescale = prescaleColumns.size();
207 int nPrescaleSets = numColumns_prescale - 1;
208 std::vector<std::string> algoNames = settings_prescale.at(
"prescales").getTableColumn<
std::string>(
"algo/prescale-index");
210 if( nPrescaleSets > 0 ){
212 for(
int iSet=0; iSet<nPrescaleSets; iSet++ ){
213 prescales.push_back(std::vector<int>());
214 for(
unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit ){
215 int inputDefaultPrescale = 0;
216 prescales[iSet].push_back(inputDefaultPrescale);
220 for(
auto &
col : prescaleColumns){
221 if(
col.second<1 )
continue;
222 int iSet =
col.second - 1;
223 std::vector<unsigned int> prescalesForSet = settings_prescale.at(
"prescales").getTableColumn<
unsigned int>(
col.first.c_str());
224 for(
unsigned int row=0; row<prescalesForSet.size(); row++){
225 unsigned int prescale = prescalesForSet[row];
227 unsigned int algoBit = algoName2bit[
algoName];
228 prescales[iSet][algoBit] = prescale;
232 }
catch ( std::runtime_error &e ){
234 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
236 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
237 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
247 ts_mask_finor.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
254 const std::map<std::string, l1t::Parameter>& settings_mask_finor = ts_mask_finor.
getParameters(
"uGtProcessor");
256 std::vector<std::string> algo_mask_finor = settings_mask_finor.at(
"finorMask").getTableColumn<
std::string>(
"algo");
257 std::vector<unsigned int> mask_mask_finor = settings_mask_finor.at(
"finorMask").getTableColumn<
unsigned int>(
"mask");
260 unsigned int default_finor_mask = 1;
261 auto default_finor_row =
262 std::find_if( algo_mask_finor.cbegin(),
263 algo_mask_finor.cend(),
266 return strcasecmp(
"all",
s.c_str()) == 0;
269 if( default_finor_row == algo_mask_finor.cend() ){
271 <<
"\nWarning: No default found in FinOR mask xml, use 1 (unmasked) as default" 274 default_finor_mask = mask_mask_finor[
std::distance( algo_mask_finor.cbegin(), default_finor_row ) ];
277 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
278 triggerMasks.push_back(default_finor_mask);
280 for(
unsigned int row=0; row<algo_mask_finor.size(); row++){
282 if( strcasecmp(
"all", algoName.c_str()) == 0 )
continue;
283 unsigned int algoBit = algoName2bit[
algoName];
284 unsigned int mask = mask_mask_finor[row];
285 if( algoBit < m_numberPhysTriggers ) triggerMasks[algoBit] =
mask;
287 }
catch ( std::runtime_error &e ){
289 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
291 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
292 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
302 ts_mask_veto.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
309 const std::map<std::string, l1t::Parameter>& settings_mask_veto = ts_mask_veto.
getParameters(
"uGtProcessor");
310 std::vector<std::string> algo_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
std::string>(
"algo");
311 std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
unsigned int>(
"veto");
314 unsigned int default_veto_mask = 1;
315 auto default_veto_row =
316 std::find_if( algo_mask_veto.cbegin(),
317 algo_mask_veto.cend(),
320 return strcasecmp(
"all",
s.c_str()) == 0;
323 if( default_veto_row == algo_mask_veto.cend() ){
325 <<
"\nWarning: No default found in Veto mask xml, use 0 (unvetoed) as default" 328 default_veto_mask = veto_mask_veto[
std::distance( algo_mask_veto.cbegin(), default_veto_row ) ];
331 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
332 triggerVetoMasks.push_back(default_veto_mask);
334 for(
unsigned int row=0; row<algo_mask_veto.size(); row++){
336 if( strcasecmp(
"all", algoName.c_str()) == 0 )
continue;
337 unsigned int algoBit = algoName2bit[
algoName];
338 unsigned int veto = veto_mask_veto[row];
339 if( algoBit < m_numberPhysTriggers ) triggerVetoMasks[algoBit] =
int(veto);
341 }
catch ( std::runtime_error &e ){
343 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
345 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
346 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
353 unsigned int m_bx_mask_default = 1;
356 std::vector<std::string> bx_algo_name;
357 std::vector<std::string> bx_range;
358 std::vector<unsigned int> bx_mask;
363 ts_mask_algobx.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
370 const std::map<std::string, l1t::Parameter>& settings_mask_algobx = ts_mask_algobx.
getParameters(
"uGtProcessor");
371 bx_algo_name = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"algo");
372 bx_range = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"range");
373 bx_mask = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
unsigned int>(
"mask");
374 }
catch ( std::runtime_error &e ){
376 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
378 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
379 return std::make_shared< L1TGlobalPrescalesVetos >( ) ;
383 int default_bxmask_row = -1;
384 typedef std::pair<unsigned long,unsigned long> Range_t;
386 struct RangeComp_t {
bool operator()(
const Range_t&
a,
const Range_t&
b)
const {
return a.first < b.first; } };
387 std::map<std::string, std::set<Range_t,RangeComp_t>> non_default_bx_ranges;
389 for(
unsigned int row = 0; row < bx_algo_name.size(); row++){
393 bool broadcastAlgo =
false;
394 bool broadcastRange =
false;
395 if( strcasecmp(
"all", s1.c_str()) == 0 ) broadcastAlgo =
true;
396 if( strcasecmp(
"all", s2.c_str()) == 0 ) broadcastRange =
true;
398 if( broadcastAlgo && broadcastRange ){
401 <<
"\nWarning: ALL-ALL row is not the first one, ignore it assuming 1 (unmasked) as the default" 405 if( default_bxmask_row >= 0 ){
407 <<
"\nWarning: multiple ALL-ALL rows found, using the first" 411 default_bxmask_row = row;
412 m_bx_mask_default = bx_mask[row];
417 if( broadcastRange ){
421 char *dash =
nullptr;
422 first = strtoul(s2.data(), &dash, 0);
423 while( *dash !=
'\0' && *dash !=
'-' ) ++dash;
424 last = (*dash !=
'\0' ? strtoul(++dash, &dash, 0) :
first);
425 if( first == 3564 ) first = 0;
430 <<
"\nWarning: parsing " << s2 <<
" as [" << first <<
"," <<
last <<
"] range" 435 <<
"\nWarning: start of interval is out of range: " << s2 <<
", skipping the row" 442 <<
"\nWarning: end of interval is out of range: " << s2 <<
", force [" << first <<
"," <<
last <<
"] range" 447 <<
"\nWarning: inverse/spillover range "<< s2 <<
", accounting for circular orbit as [0," <<
last <<
"] & [" << first <<
",3563]" 452 std::vector<std::string>
algos;
453 std::vector<std::pair<unsigned long,unsigned long>> orderedRanges;
455 if( !broadcastAlgo ){
456 algos.push_back( bx_algo_name[row] );
457 orderedRanges.push_back( std::make_pair(first,
last) );
459 for(
const auto &
i: non_default_bx_ranges){
460 algos.push_back(
i.first);
461 orderedRanges.push_back( std::make_pair(first,
last) );
465 if( !broadcastAlgo ){
466 algos.push_back( bx_algo_name[row] );
467 algos.push_back( bx_algo_name[row] );
468 orderedRanges.push_back( std::make_pair(0,
last) );
469 orderedRanges.push_back( std::make_pair(first,3563) );
471 for(
const auto &
i: non_default_bx_ranges){
472 algos.push_back(
i.first);
473 algos.push_back(
i.first);
474 orderedRanges.push_back( std::make_pair(0,
last) );
475 orderedRanges.push_back( std::make_pair(first,3563) );
480 for(
unsigned int item=0; item < algos.size(); item++){
482 unsigned int first = orderedRanges[item].first;
483 unsigned int last = orderedRanges[item].second;
485 std::set<Range_t,RangeComp_t> &
ranges = non_default_bx_ranges[
algoName];
499 std::set<Range_t>::iterator curr = ranges.end();
500 std::set<Range_t>::iterator succ = ranges.lower_bound(std::make_pair(first,last));
501 std::set<Range_t>::iterator pred = succ;
502 if( pred != ranges.begin() ) pred--;
else pred = ranges.end();
504 if( (pred == ranges.end() || pred->second <
first) &&
505 (succ == ranges.end() || succ->first >
last) ){
507 if( m_bx_mask_default != bx_mask[row] )
508 curr = ranges.insert(std::make_pair(first,last)).first;
512 Range_t newPred, newSucc;
513 bool modifiedPred =
false, gapInPred =
false, modifiedSucc =
false, dropSucc =
false;
515 if( pred != ranges.end() && pred->second >= first && pred->second <=
last ){
516 if( m_bx_mask_default != bx_mask[row] ){
517 if( last == pred->second ){
519 modifiedPred =
false;
522 newPred.first = pred->first;
523 newPred.second =
last;
528 newPred.first = pred->first;
529 newPred.second = first-1;
535 if( pred != ranges.end() && pred->second > first && pred->second >
last ){
536 if( m_bx_mask_default != bx_mask[row] ){
538 modifiedPred =
false;
541 newPred.first =
first;
542 newPred.second =
last;
548 if( succ != ranges.end() && succ->first <=
last ){
549 if( m_bx_mask_default != bx_mask[row] ){
551 newSucc.first =
first;
552 newSucc.second = succ->second;
555 newSucc.first = last+1;
556 newSucc.second = succ->second;
557 if( newSucc.first > 3563 || newSucc.first > newSucc.second )
563 if( modifiedPred && modifiedSucc && newPred.second >= newSucc.first ){
565 newPred.second = newSucc.second;
566 newSucc.first = newPred.first;
567 ranges.erase(pred,++succ);
568 curr = ranges.insert(newPred).first;
574 curr = ranges.insert(newPred).first;
577 Range_t
r1(pred->first, newPred.first-1);
578 Range_t
r2(newPred.second+1, pred->second);
588 curr = ranges.insert(newSucc).first;
595 if( curr != ranges.end() ){
596 std::set<Range_t,RangeComp_t>::iterator last_covered = ranges.upper_bound(std::make_pair(curr->second,0));
597 if( last_covered != ranges.begin() ) last_covered--;
else last_covered = ranges.end();
599 if( last_covered != ranges.end() && last_covered->first != curr->first ){
601 if( curr->second < last_covered->second ){
603 Range_t newRange(curr->first, last_covered->second);
605 curr = ranges.insert(newRange).first;
607 ranges.erase(++curr,last_covered);
613 if( default_bxmask_row < 0 ){
615 <<
"\nWarning: No default found in BX mask xml, used 1 (unmasked) as default" 619 for(
const std::pair<
std::string, std::set<Range_t,RangeComp_t>> &
algo : non_default_bx_ranges){
621 unsigned int algoBit = algoName2bit[
algoName];
622 for(
auto range :
algo.second)
623 for(
unsigned int bx = range.first; bx <= range.second; bx++){
624 triggerAlgoBxMaskAlgoTrig[bx].push_back(algoBit);
630 for(
unsigned int iSet=0; iSet < prescales.size(); iSet++ ){
631 for(
unsigned int iBit=0; iBit < prescales[iSet].size(); iBit++ ){
633 if( iBit >= triggerMasks.size() ){
635 <<
"\nWarning: algoBit in prescale table >= triggerMasks.size() " 636 <<
"\nWarning: no information on masking bit or not, setting as unmasked " 639 prescales[iSet][iBit] *= triggerMasks[iBit];
654 std::shared_ptr<L1TGlobalPrescalesVetos>
payload( std::make_shared<L1TGlobalPrescalesVetos>(*data_.
getWriteInstance()) );
656 edm::LogInfo(
"L1-O2O: L1TCaloParamsOnlineProd" ) <<
"SummaryForFunctionManager: uGTrs | OK | All looks good";
T getParameter(std::string const &) const
L1TGlobalPrescalesVetosOnlineProd(const edm::ParameterSet &)
void setConfigured(bool state=true) noexcept
bool fillVariable(const std::string &columnName, T &outputVariable) const
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
const QueryResults singleAttribute(const T &data) const
std::shared_ptr< L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
l1t::OMDSReader m_omdsReader
void readDOMFromString(const std::string &str, xercesc::DOMDocument *&doc)
static std::map< std::string, std::string > fetch(const std::vector< std::string > &queryColumns, const std::string &table, const std::string &key, l1t::OMDSReader &m_omdsReader)
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
void setTriggerMaskVeto(std::vector< int > value)
~L1TGlobalPrescalesVetosOnlineProd(void) override
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
const std::map< std::string, Parameter > & getParameters(const char *processor) const
void setBxMaskDefault(int value)
void readRootElement(TriggerSystem &aTriggerSystem, const std::string &sysId="")
void addProcessor(const char *processor, const char *role, const char *crate, const char *slot)
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
L1TGlobalPrescalesVetos * getWriteInstance()