ATLAS Offline Software
Loading...
Searching...
No Matches
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"
10#include "GaudiKernel/IService.h"
11#include "GaudiKernel/ISvcLocator.h"
13
14#include "GeoModelKernel/GeoDefinitions.h"
15#include "GeoModelKernel/GeoVolumeCursor.h"
16#include <string>
17
18ToyDetectorTool::ToyDetectorTool( const std::string& type, const std::string& name, const IInterface* parent )
19 : GeoModelTool( type, name, parent )
20{
21}
22
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
63void 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()?std::to_string(cursor.getId().value()).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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
GeoPhysVol * getPhysVol()
Destructor.
void addManager(const GeoVDetectorManager *)
GeoVDetectorManager * m_detector
virtual const ToyDetectorManager * getDetectorManager() const
virtual void create(GeoPhysVol *world)
virtual StatusCode create() override final
virtual ~ToyDetectorTool() override final
ToyDetectorTool(const std::string &type, const std::string &name, const IInterface *parent)
void printVolume(GeoPVConstLink volime, int level=0)