ATLAS Offline Software
TrigConfVar.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 <sstream>
7 
10 
11 
12 namespace TrigVar {
13  static std::vector<TrigConfVar> gVarVec;
14  static unsigned int gCounter = 60000;
15 }
16 
17 //--------------------------------------------------------------------------------------
19  :m_id(0),
20  m_name()
21 {
22 }
23 
24 //--------------------------------------------------------------------------------------
25 TrigConfVar::TrigConfVar(const std::string &name, uint32_t id)
26  :m_id(id),
27  m_name(name)
28 {
29 }
30 
31 //--------------------------------------------------------------------------------------
32 void TrigConfVar::print(std::ostream &os) const
33 {
34  os << str(*this) << std::endl;
35 }
36 
37 //--------------------------------------------------------------------------------------
38 std::string str(const TrigConfVar &o)
39 {
40  std::stringstream s;
41  s << "TrigConfVar: " << o.name() << "=" << o.id();
42 
43  return s.str();
44 }
45 
46 //--------------------------------------------------------------------------------------
47 uint16_t Trig::ReserveVarId ATLAS_NOT_THREAD_SAFE (const std::string &name)
48 {
49  //
50  // Return matching id, if it does not exist then create new id
51  //
52  for(unsigned int i = 0; i < TrigVar::gVarVec.size(); i++) {
53  //
54  // Check name already exists
55  //
56  if(TrigVar::gVarVec[i].getName() == name) {
57  return TrigVar::gVarVec[i].getId();
58  }
59  }
60 
61  if(TrigVar::gCounter+1 >= 65535) {
62  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "ReserveVarId") << "Overflow of 16 bits key.";
63  return 0;
64  }
65 
66  //
67  // Add new configuration
68  //
69  TrigVar::gVarVec.push_back(TrigConfVar(name, TrigVar::gCounter++));
70 
71  return TrigVar::gVarVec.back().getId();
72 }
73 
74 //--------------------------------------------------------------------------------------
75 uint16_t Trig::ReserveVarId ATLAS_NOT_THREAD_SAFE (const std::string &name, uint16_t id)
76 {
77  //
78  // Create new id using input id as suggestion.
79  //
80  bool matched_id = false;
81 
82  for(unsigned int i = 0; i < TrigVar::gVarVec.size(); i++) {
83 
84  if(TrigVar::gVarVec[i].getName() == name) {
85  //
86  // Check if already stored id matches
87  //
88  if(TrigVar::gVarVec[i].getId() != id) {
89  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "ReserveVarId")
90  << "ReserveVarId - error! Existing var with " << name << " and id=" << TrigVar::gVarVec[i].getId() << ": new id=" << id;
91  }
92 
93  return TrigVar::gVarVec[i].getId();
94  }
95  else if(TrigVar::gVarVec[i].getId() == id) {
96  //
97  // Check if already stored name matches
98  //
99  matched_id = true;
100 
101  if(TrigVar::gVarVec[i].getName() != name) {
102  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "ReserveVarId")
103  << "ReserveVarId - error! Existing var with " << name << " and id=" << TrigVar::gVarVec[i].getId() << ": new name=" << name;
104  }
105  else {
106  return id;
107  }
108  }
109  }
110 
111  //
112  // Add new configuration
113  //
114  if(matched_id) {
115  if(TrigVar::gCounter+1 >= 65535) {
116  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "ReserveVarId") << "Overflow of 16 bits key";
117  return 0;
118  }
119 
120  TrigVar::gVarVec.push_back(TrigConfVar(name, TrigVar::gCounter++));
121  }
122  else {
123  TrigVar::gVarVec.push_back(TrigConfVar(name, id));
124  }
125 
126  return TrigVar::gVarVec.back().getId();
127 }
128 
129 //--------------------------------------------------------------------------------------
130 bool Trig::FindVarId ATLAS_NOT_THREAD_SAFE (const std::string &name, uint16_t &id)
131 {
132  //
133  // Find id for variable name
134  //
135  for(unsigned int i = 0; i < TrigVar::gVarVec.size(); i++) {
136 
137  if(TrigVar::gVarVec[i].getName() == name) {
138  id = TrigVar::gVarVec[i].getId();
139  return true;
140  }
141  }
142 
143  return false;
144 }
145 
146 //--------------------------------------------------------------------------------------
147 bool Trig::FindVarName ATLAS_NOT_THREAD_SAFE (const uint16_t id, std::string &name)
148 {
149  //
150  // Find id for variable name
151  //
152  for(unsigned int i = 0; TrigVar::gVarVec.size(); i++) {
153 
154  if(TrigVar::gVarVec[i].getId() == id) {
155  name = TrigVar::gVarVec[i].getName();
156  return true;
157  }
158  }
159 
160  return false;
161 }
162 
163 //--------------------------------------------------------------------------------------
164 std::vector<TrigConfVar> Trig::GetCurrentTrigConfVarVector ATLAS_NOT_THREAD_SAFE ()
165 {
166  //
167  // Return copy of static vector
168  //
169  return TrigVar::gVarVec;
170 }
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigConfVar
Definition: TrigConfVar.h:29
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TrigConfVar::print
void print(std::ostream &os) const
Definition: TrigConfVar.cxx:32
TrigConfVar.h
TrigConfVar::id
uint32_t id() const
Definition: TrigConfVar.h:39
TrigConfVar::name
const std::string & name() const
Definition: TrigConfVar.h:36
TrigConfVar::TrigConfVar
TrigConfVar()
Definition: TrigConfVar.cxx:18
dumpTruth.getName
getName
Definition: dumpTruth.py:34
ATLAS_NOT_THREAD_SAFE
uint16_t Trig::ReserveVarId ATLAS_NOT_THREAD_SAFE(const std::string &name)
Definition: TrigConfVar.cxx:47
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
lumiFormat.i
int i
Definition: lumiFormat.py:85
str
std::string str(const TrigConfVar &o)
Definition: TrigConfVar.cxx:38
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TrigVar
Definition: TrigConfVar.cxx:12