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" 44 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Producing L1TGlobalPrescalesVetos with TSC:RS key = " << objectKey ;
46 if( objectKey.empty() ){
48 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
50 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
51 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
55 unsigned int m_numberPhysTriggers = 512;
58 std::unordered_map<std::string, int, std::hash<std::string>> algoName2bit;
60 std::string uGTtscKey = objectKey.substr(0, objectKey.find(
":"));
61 std::string uGTrsKey = objectKey.substr(objectKey.find(
":")+1, std::string::npos);
66 std::vector< std::string > queryStrings ;
67 queryStrings.push_back(
"L1_MENU" ) ;
79 edm::LogError(
"L1-O2O" ) <<
"Cannot get UGT_KEYS.L1_MENU for ID = " << uGTtscKey <<
" " ;
81 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
83 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
84 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
88 if( !queryResult.
fillVariable(
"L1_MENU", l1_menu_key) ) l1_menu_key =
"";
90 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Producing L1TUtmTriggerMenu with key =" << l1_menu_key;
92 if( uGTtscKey.empty() ){
93 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"TSC key is empty, returning";
95 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Empty objectKey");
97 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
98 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
102 std::vector< std::string > queryColumns;
103 queryColumns.push_back(
"CONF" ) ;
114 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_L1_MENU.CONF for ID = " << l1_menu_key;
116 throw std::runtime_error(
"SummaryForFunctionManager: uGTrs | Faulty | Broken key");
118 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
119 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
126 std::istringstream iss(l1Menu);
128 std::shared_ptr<L1TUtmTriggerMenu> pMenu(
129 const_cast<L1TUtmTriggerMenu*>(
130 reinterpret_cast<const L1TUtmTriggerMenu*>(tmeventsetup::getTriggerMenu(iss))
134 for(
auto algo : pMenu->getAlgorithmMap())
135 algoName2bit[
algo.first] =
algo.second.getIndex();
141 queryColumns.clear();
142 queryColumns.push_back(
"ALGOBX_MASK" ) ;
143 queryColumns.push_back(
"ALGO_FINOR_MASK" ) ;
144 queryColumns.push_back(
"ALGO_FINOR_VETO" ) ;
145 queryColumns.push_back(
"ALGO_PRESCALE" ) ;
147 std::string prescale_key, bxmask_key, mask_key, vetomask_key;
148 std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
151 prescale_key = subKeys[
"ALGO_PRESCALE"];
152 bxmask_key = subKeys[
"ALGOBX_MASK"];
153 mask_key = subKeys[
"ALGO_FINOR_MASK"];
154 vetomask_key = subKeys[
"ALGO_FINOR_VETO"];
159 }
catch ( std::runtime_error &
e ) {
160 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) << e.what();
162 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
164 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
165 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
171 std::ofstream output1(
std::string(
"/tmp/").
append(prescale_key.substr(0,prescale_key.find(
"/"))).append(
".xml"));
172 output1<<xmlPayload_prescale;
174 std::ofstream output2(
std::string(
"/tmp/").
append(mask_key.substr(0,mask_key.find(
"/"))).append(
".xml"));
175 output2<<xmlPayload_mask_finor;
177 std::ofstream output3(
std::string(
"/tmp/").
append(bxmask_key.substr(0,bxmask_key.find(
"/"))).append(
".xml"));
178 output3<<xmlPayload_mask_algobx;
180 std::ofstream output4(
std::string(
"/tmp/").
append(vetomask_key.substr(0,vetomask_key.find(
"/"))).append(
".xml"));
181 output4<<xmlPayload_mask_veto;
186 std::vector<std::vector<int> > prescales;
187 std::vector<unsigned int> triggerMasks;
188 std::vector<int> triggerVetoMasks;
189 std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
195 ts_prescale.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
202 const std::map<std::string, l1t::Parameter> &settings_prescale = ts_prescale.
getParameters(
"uGtProcessor");
203 std::map<std::string,unsigned int> prescaleColumns = settings_prescale.at(
"prescales").getColumnIndices();
205 unsigned int numColumns_prescale = prescaleColumns.size();
206 int nPrescaleSets = numColumns_prescale - 1;
207 std::vector<std::string> algoNames = settings_prescale.at(
"prescales").getTableColumn<
std::string>(
"algo/prescale-index");
209 if( nPrescaleSets > 0 ){
211 for(
int iSet=0; iSet<nPrescaleSets; iSet++ ){
212 prescales.push_back(std::vector<int>());
213 for(
unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit ){
214 int inputDefaultPrescale = 0;
215 prescales[iSet].push_back(inputDefaultPrescale);
219 for(
auto &
col : prescaleColumns){
220 if(
col.second<1 )
continue;
221 int iSet =
col.second - 1;
222 std::vector<unsigned int> prescalesForSet = settings_prescale.at(
"prescales").getTableColumn<
unsigned int>(
col.first.c_str());
223 for(
unsigned int row=0; row<prescalesForSet.size(); row++){
224 unsigned int prescale = prescalesForSet[row];
226 unsigned int algoBit = algoName2bit[
algoName];
227 prescales[iSet][algoBit] = prescale;
231 }
catch ( std::runtime_error &e ){
233 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
235 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
236 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
246 ts_mask_finor.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
253 const std::map<std::string, l1t::Parameter>& settings_mask_finor = ts_mask_finor.
getParameters(
"uGtProcessor");
255 std::vector<std::string> algo_mask_finor = settings_mask_finor.at(
"finorMask").getTableColumn<
std::string>(
"algo");
256 std::vector<unsigned int> mask_mask_finor = settings_mask_finor.at(
"finorMask").getTableColumn<
unsigned int>(
"mask");
259 unsigned int default_finor_mask = 1;
260 auto default_finor_row =
261 std::find_if( algo_mask_finor.cbegin(),
262 algo_mask_finor.cend(),
265 return strcasecmp(
"all",
s.c_str()) == 0;
268 if( default_finor_row == algo_mask_finor.cend() ){
270 <<
"\nWarning: No default found in FinOR mask xml, use 1 (unmasked) as default" 273 default_finor_mask = mask_mask_finor[
std::distance( algo_mask_finor.cbegin(), default_finor_row ) ];
276 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
277 triggerMasks.push_back(default_finor_mask);
279 for(
unsigned int row=0; row<algo_mask_finor.size(); row++){
281 if( strcasecmp(
"all", algoName.c_str()) == 0 )
continue;
282 unsigned int algoBit = algoName2bit[
algoName];
283 unsigned int mask = mask_mask_finor[row];
284 if( algoBit < m_numberPhysTriggers ) triggerMasks[algoBit] =
mask;
286 }
catch ( std::runtime_error &e ){
288 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
290 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
291 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
301 ts_mask_veto.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
308 const std::map<std::string, l1t::Parameter>& settings_mask_veto = ts_mask_veto.
getParameters(
"uGtProcessor");
309 std::vector<std::string> algo_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
std::string>(
"algo");
310 std::vector<unsigned int> veto_mask_veto = settings_mask_veto.at(
"vetoMask").getTableColumn<
unsigned int>(
"veto");
313 unsigned int default_veto_mask = 1;
314 auto default_veto_row =
315 std::find_if( algo_mask_veto.cbegin(),
316 algo_mask_veto.cend(),
319 return strcasecmp(
"all",
s.c_str()) == 0;
322 if( default_veto_row == algo_mask_veto.cend() ){
324 <<
"\nWarning: No default found in Veto mask xml, use 0 (unvetoed) as default" 327 default_veto_mask = veto_mask_veto[
std::distance( algo_mask_veto.cbegin(), default_veto_row ) ];
330 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
331 triggerVetoMasks.push_back(default_veto_mask);
333 for(
unsigned int row=0; row<algo_mask_veto.size(); row++){
335 if( strcasecmp(
"all", algoName.c_str()) == 0 )
continue;
336 unsigned int algoBit = algoName2bit[
algoName];
337 unsigned int veto = veto_mask_veto[row];
338 if( algoBit < m_numberPhysTriggers ) triggerVetoMasks[algoBit] =
int(veto);
340 }
catch ( std::runtime_error &e ){
342 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
344 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
345 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
352 unsigned int m_bx_mask_default = 1;
355 std::vector<std::string> bx_algo_name;
356 std::vector<std::string> bx_range;
357 std::vector<unsigned int> bx_mask;
362 ts_mask_algobx.
addProcessor(
"uGtProcessor",
"uGtProcessor",
"-1",
"-1");
369 const std::map<std::string, l1t::Parameter>& settings_mask_algobx = ts_mask_algobx.
getParameters(
"uGtProcessor");
370 bx_algo_name = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"algo");
371 bx_range = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
std::string>(
"range");
372 bx_mask = settings_mask_algobx.at(
"algorithmBxMask").getTableColumn<
unsigned int>(
"mask");
373 }
catch ( std::runtime_error &e ){
375 throw std::runtime_error(
std::string(
"SummaryForFunctionManager: uGTrs | Faulty | ") + e.what());
377 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"returning empty L1TGlobalPrescalesVetos object";
378 return std::make_unique< const L1TGlobalPrescalesVetos >( ) ;
382 int default_bxmask_row = -1;
383 typedef std::pair<unsigned long,unsigned long> Range_t;
385 struct RangeComp_t {
bool operator()(
const Range_t&
a,
const Range_t&
b)
const {
return a.first < b.first; } };
386 std::map<std::string, std::set<Range_t,RangeComp_t>> non_default_bx_ranges;
388 for(
unsigned int row = 0; row < bx_algo_name.size(); row++){
392 bool broadcastAlgo =
false;
393 bool broadcastRange =
false;
394 if( strcasecmp(
"all", s1.c_str()) == 0 ) broadcastAlgo =
true;
395 if( strcasecmp(
"all", s2.c_str()) == 0 ) broadcastRange =
true;
397 if( broadcastAlgo && broadcastRange ){
400 <<
"\nWarning: ALL-ALL row is not the first one, ignore it assuming 1 (unmasked) as the default" 404 if( default_bxmask_row >= 0 ){
406 <<
"\nWarning: multiple ALL-ALL rows found, using the first" 410 default_bxmask_row = row;
411 m_bx_mask_default = bx_mask[row];
416 if( broadcastRange ){
420 char *dash =
nullptr;
421 first = strtoul(s2.data(), &dash, 0);
422 while( *dash !=
'\0' && *dash !=
'-' ) ++dash;
423 last = (*dash !=
'\0' ? strtoul(++dash, &dash, 0) :
first);
424 if( first == 3564 ) first = 0;
429 <<
"\nWarning: parsing " << s2 <<
" as [" << first <<
"," <<
last <<
"] range" 434 <<
"\nWarning: start of interval is out of range: " << s2 <<
", skipping the row" 441 <<
"\nWarning: end of interval is out of range: " << s2 <<
", force [" << first <<
"," <<
last <<
"] range" 446 <<
"\nWarning: inverse/spillover range "<< s2 <<
", accounting for circular orbit as [0," <<
last <<
"] & [" << first <<
",3563]" 451 std::vector<std::string>
algos;
452 std::vector<std::pair<unsigned long,unsigned long>> orderedRanges;
454 if( !broadcastAlgo ){
455 algos.push_back( bx_algo_name[row] );
456 orderedRanges.push_back( std::make_pair(first,
last) );
458 for(
const auto &
i: non_default_bx_ranges){
459 algos.push_back(
i.first);
460 orderedRanges.push_back( std::make_pair(first,
last) );
464 if( !broadcastAlgo ){
465 algos.push_back( bx_algo_name[row] );
466 algos.push_back( bx_algo_name[row] );
467 orderedRanges.push_back( std::make_pair(0,
last) );
468 orderedRanges.push_back( std::make_pair(first,3563) );
470 for(
const auto &
i: non_default_bx_ranges){
471 algos.push_back(
i.first);
472 algos.push_back(
i.first);
473 orderedRanges.push_back( std::make_pair(0,
last) );
474 orderedRanges.push_back( std::make_pair(first,3563) );
479 for(
unsigned int item=0; item < algos.size(); item++){
481 unsigned int first = orderedRanges[item].first;
482 unsigned int last = orderedRanges[item].second;
484 std::set<Range_t,RangeComp_t> &
ranges = non_default_bx_ranges[
algoName];
498 std::set<Range_t>::iterator curr = ranges.end();
499 std::set<Range_t>::iterator succ = ranges.lower_bound(std::make_pair(first,last));
500 std::set<Range_t>::iterator pred = succ;
501 if( pred != ranges.begin() ) pred--;
else pred = ranges.end();
503 if( (pred == ranges.end() || pred->second <
first) &&
504 (succ == ranges.end() || succ->first >
last) ){
506 if( m_bx_mask_default != bx_mask[row] )
507 curr = ranges.insert(std::make_pair(first,last)).first;
511 Range_t newPred, newSucc;
512 bool modifiedPred =
false, gapInPred =
false, modifiedSucc =
false, dropSucc =
false;
514 if( pred != ranges.end() && pred->second >= first && pred->second <=
last ){
515 if( m_bx_mask_default != bx_mask[row] ){
516 if( last == pred->second ){
518 modifiedPred =
false;
521 newPred.first = pred->first;
522 newPred.second =
last;
527 newPred.first = pred->first;
528 newPred.second = first-1;
534 if( pred != ranges.end() && pred->second > first && pred->second >
last ){
535 if( m_bx_mask_default != bx_mask[row] ){
537 modifiedPred =
false;
540 newPred.first =
first;
541 newPred.second =
last;
547 if( succ != ranges.end() && succ->first <=
last ){
548 if( m_bx_mask_default != bx_mask[row] ){
550 newSucc.first =
first;
551 newSucc.second = succ->second;
554 newSucc.first = last+1;
555 newSucc.second = succ->second;
556 if( newSucc.first > 3563 || newSucc.first > newSucc.second )
562 if( modifiedPred && modifiedSucc && newPred.second >= newSucc.first ){
564 newPred.second = newSucc.second;
565 newSucc.first = newPred.first;
566 ranges.erase(pred,++succ);
567 curr = ranges.insert(newPred).first;
573 curr = ranges.insert(newPred).first;
576 Range_t
r1(pred->first, newPred.first-1);
577 Range_t
r2(newPred.second+1, pred->second);
587 curr = ranges.insert(newSucc).first;
594 if( curr != ranges.end() ){
595 std::set<Range_t,RangeComp_t>::iterator last_covered = ranges.upper_bound(std::make_pair(curr->second,0));
596 if( last_covered != ranges.begin() ) last_covered--;
else last_covered = ranges.end();
598 if( last_covered != ranges.end() && last_covered->first != curr->first ){
600 if( curr->second < last_covered->second ){
602 Range_t newRange(curr->first, last_covered->second);
604 curr = ranges.insert(newRange).first;
606 ranges.erase(++curr,last_covered);
612 if( default_bxmask_row < 0 ){
614 <<
"\nWarning: No default found in BX mask xml, used 1 (unmasked) as default" 618 for(
const std::pair<
std::string, std::set<Range_t,RangeComp_t>> &
algo : non_default_bx_ranges){
620 unsigned int algoBit = algoName2bit[
algoName];
621 for(
auto range :
algo.second)
622 for(
unsigned int bx = range.first; bx <= range.second; bx++){
623 triggerAlgoBxMaskAlgoTrig[bx].push_back(algoBit);
629 for(
unsigned int iSet=0; iSet < prescales.size(); iSet++ ){
630 for(
unsigned int iBit=0; iBit < prescales[iSet].size(); iBit++ ){
632 if( iBit >= triggerMasks.size() ){
634 <<
"\nWarning: algoBit in prescale table >= triggerMasks.size() " 635 <<
"\nWarning: no information on masking bit or not, setting as unmasked " 638 prescales[iSet][iBit] *= triggerMasks[iBit];
654 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
std::unique_ptr< const L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
bool fillVariable(const std::string &columnName, T &outputVariable) const
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
const QueryResults singleAttribute(const T &data) const
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)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
~L1TGlobalPrescalesVetosOnlineProd(void) override
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()