Belle II Software  release-06-02-00
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 include
10 #include <top/modules/TOPGeometryParInitializer/TOPGeometryParInitializerModule.h>
11 #include <top/geometry/TOPGeometryPar.h>
12 
13 // framework aux
14 #include <framework/logging/Logger.h>
15 #include <framework/gearbox/GearDir.h>
16 
17 
18 using namespace std;
19 
20 namespace Belle2 {
25  using namespace TOP;
26 
27  //-----------------------------------------------------------------
28  // Register module
29  //-----------------------------------------------------------------
30 
31  REG_MODULE(TOPGeometryParInitializer)
32 
33  //-----------------------------------------------------------------
34  // Implementation
35  //-----------------------------------------------------------------
36 
38 
39  {
40  // set module description
41  setDescription("Class for initializing TOPGeometryPar. "
42  "This class is by default initialized when Geant geometry is created. "
43  "Useful if Geant geometry is not needed. Be carefull when using!");
44  setPropertyFlags(c_ParallelProcessingCertified);
45 
46  // Add parameters
47  addParam("useDB", m_useDB,
48  "If true load the Geometry from the database instead of the gearbox", true);
49  }
50 
51  void TOPGeometryParInitializerModule::initialize()
52  {
53  auto* gp = TOPGeometryPar::Instance();
54  if (gp->isValid()) {
55  B2WARNING("TOPGeometryPar has already been initialized");
56  return;
57  }
58 
59  if (m_useDB) {
60  gp->Initialize();
61  } else {
62  bool found = false;
63  GearDir detectorDir("/Detector");
64  for (const GearDir& component : detectorDir.getNodes("DetectorComponent")) {
65  if (component.getString("@name") == "TOP") {
66  gp->Initialize(GearDir(component, "Content"));
67  found = true;
68  break;
69  }
70  }
71  if (not found) B2ERROR("Component TOP does not exist or is empty");
72  }
73 
74  }
75 
76 
78 } // end Belle2 namespace
79 
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
Base class for Modules.
Definition: Module.h:72
Class for initializing TOPGeometryPar.
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
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.