ATLAS Offline Software
ZdcGeometryDB.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/Bootstrap.h"
8 #include <GaudiKernel/ISvcLocator.h>
14 
15 #include <fstream>
16 
17 
19 {
20  static const ZdcFileGeometryDB file_db_run3;
21  return &file_db_run3;
22 }
23 
25 {
26  static const ZdcGeoDBGeometryDB geodb_run3;
27  return &geodb_run3;
28 }
29 
30 //constructor
32  asg::AsgMessaging("ZdcFileGeometryDB"),
33  m_fileStr("ZdcConditions/ZDCgeom_Run3.json")
34 {
35 
36  msg().setLevel(MSG::INFO);
37 
39 
40 }
41 
42 ZdcGeoDBGeometryDB::ZdcGeoDBGeometryDB() : asg::AsgMessaging("ZdcGeoDBGeometryDB")
43 {
44  msg().setLevel(MSG::INFO);
45 
47 }
48 
49 
51 {
52  bool ret = false;
53  if (m_fileStr == "")
54  {
55  ATH_MSG_WARNING("No JSON filename defined!");
56  return ret;
57  }
59  if (!filePath.empty())
60  {
61  ATH_MSG_DEBUG( "ZdcGeometryDB::found ZDC JSON at " << filePath );
62  }
63  else
64  {
65  ATH_MSG_DEBUG( "ZdcGeometryDB::geometry NOT FOUND! Trying local file!" ) ;
66  filePath = "./"+m_fileStr;
67  }
68 
69  std::ifstream ifs(filePath);
70 
71  if (ifs.is_open())
72  {
73  ifs >> m_mainJson;
74  ret = true;
75  ATH_MSG_INFO("Loaded ZDC DB from file");
76  }
77  else
78  ATH_MSG_ERROR("No ZDC geometry found");
79 
80  return ret;
81 }
82 
84 {
85  SmartIF<IRDBAccessSvc> iAccessSvc(Gaudi::svcLocator()->service("RDBAccessSvc"));
86  if (!iAccessSvc)
87  {
88  ATH_MSG_FATAL("No RDBAccessSvc");
89  throw std::runtime_error("No RDBAccessSvc found!");
90  }
91 
92  SmartIF<IGeoModelSvc> geoModel{Gaudi::svcLocator()->service ("GeoModelSvc")};
93  if (!geoModel)
94  {
95  ATH_MSG_FATAL("No GeoModelSvc");
96  throw std::runtime_error("No GeoModelSvc found!");
97  }
98  DecodeVersionKey versionKey(geoModel, "ForwardDetectors");
99 
100  ATH_MSG_INFO("Loading ZDC geometry from tag: " << versionKey.tag() << " node: " << versionKey.node());
101  IRDBRecordset_ptr tanParams = iAccessSvc->getRecordsetPtr("TanTaxn",versionKey.tag(), versionKey.node());
102  IRDBRecordset_ptr zdcParams = iAccessSvc->getRecordsetPtr("ZdcPrd",versionKey.tag(), versionKey.node());
103 
104  IRDBRecordset::const_iterator AccessSvc_iter;
105  for(AccessSvc_iter = tanParams->begin(); AccessSvc_iter != tanParams->end(); ++AccessSvc_iter)
106  {
107  const std::string & name = (*AccessSvc_iter)->getString("NAME");
108  int side = (*AccessSvc_iter)->getInt("SIDE");
109  double x = (*AccessSvc_iter)->getDouble("X");
110  double y = (*AccessSvc_iter)->getDouble("Y");
111  double z = (*AccessSvc_iter)->getDouble("Z");
112  double w = (*AccessSvc_iter)->getDouble("WIDTH");
113  double h = (*AccessSvc_iter)->getDouble("HEIGHT");
114  double d = (*AccessSvc_iter)->getDouble("DEPTH");
115 
116  m_mainJson["TAN/TAXN"][name]["name"]=name;
117  m_mainJson["TAN/TAXN"][name]["side"]=side;
118  m_mainJson["TAN/TAXN"][name]["x"]=x;
119  m_mainJson["TAN/TAXN"][name]["y"]=y;
120  m_mainJson["TAN/TAXN"][name]["z"]=z;
121  m_mainJson["TAN/TAXN"][name]["width"]=w;
122  m_mainJson["TAN/TAXN"][name]["height"]=h;
123  m_mainJson["TAN/TAXN"][name]["depth"]=d;
124  }
125 
126  for(AccessSvc_iter = zdcParams->begin(); AccessSvc_iter != zdcParams->end(); ++AccessSvc_iter)
127  {
128  const std::string & name = (*AccessSvc_iter)->getString("NAME");
129  std::string key = name;
130  if ( (key.find("RPD") == std::string::npos) &&
131  (key.find("BRAN") == std::string::npos) )
132  key = "ZDC"+key;
133 
134  int side = (*AccessSvc_iter)->getInt("SIDE");
135  int mod = (*AccessSvc_iter)->getInt("MODUL");
136  int type = -1;
137  if (!(*AccessSvc_iter)->isFieldNull("TYPE"))
138  {
139  type = (*AccessSvc_iter)->getInt("TYPE");
140  }
141  double x = (*AccessSvc_iter)->getDouble("X");
142  double y = (*AccessSvc_iter)->getDouble("Y");
143  double z = (*AccessSvc_iter)->getDouble("Z");
144  double q = (*AccessSvc_iter)->getDouble("Q");
145  double i = (*AccessSvc_iter)->getDouble("I");
146  double j = (*AccessSvc_iter)->getDouble("J");
147  double k = (*AccessSvc_iter)->getDouble("K");
148 
149  m_mainJson["Detector"][key]["name"]=name;
150  m_mainJson["Detector"][key]["module"]=mod;
151  m_mainJson["Detector"][key]["side"]=side;
152  if (type>-1) m_mainJson["Detector"][key]["type"]=type; // RPD & BRAN have no "type" in some versions of the GeoDB
153  m_mainJson["Detector"][key]["x"]=x;
154  m_mainJson["Detector"][key]["y"]=y;
155  m_mainJson["Detector"][key]["z"]=z;
156  m_mainJson["Detector"][key]["q"]=q;
157  m_mainJson["Detector"][key]["i"]=i;
158  m_mainJson["Detector"][key]["j"]=j;
159  m_mainJson["Detector"][key]["k"]=k;
160  }
161 
162  ATH_MSG_INFO("Loaded ZDC DB from GeoDB" << versionKey.tag());
163  return true;
164 }
165 
166 
ZdcFileGeometryDB::m_fileStr
std::string m_fileStr
Definition: ZdcGeometryDB.h:28
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ZdcGeoDBGeometryDB::getInstance
static const IZdcGeometryDB * getInstance()
Definition: ZdcGeometryDB.cxx:24
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ZdcFileGeometryDB::loadJSONFile
bool loadJSONFile()
Definition: ZdcGeometryDB.cxx:50
hist_file_dump.d
d
Definition: hist_file_dump.py:142
asg
Definition: DataHandleTestTool.h:28
DecodeVersionKey::node
const std::string & node() const
Return the version node.
Definition: DecodeVersionKey.cxx:97
ZdcFileGeometryDB::getInstance
static const IZdcGeometryDB * getInstance()
Definition: ZdcGeometryDB.cxx:18
ZdcGeometryDB.h
x
#define x
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
IZdcGeometryDB
Definition: ZdcGeometryDB.h:12
TRT::Hit::side
@ side
Definition: HitInfo.h:83
IZdcGeometryDB::m_geoLoaded
bool m_geoLoaded
Definition: ZdcGeometryDB.h:15
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
ZdcGeoDBGeometryDB
Definition: ZdcGeometryDB.h:38
extractSporadic.h
list h
Definition: extractSporadic.py:96
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
DecodeVersionKey
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
Definition: DecodeVersionKey.h:18
ZdcFileGeometryDB
Definition: ZdcGeometryDB.h:26
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
DecodeVersionKey::tag
const std::string & tag() const
Return version tag.
Definition: DecodeVersionKey.cxx:91
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
PathResolver.h
hancool.filePath
string filePath
Definition: hancool.py:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ZdcFileGeometryDB::ZdcFileGeometryDB
ZdcFileGeometryDB()
Definition: ZdcGeometryDB.cxx:31
DecodeVersionKey.h
PathResolverFindDataFile
std::string PathResolverFindDataFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:278
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
y
#define y
h
ZdcGeoDBGeometryDB::ZdcGeoDBGeometryDB
ZdcGeoDBGeometryDB()
Definition: ZdcGeometryDB.cxx:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
extractSporadic.q
list q
Definition: extractSporadic.py:97
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:198
IZdcGeometryDB::m_mainJson
nlohmann::json m_mainJson
Definition: ZdcGeometryDB.h:16
IGeoModelSvc.h
IRDBRecordset::const_iterator
RecordsVector::const_iterator const_iterator
Definition: IRDBRecordset.h:52
ZdcGeoDBGeometryDB::loadGeoDB
bool loadGeoDB()
Definition: ZdcGeometryDB.cxx:83
fitman.k
k
Definition: fitman.py:528
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37