ATLAS Offline Software
ToyDetectorTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef BUILDVP1LIGHT
6 #include "ToyDetectorTool.h"
7 #include "ToyDetectorFactory.h"
10 #include "GaudiKernel/IService.h"
11 #include "GaudiKernel/ISvcLocator.h"
12 #include "StoreGate/StoreGateSvc.h"
13 
14 #include "GeoModelKernel/GeoDefinitions.h"
15 #include "GeoModelKernel/GeoVolumeCursor.h"
16 #include <string>
17 
18 ToyDetectorTool::ToyDetectorTool( const std::string& type, const std::string& name, const IInterface* parent )
20 {
21 }
22 
24 {
25  delete m_detector;
26 }
27 
29 {
30  ATH_MSG_INFO("ToyDetectorTool::create() ...");
31 
32  // Locate the top level experiment
33  GeoModelExperiment* theExpt = nullptr;
34  ATH_CHECK(detStore()->retrieve(theExpt, "ATLAS"));
35 
36  ToyDetectorFactory theToyFactory(detStore().operator->());
37  if(m_detector==nullptr) {
38  // Build geometry
39  try {
40  //
41  // This strange way of casting is to avoid an
42  // utterly brain damaged compiler warning.
43  //
44  GeoPhysVol *world=theExpt->getPhysVol();
45  theToyFactory.create(world);
46  printVolume(world);
47  }
48  catch (const std::bad_alloc&) {
49  ATH_MSG_FATAL("Could not Toy Detector Geometry!");
50  return StatusCode::FAILURE;
51  }
52  // Add detector manager to AtlasExperiment and also record it into DetStore
53  theExpt->addManager(theToyFactory.getDetectorManager());
54  if (detStore()->record(theToyFactory.getDetectorManager(),theToyFactory.getDetectorManager()->getName()).isSuccess()) return StatusCode::SUCCESS;
55  ATH_MSG_FATAL("Failed to record Toy Detector Manager into Detector Store!");
56  }
57  else {
58  ATH_MSG_FATAL("Attempt to build Toy Detector Geometry one more time. The geometry can be built only once!");
59  }
60  return StatusCode::FAILURE;
61 }
62 
63 void ToyDetectorTool::printVolume(GeoPVConstLink volume, int level /*= 0*/)
64 {
65  GeoVolumeCursor cursor(volume);
66  while(!cursor.atEnd()) {
67  GeoPVConstLink physChild = cursor.getVolume();
68  GeoTrf::Transform3D position = cursor.getTransform();
69  for(int k{0};k<level;++k) std::cout << "... ";
70  std::cout << cursor.getName() << " " << (cursor.getId().isValid()?std::to_string(cursor.getId()).c_str():"N/A")
71  << " Transform:" << "\n";
72  for(int i{0};i<3;++i) {
73  for(int j{0};j<4;++j) {
74  std::cout << position(i,j) << " ";
75  }
76  std::cout << "\n";
77  }
78  printVolume(physChild, level+1);
79  cursor.next();
80  }
81 }
82 
83 #endif // BUILDVP1LIGHT
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ToyDetectorTool.h
GeoModelExperiment::getPhysVol
GeoPhysVol * getPhysVol()
Destructor.
Definition: GeoModelExperiment.cxx:21
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GeoModelExperiment
Definition: GeoModelExperiment.h:32
ToyDetectorTool::ToyDetectorTool
ToyDetectorTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ToyDetectorTool.cxx:18
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
GeoModelExperiment.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ToyDetectorTool::printVolume
void printVolume(GeoPVConstLink volime, int level=0)
Definition: ToyDetectorTool.cxx:63
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
test_pyathena.parent
parent
Definition: test_pyathena.py:15
GeoModelTool
Definition: GeoModelTool.h:17
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
ToyDetectorFactory.h
GeoModelTool::m_detector
GeoVDetectorManager * m_detector
Definition: GeoModelTool.h:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
ToyDetectorManager.h
ToyDetectorFactory
Definition: ToyDetectorFactory.h:10
GeoModelExperiment::addManager
void addManager(const GeoVDetectorManager *)
Definition: GeoModelExperiment.cxx:40
query_example.cursor
cursor
Definition: query_example.py:21
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ToyDetectorTool::~ToyDetectorTool
virtual ~ToyDetectorTool() override final
Definition: ToyDetectorTool.cxx:23
ToyDetectorTool::create
virtual StatusCode create() override final
Definition: ToyDetectorTool.cxx:28
StoreGateSvc.h
fitman.k
k
Definition: fitman.py:528