Belle II Software light-2406-ragdoll
DBCreatorExample.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/* This is just a short example header to show how to implement the geometry
10 * from the database. For simplicity this is just in one cc file, the division
11 * into suitable header and cc files is left as exercise for the reader.
12 *
13 * The old CreatorBase had only one public member called
14 * create(). Now we have three:
15 *
16 * 1. create() to create the Geometry from the Gearbox as before
17 * 2. createFromDB() to create the Geometry from the Database
18 * 3. createPayloads() to create Database configuration from Gearbox
19 *
20 * (1) will be deprecated in the future and (3) will probably be split into a
21 * separate class once (1) is gone. For now we require all three to be
22 * implemented.
23 *
24 * The following is just an example how all three interface members should be
25 * implemented using two private members: One to convert the Gearbox parameters
26 * to an Parameter object and one to Create the Geometry from this object. This
27 * has not been done more generic to a) allow for more then one parameter
28 * object to be created from the Gearbox parameters and b) don't bloat the code
29 * with endless templates. But all Creators should follow this scheme.
30 *
31 * If you don't I do have are a very particular set of skills, skills I have
32 * acquired over a very long career. Skills that make me a nightmare for people
33 * like you. I will look for you, I will find you and I will annoy you until
34 * you fix it.
35 */
36
37#include <geometry/CreatorBase.h>
38#include <framework/logging/Logger.h>
39#include <framework/database/DBObjPtr.h>
40#include <framework/database/DBImportObjPtr.h>
41#include <framework/database/IntervalOfValidity.h>
42
43namespace Belle2 {
50 class MyDBPayloadClass: public TObject {
53 };
54
58 private:
66 void createGeometry(const MyDBPayloadClass& parameters, G4LogicalVolume& topVolume, geometry::GeometryTypes type);
67 public:
71 virtual void create(const GearDir& content, G4LogicalVolume& topVolume, geometry::GeometryTypes type) override
72 {
73 MyDBPayloadClass config = createConfiguration(content);
74 createGeometry(config, topVolume, type);
75 }
76
79 virtual void createPayloads(const GearDir& content, const IntervalOfValidity& iov) override
80 {
82 importObj.construct(createConfiguration(content));
83 importObj.import(iov);
84 }
85
87 virtual void createFromDB(const std::string& name, G4LogicalVolume& topVolume, geometry::GeometryTypes type) override
88 {
90 if (!dbObj) {
91 // Check that we found the object and if not report the problem
92 B2FATAL("No configuration for " << name << " found.");
93 }
94 createGeometry(*dbObj, topVolume, type);
95 }
96 };
98}; //end of namespace Belle2
99
bool import(const IntervalOfValidity &iov)
Import the object to database.
Definition: DBImportBase.cc:36
Class for importing a single object to the database.
void construct(Args &&... params)
Construct an object of type T in this DBImportObjPtr using the provided constructor arguments.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:31
A class that describes the interval of experiments/runs for which an object in the database is valid.
Very simple Creator class which actually does not do anything but shows how creators should implement...
virtual void createPayloads(const GearDir &content, const IntervalOfValidity &iov) override
Create the configuration objects and save them in the Database.
void createGeometry(const MyDBPayloadClass &parameters, G4LogicalVolume &topVolume, geometry::GeometryTypes type)
Create the geometry from a parameter object.
MyDBPayloadClass createConfiguration(const GearDir &param)
Create a parameter object from the Gearbox XML parameters.
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...
virtual void createFromDB(const std::string &name, G4LogicalVolume &topVolume, geometry::GeometryTypes type) override
Create the geometry from the Database.
Class containing all the parameters needed to create the geometry and suitable to save into a ROOT fi...
ClassDef(MyDBPayloadClass, 1)
Database objects need a dictionary.
Pure virtual base class for all geometry creators.
Definition: CreatorBase.h:28
GeometryTypes
Flag indiciating the type of geometry to be used.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24