Belle II Software  release-05-02-19
TOPGeometryParInitializerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <top/modules/TOPGeometryParInitializer/TOPGeometryParInitializerModule.h>
13 #include <top/geometry/TOPGeometryPar.h>
14 
15 // framework aux
16 #include <framework/logging/Logger.h>
17 #include <framework/gearbox/GearDir.h>
18 
19 
20 using namespace std;
21 
22 namespace Belle2 {
27  using namespace TOP;
28 
29  //-----------------------------------------------------------------
30  // Register module
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!");
46  setPropertyFlags(c_ParallelProcessingCertified);
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 
53  void TOPGeometryParInitializerModule::initialize()
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 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::TOPGeometryParInitializerModule
Class for initializing TOPGeometryPar.
Definition: TOPGeometryParInitializerModule.h:47
Belle2::gearbox::Interface::getNodes
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:31