ATLAS Offline Software
TileDetectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*
6  * Updates:
7  * - 2021, Riccardo Maria BIANCHI <riccardo.maria.bianchi@cern.ch>
8  * * Added TileDetectorFactoryLite to load the Tile geomnetry from SQLite
9  */
10 
12 #include "TileDetectorFactory.h"
13 #include "TileAtlasFactory.h"
14 #include "TileTBFactory.h"
16 
20 
21 #include "CaloIdentifier/TileID.h"
24 
27 #include "GaudiKernel/IService.h"
28 #include "GaudiKernel/MsgStream.h"
29 #include "StoreGate/StoreGateSvc.h"
31 
32 #include "GeoModelRead/ReadGeoModel.h"
33 
36 #include "SGTools/DataProxy.h"
37 
38 
40  const std::string& name,
41  const IInterface* parent)
43  , m_switches(false,true)
44  , m_not_locked(true)
45  , m_useNewFactory(true)
46  , m_geometryConfig("FULL")
47  , m_manager(0)
48 {
49  declareProperty("UseNewFactory", m_useNewFactory);
50  declareProperty("GeometryConfig",m_geometryConfig);
51  declareProperty("TestBeam", m_switches.testBeam);
52  // declareProperty("AddPlatesToCellVolume", m_switches.addPlatesToCell); to make user aware that the value is taken from DB rather from JO
58  declareProperty("CrackOption",m_switches.crackOption);
59 }
60 
61 
63 {
64 }
65 
66 
67 void TileDetectorTool::setSwitch(int & param, int value, const char * name)
68 {
69  if (param < 0) {
70  param = value;
71  ATH_MSG_INFO(name << " parameter from database is: " << param);
72  } else {
73  if (param != value) {
74  ATH_MSG_WARNING("Overriding " << name << " value from DB by value from jobOptions, using "
75  << param << " instead of " << value);
76  } else {
77  ATH_MSG_INFO(name << " parameter from jobOptions is: " << param);
78  }
79  }
80 }
81 
82 
84 {
85  MsgStream log(msgSvc(), name());
86  ATH_MSG_INFO(" Entering TileDetectorTool::create()");
87 
88  // Get the detector configuration
89  IGeoModelSvc *geoModel;
90  ATH_CHECK(service ("GeoModelSvc",geoModel));
91 
92  std::string atlasVersion = geoModel->atlasVersion();
93  std::string tileVersion = geoModel->tileVersionOverride();
94 
95  std::string versionTag = tileVersion.empty()? atlasVersion : tileVersion;
96  std::string versionNode = tileVersion.empty()? "ATLAS" : "TileCal";
97 
98  if (versionTag == "AUTO") {
99  versionTag = "TileCal-00";
100  versionNode = "TileCal";
101  }
102  if (atlasVersion.compare(0,9,"ATLAS-CTB") == 0 || tileVersion.compare(0,6,"TileTB") == 0) {
103  ATH_MSG_INFO("CTB geometry detected: " << atlasVersion << " " << tileVersion);
104  m_switches.testBeam = true;
105  }
106 
107  //Locate the top level experiment node
108  GeoModelExperiment* theExpt = nullptr;
109  CHECK( detStore()->retrieve(theExpt, "ATLAS") );
110 
111  if ( 0 == m_detector ) {
112  // Get the detector configuration.
113  ServiceHandle<IGeoDbTagSvc> geoDbTag("GeoDbTagSvc",name());
114  ATH_CHECK(geoDbTag.retrieve());
115 
116  // Get the 'new' accessSvc to get parameters / DB data from the DD SQLite input file.
117  ServiceHandle<IRDBAccessSvc> accessSvc(geoDbTag->getParamSvcName(),name());
118  ATH_CHECK(accessSvc.retrieve());
119 
120  // Get the SQLite reader, if specified in the jobOption
121  GeoModelIO::ReadGeoModel* sqliteReader = geoDbTag->getSqliteReader();
122 
123  // Get the Tile 'DDDB' and 'DetDescr' managers
124  // Note: we need to pass the raw IRDBAccess* to the TildDddbManager constructor.
125  bool sqliteInput = false;
126  if (sqliteReader) sqliteInput = true;
127  TileDddbManager_ptr dbManager(new TileDddbManager(&*accessSvc,versionTag,versionNode, sqliteInput));
128  m_manager = new TileDetDescrManager(dbManager);
129 
130  // check what factory can be used
131  if (0==dbManager->GetNumberOfEnv() && m_useNewFactory) {
132  ATH_MSG_WARNING("New TileAtlasFactory can not be used because TileGlobals do not exist in Database");
133  ATH_MSG_WARNING("Use old TileDetectorFactory instead");
134  m_useNewFactory = false;
135  }
136 
137  CHECK( initIds() );
138 
139  m_switches.addPlatesToCell = dbManager->addPlatesToCell();
140  setSwitch(m_switches.uShape, dbManager->uShape(), "Ushape");
141  setSwitch(m_switches.glue, dbManager->glue(), "Glue");
142  setSwitch(m_switches.pvt, dbManager->PVT(), "PVT");
143  setSwitch(m_switches.steel, dbManager->steel(), "Steel");
144  setSwitch(m_switches.csTube, dbManager->csTube(), "CsTube");
145 
146  m_not_locked = false;
147 
148  GeoPhysVol *world=&*theExpt->getPhysVol();
149 
150  // build the geometry from the standalone SQLite file
151  if (sqliteReader) {
152  TileDetectorFactoryLite theTileFactoryLite(detStore().operator->(),
153  m_manager,
154  sqliteReader,
155  accessSvc.operator->(),
156  m_switches,
157  &log,
158  true);
159  theTileFactoryLite.create(world);
160  } else {
161  // build the geometry from the Oracle-based GeometryDB
162  if (m_switches.testBeam) {
163  // TileTBFactory is not thread-safe. But since this code should only be
164  // ever called once (and this is "only" for test beam geometry), we use
165  // this rather ugly hack to silence the thread-checker warnings:
166  [[maybe_unused]] static const bool do_once ATLAS_THREAD_SAFE = [&]() ATLAS_NOT_THREAD_SAFE {
167  TileCablingService::getInstance_nc()->setTestBeam(true);
168  TileTBFactory theTileTBFactory = TileTBFactory(detStore().operator->(),m_manager,m_switches,&log);
169  theTileTBFactory.create(world);
170  return true;
171  }();
172 
173  } else if (m_useNewFactory) {
174  std::vector<GeoPhysVol *> volumePtrs;
175  std::vector<double> volumePositions;
176  TileAtlasFactory theTileFactory(detStore().operator->(),m_manager,m_switches,m_volumes,volumePtrs,volumePositions,&log,m_geometryConfig=="FULL");
177  theTileFactory.create(world);
178 
179  } else {
180  TileDetectorFactory theTileFactory(detStore().operator->(),m_manager,m_switches,&log);
181  theTileFactory.create(world);
182  }
183  } // end of building the geometry from the GeometryDB
184  ATH_MSG_DEBUG( "The Tile raw geometry has been built.");
185 
186  CHECK( createElements() );
187 
188  // Register the TileDetDescrManager instance with the Transient Detector Store
189  CHECK( detStore()->record(m_manager, m_manager->getName()) );
190  theExpt->addManager(m_manager);
191 
192  // For reco jobs: release DB manager. Cannot do it here for simulation jobs, they
193  // release DB manager as part of global GeoModel release
194  if (m_geometryConfig=="RECO")
196 
197  return StatusCode::SUCCESS;
198 
199  }
200 
201  return StatusCode::FAILURE;
202 }
203 
204 
206 {
208  if (proxy) {
209  proxy->reset();
210  m_manager = 0;
211  }
212  return StatusCode::SUCCESS;
213 }
214 
215 
217 {
218  const TileID* tileID;
219  const CaloCell_ID* cellID;
220  const TileHWID* tileHWID;
221 
222  // Retrieve all helpers from the detector store
223  CHECK( detStore()->retrieve(tileID, "TileID") );
224  CHECK( detStore()->retrieve(tileHWID, "TileHWID") );
225  CHECK( detStore()->retrieve(cellID, "CaloCell_ID") );
226 
227  m_manager->set_helper(tileID);
228  m_manager->set_helper(cellID);
229  m_manager->set_helper(tileHWID);
230 
231  // instantiate Cabling Svc to initialize pointers to helpers there
233  if (cabling==0) {
234  ATH_MSG_ERROR("Could not get instance of TileCablingService");
235  return StatusCode::FAILURE;
236  }
237 
238  return StatusCode::SUCCESS;
239 }
240 
241 
243 {
244  m_manager->create_elements(true);
245  return StatusCode::SUCCESS;
246 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
GeoModelExperiment::getPhysVol
GeoPhysVol * getPhysVol()
Destructor.
Definition: GeoModelExperiment.cxx:21
TileTBFactory::create
virtual void create(GeoPhysVol *world) override
Creation of Test Beam Tile geometry.
Definition: TileTBFactory.cxx:65
TileDddbManager_ptr
std::shared_ptr< TileDddbManager > TileDddbManager_ptr
Definition: TileDetDescrManager.h:28
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
IGeoModelSvc
Definition: IGeoModelSvc.h:17
TileCablingService::getInstance
static const TileCablingService * getInstance()
get pointer to service instance
Definition: TileCablingService.cxx:24
TileTBFactory.h
Definition of TileTBFactory class.
TileAtlasFactory
Definition: TileAtlasFactory.h:27
TileAtlasFactory::create
virtual void create(GeoPhysVol *world)
Creation of Tile geometry.
Definition: TileAtlasFactory.cxx:100
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
TileDetectorTool::m_volumes
Gaudi::Property< std::vector< std::string > > m_volumes
Definition: TileDetectorTool.h:40
GeoModelExperiment
Definition: GeoModelExperiment.h:32
TileAtlasFactory.h
Definition of TileAtlasFactory class.
athena.value
value
Definition: athena.py:122
TileSwitches::testBeam
bool testBeam
setting up testbeam geometry or ATLAS geometry
Definition: TileSwitches.h:31
TileDetectorTool::m_not_locked
bool m_not_locked
Definition: TileDetectorTool.h:42
TileDetDescrManager::create_elements
void create_elements()
Definition: TileDetDescrManager.cxx:139
TileDetectorTool::m_useNewFactory
bool m_useNewFactory
Definition: TileDetectorTool.h:43
TileDetectorTool::TileDetectorTool
TileDetectorTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: TileDetectorTool.cxx:39
TileSwitches::steel
int steel
0: Absorber is pure Iron 1: Absorber is tile::Steel defined in DB
Definition: TileSwitches.h:51
TileID.h
TileDetDescrManager.h
CaloCell_ID.h
TileDetectorFactory.h
Definition of TileDetectorFactory class.
GeoModelExperiment.h
TileHWID
Helper class for TileCal online (hardware) identifiers.
Definition: TileHWID.h:49
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
TileSwitches::uShape
int uShape
0: simulation without U-shape 1: simulation with U-shape
Definition: TileSwitches.h:38
TileHWID.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TileSwitches::glue
int glue
0: glue layer is removed and replaced by iron, 1: simulation with glue, 2: glue is replaced by iron +...
Definition: TileSwitches.h:43
TileDetectorFactory::create
virtual void create(GeoPhysVol *world)
Creation of Tile geometry.
Definition: TileDetectorFactory.cxx:63
TileCablingService.h
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
TileTBFactory
Definition: TileTBFactory.h:28
TileDetectorTool.h
TileDetectorTool::m_switches
TileSwitches m_switches
Definition: TileDetectorTool.h:39
TileDetDescrManager
Definition: TileDetDescrManager.h:33
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
TileID
Helper class for TileCal offline identifiers.
Definition: TileID.h:68
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TileDetectorFactoryLite::create
virtual void create(GeoPhysVol *world)
Creation of Tile geometry.
Definition: TileDetectorFactoryLite.cxx:61
TileDetectorTool::create
virtual StatusCode create() override final
Definition: TileDetectorTool.cxx:83
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:40
TileDetDescrManager::set_helper
void set_helper(const TileID *id)
Definition: TileDetDescrManager.h:190
TileDetectorTool::~TileDetectorTool
virtual ~TileDetectorTool() override final
Definition: TileDetectorTool.cxx:62
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TileDetectorFactoryLite
Definition of the TileDetectorFactoryLite class. The TileDetectorFactoryLite is invoked by the TileDe...
Definition: TileDetectorFactoryLite.h:42
GeoModelTool
Definition: GeoModelTool.h:17
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TileDetectorTool::m_manager
TileDetDescrManager * m_manager
Definition: TileDetectorTool.h:45
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
GeoModelTool::ATLAS_NOT_THREAD_SAFE
virtual StatusCode registerCallback ATLAS_NOT_THREAD_SAFE() override
TileDetectorFactory
Definition: TileDetectorFactory.h:25
TileCablingService
Definition: TileCablingService.h:23
TileDetectorTool::createElements
StatusCode createElements()
Definition: TileDetectorTool.cxx:242
TileSwitches::csTube
int csTube
0: without Cesium tubes 1: with cesium tubes
Definition: TileSwitches.h:55
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
TileSwitches::addPlatesToCell
bool addPlatesToCell
calculate cell volumes with or without front-plates and end-plates
Definition: TileSwitches.h:34
GeoModelTool::m_detector
GeoVDetectorManager * m_detector
Definition: GeoModelTool.h:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TileDetectorTool::initIds
StatusCode initIds()
Definition: TileDetectorTool.cxx:216
TileDddbManager.h
GeoModelExperiment::addManager
void addManager(const GeoVDetectorManager *)
Definition: GeoModelExperiment.cxx:40
TileSwitches::crackOption
int crackOption
0: crack scintillators in ext.barrel top-level envelopes 1: crack scintillators in separate TileCal t...
Definition: TileSwitches.h:70
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TileSwitches::pvt
int pvt
0: all scintillators are polystyrene 1: crack scrintillators are PVT, others - polystyrene
Definition: TileSwitches.h:47
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
TileDetectorFactoryLite.h
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
TileDetectorTool::setSwitch
void setSwitch(int &param, int value, const char *name)
Definition: TileDetectorTool.cxx:67
TileDetDescrManager::releaseDbManager
void releaseDbManager()
Definition: TileDetDescrManager.cxx:100
checker_macros.h
Define macros for attributes used to control the static checker.
IGeoModelSvc::atlasVersion
virtual const std::string & atlasVersion() const =0
IGeoModelSvc.h
TileDddbManager
This class provides access to constants in the Geometry DB.
Definition: TileDddbManager.h:38
SG::DataProxy
Definition: DataProxy.h:44
TileDetectorTool::clear
virtual StatusCode clear() override final
Definition: TileDetectorTool.cxx:205
StoreGateSvc.h
IGeoModelSvc::tileVersionOverride
virtual const std::string & tileVersionOverride() const =0
TileDetectorTool::m_geometryConfig
std::string m_geometryConfig
Definition: TileDetectorTool.h:44
ServiceHandle< IGeoDbTagSvc >
DataProxy.h