ATLAS Offline Software
TrigMonConfig.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // C/C++
6 #include <algorithm>
7 #include <sstream>
8 
11 
12 //--------------------------------------------------------------------------------------
14  :m_event(0),
15  m_lumi(0),
16  m_run(0),
17  m_sec(0),
18  m_nsec(0),
19  m_master_key(0),
20  m_hlt_ps_key(0),
21  m_lv1_ps_key(0)
22 {
23 }
24 
25 //--------------------------------------------------------------------------------------
27 {
28  //
29  // Erase all configuration data
30  //
31  m_event = 0;
32  m_lumi = 0;
33  m_run = 0;
34  m_sec = 0;
35  m_nsec = 0;
36 
37  m_master_key = 0;
38  m_hlt_ps_key = 0;
39  m_lv1_ps_key = 0;
40 
41  m_chain.clear();
42  m_seq.clear();
43  m_var_id.clear();
44  m_var_name.clear();
45  m_pair_key.clear();
46  m_pair_val.clear();
47 }
48 
49 //--------------------------------------------------------------------------------------
51 {
52  //
53  // Clear string variables
54  //
55  for(unsigned int i = 0; i < m_chain.size(); ++i) m_chain[i].clearStrings();
56  for(unsigned int i = 0; i < m_seq.size(); ++i) m_seq [i].clearStrings();
57 }
58 
59 //--------------------------------------------------------------------------------------
60 void TrigMonConfig::processConfig ATLAS_NOT_THREAD_SAFE ()
61 {
62  //
63  // Sync TrigConfVar with global static vector in TrigConfVar.cxx file
64  //
65 
66  // First, save global vector
67  const std::vector<TrigConfVar> var_vec = Trig::GetCurrentTrigConfVarVector();
68 
69  // Add our own configuration
70  if(m_var_name.size() == m_var_id.size()) {
71  for(unsigned int i = 0; i < m_var_id.size(); ++i) {
72  Trig::ReserveVarId(m_var_name[i], m_var_id[i]);
73  }
74  }
75 
76  // Save global data
77  for(unsigned int i = 0; i < var_vec.size(); ++i) {
78  if(std::find(m_var_name.begin(), m_var_name.end(), var_vec[i]) == m_var_name.end()) {
79  add<TrigConfVar>(var_vec[i]);
80  }
81  }
82 }
83 
84 //--------------------------------------------------------------------------------------
86  uint32_t lumi,
87  uint32_t run,
88  uint32_t sec,
89  uint32_t nsec)
90 {
91  //
92  // Fill EventID data
93  //
94  m_event = event;
95  m_lumi = lumi;
96  m_run = run;
97  m_sec = sec;
98  m_nsec = nsec;
99 }
100 
101 //--------------------------------------------------------------------------------------
103  uint32_t lv1_ps_key,
104  uint32_t hlt_ps_key)
105 {
106  //
107  // Save trigger configurations keys
108  //
109  m_master_key = master_key;
110  m_lv1_ps_key = lv1_ps_key;
111  m_hlt_ps_key = hlt_ps_key;
112 }
113 
114 //--------------------------------------------------------------------------------------
115 void TrigMonConfig::addValue(const std::string &key, const std::string &val)
116 {
117  //
118  // Save string pair
119  //
120  m_pair_key.push_back(key);
121  m_pair_val.push_back(val);
122 }
123 
124 //--------------------------------------------------------------------------------------
125 bool TrigMonConfig::keyExists(const std::string &key) const
126 {
127  //
128  // Find key and copy its value
129  //
130  if(m_pair_key.size() != m_pair_val.size()) {
131  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig") << "KeyExists - logic error!";
132  return false;
133  }
134 
135  for(unsigned int i = 0; i < m_pair_key.size(); ++i) {
136  if(m_pair_key[i] == key) {
137  return true;
138  }
139  }
140 
141  return false;
142 }
143 
144 //--------------------------------------------------------------------------------------
145 bool TrigMonConfig::readValue(const std::string &key, std::string &val) const
146 {
147  //
148  // Find key and copy its value
149  //
150  if(m_pair_key.size() != m_pair_val.size()) {
151  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig") << "ReadValue - logic error!";
152  return false;
153  }
154 
155  for(unsigned int i = 0; i < m_pair_key.size(); ++i) {
156  if(m_pair_key[i] == key) {
157  val = m_pair_val[i];
158  return true;
159  }
160  }
161 
162  return false;
163 }
164 
165 //--------------------------------------------------------------------------------------
166 uint32_t TrigMonConfig::getId(const std::string &name, const std::string &key) const
167 {
168  //
169  // convert name to 32 bits hash id - unique for given name
170  //
171 
172  if(key == "CHN") {
173  const std::vector<TrigConfChain>::const_iterator fit = std::find(m_chain.begin(),
174  m_chain.end(), name);
175  if(fit != m_chain.end()) {
176  return fit -> getId();
177  }
178  else {
179  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
180  << "getId - failed to find chain: " << name;
181  return 0;
182  }
183  } else if(key == "SEQ") {
184  const std::vector<TrigConfSeq>::const_iterator fit = std::find(m_seq.begin(), m_seq.end(), name);
185  if(fit != m_seq.end()) {
186  return fit -> getId();
187  }
188  else {
189  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
190  << "getId - failed to find sequence: " << name;
191  return 0;
192  }
193  } else if(key.find("ALG") != std::string::npos) {
194  // iterate over all configured sequences
195  for(unsigned int i = 0; i < m_seq.size(); ++i) {
196  const TrigConfSeq &seq = m_seq[i];
197  const std::vector<TrigConfAlg> &avec = seq.getAlg();
198 
199  // iterate over algorithms
200  for(unsigned int j = 0; j < avec.size(); ++j) {
201  const TrigConfAlg &alg = avec[j];
202  if(alg.getName() == name) return alg.getNameId();
203  }
204  }
205  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
206  << "getId - ERROR! Failed to find algorithm: " << name << ", " << key;
207  return 0;
208  }
209  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
210  << "getId - ERROR! Failed to match: " << name << ", " << key;
211  return 0;
212 }
213 
214 //--------------------------------------------------------------------------------------
215 uint16_t TrigMonConfig::getEncodedId(const std::string &name, const std::string &key) const
216 {
217  //
218  // convert name to 16 bits encoded id - unique for given configuration
219  //
220 
221  if(key == "CHN") {
222  const std::vector<TrigConfChain>::const_iterator fit = std::find(m_chain.begin(),
223  m_chain.end(), name);
224  if(fit != m_chain.end()) {
225  return fit -> getEncodedId();
226  }
227  else {
228  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
229  << "getEncoded - failed to find chain: " << name;
230  return 0;
231  }
232  }
233  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
234  << "getEncoded(" << name << ", " << key << ") - no match found";
235  return 0;
236 }
237 
238 //--------------------------------------------------------------------------------------
239 const std::string TrigMonConfig::getName(uint32_t id, const std::string &key) const
240 {
241  //
242  // convert hash id to unique name
243  //
244 
245  if(key == "CHN") {
246  const std::vector<TrigConfChain>::const_iterator fit = std::find(m_chain.begin(),
247  m_chain.end(), id);
248  if(fit != m_chain.end()) {
249  return fit -> getName();
250  }
251  else {
252  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
253  << "getId - failed to find chain: " << id;
254  return "";
255  }
256  } else if(key == "SEQ") {
257  const std::vector<TrigConfSeq>::const_iterator fit = std::find(m_seq.begin(), m_seq.end(), id);
258  if(fit != m_seq.end()) {
259  return fit -> getName();
260  }
261  else {
262  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
263  << "getId - failed to find sequence: " << id;
264  return "";
265  }
266  } else if(key.find("ALG") != std::string::npos){
267  // iterate over all configured sequences
268  for(unsigned int i = 0; i < m_seq.size(); ++i) {
269  const TrigConfSeq &seq = m_seq[i];
270  const std::vector<TrigConfAlg> &avec = seq.getAlg();
271 
272  // iterate over algorithms
273  for(unsigned int j = 0; j < avec.size(); ++j) {
274  const TrigConfAlg &alg = avec[j];
275 
276  if(alg.getNameId() == id) return alg.getName();
277  }
278  }
279  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
280  << "getId - failed to find algorithm: " << id;
281  return "";
282  }
283 
284  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonConfig")
285  << "getId - failed to match: " << id << ", " << key;
286 
287  return "";
288 }
289 
290 //--------------------------------------------------------------------------------------
291 const std::vector<TrigConfVar> TrigMonConfig::getConfVar() const
292 {
293  //
294  // Build variables on a fly and return vector by value
295  //
296  std::vector<TrigConfVar> var;
297 
298  if(m_var_name.size() == m_var_id.size()) {
299  //
300  // Iterate over keys and values
301  //
302  var.reserve(m_var_name.size());
303 
304  for(unsigned int i = 0; i < m_var_name.size(); ++i) {
305  if(m_var_id[i] != 0) {
306  var.push_back(TrigConfVar(m_var_name[i], m_var_id[i]));
307  }
308  }
309  }
310 
311  return var;
312 }
test_athena_ntuple_filter.seq
seq
filter configuration ## -> we use the special sequence 'AthMasterSeq' which is run before any other a...
Definition: test_athena_ntuple_filter.py:18
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
SGout2dot.alg
alg
Definition: SGout2dot.py:243
TrigConfVar
Definition: TrigConfVar.h:29
TrigMonConfig::m_nsec
uint32_t m_nsec
Definition: TrigMonConfig.h:108
TrigMonConfig::m_hlt_ps_key
uint32_t m_hlt_ps_key
Definition: TrigMonConfig.h:112
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
TrigMonConfig::m_run
uint32_t m_run
Definition: TrigMonConfig.h:106
TrigMonConfig::m_pair_key
std::vector< std::string > m_pair_key
Definition: TrigMonConfig.h:121
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigMonConfig::m_seq
std::vector< TrigConfSeq > m_seq
Definition: TrigMonConfig.h:116
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
TrigMonConfig::m_chain
std::vector< TrigConfChain > m_chain
Definition: TrigMonConfig.h:115
TrigMonConfig::getEncodedId
uint16_t getEncodedId(const std::string &name, const std::string &key) const
Definition: TrigMonConfig.cxx:215
TrigMonConfig::m_var_name
std::vector< std::string > m_var_name
Definition: TrigMonConfig.h:118
TrigMonConfig::TrigMonConfig
TrigMonConfig()
Definition: TrigMonConfig.cxx:13
TrigMonConfig::setTriggerKeys
void setTriggerKeys(uint32_t master_key, uint32_t lv1_ps_key, uint32_t hlt_ps_key)
Definition: TrigMonConfig.cxx:102
TrigMonConfig::m_event
uint32_t m_event
Definition: TrigMonConfig.h:104
TrigMonConfig::getConfVar
const std::vector< TrigConfVar > getConfVar() const
Definition: TrigMonConfig.cxx:291
TrigMonConfig::m_pair_val
std::vector< std::string > m_pair_val
Definition: TrigMonConfig.h:122
TrigMonConfig::setEventID
void setEventID(uint32_t event, uint32_t lumi, uint32_t run, uint32_t sec, uint32_t nsec)
Definition: TrigMonConfig.cxx:85
TrigMonConfig::clearStrings
void clearStrings()
Definition: TrigMonConfig.cxx:50
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigConfSeq
Definition: TrigConfSeq.h:29
TrigMonConfig::getName
const std::string getName(uint32_t id, const std::string &key) const
Definition: TrigMonConfig.cxx:239
TrigConfAlg
Definition: TrigConfAlg.h:25
TrigMonConfig::m_master_key
uint32_t m_master_key
Definition: TrigMonConfig.h:111
run
Definition: run.py:1
TrigMonConfig::getId
uint32_t getId(const std::string &name, const std::string &key) const
Definition: TrigMonConfig.cxx:166
MuonValidation_CreateResolutionProfiles.fit
def fit(h, emin, emax)
Definition: MuonValidation_CreateResolutionProfiles.py:69
ATLAS_NOT_THREAD_SAFE
void TrigMonConfig::processConfig ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: TrigMonConfig.cxx:60
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
TrigMonConfig.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigMonConfig::addValue
void addValue(const std::string &key, const std::string &val)
Definition: TrigMonConfig.cxx:115
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TrigMonConfig::m_sec
uint32_t m_sec
Definition: TrigMonConfig.h:107
TrigMonConfig::m_var_id
std::vector< uint32_t > m_var_id
Definition: TrigMonConfig.h:119
lumiFormat.lumi
lumi
Definition: lumiFormat.py:106
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
TrigMonConfig::keyExists
bool keyExists(const std::string &key) const
Definition: TrigMonConfig.cxx:125
TrigMonConfig::clear
void clear()
Definition: TrigMonConfig.cxx:26
TrigMonConfig::m_lv1_ps_key
uint32_t m_lv1_ps_key
Definition: TrigMonConfig.h:113
TrigMonConfig::m_lumi
uint32_t m_lumi
Definition: TrigMonConfig.h:105
TrigMonConfig::readValue
bool readValue(const std::string &key, std::string &val) const
Definition: TrigMonConfig.cxx:145
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37