Belle II Software development
TOPGeometryParInitializerModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <top/modules/TOPGeometryParInitializer/TOPGeometryParInitializerModule.h>
11
12// TOP headers.
13#include <top/geometry/TOPGeometryPar.h>
14
15// framework aux
16#include <framework/logging/Logger.h>
17#include <framework/gearbox/GearDir.h>
18
19
20using namespace std;
21
22namespace Belle2 {
27 using namespace TOP;
28
29 //-----------------------------------------------------------------
31 //-----------------------------------------------------------------
32
33 REG_MODULE(TOPGeometryParInitializer);
34
35 //-----------------------------------------------------------------
36 // Implementation
37 //-----------------------------------------------------------------
38
40
41 {
42 // set module description
43 setDescription("Class for initializing TOPGeometryPar. "
44 "This class is by default initialized when Geant geometry is created. "
45 "Useful if Geant geometry is not needed. Be carefull when using!");
47
48 // Add parameters
49 addParam("useDB", m_useDB,
50 "If true load the Geometry from the database instead of the gearbox", true);
51 }
52
54 {
55 auto* gp = TOPGeometryPar::Instance();
56 if (gp->isValid()) {
57 B2WARNING("TOPGeometryPar has already been initialized");
58 return;
59 }
60
61 if (m_useDB) {
62 gp->Initialize();
63 } else {
64 bool found = false;
65 GearDir detectorDir("/Detector");
66 for (const GearDir& component : detectorDir.getNodes("DetectorComponent")) {
67 if (component.getString("@name") == "TOP") {
68 gp->Initialize(GearDir(component, "Content"));
69 found = true;
70 break;
71 }
72 }
73 if (not found) B2ERROR("Component TOP does not exist or is empty");
74 }
75
76 }
77
78
80} // end Belle2 namespace
81
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
bool m_useDB
If true load the Geometry from the database instead of gearbox.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
std::vector< GearDir > getNodes(const std::string &path="") const
Get vector of GearDirs which point to all the nodes the given path evaluates to.
Definition: Interface.cc:21
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
virtual void initialize() override
Initialize the Module.
Abstract base class for different kinds of events.
STL namespace.