Skip to content

Commit 89a4f2c

Browse files
committed
Towards configuration of digitization geometry
- DigiParams keeps tracks of which geometryfile and which grpfile to use - DigitizerWorkflow can set these values at startup - improvement in digitizer workflow setup: easily find out if this is the master process
1 parent 278a4bb commit 89a4f2c

20 files changed

Lines changed: 101 additions & 37 deletions

File tree

Common/SimConfig/include/SimConfig/DigiParams.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ namespace o2
2121
{
2222
namespace conf
2323
{
24-
// Global parameters for digitization
2524

25+
// Global parameters for digitization
2626
struct DigiParams : public o2::conf::ConfigurableParamHelper<DigiParams> {
2727

2828
std::string ccdb = "http://ccdb-test.cern.ch:8080"; // URL for CCDB acces
29+
std::string digitizationgeometry = ""; // with with geometry file to digitize -> leave empty as this needs to be filled by the digitizer workflow
30+
std::string grpfile = ""; // which GRP file to use --> leave empty as this needs to be filled by the digitizer workflow
2931

3032
O2ParamDef(DigiParams, "DigiParams");
3133
};

Common/Utils/include/CommonUtils/StringUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef ALICEO2_STRINGUTILS_H
1717
#define ALICEO2_STRINGUTILS_H
1818

19+
#include <sstream>
20+
1921
namespace o2
2022
{
2123
namespace utils

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/NameConf.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
#define ALICEO2_NAME_GENERATOR_H_
1313

1414
#include "DetectorsCommonDataFormats/DetID.h"
15-
#include "CommonUtils/ConfigurableParam.h"
16-
#include "CommonUtils/ConfigurableParamHelper.h"
1715
#include "CommonUtils/StringUtils.h"
1816
#include <string_view>
1917

2018
/// \file NameConf.h
2119
/// \brief Definition of the Names Generator class
22-
2320
namespace o2
2421
{
2522
namespace base
2623
{
27-
// class for book-keeping of the names for output files and trees
2824

29-
class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
25+
// Class for standardization of the names for output files and trees
26+
class NameConf
3027
{
3128

3229
public:
@@ -54,14 +51,23 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
5451
return o2::utils::concat_string(prefix, "_", KINE_STRING, ".root");
5552
}
5653

54+
// Filename to store geometry file
55+
static std::string getGeomFileName(const std::string_view prefix = "");
56+
57+
// public standard TTree key (for MC ) -- not a function
58+
static constexpr std::string_view MCTTREENAME = "o2sim"; // hardcoded
59+
60+
// standard name for digitization configuration output
61+
static constexpr std::string_view DIGITIZATIONCONFIGFILE = "o2simdigitizerworkflow_configuration.ini";
62+
5763
private:
64+
// unmodifiable constants used to construct filenames etc
5865
static constexpr std::string_view STANDARDSIMPREFIX = "o2sim";
5966
static constexpr std::string_view HITS_STRING = "Hits"; // hardcoded
6067
static constexpr std::string_view DIGITS_STRING = "Digits"; // hardcoded
6168
static constexpr std::string_view GRP_STRING = "grp"; // hardcoded
6269
static constexpr std::string_view KINE_STRING = "Kine"; // hardcoded
63-
64-
O2ParamDef(NameConf, "NameConf");
70+
static constexpr std::string_view GEOM_STRING = "geometry";
6571
};
6672

6773
} // namespace base

DataFormats/Detectors/Common/src/DetectorsCommonDataFormatsLinkDef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@
2424
#pragma link C++ class o2::detectors::SimTraits + ;
2525

2626
#pragma link C++ class o2::base::NameConf + ;
27-
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::base::NameConf> + ;
2827

2928
#endif

DataFormats/Detectors/Common/src/NameConf.cxx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,24 @@
99
// or submit itself to any jurisdiction.
1010

1111
#include "DetectorsCommonDataFormats/NameConf.h"
12+
#include <sys/stat.h>
1213

13-
O2ParamImpl(o2::base::NameConf);
14+
bool pathExists(const std::string_view p)
15+
{
16+
struct stat buffer;
17+
return (stat(p.data(), &buffer) == 0);
18+
}
19+
20+
using namespace o2::base;
21+
22+
// Filename to store geometry file
23+
std::string NameConf::getGeomFileName(const std::string_view prefix)
24+
{
25+
// check if the prefix is an existing path
26+
const bool prefixispath = pathExists(prefix);
27+
if (prefixispath) {
28+
return o2::utils::concat_string(prefix, "/", STANDARDSIMPREFIX, "_", GEOM_STRING, ".root");
29+
} else {
30+
return o2::utils::concat_string(prefix.empty() ? STANDARDSIMPREFIX : prefix, "_", GEOM_STRING, ".root");
31+
}
32+
}

Detectors/Base/include/DetectorsBase/GeometryManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class GeometryManager : public TObject
4848
{
4949
public:
5050
///< load geometry from file
51-
static void loadGeometry(std::string geomFileName = "O2geometry.root", std::string geomName = "FAIRGeom");
51+
static void loadGeometry(std::string geomFileName = "", std::string geomName = "FAIRGeom");
5252

5353
///< Get the global transformation matrix (ideal geometry) for a given alignable volume
5454
///< The alignable volume is identified by 'symname' which has to be either a valid symbolic

Detectors/Base/src/GeometryManager.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "DetectorsBase/GeometryManager.h"
2727
#include "DetectorsCommonDataFormats/AlignParam.h"
28+
#include <DetectorsCommonDataFormats/NameConf.h>
2829

2930
using namespace o2::detectors;
3031
using namespace o2::base;
@@ -444,8 +445,9 @@ o2::base::MatBudget GeometryManager::meanMaterialBudget(float x0, float y0, floa
444445
void GeometryManager::loadGeometry(std::string geomFileName, std::string geomName)
445446
{
446447
///< load geometry from file
447-
LOG(INFO) << "Loading geometry " << geomName << " from " << geomFileName;
448-
TFile flGeom(geomFileName.data());
448+
auto fname = geomFileName.empty() ? o2::base::NameConf::getGeomFileName() : geomFileName;
449+
LOG(INFO) << "Loading geometry " << geomName << " from " << fname;
450+
TFile flGeom(fname.data());
449451
if (flGeom.IsZombie()) {
450452
LOG(FATAL) << "Failed to open file " << geomFileName;
451453
}

Detectors/Base/test/buildMatBudLUT.C

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "DetectorsBase/MatLayerCylSet.h"
1616
#include "DetectorsBase/MatLayerCyl.h"
1717
#include "DetectorsBase/GeometryManager.h"
18+
#include "DetectorsCommonDataFormats/NameConf.h"
1819
#include <TFile.h>
1920
#include <TSystem.h>
2021
#endif
@@ -27,7 +28,7 @@ bool testMBLUT(std::string lutName = "MatBud", std::string lutFile = "matbud.roo
2728

2829
bool buildMatBudLUT(int nTst = 30, int maxLr = -1,
2930
std::string outName = "MatBud", std::string outFile = "matbud.root",
30-
std::string geomName = "O2geometry.root");
31+
std::string geomName = "");
3132

3233
struct LrData {
3334
float rMin = 0.f;
@@ -42,13 +43,13 @@ struct LrData {
4243
std::vector<LrData> lrData;
4344
void configLayers();
4445

45-
bool buildMatBudLUT(int nTst, int maxLr, std::string outName, std::string outFile, std::string geomName)
46+
bool buildMatBudLUT(int nTst, int maxLr, std::string outName, std::string outFile, std::string geomNameInput)
4647
{
47-
48+
auto geomName = geomNameInput.empty() ? o2::base::NameConf::getGeomFileName() : geomNameInput;
4849
if (gSystem->AccessPathName(geomName.c_str())) { // if needed, create geometry
4950
std::cout << geomName << " does not exist. Will create it\n";
5051
gSystem->Exec("$O2_ROOT/bin/o2-sim -n 0");
51-
geomName = "./O2geometry.root";
52+
geomName = o2::base::NameConf::getGeomFileName();
5253
}
5354
o2::base::GeometryManager::loadGeometry(geomName);
5455
configLayers();

Steer/DigitizerWorkflow/src/ITSMFTDigitizerSpec.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "ITSMFTBase/DPLAlpideParam.h"
3030
#include "ITSBase/GeometryTGeo.h"
3131
#include "MFTBase/GeometryTGeo.h"
32+
#include "SimConfig/DigiParams.h"
3233
#include <TGeoManager.h>
3334
#include <TChain.h>
3435
#include <TStopwatch.h>
@@ -65,7 +66,7 @@ class ITSMFTDPLDigitizerTask
6566

6667
// make sure that the geometry is loaded (TODO will this be done centrally?)
6768
if (!gGeoManager) {
68-
o2::base::GeometryManager::loadGeometry();
69+
o2::base::GeometryManager::loadGeometry(o2::conf::DigiParams::Instance().digitizationgeometry);
6970
}
7071

7172
// configure digitizer

Steer/DigitizerWorkflow/src/SimpleDigitizerWorkflow.cxx

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,26 @@ bool helpOnCommandLine(ConfigContext const& configcontext)
317317
return helpasked;
318318
}
319319

320+
// Finding out if the current process is the master DPL driver process,
321+
// first setting up the topology. Might be important to know when we write
322+
// files (to prevent that multiple processes write the same file)
323+
bool isMasterWorkflowDefinition(ConfigContext const& configcontext)
324+
{
325+
int argc = configcontext.argc();
326+
auto argv = configcontext.argv();
327+
bool ismaster = true;
328+
for (int argi = 0; argi < argc; ++argi) {
329+
LOG(INFO) << argi << " " << argv[argi];
330+
// when channel-config is present it means that this is started as
331+
// as FairMQDevice which means it is already a forked process
332+
if (strcmp(argv[argi], "--channel-config")) {
333+
ismaster = false;
334+
break;
335+
}
336+
}
337+
return ismaster;
338+
}
339+
320340
// ------------------------------------------------------------------
321341

322342
/// This function is required to be implemented to define the workflow
@@ -326,21 +346,20 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
326346
// check if we merely construct the topology to create help options
327347
// if this is the case we don't need to read from GRP
328348
bool helpasked = helpOnCommandLine(configcontext);
349+
bool ismaster = isMasterWorkflowDefinition(configcontext);
329350

330351
// Reserve one entry which fill be filled with the SimReaderSpec
331352
// at the end. This places the processor at the beginning of the
332353
// workflow in the upper left corner of the GUI.
333354
WorkflowSpec specs(1);
334355

335-
o2::conf::ConfigurableParam::updateFromFile(configcontext.options().get<std::string>("configFile"));
356+
using namespace o2::conf;
357+
ConfigurableParam::updateFromFile(configcontext.options().get<std::string>("configFile"));
336358

337359
// Update the (declared) parameters if changed from the command line
338360
// Note: In the future this should be done only on a dedicated processor managing
339361
// the parameters and then propagated automatically to all devices
340-
o2::conf::ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"));
341-
342-
// write the configuration used for the digitizer workflow
343-
o2::conf::ConfigurableParam::writeINI("o2digitizerworkflow_configuration.ini");
362+
ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"));
344363

345364
// which sim productions to overlay and digitize
346365
auto simPrefixes = splitString(configcontext.options().get<std::string>("sims"), ',');
@@ -355,6 +374,17 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
355374
}
356375
}
357376

377+
// update the digitization configuration with the right geometry file
378+
// we take the geometry from the first simPrefix (could actually check if they are
379+
// all compatible)
380+
auto geomfilename = o2::conf::NameConf::getGeomFileName(simPrefixes[0]);
381+
ConfigurableParam::setValue("DigiParams.digitizationgeometry", geomfilename);
382+
383+
// write the configuration used for the digitizer workflow
384+
if (ismaster) {
385+
o2::conf::ConfigurableParam::writeINI(std::string(o2::base::NameConf::DIGITIZATIONCONFIGFILE));
386+
}
387+
358388
// onlyDet takes precedence on skipDet
359389
DetFilterer filterers[2] = {
360390
whitelister(configcontext.options().get<std::string>("onlyDet"), "none", ','),
@@ -393,7 +423,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
393423

394424
// the TPC part
395425
// we need to init this anyway since TPC is treated a bit special (for the moment)
396-
if (!helpasked) {
426+
if (!helpasked && ismaster) {
397427
initTPC();
398428
}
399429

0 commit comments

Comments
 (0)