ATLAS Offline Software
Loading...
Searching...
No Matches
HLTPrescaleSetCollection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8#include <iomanip>
9#include <stdexcept>
10#include <iostream>
11#include <sstream>
12
13using namespace std;
14using namespace TrigConf;
15
20
24
26 // don't use
27 throw std::runtime_error("HLTPrescaleSetCollection::operator= is not implemented");
28}
29
32 // don't use
33 throw std::runtime_error("HLTPrescaleSetCollection::operator= is not implemented");
34 return *this;
35}
36
37
38void
40 lock_guard<recursive_mutex> lock(m_prescaleSetCollection_mutex);
41 for(const cont& psinfo : m_prescaleSets)
42 delete psinfo.pss;
43 m_prescaleSets.clear();
44}
45
46
47
50 return thePrescaleSet(lumiblock);
51}
52
55
56 lock_guard<recursive_mutex> lock(m_prescaleSetCollection_mutex);
57
58 if(m_prescaleSets.empty())
59 return nullptr;
60
61 // check that the first LB of the prescale set collection (minLB) is <= than the requested lumiblock
62 unsigned int minLB = m_prescaleSets.begin()->lb;
63 if(minLB > lumiblock)
64 throw runtime_error("HLTPrescaleSetCollecion access with LBN which is smaller than the first prescale set");
65
66 // look for the right prescale set
67 HLTPrescaleSet* pss = m_prescaleSets.begin()->pss;
68
69 for(const cont& psinfo : m_prescaleSets) {
70 if( psinfo.lb > lumiblock ) break;
71 pss = psinfo.pss;
72 }
73
74 // found the PSS that covers the requested LB
75 return pss;
76}
77
78
79
82 /*
83 * Lock mutex while we are inserting a new prescale set.
84 * Everybody accessing m_prescaleSetCollection needs to obtain this mutex
85 * before accessing this list.
86 */
87 lock_guard<recursive_mutex> lock(m_prescaleSetCollection_mutex);
88 clear();
89 m_prescaleSets.insert(m_prescaleSets.begin(), cont(0, pss->id(), pss));
90 return pss;
91}
92
93void
95 return addPrescaleSet(cont(lumiblock, pss?pss->id():0, pss));
96}
97
98
99void
101
102 std::list<cont>::iterator psinfo_it = m_prescaleSets.begin();
103 for(; psinfo_it!=m_prescaleSets.end(); ++psinfo_it)
104 if( psinfo_it->lb >= add_psinfo.lb ) break;
105 {
106 /*
107 * Lock mutex while we are inserting a new prescale set.
108 * Everybody accessing m_prescaleSetCollection needs to obtain this mutex
109 * before accessing this list.
110 */
111 lock_guard<recursive_mutex> lock(m_prescaleSetCollection_mutex);
112 if( (psinfo_it != m_prescaleSets.end()) && (psinfo_it->lb == add_psinfo.lb) ) {
113 delete psinfo_it->pss;
114 psinfo_it->pss = add_psinfo.pss;
115 //if(psinfo_it->pss != 0)
116 psinfo_it->psk = add_psinfo.psk;
117 } else {
118 m_prescaleSets.insert( psinfo_it, add_psinfo );
119 }
120 }
121}
122
123
124vector<pair<unsigned int, unsigned int> >
126 vector<pair<unsigned int, unsigned int> > lbpsk;
127 for(const cont& psinfo : m_prescaleSets)
128 lbpsk.push_back(std::make_pair(psinfo.lb,psinfo.psk));
129 return lbpsk;
130}
131
132
133void
135 vector<pair<unsigned int, unsigned int> > lbnpsk;
136 lbnpsk.push_back(make_pair(0,hltpsk));
138}
139
140void
141TrigConf::HLTPrescaleSetCollection::set_prescale_keys_to_load(const vector<pair<unsigned int, unsigned int> >& lbnpsk) {
142 // if(m_prescaleSets.size()>0) {
143 // throw std::runtime_error("ERROR: HLTPrescaleSetCollection: set_prescale_keys_to_load called on a non-empty collection. clear() needs to be called before");
144 // }
145 for(auto & lbpsk : lbnpsk) {
146 if( ! contains(lbpsk.first, lbpsk.second)) {
147 addPrescaleSet( cont(lbpsk.first, lbpsk.second, 0) ); // register empty prescale sets with lb and psk, so they can later be loaded
148 }
149 }
150}
151
152bool
153TrigConf::HLTPrescaleSetCollection::contains(unsigned int lumiblock, unsigned int psk) {
154 lock_guard<recursive_mutex> lock(m_prescaleSetCollection_mutex);
155 for(const cont& psinfo: m_prescaleSets)
156 if( psinfo.lb==lumiblock && psinfo.psk==psk ) return true;
157 return false;
158}
159
160
161void
162TrigConf::HLTPrescaleSetCollection::print(const std::string& indent, unsigned int detail) const {
163 lock_guard<recursive_mutex> lock(m_prescaleSetCollection_mutex);
164 if(detail>=1) {
165 unsigned int count_loaded(0);
166 for(const cont& psinfo : m_prescaleSets)
167 if(psinfo.pss!=0) count_loaded++;
168
169 cout << indent << "HLTPrescaleSetCollection has " << size() << " prescale set(s) defined, " << count_loaded << " loaded." << endl;
170 if(size()>0) {
171 cout << indent << " LB PSK Loaded Name" << endl;
172 for(const cont& psinfo : m_prescaleSets)
173 cout << indent << setw(9) << right << psinfo.lb << setw(9) << right << psinfo.psk << " " << (psinfo.pss!=0?"yes":" no")
174 << " " << (psinfo.pss!=0?psinfo.pss->name():"") << endl;
175 }
176 if(detail>=2) {
177 for(const cont& psinfo : m_prescaleSets)
178 psinfo.pss->print(indent+" ", detail);
179 }
180 }
181}
182
183
184std::ostream&
185TrigConf::operator<<(std::ostream & o, const TrigConf::HLTPrescaleSetCollection & c) {
186 lock_guard<recursive_mutex> lock(c.m_prescaleSetCollection_mutex);
187 o << "HLTPrescaleSetCollection has " << c.size() << " prescale sets" << endl;
188 if(c.size()>0) {
189 o << " LB Prescale set key Loaded Prescale set" << endl;
190 for(const TrigConf::HLTPrescaleSetCollection::cont& psinfo : c.m_prescaleSets)
191 o << setw(9) << psinfo.lb << setw(19) << psinfo.psk << " " << (psinfo.pss!=0?"yes":" no")
192 << " " << (psinfo.pss!=0?psinfo.pss->name():"") << endl;
193 }
194 return o;
195}
196
197
198string
200 stringstream s;
201 s << *this;
202 return s.str();
203}
HLT chain configuration information.
void clear()
Deletes all prescale sets.
void print(const std::string &indent="", unsigned int detail=1) const
Print the prescale set.
std::recursive_mutex m_prescaleSetCollection_mutex
Mutex for m_prescaleSetCollection.
std::vector< std::pair< unsigned int, unsigned int > > prescale_keys() const
void addPrescaleSet(unsigned int lumiblock, HLTPrescaleSet *pss)
Add prescale set for this lumiblock number.
HLTPrescaleSet * setPrescaleSet(HLTPrescaleSet *pss)
Add prescale set for this lumiblock number.
std::list< cont > m_prescaleSets
all prescale sets with start lb
HLTPrescaleSet * thePrescaleSet(unsigned int lumiblock) const
get prescale set for lumiblock and set the internal current lumiblock counter
void set_prescale_keys_to_load(const std::vector< std::pair< unsigned int, unsigned int > > &)
HLTPrescaleSetCollection & operator=(const HLTPrescaleSetCollection &)
bool contains(unsigned int lumiblock, unsigned int psk)
Check if prescale set with this lumiblock and prescale keys exists.
size_t size() const
number of prescale sets
const HLTPrescaleSet * prescaleSet(unsigned int lumiblock) const
HLT chain configuration information.
unsigned int id() const
const std::string & name() const
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
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)
STL namespace.