ATLAS Offline Software
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 
5 #include "MuonGeoModel/MYSQL.h"
6 
7 
12 
13 #include <cassert>
14 #include <iostream>
15 #include <sstream>
16 #include <utility>
17 
18 namespace MuonGM {
19 
21  AthMessaging{"MuonGeoModel.MYSQL"} {}
22 
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 
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 );
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 );
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 );
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 << ">" );
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) {
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 {
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 
150  void MYSQL::PrintAllStations() const {
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 {
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 
217 
218  std::string MYSQL::AllocposFindName(int i) const {
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;
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;
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
MuonGM::MYSQL::setLayoutName
void setLayoutName(const std::string &s)
Definition: MYSQL.cxx:289
MuonGM::MYSQL::GetTechnology
Technology * GetTechnology(const std::string &name)
Definition: MYSQL.cxx:105
MuonGM::MYSQL::AllocposBegin
AllocposIterator AllocposBegin() const
Definition: MYSQL.cxx:214
MuonGM::MYSQL::m_amdb_from_rdb
bool m_amdb_from_rdb
Definition: MYSQL.h:138
GeoModel::TransientConstSharedPtr< TgcReadoutParams >
MuonGM
Ensure that the Athena extensions are properly loaded.
Definition: GeoMuonHits.h:27
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
MuonGM::MYSQL::getNovaReadVersion
int getNovaReadVersion() const
Definition: MYSQL.cxx:260
checkxAOD.nameType
nameType
Definition: Tools/PyUtils/bin/checkxAOD.py:188
MuonGM::allocPosIterator
std::map< std::string, int >::const_iterator allocPosIterator
Definition: MYSQL.h:41
MuonGM::MYSQL::m_allocPos
std::map< std::string, int > m_allocPos
Definition: MYSQL.h:126
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MuonGM::MYSQL::LockedMYSQL
CxxUtils::LockedPointer< MYSQL > LockedMYSQL
Definition: MYSQL.h:47
MuonGM::MYSQL::allocPosEnd
allocPosIterator allocPosEnd() const
Definition: MYSQL.cxx:238
CxxUtils::LockedPointer
A pointer together with a movable lock.
Definition: LockedPointer.h:35
MuonGM::MYSQL::allocPosFindSubtype
int allocPosFindSubtype(const std::string &statType, int fi, int zi) const
Definition: MYSQL.cxx:196
MuonGM::MYSQL::setNovaVersion
void setNovaVersion(int i)
Definition: MYSQL.cxx:300
MuonGM::MYSQL::GetStation
const Station * GetStation(const std::string &name) const
Definition: MYSQL.cxx:51
MuonGM::MYSQL::tgcReadParsMap
const TgcReadParsMap & tgcReadParsMap() const
Definition: MYSQL.cxx:228
MuonGM::Station
Definition: Station.h:40
skel.it
it
Definition: skel.GENtoEVGEN.py:396
MuonGM::MYSQL::PrintTechnologies
void PrintTechnologies()
Definition: MYSQL.cxx:156
MuonGM::MYSQL::AllocposEnd
AllocposIterator AllocposEnd() const
Definition: MYSQL.cxx:212
athena.value
value
Definition: athena.py:124
MuonGM::MYSQL::getLayoutName
const std::string & getLayoutName() const
Definition: MYSQL.cxx:262
MuonGM::MYSQL::m_amdb_version
int m_amdb_version
Definition: MYSQL.h:137
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
MuonGM::Technology
Definition: Technology.h:15
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
MuonGM::MYSQL::m_tgcReadouts
TgcReadParsMap m_tgcReadouts
Definition: MYSQL.h:129
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonGM::MYSQL::allocPosFindCutout
int allocPosFindCutout(const std::string &statType, int fi, int zi) const
Definition: MYSQL.cxx:201
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
MuonGM::MYSQL::GetStationPosition
Position GetStationPosition(const std::string &nameType, int fi, int zi) const
Definition: MYSQL.cxx:71
TgcReadoutParams.h
AthMessaging::ATLAS_THREAD_SAFE
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
Definition: AthMessaging.h:141
MuonGM::MYSQL::m_layout_name
std::string m_layout_name
Definition: MYSQL.h:134
MuonGM::MYSQL::~MYSQL
~MYSQL()
Definition: MYSQL.cxx:23
MuonGM::MYSQL::m_geometry_version
std::string m_geometry_version
Definition: MYSQL.h:133
MuonGM::MYSQL::m_nova_version
int m_nova_version
Definition: MYSQL.h:136
MuonGM::MYSQL::setGeometryVersion
void setGeometryVersion(const std::string &s)
Definition: MYSQL.cxx:271
SG::SlotSpecificObj
Maintain a set of objects, one per slot.
Definition: AthenaKernel/AthenaKernel/SlotSpecificObj.h:70
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
MuonGM::MYSQL::StoreTgcRPars
void StoreTgcRPars(GeoModel::TransientConstSharedPtr< TgcReadoutParams > t)
Definition: MYSQL.cxx:141
MuonGM::MYSQL::PrintAllStations
void PrintAllStations() const
Definition: MYSQL.cxx:150
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MuonGM::Position
Definition: Position.h:11
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonGM::MYSQL::addAllocpos
void addAllocpos(int i, const std::string &str)
Definition: MYSQL.cxx:210
MuonGM::MYSQL::getGeometryVersion
const std::string & getGeometryVersion() const
Definition: MYSQL.cxx:258
MuonGM::MYSQL::allocPosBegin
allocPosIterator allocPosBegin() const
Definition: MYSQL.cxx:236
MuonGM::Station::FindPosition
PositionIterator FindPosition(int iz, int iphi) const
Definition: Station.cxx:99
MuonGM::MYSQL::allocPosBuildValue
int allocPosBuildValue(int subtype, int cutout) const
Definition: MYSQL.cxx:234
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonGM::MYSQL::NTgcReadTypes
int NTgcReadTypes() const
Definition: MYSQL.cxx:232
MuonGM::MYSQL::set_amdb_from_RDB
void set_amdb_from_RDB(bool)
Definition: MYSQL.cxx:268
MuonGM::AllocposIterator
std::map< int, std::string >::const_iterator AllocposIterator
Definition: MYSQL.h:40
MuonGM::MYSQL::m_technologies
TechnologyMap m_technologies
Definition: MYSQL.h:128
MuonGM::MYSQL::m_allocatedpos
std::map< int, std::string > m_allocatedpos
Definition: MYSQL.h:125
MuonGM::MYSQL::NTgcReadouts
@ NTgcReadouts
Definition: MYSQL.h:45
MYSQL.h
MuonGM::MYSQL::amdb_from_RDB
bool amdb_from_RDB() const
Definition: MYSQL.cxx:266
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonGM::MYSQL::AllocposFind
AllocposIterator AllocposFind(int) const
Definition: MYSQL.cxx:216
MuonGM::MYSQL::MYSQL
MYSQL()
Definition: MYSQL.cxx:20
MuonGM::MYSQL::GetPointer
static LockedMYSQL GetPointer()
Definition: MYSQL.cxx:42
MuonGM::MYSQL::addallocPos
void addallocPos(const std::string &key, int value)
Definition: MYSQL.cxx:254
MuonGM::MYSQL::m_tgcReadout
std::array< GeoModel::TransientConstSharedPtr< TgcReadoutParams >, NTgcReadouts > m_tgcReadout
Definition: MYSQL.h:130
MuonGM::MYSQL::setNovaReadVersion
void setNovaReadVersion(int i)
Definition: MYSQL.cxx:284
MuonGM::MYSQL::TgcReadParsMap
std::map< std::string, GeoModel::TransientConstSharedPtr< TgcReadoutParams > > TgcReadParsMap
Definition: MYSQL.h:51
MuonGM::MYSQL::StoreTechnology
void StoreTechnology(Technology *t)
Definition: MYSQL.cxx:125
MuonGM::MYSQL::StationMap
std::map< std::string, std::unique_ptr< Station > > StationMap
Definition: MYSQL.h:48
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
MuonGM::MYSQL::GetATechnology
const Technology * GetATechnology(const std::string &name) const
Definition: MYSQL.cxx:162
MuonGM::MYSQL::allocPosFind
allocPosIterator allocPosFind(const std::string &key) const
Definition: MYSQL.cxx:240
MuonGM::MYSQL::StoreStation
void StoreStation(Station *s)
Definition: MYSQL.cxx:136
checkFileSG.fi
fi
Definition: checkFileSG.py:65
MuonGM::MYSQL::getNovaVersion
int getNovaVersion() const
Definition: MYSQL.cxx:264
createCoolChannelIdFile.newname
newname
Definition: createCoolChannelIdFile.py:106
SlotSpecificObj.h
Maintain a set of objects, one per slot.
MuonGM::MYSQL::GetTgcRPars
GeoModel::TransientConstSharedPtr< TgcReadoutParams > GetTgcRPars(const std::string &name) const
Definition: MYSQL.cxx:88
str
Definition: BTagTrackIpAccessor.cxx:11
MuonGM::MYSQL::allocPosBuildKey
std::string allocPosBuildKey(const std::string &statType, int fi, int zi) const
Definition: MYSQL.cxx:184
checker_macros.h
Define macros for attributes used to control the static checker.
MuonGM::MYSQL::TechnologyIterator
TechnologyMap::const_iterator TechnologyIterator
Definition: MYSQL.h:55
MuonGM::buildString
std::string buildString(int i, int ncha)
Definition: GlobalUtilities.cxx:23
MuonGM::MYSQL::NStations
int NStations() const
Definition: MYSQL.cxx:230
MuonGM::MYSQL::GetMYSQLPtr
static MYSQLPtr & GetMYSQLPtr()
Definition: MYSQL.cxx:32
MuonGM::MYSQL::m_stations
StationMap m_stations
Definition: MYSQL.h:127
MuonGM::Station::GetName
const std::string & GetName() const
Definition: Station.cxx:110
Technology.h
subproc.subtype
string subtype
Definition: subproc.py:19
MuonGM::MYSQL::AllocposFindName
std::string AllocposFindName(int) const
Definition: MYSQL.cxx:218
MuonGM::MYSQL::stationMap
const StationMap & stationMap() const
Definition: MYSQL.cxx:227
MuonGM::MYSQL::TgcReadParsIterator
TgcReadParsMap::const_iterator TgcReadParsIterator
Definition: MYSQL.h:52
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
MuonGM::MYSQL::StationIterator
StationMap::const_iterator StationIterator
Definition: MYSQL.h:49
MuonGM::MYSQL::MYSQLPtr
Definition: MYSQL.h:118