Belle II Software  release-05-01-25
DBCreatorExample.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 /* This is just a short example header to show how to implement the geometry
12  * from the database. For simplicity this is just in one cc file, the division
13  * into suitable header and cc files is left as exercise for the reader.
14  *
15  * The old CreatorBase had only one public member called
16  * create(). Now we have three:
17  *
18  * 1. create() to create the Geometry from the Gearbox as before
19  * 2. createFromDB() to create the Geometry from the Database
20  * 3. createPayloads() to create Database configuration from Gearbox
21  *
22  * (1) will be deprecated in the future and (3) will probably be split into a
23  * separate class once (1) is gone. For now we require all three to be
24  * implemented.
25  *
26  * The following is just an example how all three interface members should be
27  * implemented using two private members: One to convert the Gearbox parameters
28  * to an Parameter object and one to Create the Geometry from this object. This
29  * has not been done more generic to a) allow for more then one parameter
30  * object to be created from the Gearbox parameters and b) don't bloat the code
31  * with endless templates. But all Creators should follow this scheme.
32  *
33  * If you don't I do have are a very particular set of skills, skills I have
34  * acquired over a very long career. Skills that make me a nightmare for people
35  * like you. I will look for you, I will find you and I will annoy you until
36  * you fix it.
37  */
38 
39 #include <geometry/CreatorBase.h>
40 #include <framework/logging/Logger.h>
41 #include <framework/database/DBObjPtr.h>
42 #include <framework/database/DBImportObjPtr.h>
43 #include <framework/database/IntervalOfValidity.h>
44 
45 namespace Belle2 {
52  class MyDBPayloadClass: public TObject {
54  ClassDef(MyDBPayloadClass, 1);
55  };
56 
59  class MyDBCreator: public geometry::CreatorBase {
60  private:
68  void createGeometry(const MyDBPayloadClass& parameters, G4LogicalVolume& topVolume, geometry::GeometryTypes type);
69  public:
73  virtual void create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes type) override
74  {
75  MyDBPayloadClass config = createConfiguration(content);
76  createGeometry(config, topVolume, type);
77  }
78 
81  virtual void createPayloads(const GearDir& content, const IntervalOfValidity& iov) override
82  {
84  importObj.construct(createConfiguration(content));
85  importObj.import(iov);
86  }
87 
89  virtual void createFromDB(const std::string& name, G4LogicalVolume& topVolume, geometry::GeometryTypes type) override
90  {
92  if (!dbObj) {
93  // Check that we found the object and if not report the problem
94  B2FATAL("No configuration for " << name << " found.");
95  }
96  createGeometry(*dbObj, topVolume, type);
97  }
98  };
100 }; //end of namespace Belle2
101 
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::MyDBCreator::create
virtual void create(const GearDir &content, G4LogicalVolume &topVolume, geometry::GeometryTypes type) override
The old create member: create the configuration object(s) on the fly and call the geometry creation r...
Definition: DBCreatorExample.cc:81
Belle2::MyDBPayloadClass
Class containing all the parameters needed to create the geometry and suitable to save into a ROOT fi...
Definition: DBCreatorExample.cc:60
Belle2::DBImportObjPtr::construct
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Definition: DBImportObjPtr.h:57
Belle2::DBImportBase::import
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:38
Belle2::MyDBCreator::createConfiguration
MyDBPayloadClass createConfiguration(const GearDir &param)
Create a parameter object from the Gearbox XML parameters.
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::MyDBPayloadClass::ClassDef
ClassDef(MyDBPayloadClass, 1)
Database objects need a dictionary.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MyDBCreator::createGeometry
void createGeometry(const MyDBPayloadClass &parameters, G4LogicalVolume &topVolume, geometry::GeometryTypes type)
Create the geometry from a parameter object.
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::DBImportObjPtr
Class for importing a single object to the database.
Definition: DBImportObjPtr.h:33
Belle2::MyDBCreator::createPayloads
virtual void createPayloads(const GearDir &content, const IntervalOfValidity &iov) override
Create the configuration objects and save them in the Database.
Definition: DBCreatorExample.cc:89
Belle2::MyDBCreator::createFromDB
virtual void createFromDB(const std::string &name, G4LogicalVolume &topVolume, geometry::GeometryTypes type) override
Create the geometry from the Database.
Definition: DBCreatorExample.cc:97
Belle2::geometry::GeometryTypes
GeometryTypes
Flag indiciating the type of geometry to be used.
Definition: GeometryManager.h:39