ATLAS Offline Software
Loading...
Searching...
No Matches
TrigConfHLTData/Root/HLTChain.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
12
13#include <algorithm>
14#include <iostream>
15#include <fstream>
16#include <sstream>
17#include <cstdlib>
18#include <unordered_set>
19
20using namespace std;
21using namespace TrigConf;
22
24 if(ch1!=0 && ch2!=0) { return *ch1 < *ch2; }
25 else { return ch1==0; }
26}
27
51
52// copy constructor
54 TrigConfData(o),
58 m_level ( o.m_level ),
64 m_groups ( o.m_groups ),
65 m_has_l2 ( o.m_has_l2 )
66{
67 // deep copy to ensure ownership
69 m_HLTSignatureList.push_back(new HLTSignature(*sig));
70
72 m_HLTTriggerTypeList.push_back(new HLTTriggerType(*tt));
73
74 for(HLTStreamTag* tt : o.m_streams_orig)
75 m_streams_orig.push_back(new HLTStreamTag(*tt));
76
77 for(HLTStreamTag* tt : o.m_streams)
78 m_streams.push_back(new HLTStreamTag(*tt));
79
80 for(const auto& strstream : o.m_streams_map)
81 m_streams_map.emplace(strstream.first, new HLTStreamTag(*strstream.second) ) ;
82}
83
84
86 for(HLTSignature *sig : m_HLTSignatureList) delete sig;
87 for(HLTTriggerType *tt : m_HLTTriggerTypeList) delete tt;
89}
90
91
92bool
94 return m_lower_chain_name.find(',')!=std::string::npos;
95}
96
97
98const std::vector<int>&
102
103
104namespace TrigConf {
105 std::vector<std::string>
106 parse(std::string names) {
107 std::erase(names,' ');
108 return TrigConf::split(names,",");
109 }
110}
111
112vector<unsigned int>
114 vector<unsigned int> ids;
115 vector<std::string> names = parse(m_lower_chain_name);
116 for ( unsigned i = names.size(); i-- ; ) {
117 ids.push_back(HLTUtils::string2hash(names[i]));
118 }
119 return ids;
120}
121
122
129
131TrigConf::HLTChain::set_triggerTypeList(const std::vector<HLTTriggerType*>&trigList)
132{
134 delete tt;
135 m_HLTTriggerTypeList = trigList;
136 return *this;
137}
138
139// @brief sets lower chain name
140// also clears the list of lower chain names (for multiple lower chains)
141// adapts the hash_id(s)
148
150TrigConf::HLTChain::set_signatureList(const vector<HLTSignature*>& sigList ) {
151 m_HLTSignatureList = sigList;
153 return *this;
154}
155
156unsigned int
158 if(m_HLTSignatureList.empty())
159 return 0;
160 return m_HLTSignatureList[m_HLTSignatureList.size()-1]->step();
161}
162
163void
166 sig->set_signature_counter( sig->signature_counter() + shift );
167}
168
169
170void
172 for (HLTSignature* signature : m_HLTSignatureList) {
173 std::stringstream os;
174 os << chain_name() << "_" << signature->signature_counter();
175 signature->set_label( os.str() );
176 }
177}
178
179namespace {
180 TrigConf::HLTStreamTag * findStreamTag(const vector<HLTStreamTag*> & streams, const std::string& streamName) {
181 for(auto stream : streams) {
182 if(stream->name() == streamName)
183 return stream;
184 }
185 for(auto stream : streams) {
186 const string &s(stream->name());
187 if( auto p = s.find('.'); (p != string::npos) &&
188 (s.compare(p+1, streamName.size(), streamName) == 0) )
189 return stream;
190 }
191 return nullptr;
192 }
193}
194
195TrigConf::HLTChain&
197
198 // copy the original (menu) stream prescales to the live set
199 for(HLTStreamTag* stream : m_streams_orig) {
200 HLTStreamTag* target = m_streams_map[stream->name()];
201 target->set_prescale(stream->prescale());
202 }
203
204 // copy the stream prescales from the new HLTPprescale to the live set
205
206 for(HLTPrescale::value_type ps : prescales.getStreamPrescales()) {
207 const string & streamName = ps.first;
208
209 HLTStreamTag* streamTag = findStreamTag(m_streams, streamName);
210
211 if(streamTag) {
212 streamTag->set_prescale(ps.second);
213 } else {
214 //throw runtime_error(string("Can not set prescale for stream ")+ ps.first + "since chain '" + name() + "' does not write to that stream.");
215 cerr << "TrigConf::HLTChain WARNING Can not set prescale for stream '" + streamName + "' since chain '" + name() + "' does not write to that stream. Available are" << endl;
216 for(auto stream : m_streams) {
217 cout << " Available are " << stream->name() << endl;
218 }
219 }
220 }
222 return *this;
223}
224
225
226void
228 if(m_streams_map.find(stream->name()) != m_streams_map.end())
229 throw runtime_error(string("Can not add stream '")+ stream->name() + "' to chain '" + name() + "', since it exists already.");
230
231 m_streams_orig.push_back(stream);
232 HLTStreamTag *cp = new HLTStreamTag(*stream);
233 m_streams.push_back(cp);
234 m_streams_map.insert(std::pair<std::string, HLTStreamTag*>(cp->name(),cp));
235
236 // copy the stream prescales from the prescales to the live prescales
237 std::pair<bool, float> sps = prescales().getStreamPrescale(cp->name());
238 if(sps.first)
239 cp->set_prescale(sps.second);
240}
241
242void
244 // The memory management between the streams map and the stream vectors is completely confused
245 // It's going to be too invasive a change to fix that directly so instead just make sure that
246 // everything is correctly deleted at the end
247 std::unordered_set<HLTStreamTag *> deleted;
249 if (deleted.insert(s).second)
250 delete s;
251 for(HLTStreamTag *s : m_streams)
252 if (deleted.insert(s).second)
253 delete s;
254 for (auto &p : m_streams_map)
255 if (deleted.insert(p.second).second)
256 delete p.second;
257 m_streams_orig.clear();
258 m_streams.clear();
259 m_streams_map.clear();
260}
261
262std::pair<bool, float>
263TrigConf::HLTChain::stream_prescale(const std::string& streamName) const {
264 std::unordered_map<std::string, HLTStreamTag*>::const_iterator i = m_streams_map.find(streamName);
265 bool found = (i!=m_streams_map.cend());
266 float ps = found ? i->second->prescale() : 0;
267 return std::make_pair(found,ps);
268}
269
270namespace {
271 string orderLowerChainNames(const string& vstr) {
272 if(vstr.find(',')==string::npos) return vstr;
273 string vstr_loc = vstr;
274 vstr_loc.erase(remove(vstr_loc.begin(),vstr_loc.end(), ' '), vstr_loc.end());
275 vector<string> splstr = split(vstr_loc, "," );
276 sort(splstr.begin(),splstr.end());
277 string out("");
278 for(const string& s : splstr)
279 out += s;
280 return out;
281 }
282}
283
284
285TrigConf::DiffStruct*
287 DiffStruct * ds = new DiffStruct("CHAIN");
288 ds->check("chain_counter", chain_counter(), o->chain_counter());
289 ds->check("lower_chain_name", orderLowerChainNames(lower_chain_name()), orderLowerChainNames(o->lower_chain_name()) );
290 ds->check("level", level(), o->level());
291 ds->check("prescale", prescales().prescale(), o->prescales().prescale());
292 ds->check("pass_through", prescales().pass_through(), o->prescales().pass_through());
293// for(StreamTag* st : streamTagList()) {
294// o->streamTagList() st->name()
295
296// }
297
298
299 if(!ds->empty()) {
300 ds->name = name();
301 } else {
302 delete ds; ds=0;
303 }
304 return ds;
305
306}
307
308//________________________________________________________________________________
309void
311 xmlfile << " <CHAIN chain_counter=\"" << chain_counter() << "\" "
312 << "chain_name=\"" << name() << "\" "
313 << "level=\"" << m_level << "\" "
314 << "lower_chain_name=\"" << m_lower_chain_name << "\" "
315 << "pass_through=\"" << prescales().pass_through() << "\" "
316 << "prescale=\"" << prescales().prescale() << "\">"
317 << endl;
318
319 xmlfile << " <PRESCALES"
320 << " chain_counter=\"" << chain_counter() << "\""
321 << " level=\"" << m_level << "\""
322 << " prescale=\"" << prescales().prescale() << "\""
323 << " pass_through=\"" << prescales().pass_through() << "\"";
324 if(prescales().getRerunPrescales().size()==0) {
325 xmlfile << "/>" << endl;
326 } else {
327 xmlfile << ">" << endl;
328 for(HLTPrescale::value_type rerun_ps : prescales().getRerunPrescales())
329 xmlfile << " <RERUN_PRESCALES target=\"" << rerun_ps.first << "\" prescale=\"" << rerun_ps.second << "\"/>" << endl;
330 xmlfile << " </PRESCALES>" << endl;
331 }
332
333 xmlfile << " <TRIGGERTYPE_LIST/>" << endl;
334
335 xmlfile << " <STREAMTAG_LIST>" << endl;
336 for (const TrigConf::HLTStreamTag* streamTag : m_streams)
337 streamTag->writeXML(xmlfile);
338 xmlfile << " </STREAMTAG_LIST>" << endl;
339
340 xmlfile << " <GROUP_LIST>" << endl;
341 for (const string& group : m_groups)
342 xmlfile << " <GROUP name=\"" << group << "\"/>" << endl;
343 xmlfile << " </GROUP_LIST>" << endl;
344
345 xmlfile << " <SIGNATURE_LIST>" << endl;
347 signature->writeXML(xmlfile);
348 xmlfile << " </SIGNATURE_LIST>" << endl;
349
350 xmlfile << " </CHAIN>" << endl;
351
352 return;
353}
354
355void
356TrigConf::HLTChain::print(const std::string& indent, unsigned int detail) const {
357 if(detail>=2) {
358 int dp = cout.precision();
359 cout.unsetf(ios_base::floatfield);
360 cout.precision(3);
361 //cout.setf(std::ios::fixed, std::ios::floatfield);
362
363 cout << indent << "HLTChain chainid = " << chain_counter() << " ";
364 printNameIdV();
365 if(detail>=3) {
366 cout << " | counter: " << chain_counter();
367 if(level()!="HLT") {
368 cout << " | " << level()
369 << " | lower chain: " << lower_chain_name()
370 << " | lower chain counter: " << lower_chain_counter();
371 } else {
372 cout << " | CTP input: " << lower_chain_name()
373 << " | lower chain counter: " << lower_chain_counter();
374 }
375 cout << " | prescale: " << prescale()
376 << " | pass through: " << pass_through();
377
378 cout << " | rerun: " << prescales().getRerunPrescales().size() << " [ ";
379 for(HLTPrescale::value_type rrps : prescales().getRerunPrescales())
380 cout << rrps.first << ":" << rrps.second << " ";
381 cout << "]" << std::endl;
382
383 }
384 if(detail>=4) {
385 cout << indent << " Groups : " << groups().size() << " [ ";
386 for(const string& group : groups()) cout << "'" << group << "' ";
387 cout << "]" << std::endl;
388
389 cout << indent << " Trigger type bits : " << triggerTypeList().size() << " [ ";
390 for(HLTTriggerType* tt : triggerTypeList()) cout << tt->bit() << " ";
391 cout << "]" << std::endl;
392
393 cout << indent << " Streams : " << streams().size() << endl;
394 for(HLTStreamTag* streamTag : streams()) cout << indent << " " << *streamTag;
395
396 cout << indent << " Steps : " << signatureList().size() << endl;
397 for(HLTSignature* sig : signatureList()) sig->print(indent);
398 cout << indent << "---------------------------------------------------------- " << endl;
399 }
400
401 cout.precision(dp);
402 }
403}
404
405
406//________________________________________________________________________________
407std::ostream &
408TrigConf::operator<<(std::ostream & o, const TrigConf::HLTChain & c) {
409 const std::streamsize oldPrecision = o.precision();
410 const std::ios::fmtflags oldFlags = o.flags();
411 o << "- -- HLTChain printout ------------------------------------- " << endl;
412 o << "- -- name='" << c.name()
413 << "' [v " << c.m_chain_version << "]"
414 << " | counter: " << c.m_chain_counter
415 << " | level: " << c.m_level
416 << " | lower_chain_name: " << c.m_lower_chain_name
417 << " | lower_chain_counter: " << c.m_lower_chain_counter;
418 if (c.m_level == "HLT") o << " | EB_after_step: " << c.m_EB_after_step;
419
420 o.precision(3);
421 o.setf(std::ios::fixed, std::ios::floatfield);
422 o << " | prescale: " << c.prescale()
423 << " | pass_through: " << c.pass_through();
424 o << " | rerun: " << c.prescales().getRerunPrescales().size() << " [ ";
425 for(TrigConf::HLTPrescale::value_type rrps : c.prescales().getRerunPrescales()) o << rrps.first << ":" << rrps.second << " ";
426 o << "]" << endl;
427 o << endl;
428
429 set<std::string>::const_iterator group = c.m_groups.begin();
430 o << "- -- Chain groups : " << c.m_groups.size() << " [ ";
431 for (; group != c.m_groups.end(); ++group) o << "'" << *group << "' ";
432 o << "]" << std::endl;
433
434 vector<TrigConf::HLTTriggerType*>::const_iterator triggerType = c.m_HLTTriggerTypeList.begin();
435 o << "- -- Trigger type bits : " << c.m_HLTTriggerTypeList.size() << " [ ";
436 for (; triggerType != c.m_HLTTriggerTypeList.end(); ++triggerType) o << (*triggerType)->bit() << " ";
437 o << "]" << std::endl;
438
439
440 vector<TrigConf::HLTStreamTag*>::const_iterator streamTag = c.m_streams.begin();
441 o << "- -- Trigger streams : " << c.m_streams.size() << std::endl;
442 for (; streamTag != c.m_streams.end(); ++streamTag) o << *(*streamTag);
443
444 vector<TrigConf::HLTSignature*>::const_iterator signature = c.m_HLTSignatureList.begin();
445 for (; signature != c.m_HLTSignatureList.end(); ++signature) o << *(*signature);
446 o << "- ---------------------------------------------------------- " << endl;
447
448 o.flags(oldFlags);
449 o.precision(oldPrecision);
450 return o;
451}
452
453string HLTChain::__str__() const {
454 stringstream s;
455 s << *this;
456 return s.str();
457}
size_t size() const
Number of registered mappings.
bool HLTChain_lt(const TrigConf::HLTChain *ch1, const TrigConf::HLTChain *ch2)
HLT chain configuration information.
std::pair< bool, float > stream_prescale(const std::string &streamName) const
DiffStruct * compareTo(const HLTChain *o) const
HLTChain & set_triggerTypeList(const std::vector< HLTTriggerType * > &trigList)
virtual ~HLTChain() override
destructor
const std::vector< HLTStreamTag * > & streams() const
std::vector< unsigned int > lower_chain_hash_ids() const
const std::string & lower_chain_name() const
std::unordered_map< std::string, HLTStreamTag * > m_streams_map
const std::set< std::string > & groups() const
std::vector< HLTSignature * > & signatureList()
const std::vector< int > & lower_chain_counters() const
std::vector< HLTStreamTag * > m_streams_orig
std::vector< int > m_lower_chain_counters
counters of the lower trigger items if more than 1
unsigned int m_lower_chain_hash_id
hash value from m_lower_chain_name, this is used to match to a chain from the previous trigger level
std::vector< HLTStreamTag * > m_streams
HLTChain & set_signatureList(const std::vector< HLTSignature * > &sigList)
HLTChain & set_chain_name(const std::string &chain_name)
std::string __str__() const override
HLTChain()=default
default constructor
void print(const std::string &indent="", unsigned int detail=1) const override
print the chain
std::string m_lower_chain_name
name of the lower trigger chain (or the LVL1 trigger item)
void createSignatureLabels()
label the signatures
std::vector< HLTTriggerType * > & triggerTypeList()
unsigned int m_chain_hash_id
hash value from m_chain_name, this is used to identify the chain in the HLTResult
int m_lower_chain_counter
counter of the lower trigger chain (or the ID of the LVL1 trigger item)
void writeXML(std::ofstream &xmlfile)
std::vector< HLTSignature * > m_HLTSignatureList
HLTChain & set_prescales(const HLTPrescale &prescales)
HLTChain & set_lower_chain_name(const std::string &lower_chain_name)
std::vector< HLTTriggerType * > m_HLTTriggerTypeList
float pass_through() const
Definition HLTPrescale.h:57
PrescaleMap_t::value_type value_type
Definition HLTPrescale.h:47
float prescale() const
Definition HLTPrescale.h:56
HLT signature configuration information.
HLT stream configuration information.
void set_prescale(float val)
HLT trigger type configuration information.
static HLTHash string2hash(std::string_view, const std::string &category=s_defaultCategory)
hash function translating TE names into identifiers
std::ostream & indent(std::ostream &o, int lvl, int size) const
void setName(const std::string &name)
const std::string & name() const
void printNameIdV(const std::string &indent="") const
TrigConfData(const std::string &name="")
void setVersion(unsigned int version)
STL iterator class.
static std::vector< std::string > xmlfile
Definition iLumiCalc.h:29
Forward iterator to traverse the main components of the trigger configuration.
std::ostream & operator<<(std::ostream &os, const TrigConf::IsolationLegacy &iso)
std::vector< std::string > split(const std::string &line, const std::string &del=" ")
std::vector< std::string > parse(std::string names)
STL namespace.
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.