ATLAS Offline Software
Loading...
Searching...
No Matches
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
12namespace 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//--------------------------------------------------------------------------------------
25TrigConfVar::TrigConfVar(const std::string &name, uint32_t id)
26 :m_id(id),
28{
29}
30
31//--------------------------------------------------------------------------------------
32void TrigConfVar::print(std::ostream &os) const
33{
34 os << str(*this) << std::endl;
35}
36
37//--------------------------------------------------------------------------------------
38std::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//--------------------------------------------------------------------------------------
47uint16_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 //
70
71 return TrigVar::gVarVec.back().getId();
72}
73
74//--------------------------------------------------------------------------------------
75uint16_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
121 }
122 else {
123 TrigVar::gVarVec.push_back(TrigConfVar(name, id));
124 }
125
126 return TrigVar::gVarVec.back().getId();
127}
128
129//--------------------------------------------------------------------------------------
130bool 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//--------------------------------------------------------------------------------------
147bool 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//--------------------------------------------------------------------------------------
164std::vector<TrigConfVar> Trig::GetCurrentTrigConfVarVector ATLAS_NOT_THREAD_SAFE ()
165{
166 //
167 // Return copy of static vector
168 //
169 return TrigVar::gVarVec;
170}
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
std::vector< TrigConfVar > Trig::GetCurrentTrigConfVarVector ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
uint32_t m_id
Definition TrigConfVar.h:46
void print(std::ostream &os) const
uint32_t id() const
Definition TrigConfVar.h:39
std::string m_name
Definition TrigConfVar.h:47
const std::string & name() const
Definition TrigConfVar.h:36
static unsigned int gCounter
static std::vector< TrigConfVar > gVarVec