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
39
63
64// copy constructor
66 TrigConfData(o),
70 m_level ( o.m_level ),
76 m_groups ( o.m_groups ),
77 m_has_l2 ( o.m_has_l2 )
78{
79 // deep copy to ensure ownership
81 m_HLTSignatureList.push_back(new HLTSignature(*sig));
82
84 m_HLTTriggerTypeList.push_back(new HLTTriggerType(*tt));
85
86 for(HLTStreamTag* tt : o.m_streams_orig)
87 m_streams_orig.push_back(new HLTStreamTag(*tt));
88
89 for(HLTStreamTag* tt : o.m_streams)
90 m_streams.push_back(new HLTStreamTag(*tt));
91
92 for(const auto& strstream : o.m_streams_map)
93 m_streams_map.emplace(strstream.first, new HLTStreamTag(*strstream.second) ) ;
94}
95
96
98 for(HLTSignature *sig : m_HLTSignatureList) delete sig;
99 for(HLTTriggerType *tt : m_HLTTriggerTypeList) delete tt;
100 clearStreams();
101}
102
103
104bool
106 return m_lower_chain_name.find(',')!=std::string::npos;
107}
108
109
110const std::vector<int>&
114
115
116namespace TrigConf {
117 std::vector<std::string>
118 parse(std::string names) {
119 std::erase(names,' ');
120 return TrigConf::split(names,",");
121 }
122}
123
124vector<unsigned int>
126 vector<unsigned int> ids;
127 vector<std::string> names = parse(m_lower_chain_name);
128 for ( unsigned i = names.size(); i-- ; ) {
129 ids.push_back(HLTUtils::string2hash(names[i]));
130 }
131 return ids;
132}
133
134
141
143TrigConf::HLTChain::set_triggerTypeList(const std::vector<HLTTriggerType*>&trigList)
144{
146 delete tt;
147 m_HLTTriggerTypeList = trigList;
148 return *this;
149}
150
151// @brief sets lower chain name
152// also clears the list of lower chain names (for multiple lower chains)
153// adapts the hash_id(s)
160
162TrigConf::HLTChain::set_signatureList(const vector<HLTSignature*>& sigList ) {
163 m_HLTSignatureList = sigList;
165 return *this;
166}
167
168unsigned int
170 if(m_HLTSignatureList.empty())
171 return 0;
172 return m_HLTSignatureList[m_HLTSignatureList.size()-1]->step();
173}
174
175void
178 sig->set_signature_counter( sig->signature_counter() + shift );
179}
180
181
182void
184 for (HLTSignature* signature : m_HLTSignatureList) {
185 std::stringstream os;
186 os << chain_name() << "_" << signature->signature_counter();
187 signature->set_label( os.str() );
188 }
189}
190
191namespace {
192 TrigConf::HLTStreamTag * findStreamTag(const vector<HLTStreamTag*> & streams, const std::string& streamName) {
193 for(auto stream : streams) {
194 if(stream->name() == streamName)
195 return stream;
196 }
197 for(auto stream : streams) {
198 const string &s(stream->name());
199 if( auto p = s.find('.'); (p != string::npos) &&
200 (s.compare(p+1, streamName.size(), streamName) == 0) )
201 return stream;
202 }
203 return nullptr;
204 }
205}
206
207TrigConf::HLTChain&
209
210 // copy the original (menu) stream prescales to the live set
211 for(HLTStreamTag* stream : m_streams_orig) {
212 HLTStreamTag* target = m_streams_map[stream->name()];
213 target->set_prescale(stream->prescale());
214 }
215
216 // copy the stream prescales from the new HLTPprescale to the live set
217
218 for(HLTPrescale::value_type ps : prescales.getStreamPrescales()) {
219 const string & streamName = ps.first;
220
221 HLTStreamTag* streamTag = findStreamTag(m_streams, streamName);
222
223 if(streamTag) {
224 streamTag->set_prescale(ps.second);
225 } else {
226 //throw runtime_error(string("Can not set prescale for stream ")+ ps.first + "since chain '" + name() + "' does not write to that stream.");
227 cerr << "TrigConf::HLTChain WARNING Can not set prescale for stream '" + streamName + "' since chain '" + name() + "' does not write to that stream. Available are" << endl;
228 for(auto stream : m_streams) {
229 cout << " Available are " << stream->name() << endl;
230 }
231 }
232 }
234 return *this;
235}
236
237
238void
240 if(m_streams_map.find(stream->name()) != m_streams_map.end())
241 throw runtime_error(string("Can not add stream '")+ stream->name() + "' to chain '" + name() + "', since it exists already.");
242
243 m_streams_orig.push_back(stream);
244 HLTStreamTag *cp = new HLTStreamTag(*stream);
245 m_streams.push_back(cp);
246 m_streams_map.insert(std::pair<std::string, HLTStreamTag*>(cp->name(),cp));
247
248 // copy the stream prescales from the prescales to the live prescales
249 std::pair<bool, float> sps = prescales().getStreamPrescale(cp->name());
250 if(sps.first)
251 cp->set_prescale(sps.second);
252}
253
254void
256 // The memory management between the streams map and the stream vectors is completely confused
257 // It's going to be too invasive a change to fix that directly so instead just make sure that
258 // everything is correctly deleted at the end
259 std::unordered_set<HLTStreamTag *> deleted;
261 if (deleted.insert(s).second)
262 delete s;
263 for(HLTStreamTag *s : m_streams)
264 if (deleted.insert(s).second)
265 delete s;
266 for (auto &p : m_streams_map)
267 if (deleted.insert(p.second).second)
268 delete p.second;
269 m_streams_orig.clear();
270 m_streams.clear();
271 m_streams_map.clear();
272}
273
274std::pair<bool, float>
275TrigConf::HLTChain::stream_prescale(const std::string& streamName) const {
276 std::unordered_map<std::string, HLTStreamTag*>::const_iterator i = m_streams_map.find(streamName);
277 bool found = (i!=m_streams_map.cend());
278 float ps = found ? i->second->prescale() : 0;
279 return std::make_pair(found,ps);
280}
281
282namespace {
283 string orderLowerChainNames(const string& vstr) {
284 if(vstr.find(',')==string::npos) return vstr;
285 string vstr_loc = vstr;
286 vstr_loc.erase(remove(vstr_loc.begin(),vstr_loc.end(), ' '), vstr_loc.end());
287 vector<string> splstr = split(vstr_loc, "," );
288 sort(splstr.begin(),splstr.end());
289 string out("");
290 for(const string& s : splstr)
291 out += s;
292 return out;
293 }
294}
295
296
297TrigConf::DiffStruct*
299 DiffStruct * ds = new DiffStruct("CHAIN");
300 ds->check("chain_counter", chain_counter(), o->chain_counter());
301 ds->check("lower_chain_name", orderLowerChainNames(lower_chain_name()), orderLowerChainNames(o->lower_chain_name()) );
302 ds->check("level", level(), o->level());
303 ds->check("prescale", prescales().prescale(), o->prescales().prescale());
304 ds->check("pass_through", prescales().pass_through(), o->prescales().pass_through());
305// for(StreamTag* st : streamTagList()) {
306// o->streamTagList() st->name()
307
308// }
309
310
311 if(!ds->empty()) {
312 ds->name = name();
313 } else {
314 delete ds; ds=0;
315 }
316 return ds;
317
318}
319
320//________________________________________________________________________________
321void
323 xmlfile << " <CHAIN chain_counter=\"" << chain_counter() << "\" "
324 << "chain_name=\"" << name() << "\" "
325 << "level=\"" << m_level << "\" "
326 << "lower_chain_name=\"" << m_lower_chain_name << "\" "
327 << "pass_through=\"" << prescales().pass_through() << "\" "
328 << "prescale=\"" << prescales().prescale() << "\">"
329 << endl;
330
331 xmlfile << " <PRESCALES"
332 << " chain_counter=\"" << chain_counter() << "\""
333 << " level=\"" << m_level << "\""
334 << " prescale=\"" << prescales().prescale() << "\""
335 << " pass_through=\"" << prescales().pass_through() << "\"";
336 if(prescales().getRerunPrescales().size()==0) {
337 xmlfile << "/>" << endl;
338 } else {
339 xmlfile << ">" << endl;
340 for(HLTPrescale::value_type rerun_ps : prescales().getRerunPrescales())
341 xmlfile << " <RERUN_PRESCALES target=\"" << rerun_ps.first << "\" prescale=\"" << rerun_ps.second << "\"/>" << endl;
342 xmlfile << " </PRESCALES>" << endl;
343 }
344
345 xmlfile << " <TRIGGERTYPE_LIST/>" << endl;
346
347 xmlfile << " <STREAMTAG_LIST>" << endl;
348 for (const TrigConf::HLTStreamTag* streamTag : m_streams)
349 streamTag->writeXML(xmlfile);
350 xmlfile << " </STREAMTAG_LIST>" << endl;
351
352 xmlfile << " <GROUP_LIST>" << endl;
353 for (const string& group : m_groups)
354 xmlfile << " <GROUP name=\"" << group << "\"/>" << endl;
355 xmlfile << " </GROUP_LIST>" << endl;
356
357 xmlfile << " <SIGNATURE_LIST>" << endl;
359 signature->writeXML(xmlfile);
360 xmlfile << " </SIGNATURE_LIST>" << endl;
361
362 xmlfile << " </CHAIN>" << endl;
363
364 return;
365}
366
367void
368TrigConf::HLTChain::print(const std::string& indent, unsigned int detail) const {
369 if(detail>=2) {
370 int dp = cout.precision();
371 cout.unsetf(ios_base::floatfield);
372 cout.precision(3);
373 //cout.setf(std::ios::fixed, std::ios::floatfield);
374
375 cout << indent << "HLTChain chainid = " << chain_counter() << " ";
376 printNameIdV();
377 if(detail>=3) {
378 cout << " | counter: " << chain_counter();
379 if(level()!="HLT") {
380 cout << " | " << level()
381 << " | lower chain: " << lower_chain_name()
382 << " | lower chain counter: " << lower_chain_counter();
383 } else {
384 cout << " | CTP input: " << lower_chain_name()
385 << " | lower chain counter: " << lower_chain_counter();
386 }
387 cout << " | prescale: " << prescale()
388 << " | pass through: " << pass_through();
389
390 cout << " | rerun: " << prescales().getRerunPrescales().size() << " [ ";
391 for(HLTPrescale::value_type rrps : prescales().getRerunPrescales())
392 cout << rrps.first << ":" << rrps.second << " ";
393 cout << "]" << std::endl;
394
395 }
396 if(detail>=4) {
397 cout << indent << " Groups : " << groups().size() << " [ ";
398 for(const string& group : groups()) cout << "'" << group << "' ";
399 cout << "]" << std::endl;
400
401 cout << indent << " Trigger type bits : " << triggerTypeList().size() << " [ ";
402 for(HLTTriggerType* tt : triggerTypeList()) cout << tt->bit() << " ";
403 cout << "]" << std::endl;
404
405 cout << indent << " Streams : " << streams().size() << endl;
406 for(HLTStreamTag* streamTag : streams()) cout << indent << " " << *streamTag;
407
408 cout << indent << " Steps : " << signatureList().size() << endl;
409 for(HLTSignature* sig : signatureList()) sig->print(indent);
410 cout << indent << "---------------------------------------------------------- " << endl;
411 }
412
413 cout.precision(dp);
414 }
415}
416
417
418//________________________________________________________________________________
419std::ostream &
420TrigConf::operator<<(std::ostream & o, const TrigConf::HLTChain & c) {
421 const std::streamsize oldPrecision = o.precision();
422 const std::ios::fmtflags oldFlags = o.flags();
423 o << "- -- HLTChain printout ------------------------------------- " << endl;
424 o << "- -- name='" << c.name()
425 << "' [v " << c.m_chain_version << "]"
426 << " | counter: " << c.m_chain_counter
427 << " | level: " << c.m_level
428 << " | lower_chain_name: " << c.m_lower_chain_name
429 << " | lower_chain_counter: " << c.m_lower_chain_counter;
430 if (c.m_level == "HLT") o << " | EB_after_step: " << c.m_EB_after_step;
431
432 o.precision(3);
433 o.setf(std::ios::fixed, std::ios::floatfield);
434 o << " | prescale: " << c.prescale()
435 << " | pass_through: " << c.pass_through();
436 o << " | rerun: " << c.prescales().getRerunPrescales().size() << " [ ";
437 for(TrigConf::HLTPrescale::value_type rrps : c.prescales().getRerunPrescales()) o << rrps.first << ":" << rrps.second << " ";
438 o << "]" << endl;
439 o << endl;
440
441 set<std::string>::const_iterator group = c.m_groups.begin();
442 o << "- -- Chain groups : " << c.m_groups.size() << " [ ";
443 for (; group != c.m_groups.end(); ++group) o << "'" << *group << "' ";
444 o << "]" << std::endl;
445
446 vector<TrigConf::HLTTriggerType*>::const_iterator triggerType = c.m_HLTTriggerTypeList.begin();
447 o << "- -- Trigger type bits : " << c.m_HLTTriggerTypeList.size() << " [ ";
448 for (; triggerType != c.m_HLTTriggerTypeList.end(); ++triggerType) o << (*triggerType)->bit() << " ";
449 o << "]" << std::endl;
450
451
452 vector<TrigConf::HLTStreamTag*>::const_iterator streamTag = c.m_streams.begin();
453 o << "- -- Trigger streams : " << c.m_streams.size() << std::endl;
454 for (; streamTag != c.m_streams.end(); ++streamTag) o << *(*streamTag);
455
456 vector<TrigConf::HLTSignature*>::const_iterator signature = c.m_HLTSignatureList.begin();
457 for (; signature != c.m_HLTSignatureList.end(); ++signature) o << *(*signature);
458 o << "- ---------------------------------------------------------- " << endl;
459
460 o.flags(oldFlags);
461 o.precision(oldPrecision);
462 return o;
463}
464
465string HLTChain::__str__() const {
466 stringstream s;
467 s << *this;
468 return s.str();
469}
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
HLTChain(void)
default constructor
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
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.