Skip to content

Commit 400a211

Browse files
committed
DPL Digitizers: Base class and improved service initialization
Introducing a first version of base class to take away boilerplate code for DPL digitizers. DPL digitizers simply tell what services they need and these will be provided automatically. No global initialization of field anymore, with a visible decrease of startup time.
1 parent 45e0928 commit 400a211

21 files changed

+191
-116
lines changed

Detectors/Base/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ o2_add_library(DetectorsBase
1717
src/MatLayerCylSet.cxx
1818
src/Ray.cxx
1919
src/DCAFitter.cxx
20+
src/BaseDPLDigitizer.cxx
2021
PUBLIC_LINK_LIBRARIES FairRoot::Base
2122
O2::CommonUtils
2223
O2::DetectorsCommonDataFormats
2324
O2::GPUCommon
2425
O2::ReconstructionDataFormats
2526
O2::Field
27+
O2::Framework
2628
FairMQ::FairMQ
2729
O2::DataFormatsParameters
2830
O2::SimConfig
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file BaseDPLDigitizer.h
12+
/// \brief Definition of the base digitizer task class
13+
14+
#ifndef ALICEO2_BASE_BASEDPLDIGITIZER_H_
15+
#define ALICEO2_BASE_BASEDPLDIGITIZER_H_
16+
17+
#include <Framework/InitContext.h>
18+
#include "DetectorsBase/Propagator.h"
19+
#include "DataFormatsParameters/GRPObject.h"
20+
#include <cstdint>
21+
22+
namespace o2
23+
{
24+
namespace base
25+
{
26+
27+
/// class listing possible services
28+
struct InitServices {
29+
using Type = std::uint32_t;
30+
static constexpr Type FIELD = 1 << 0;
31+
static constexpr Type GEOM = 1 << 1;
32+
};
33+
34+
/// Class trying to reduce boilerplate (initialization) work/code for
35+
/// digitizer tasks. In particular it will try to provide/initialize field and geometry
36+
/// when needed. Also providing some common data members.
37+
///
38+
/// Deriving classes need to implement a function initDigitizerTask instead of just init.
39+
class BaseDPLDigitizer
40+
{
41+
public:
42+
BaseDPLDigitizer() = default;
43+
virtual ~BaseDPLDigitizer() = default;
44+
45+
/// a constructor accepting a service code encoding the asked
46+
/// services in bits. Example:
47+
/// BaseDPLDigitizer(InitServices::FIELD | InitServices::GEOM)
48+
BaseDPLDigitizer(InitServices::Type servicecode);
49+
50+
virtual void init(o2::framework::InitContext&) final;
51+
52+
virtual void initDigitizerTask(o2::framework::InitContext& ic) = 0;
53+
54+
private:
55+
bool mNeedField = false;
56+
bool mNeedGeom = false;
57+
};
58+
59+
} // namespace base
60+
} // namespace o2
61+
62+
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include <DetectorsBase/BaseDPLDigitizer.h>
12+
#include <SimConfig/DigiParams.h>
13+
#include <DetectorsBase/GeometryManager.h>
14+
#include <DataFormatsParameters/GRPObject.h>
15+
#include <DetectorsBase/Propagator.h>
16+
#include <FairLogger.h>
17+
18+
using namespace o2::base;
19+
20+
BaseDPLDigitizer::BaseDPLDigitizer(InitServices::Type servicecode)
21+
{
22+
mNeedGeom = servicecode & InitServices::GEOM;
23+
mNeedField = servicecode & InitServices::FIELD;
24+
}
25+
26+
void BaseDPLDigitizer::init(o2::framework::InitContext& ic)
27+
{
28+
// init basic stuff when this was asked for
29+
if (mNeedGeom) {
30+
LOG(INFO) << "Initializing geometry service";
31+
o2::base::GeometryManager::loadGeometry(o2::conf::DigiParams::Instance().digitizationgeometry);
32+
}
33+
34+
if (mNeedField) {
35+
LOG(INFO) << "Initializing field service";
36+
// load from GRP
37+
auto inputGRP = o2::conf::DigiParams::Instance().grpfile;
38+
if (inputGRP.empty()) {
39+
LOG(ERROR) << "GRP filename not initialized in DigiParams";
40+
}
41+
auto grp = o2::parameters::GRPObject::loadFrom(inputGRP);
42+
if (!grp) {
43+
LOG(ERROR) << "This workflow needs a valid GRP file to start";
44+
}
45+
// init magnetic field
46+
o2::base::Propagator::initFieldFromGRP(grp);
47+
}
48+
49+
// finally call specific init
50+
this->initDigitizerTask(ic);
51+
}

Detectors/TRD/workflow/src/TRDDigitizerSpec.cxx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
#include "TRDBase/Digit.h" // for the Digit type
2626
#include "TRDSimulation/Digitizer.h"
2727
#include "TRDSimulation/Detector.h" // for the Hit type
28-
#include "DetectorsBase/GeometryManager.h"
28+
#include "DetectorsBase/BaseDPLDigitizer.h"
2929
#include "TRDBase/Calibrations.h"
3030
#include "DataFormatsTRD/TriggerRecord.h"
31-
#include "SimConfig/DigiParams.h"
3231

3332
using namespace o2::framework;
3433
using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
@@ -38,17 +37,15 @@ namespace o2
3837
namespace trd
3938
{
4039

41-
class TRDDPLDigitizerTask
40+
class TRDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
4241
{
4342
public:
44-
void init(framework::InitContext& ic)
43+
TRDDPLDigitizerTask() : o2::base::BaseDPLDigitizer(o2::base::InitServices::GEOM | o2::base::InitServices::FIELD) {}
44+
45+
void initDigitizerTask(framework::InitContext& ic) override
4546
{
4647
LOG(INFO) << "initializing TRD digitization";
47-
if (!gGeoManager) {
48-
o2::base::GeometryManager::loadGeometry(o2::conf::DigiParams::Instance().digitizationgeometry);
49-
}
5048
mDigitizer.init();
51-
LOG(INFO) << "initialized TRD digitization";
5249
}
5350

5451
void run(framework::ProcessingContext& pc)

Steer/DigitizerWorkflow/src/CPVDigitizerSpec.cxx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "DataFormatsParameters/GRPObject.h"
2626
#include "SimulationDataFormat/MCCompLabel.h"
2727
#include "SimulationDataFormat/MCTruthContainer.h"
28-
#include "DetectorsBase/GeometryManager.h"
28+
#include "DetectorsBase/BaseDPLDigitizer.h"
2929
#include "SimConfig/DigiParams.h"
3030

3131
using namespace o2::framework;
@@ -36,12 +36,8 @@ namespace o2
3636
namespace cpv
3737
{
3838

39-
void DigitizerSpec::init(framework::InitContext& ic)
39+
void DigitizerSpec::initDigitizerTask(framework::InitContext& ic)
4040
{
41-
// make sure that the geometry is loaded (TODO will this be done centrally?)
42-
if (!gGeoManager) {
43-
o2::base::GeometryManager::loadGeometry(o2::conf::DigiParams::Instance().digitizationgeometry);
44-
}
4541
// init digitizer
4642
mDigitizer.init();
4743

Steer/DigitizerWorkflow/src/CPVDigitizerSpec.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "CPVBase/Hit.h"
1818
#include "CPVSimulation/Digitizer.h"
1919
#include "SimulationDataFormat/MCTruthContainer.h"
20+
#include "DetectorsBase/BaseDPLDigitizer.h"
2021

2122
class TChain;
2223

@@ -29,18 +30,18 @@ namespace cpv
2930
/// \author Dmitri Peresunko, NRC "Kurchatov institute"
3031
/// \author Adopted from PHOS code
3132
/// \since Jan, 2020
32-
class DigitizerSpec : public framework::Task
33+
class DigitizerSpec : public o2::base::BaseDPLDigitizer
3334
{
3435
public:
3536
/// \brief Constructor
36-
DigitizerSpec() = default;
37+
DigitizerSpec() : o2::base::BaseDPLDigitizer(o2::base::InitServices::GEOM) {}
3738

3839
/// \brief Destructor
3940
~DigitizerSpec() final = default;
4041

4142
/// \brief init digitizer
4243
/// \param ctx Init context
43-
void init(framework::InitContext& ctx) final;
44+
void initDigitizerTask(framework::InitContext& ctx) final;
4445

4546
/// \brief run digitizer
4647
/// \param ctx Processing context
@@ -49,7 +50,7 @@ class DigitizerSpec : public framework::Task
4950
/// - Open readout window when the event sets a trigger
5051
/// - Accumulate digits sampled via the time response from different bunch crossings
5152
/// - Retrieve digits when the readout window closes
52-
void run(framework::ProcessingContext& ctx) final;
53+
void run(framework::ProcessingContext& ctx);
5354

5455
private:
5556
/// \brief helper function which will be offered as a service

Steer/DigitizerWorkflow/src/EMCALDigitizerSpec.cxx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include "CommonDataFormat/EvIndex.h"
2323
#include "DataFormatsParameters/GRPObject.h"
2424
#include "DataFormatsEMCAL/TriggerRecord.h"
25-
#include "DetectorsBase/GeometryManager.h"
26-
#include <SimConfig/DigiParams.h>
2725

2826
using namespace o2::framework;
2927
using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
@@ -33,11 +31,10 @@ namespace o2
3331
namespace emcal
3432
{
3533

36-
void DigitizerSpec::init(framework::InitContext& ctx)
34+
void DigitizerSpec::initDigitizerTask(framework::InitContext& ctx)
3735
{
38-
// make sure that the geometry is loaded (TODO will this be done centrally?)
3936
if (!gGeoManager) {
40-
o2::base::GeometryManager::loadGeometry(o2::conf::DigiParams::Instance().digitizationgeometry);
37+
LOG(ERROR) << "Geometry needs to be loaded before";
4138
}
4239
// run 3 geometry == run 2 geometry for EMCAL
4340
// to be adapted with run numbers at a later stage

Steer/DigitizerWorkflow/src/EMCALDigitizerSpec.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "EMCALBase/Hit.h"
2020
#include "EMCALSimulation/Digitizer.h"
2121
#include "SimulationDataFormat/MCTruthContainer.h"
22+
#include <DetectorsBase/BaseDPLDigitizer.h>
2223

2324
class TChain;
2425

@@ -34,18 +35,18 @@ namespace emcal
3435
/// \author Anders Garritt Knospe <anders.knospe@cern.ch>, University of Houston
3536
/// \author Markus Fasel <markus.fasel@cern.ch> Oak Ridge National laboratory
3637
/// \since Nov 12, 2018
37-
class DigitizerSpec : public framework::Task
38+
class DigitizerSpec : public o2::base::BaseDPLDigitizer
3839
{
3940
public:
4041
/// \brief Constructor
41-
DigitizerSpec() = default;
42+
DigitizerSpec() : o2::base::BaseDPLDigitizer(o2::base::InitServices::GEOM) {}
4243

4344
/// \brief Destructor
4445
~DigitizerSpec() final = default;
4546

4647
/// \brief init digitizer
4748
/// \param ctx Init context
48-
void init(framework::InitContext& ctx) final;
49+
void initDigitizerTask(framework::InitContext& ctx) final;
4950

5051
/// \brief run digitizer
5152
/// \param ctx Processing context
@@ -54,7 +55,7 @@ class DigitizerSpec : public framework::Task
5455
/// - Open readout window when the event sets a trigger
5556
/// - Accumulate digits sampled via the time response from different bunch crossings
5657
/// - Retrieve digits when the readout window closes
57-
void run(framework::ProcessingContext& ctx) final;
58+
void run(framework::ProcessingContext& ctx);
5859

5960
private:
6061
Bool_t mFinished = false; ///< Flag for digitization finished

Steer/DigitizerWorkflow/src/FDDDigitizerSpec.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "Framework/Lifetime.h"
1818
#include "Headers/DataHeader.h"
1919
#include "Steer/HitProcessingManager.h" // for DigitizationContext
20-
#include "DetectorsBase/GeometryManager.h"
20+
#include "DetectorsBase/BaseDPLDigitizer.h"
2121
#include "SimulationDataFormat/MCTruthContainer.h"
2222
#include "Framework/Task.h"
2323
#include "DataFormatsParameters/GRPObject.h"
@@ -37,12 +37,12 @@ namespace o2
3737
namespace fdd
3838
{
3939

40-
class FDDDPLDigitizerTask
40+
class FDDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
4141
{
4242
using GRP = o2::parameters::GRPObject;
4343

4444
public:
45-
void init(framework::InitContext& ic)
45+
void initDigitizerTask(framework::InitContext& ic) override
4646
{
4747
LOG(INFO) << "initializing FDD digitization";
4848

Steer/DigitizerWorkflow/src/FT0DigitizerSpec.cxx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#include "SimulationDataFormat/MCCompLabel.h"
2626
#include "SimulationDataFormat/MCTruthContainer.h"
2727
#include "Framework/Task.h"
28+
#include "DetectorsBase/BaseDPLDigitizer.h"
2829
#include "DataFormatsParameters/GRPObject.h"
2930
#include <TChain.h>
30-
#include <iostream>
3131
#include <TStopwatch.h>
3232

3333
using namespace o2::framework;
@@ -37,21 +37,19 @@ namespace o2
3737
{
3838
namespace ft0
3939
{
40-
// helper function which will be offered as a service
41-
//template <typename T>
4240

43-
class FT0DPLDigitizerTask
41+
class FT0DPLDigitizerTask : public o2::base::BaseDPLDigitizer
4442
{
4543

4644
using GRP = o2::parameters::GRPObject;
4745

4846
public:
49-
FT0DPLDigitizerTask() : mDigitizer(DigitizationParameters{}) {}
47+
FT0DPLDigitizerTask() : o2::base::BaseDPLDigitizer(), mDigitizer(DigitizationParameters{}) {}
5048
explicit FT0DPLDigitizerTask(o2::ft0::DigitizationParameters const& parameters)
51-
: mDigitizer(parameters){};
52-
~FT0DPLDigitizerTask() = default;
49+
: o2::base::BaseDPLDigitizer(), mDigitizer(parameters){};
50+
~FT0DPLDigitizerTask() override = default;
5351

54-
void init(framework::InitContext& ic)
52+
void initDigitizerTask(framework::InitContext& ic) override
5553
{
5654
mDigitizer.init();
5755
mROMode = mDigitizer.isContinuous() ? o2::parameters::GRPObject::CONTINUOUS : o2::parameters::GRPObject::PRESENT;

0 commit comments

Comments
 (0)