ATLAS Offline Software
Loading...
Searching...
No Matches
MYSQL.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
12
13#include <cassert>
14#include <iostream>
15#include <sstream>
16#include <utility>
17
18namespace MuonGM {
19
21 AthMessaging{"MuonGeoModel.MYSQL"} {}
22
24 MYSQLPtr& ptr = GetMYSQLPtr();
25 std::unique_lock l (ptr.m_mutex);
26
27 // reset the pointer so that at next initialize the MYSQL object will be re-created
28 if (ptr.m_ptr == this)
29 ptr.m_ptr = nullptr;
30 }
31
34 const EventContext& ctx = Gaudi::Hive::currentContext();
35 if (ctx.slot() == EventContext::INVALID_CONTEXT_ID) {
36 EventContext ctx2 (0, 0);
37 return *ptrs.get(ctx2);
38 }
39 return *ptrs.get(ctx);
40 }
41
43 MYSQLPtr& ptr = GetMYSQLPtr();
44 std::unique_lock l (ptr.m_mutex);
45 if (!ptr.m_ptr) {
46 ptr.m_ptr = new MYSQL;
47 }
48 return LockedMYSQL (*ptr.m_ptr, std::move(l));
49 }
50
51 const Station *MYSQL::GetStation(const std::string& name) const {
52 ATH_MSG_VERBOSE( " looking for station " << name );
53 StationIterator it = m_stations.find(name);
54 if (it != m_stations.end()) {
55 ATH_MSG_VERBOSE( "found the station" );
56 return it->second.get();
57 }
58 return nullptr;
59 }
60
61 Station *MYSQL::GetStation(const std::string& name) {
62 ATH_MSG_VERBOSE( " looking for station " << name );
63 StationIterator it = m_stations.find(name);
64 if (it != m_stations.end()) {
65 ATH_MSG_VERBOSE( "found the station" );
66 return it->second.get();
67 }
68 return nullptr;
69 }
70
71 Position MYSQL::GetStationPosition(const std::string& nameType, int fi, int zi) const {
72 Position p;
73 ATH_MSG_VERBOSE( " MYSQL::GetStationPosition for " << nameType << " fi/zi " << fi << " " << zi );
74 int subtype = allocPosFindSubtype(nameType, fi, zi);
75 std::string stname = nameType + MuonGM::buildString(subtype, 0);
76 const Station *st = GetStation(stname);
77 if (st != nullptr) {
78 ATH_MSG_VERBOSE( " found in Station " << st->GetName());
79 p = (*(st->FindPosition(zi, fi))).second;
80 ATH_MSG_VERBOSE( " at p.fi,zi " << p.phiindex << " " << p.zindex << " shift/z " << p.shift << " " << p.z );
81
82 } else {
83 ATH_MSG_WARNING( "::GetStationPosition nothing found for " << nameType << " at fi/zi " << fi << " " << zi );
84 }
85 return p;
86 }
87
89 ATH_MSG_VERBOSE( "MYSQL::GetTgcRPars looking for a TgcRPars named <" << name << ">" );
90 TgcReadParsIterator it = m_tgcReadouts.find(name);
91 if (it != m_tgcReadouts.end()) {
92 return it->second;
93 }
94 return nullptr;
95 }
96
98 if (jsta - 1 < 0 || jsta >= NTgcReadouts) {
99 ATH_MSG_ERROR( "MYSQL::GetTgcRPars jsta = " << jsta << " out of range (0," << NTgcReadouts - 1 << ")" );
100 return nullptr;
101 }
102 return m_tgcReadout[jsta - 1];
103 }
104
105 Technology *MYSQL::GetTechnology(const std::string& name) {
106 TechnologyIterator it = m_technologies.find(name);
107 if (it != m_technologies.end()) {
108 ATH_MSG_VERBOSE( "found the station technology name " << name );
109 return it->second.get();
110 }
111 ATH_MSG_VERBOSE( "MYSQL:: Technology " << name << "+++++++++ not found!" );
112 return nullptr;
113 }
114
115 const Technology *MYSQL::GetTechnology(const std::string& name) const {
116 TechnologyIterator it = m_technologies.find(name);
117 if (it != m_technologies.end()) {
118 ATH_MSG_VERBOSE( "found the station technology name " << name );
119 return it->second.get();
120 }
121 ATH_MSG_VERBOSE( "MYSQL:: Technology " << name << "+++++++++ not found!" );
122 return nullptr;
123 }
124
126 ATH_MSG_VERBOSE( "MYSQL::StoreTechnology /// techn. named " << t->GetName() );
127
128 std::unique_ptr<Technology>& stored = m_technologies[t->GetName()];
129 if (stored) {
130 ATH_MSG_ERROR( "MYSQL::StoreTechnology ERROR /// This place is already taken !!! for " << t->GetName() );
131 } else {
132 stored.reset(t);
133 }
134 }
135
137 ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" name " << s->GetName() );
138 m_stations[s->GetName()].reset(s);
139 }
140
142 ATH_MSG_VERBOSE( "MYSQL::StoreTgcRPars named " << s->GetName() << " located @ " << s << " jsta = " << s->chamberType() );
143 if (s->chamberType() >= NTgcReadouts) {
144 ATH_MSG_ERROR( "MYSQL::StoreTgcRPars ChamberType(JSTA) " << s->chamberType() << " > NTgcReadouts=" << NTgcReadouts );
145 return;
146 }
147 m_tgcReadout[s->chamberType() - 1] = s;
148 }
149
151 for (const auto& p : m_stations) {
152 ATH_MSG_INFO( "---> Station " << p.first );
153 }
154 }
155
157 for (const auto& p : m_technologies) {
158 ATH_MSG_INFO( "---> Technology " << p.first );
159 }
160 }
161
162 const Technology *MYSQL::GetATechnology(const std::string& name) const {
163 TechnologyIterator it = m_technologies.find(name);
164
165 if (it != m_technologies.end()) {
166 ATH_MSG_VERBOSE( "found the station technology name " << name );
167 return it->second.get();
168 }
169 ATH_MSG_VERBOSE( "MYSQL:: Technology " << name << "+++++++++ not found!" );
170 for (unsigned int i = 1; i <= 20; i++) {
171 char chindex[3];
172 sprintf(chindex, "%u", i);
173 // std::string newname = name.substr(0,3)+chindex;
174 std::string newname = name.substr(0, 3) + MuonGM::buildString(i, 2);
175 it = m_technologies.find(newname);
176 if (it != m_technologies.end()) {
177 ATH_MSG_VERBOSE( " Selecting a technology called <" << newname << ">" );
178 return it->second.get();
179 }
180 }
181 return nullptr;
182 }
183
184 std::string MYSQL::allocPosBuildKey(const std::string& statType, int fi, int zi) const {
185 std::ostringstream mystream;
186 mystream << statType << "fi" << MuonGM::buildString(fi, 1) << "zi" << MuonGM::buildString(zi, -1);
187 ATH_MSG_VERBOSE(__FILE__<<":"<<__LINE__<<" from " << statType << " fi " << fi << " zi " << zi << " we get as key " << mystream.str() );
188 return mystream.str();
189 }
190
191 allocPosIterator MYSQL::allocPosFind(const std::string& statType, int fi, int zi) const {
192 std::string key = allocPosBuildKey(statType, fi, zi);
193 return allocPosFind(key);
194 }
195
196 int MYSQL::allocPosFindSubtype(const std::string& statType, int fi, int zi) const {
197 std::string key = allocPosBuildKey(statType, fi, zi);
198 return allocPosFindSubtype(key);
199 }
200
201 int MYSQL::allocPosFindCutout(const std::string& statType, int fi, int zi) const {
202 std::string key = allocPosBuildKey(statType, fi, zi);
203 return allocPosFindCutout(key);
204 }
205
206 void MYSQL::addallocPos(const std::string& statType, int fi, int zi, int subtyp, int cutout) {
207 std::string key = allocPosBuildKey(statType, fi, zi);
208 addallocPos(key, subtyp, cutout);
209 }
210 void MYSQL::addAllocpos(int i, const std::string& str) { m_allocatedpos[i] = str; }
211
213
215
216 AllocposIterator MYSQL::AllocposFind(int i) const { return m_allocatedpos.find(i); }
217
218 std::string MYSQL::AllocposFindName(int i) const {
219 AllocposIterator it = m_allocatedpos.find(i);
220 // imt fix in case key is wrong:
221 if (it == m_allocatedpos.end()) {
222 throw std::runtime_error("AllocPosFIndName() -- Bad key");
223 }
224 return (*it).second;
225 }
226 //
229
230 int MYSQL::NStations() const { return m_stations.size(); }
231
232 int MYSQL::NTgcReadTypes() const { return m_tgcReadouts.size(); }
233
234 int MYSQL::allocPosBuildValue(int subtype, int cutout) const { return 100 * subtype + cutout; }
235
237
239
240 allocPosIterator MYSQL::allocPosFind(const std::string& key) const { return m_allocPos.find(key); }
241
243 int value = it->second;
244 int subtype = static_cast<int>(value / 100);
245 return subtype;
246 }
247
249 int value = (*it).second;
250 int cutout = static_cast<int>(value % 100);
251 return cutout;
252 }
253
254 void MYSQL::addallocPos(const std::string& key, int value) { m_allocPos[key] = value; }
255
256 void MYSQL::addallocPos(const std::string& key, int subtype, int cutout) { m_allocPos[key] = allocPosBuildValue(subtype, cutout); }
257
258 const std::string& MYSQL::getGeometryVersion() const { return m_geometry_version; }
259
261
262 const std::string& MYSQL::getLayoutName() const { return m_layout_name; }
263
264 int MYSQL::getNovaVersion() const { return m_nova_version; }
265
266 bool MYSQL::amdb_from_RDB() const { return m_amdb_from_rdb; }
267
269
270
271 void MYSQL::setGeometryVersion(const std::string& s) {
272
273
274 if (m_geometry_version != "unknown") {
275 if (s == m_geometry_version)
276 return;
277 ATH_MSG_WARNING( "GeometryVersion already set to <" << m_geometry_version << ">"
278 << " resetting to <" << s << ">" );
279 }
281 ATH_MSG_INFO( "GeometryVersion set to <" << m_geometry_version << ">" );
282 }
283
285 m_amdb_version = i;
286 ATH_MSG_VERBOSE("setNovaReadVersion to " << m_amdb_version );
287 }
288
289 void MYSQL::setLayoutName(const std::string& s) {
290 if (m_layout_name != "unknown") {
291 if (s == m_layout_name)
292 return;
293 ATH_MSG_WARNING( "LayoutName already set to <" << m_layout_name << ">"
294 << " resetting to <" << s << ">" );
295 }
296 m_layout_name = s;
297 ATH_MSG_INFO( "LayoutName (from DBAM) set to <" << m_layout_name << "> -- relevant for CTB2004" );
298 }
299
301 m_nova_version = i;
302 ATH_MSG_VERBOSE("setNovaVersion to " << m_nova_version );
303 }
304
305 int MYSQL::allocPosFindCutout(const std::string& key) const {
306 int cutout = 0;
307 allocPosIterator it = m_allocPos.find(key);
308 if (it != allocPosEnd()) {
309 return allocPosFindCutout(it);
310 }
311 ATH_MSG_ERROR("MYSQL::allocPosFindCutout for key " << key << " no element found" );
312 return cutout;
313 }
314
315 int MYSQL::allocPosFindSubtype(const std::string& key) const {
316 int subtype = 0;
317 allocPosIterator it = m_allocPos.find(key);
318 if (it != allocPosEnd()) {
319 return allocPosFindSubtype(it);
320 }
321 ATH_MSG_ERROR("MYSQL::allocPosFindSubtype for key " << key << " no element found" );
322 return subtype;
323 }
324
325} // namespace MuonGM
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Maintain a set of objects, one per slot.
Define macros for attributes used to control the static checker.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
The TransientConstSharedPtr allows non-const access if the pointer itself is non-const but in the con...
@ NTgcReadouts
Definition MYSQL.h:45
AllocposIterator AllocposBegin() const
Definition MYSQL.cxx:214
const std::string & getGeometryVersion() const
Definition MYSQL.cxx:258
std::string m_geometry_version
Definition MYSQL.h:133
const Station * GetStation(const std::string &name) const
Definition MYSQL.cxx:51
void setLayoutName(const std::string &s)
Definition MYSQL.cxx:289
const std::string & getLayoutName() const
Definition MYSQL.cxx:262
void StoreTgcRPars(GeoModel::TransientConstSharedPtr< TgcReadoutParams > t)
Definition MYSQL.cxx:141
void StoreStation(Station *s)
Definition MYSQL.cxx:136
std::string AllocposFindName(int) const
Definition MYSQL.cxx:218
int NTgcReadTypes() const
Definition MYSQL.cxx:232
Position GetStationPosition(const std::string &nameType, int fi, int zi) const
Definition MYSQL.cxx:71
int m_amdb_version
Definition MYSQL.h:137
void set_amdb_from_RDB(bool)
Definition MYSQL.cxx:268
TgcReadParsMap m_tgcReadouts
Definition MYSQL.h:129
Technology * GetTechnology(const std::string &name)
Definition MYSQL.cxx:105
StationMap::const_iterator StationIterator
Definition MYSQL.h:49
int getNovaVersion() const
Definition MYSQL.cxx:264
static LockedMYSQL GetPointer()
Definition MYSQL.cxx:42
std::map< std::string, GeoModel::TransientConstSharedPtr< TgcReadoutParams > > TgcReadParsMap
Definition MYSQL.h:51
AllocposIterator AllocposFind(int) const
Definition MYSQL.cxx:216
StationMap m_stations
Definition MYSQL.h:127
const Technology * GetATechnology(const std::string &name) const
Definition MYSQL.cxx:162
allocPosIterator allocPosBegin() const
Definition MYSQL.cxx:236
const TgcReadParsMap & tgcReadParsMap() const
Definition MYSQL.cxx:228
int NStations() const
Definition MYSQL.cxx:230
void PrintAllStations() const
Definition MYSQL.cxx:150
const StationMap & stationMap() const
Definition MYSQL.cxx:227
std::string allocPosBuildKey(const std::string &statType, int fi, int zi) const
Definition MYSQL.cxx:184
std::map< std::string, std::unique_ptr< Station > > StationMap
Definition MYSQL.h:48
bool amdb_from_RDB() const
Definition MYSQL.cxx:266
int m_nova_version
Definition MYSQL.h:136
int getNovaReadVersion() const
Definition MYSQL.cxx:260
std::array< GeoModel::TransientConstSharedPtr< TgcReadoutParams >, NTgcReadouts > m_tgcReadout
Definition MYSQL.h:130
AllocposIterator AllocposEnd() const
Definition MYSQL.cxx:212
std::map< std::string, int > m_allocPos
Definition MYSQL.h:126
allocPosIterator allocPosEnd() const
Definition MYSQL.cxx:238
void setNovaVersion(int i)
Definition MYSQL.cxx:300
TechnologyMap m_technologies
Definition MYSQL.h:128
TgcReadParsMap::const_iterator TgcReadParsIterator
Definition MYSQL.h:52
static MYSQLPtr & GetMYSQLPtr()
Definition MYSQL.cxx:32
std::string m_layout_name
Definition MYSQL.h:134
void StoreTechnology(Technology *t)
Definition MYSQL.cxx:125
CxxUtils::LockedPointer< MYSQL > LockedMYSQL
Definition MYSQL.h:47
void addAllocpos(int i, const std::string &str)
Definition MYSQL.cxx:210
void addallocPos(const std::string &key, int value)
Definition MYSQL.cxx:254
int allocPosFindCutout(const std::string &statType, int fi, int zi) const
Definition MYSQL.cxx:201
allocPosIterator allocPosFind(const std::string &key) const
Definition MYSQL.cxx:240
GeoModel::TransientConstSharedPtr< TgcReadoutParams > GetTgcRPars(const std::string &name) const
Definition MYSQL.cxx:88
std::map< int, std::string > m_allocatedpos
Definition MYSQL.h:125
void setGeometryVersion(const std::string &s)
Definition MYSQL.cxx:271
bool m_amdb_from_rdb
Definition MYSQL.h:138
int allocPosBuildValue(int subtype, int cutout) const
Definition MYSQL.cxx:234
TechnologyMap::const_iterator TechnologyIterator
Definition MYSQL.h:55
void setNovaReadVersion(int i)
Definition MYSQL.cxx:284
int allocPosFindSubtype(const std::string &statType, int fi, int zi) const
Definition MYSQL.cxx:196
void PrintTechnologies()
Definition MYSQL.cxx:156
Maintain a set of objects, one per slot.
Ensure that the Athena extensions are properly loaded.
Definition GeoMuonHits.h:27
std::map< std::string, int >::const_iterator allocPosIterator
Definition MYSQL.h:41
std::string buildString(int i, int ncha)
std::map< int, std::string >::const_iterator AllocposIterator
Definition MYSQL.h:40