ATLAS Offline Software
Loading...
Searching...
No Matches
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
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 }
58 std::string filePath = PathResolverFindDataFile(m_fileStr);
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 //coverity[copy_constructor_call]
160 m_mainJson["Detector"][key]["k"]=k;
161 }
162
163 ATH_MSG_INFO("Loaded ZDC DB from GeoDB" << versionKey.tag());
164 return true;
165}
166
167
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Definition of the abstract IRDBAccessSvc interface.
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
std::string PathResolverFindDataFile(const std::string &logical_file_name)
#define y
#define x
#define z
Header file for AthHistogramAlgorithm.
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
const std::string & tag() const
Return version tag.
const std::string & node() const
Return the version node.
RecordsVector::const_iterator const_iterator
virtual const_iterator begin() const =0
virtual const_iterator end() const =0
nlohmann::json m_mainJson
static const IZdcGeometryDB * getInstance()
std::string m_fileStr
static const IZdcGeometryDB * getInstance()
MsgStream & msg() const
The standard message stream.
AsgMessaging(const std::string &name)
Constructor with a name.