9 #include <geometry/modules/GeometryModule.h>
10 #include <geometry/GeometryManager.h>
11 #include <framework/gearbox/GearDir.h>
12 #include <framework/database/DBImportObjPtr.h>
25 GeometryModule::GeometryModule()
27 setDescription(
"Setup geometry description");
28 setPropertyFlags(c_ParallelProcessingCertified);
30 addParam(
"geometryPath", m_geometryPath,
31 "Path where the parameters for the Geometry can be found",
string(
"/Detector"));
32 addParam(
"geometryType", m_geometryType,
33 "Type of geometry to build. Valid values: Full, Tracking, Display", 0);
34 addParam(
"components", m_components,
35 "Name of the components to be created. If not empty, all other components found "
36 "in the parameter file will be ignored", m_components);
37 addParam(
"excludedComponents", m_excluded,
38 "Name of the components to excluded from creation", m_excluded);
39 addParam(
"additionalComponents", m_additional,
40 "Name of components to be created in addition to the default parameters", m_additional);
41 addParam(
"assignRegions", m_assignRegions,
42 "If true, automatically assign a Geant4 Region with the name of the "
43 "creator to all volumes created by that creator", m_assignRegions);
44 addParam(
"ignoreIfPresent", m_ignoreIfPresent,
45 "If true this module will silently ignore if the geometry is already "
46 "present and do nothing in that case. If false a B2FATAL will be "
47 "if the geometry was already created before", m_ignoreIfPresent);
48 addParam(
"useDB", m_useDB,
"If true load the Geometry from the database instead of the gearbox", m_useDB);
49 addParam(
"payloadIov", m_payloadIov,
"Payload IoV when creating a geometry configuration", m_payloadIov);
50 addParam(
"createPayloads", m_createGeometryPayload,
"If true create a "
51 "Geometry payload with the given configuration", m_createGeometryPayload);
54 void GeometryModule::initialize()
58 if (m_ignoreIfPresent) {
59 B2DEBUG(10,
"Geometry already created, skipping");
62 B2FATAL(
"Geometry already created, more than one Geometry module present?");
67 vector<string> filteredComponents;
68 copy_if(m_components.begin(), m_components.end(),
69 std::back_inserter(filteredComponents), [](
const std::string & component) { return component !=
"TRG"; });
76 if (m_createGeometryPayload) {
77 B2INFO(
"Creating Database configuration.");
78 if (m_payloadIov.size() != 4) {
79 B2ERROR(
"Geometry: payloadIov must be exactly 4 values: [first experiment, first run, final experiment, final run]");
83 IntervalOfValidity iov(m_payloadIov[0], m_payloadIov[1], m_payloadIov[2], m_payloadIov[3]);
85 B2ERROR(
"Cannot create payloads for an empty iov");
94 if (getParam<std::string>(
"geometryPath").isSetInSteering()) {
95 B2WARNING(
"Loading Geometry from Database: parameter 'geometryPath' is ignored");
97 for (
auto par : {
"components",
"additionalComponents",
"excludedComponents"}) {
98 if (getParam<std::vector<std::string>>(par).isSetInSteering()) {
99 B2WARNING(
"Loading Geometry from Database: parameter '" << par <<
"' is ignored");
103 if (!m_geometryConfig->isValid()) {
104 B2ERROR(
"Cannot create Geometry from Database: no configuration found");
108 m_geometryConfig->addCallback([]() {B2FATAL(
"Geometry cannot change during processing, aborting");});
112 if (!evtMeta.
isValid() or not(evtMeta->getExperiment() == 0 and evtMeta->getRun() == 0)) {
113 B2FATAL(R
"RAW(We no longer allow to disable the database when exp, run != 0, 0
115 If you want to create geometry configuration please create them from the
116 correct set of xml files and test them with exp,run == 0, 0 and then create
117 payloads for the correct iovs.
119 Otherwise just use the database configuration created by the experts.
121 This is for your own protection.)RAW");
124 B2WARNING(R
"RAW(You've decided to disable database for the Geometry.
126 Be aware, this is ONLY VALID for debugging purposes and validation of
129 Do NOT USE THIS just to disable some parts in the geometry.
131 -> This is in any case very dangerous and will result in unrealistic
132 results. If you really want this and really know what you are doing you
133 will have no problems to create and use a custom geometry configuration
134 using the parameter `createPayloads=True`.
136 DEFINITELY don't use this just because it works without internet connection.
138 -> Please just use `b2conditionsdb` to download a snapshot of the global
139 tag you want to use ahead of time. Your results will not be correct if
140 you disable building the geometry from the database configuration
142 YOU HAVE BEEN WARNED!)RAW");
147 void GeometryModule::terminate()
151 delete m_geometryConfig;
Class for importing a single object to the database.
Class for accessing objects in the database.
GearDir is the basic class used for accessing the parameter store.
A class that describes the interval of experiments/runs for which an object in the database is valid.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
Class to manage the creation and conversion of the geometry.
void setDetectorComponents(const std::vector< std::string > &components)
Set the names of the components to create.
void setAssignRegions(bool assignRegions)
Choose whether a region should be assigned to each creator.
void setExcludedComponents(const std::vector< std::string > &components)
Set the names of the components to exclude from creation.
GeoConfiguration createGeometryConfig(const GearDir &detectorDir, const IntervalOfValidity &iov)
Create Geometry configuration object.
void createGeometry(const GearDir ¶ms, GeometryTypes type=FullGeometry)
Create Geometry.
void clear()
Delete the existing Geant4 Geometry.
G4VPhysicalVolume * getTopVolume()
Return a pointer to the top volume.
void setAdditionalComponents(const std::vector< std::string > &components)
Set the names of addtional components to be added to the default set.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.