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