Skip to content

Commit 0c2f4d7

Browse files
committed
update NewTask template
1 parent 782356b commit 0c2f4d7

File tree

2 files changed

+128
-130
lines changed

2 files changed

+128
-130
lines changed

template/NewTask/base/NewTask.cxx

Lines changed: 62 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,101 +11,86 @@
1111
* or submit itself to any jurisdiction. *
1212
******************************************************************************/
1313

14+
// NOTE: comments below are only meant for eduational purpose. DO NOT include them in your code!
15+
1416
// ROOT headers
15-
#include "TClonesArray.h"
16-
#include "TMath.h"
17-
#include "TRandom.h"
17+
#include <TClonesArray.h>
18+
#include <TMath.h>
19+
#include <TRandom.h>
1820

1921
// Fair headers
20-
#include "FairLogger.h"
21-
#include "FairRootManager.h"
22-
#include "FairRunAna.h"
23-
#include "FairRuntimeDb.h"
22+
#include <FairLogger.h>
23+
#include <FairRootManager.h>
24+
#include <FairRunAna.h>
25+
#include <FairRuntimeDb.h>
2426

2527
// R3B headers
2628
#include "NewTask.h"
29+
#include <R3BLogger.h>
30+
#include <fmt/core.h>
2731

28-
// ---- Default constructor -------------------------------------------
29-
NewTask::NewTask()
30-
: NewTask("NewTask", 1)
31-
{
32-
}
33-
34-
// ---- Standard Constructor ------------------------------------------
35-
NewTask::NewTask(const TString& name, Int_t iVerbose)
36-
: FairTask(name, iVerbose)
37-
, fOnline(kFALSE)
38-
{
39-
}
40-
41-
// ---- Destructor ----------------------------------------------------
42-
NewTask::~NewTask()
43-
{
44-
LOG(debug) << "Destructor of NewTask";
45-
if (fDataInput)
46-
delete fDataInput;
47-
}
48-
49-
// ---- Initialisation ----------------------------------------------
50-
void NewTask::SetParContainers()
51-
{
52-
LOG(debug) << "SetParContainers of NewTask";
53-
// Load all necessary parameter containers from the runtime data base
54-
}
55-
56-
// ---- Init ----------------------------------------------------------
57-
InitStatus NewTask::Init()
32+
namespace R3B
5833
{
59-
LOG(info) << "NewTask::Init()";
34+
// ---- Standard Constructor ------------------------------------------
35+
NewTask::NewTask(const std::string& name, int iVerbose)
36+
: FairTask(name.c_str(), iVerbose)
37+
{
38+
}
6039

61-
// Get a handle from the IO manager
62-
FairRootManager* ioman = FairRootManager::Instance();
63-
if (!ioman)
40+
// ---- Default constructor -------------------------------------------
41+
// use constructor delegation
42+
NewTask::NewTask()
43+
: NewTask("NewTask", 1)
6444
{
65-
return kFATAL;
6645
}
6746

68-
// Get a pointer to the previous already existing data level
69-
/*
70-
fDataInput = (TClonesArray*) ioman->GetObject("InputDataLevelName");
71-
if ( ! fDataInput ) {
72-
return kERROR;
47+
// ---- Initialisation ----------------------------------------------
48+
void NewTask::SetParContainers()
49+
{
50+
R3BLOG(debug, "SetParContainers of NewTask");
51+
// Load all necessary parameter containers from the runtime data base
7352
}
74-
*/
7553

76-
// Create the TClonesArray for the output data and register it
77-
/*
78-
fDataOutput = new TClonesArray("OutputDataLevelName", 10);
79-
ioman->Register("OutputDataLevelName","OutputDataLevelName",fDataOutput,fOnline);
80-
*/
54+
// ---- Init ----------------------------------------------------------
55+
InitStatus NewTask::Init()
56+
{
57+
R3BLOG(debug, "NewTask::Init()");
8158

82-
// Do whatever else is needed at the initilization stage
83-
// Create histograms to be filled
84-
// initialize variables
59+
// Get a handle from the IO manager
60+
if (auto* ioman = FairRootManager::Instance(); ioman == nullptr)
61+
{
62+
return kFATAL;
63+
}
8564

86-
return kSUCCESS;
87-
}
65+
input_data_.init();
66+
output_data_.init();
8867

89-
// ---- ReInit -------------------------------------------------------
90-
InitStatus NewTask::ReInit()
91-
{
92-
LOG(debug) << "ReInit of NewTask";
93-
SetParContainers();
94-
return kSUCCESS;
95-
}
68+
// Do whatever else is needed at the initilization stage
69+
// Create histograms to be filled
70+
// initialize variables
9671

97-
// ---- Exec ----------------------------------------------------------
98-
void NewTask::Exec(Option_t* opt) { LOG(debug) << "Exec of NewTask"; }
72+
return kSUCCESS;
73+
}
9974

100-
// ---- Finish --------------------------------------------------------
101-
void NewTask::Finish() { LOG(debug) << "Finish of NewTask"; }
75+
// ---- Exec ----------------------------------------------------------
76+
void NewTask::Exec(Option_t* /*opt*/)
77+
{
78+
R3BLOG(debug, "Exec of NewTask");
79+
output_data_.clear();
80+
81+
// Read input data
82+
for (const auto& calData : input_data_)
83+
{
84+
// do something with calData
85+
fmt::print("qdc value: {}", calData.GetQdc());
86+
87+
// to write data:
88+
output_data_.get().emplace_back();
89+
}
90+
}
10291

103-
// ---- Reset ---------------------------------------------------------
104-
void NewTask::Reset()
105-
{
106-
LOG(debug) << "Reset Data Structures";
107-
if (fDataOutput)
108-
fDataOutput->Clear();
109-
}
92+
// ---- Finish --------------------------------------------------------
93+
void NewTask::Finish() { R3BLOG(debug, "Finish of NewTask"); }
94+
} // namespace R3B
11095

111-
ClassImp(NewTask);
96+
ClassImp(R3B::NewTask);

template/NewTask/base/NewTask.h

Lines changed: 66 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,73 @@
1111
* or submit itself to any jurisdiction. *
1212
******************************************************************************/
1313

14-
#ifndef NEWTASK_H
15-
#define NEWTASK_H
14+
#pragma once
1615

17-
#include "FairTask.h"
18-
#include <Rtypes.h>
16+
// NOTE: comments below are only meant for eduational purpose. DO NOT include them in your code!
1917

20-
class TClonesArray;
18+
#include <FairTask.h>
19+
#include <R3BIOConnector.h>
20+
#include <R3BNeulandCalData.h>
21+
#include <R3BNeulandHit.h>
22+
#include <string>
2123

22-
class NewTask : public FairTask
24+
// namespace here is optional.
25+
namespace R3B
2326
{
24-
public:
25-
// Default constructor
26-
NewTask();
27-
28-
// Standard constructor
29-
NewTask(const TString& name, Int_t iVerbose = 1);
30-
31-
// Destructor
32-
virtual ~NewTask();
33-
34-
// Initiliazation of task at the beginning of a run
35-
virtual InitStatus Init() override;
36-
37-
// ReInitiliazation of task when the runID changes
38-
virtual InitStatus ReInit() override;
39-
40-
// Executed for each event
41-
virtual void Exec(Option_t* opt) override;
42-
43-
// Load the parameter container from the runtime database
44-
virtual void SetParContainers() override;
45-
46-
// Finish task called at the end of the run
47-
virtual void Finish() override;
48-
49-
// Virtual method Reset
50-
virtual void Reset();
51-
52-
// Method to setup online mode
53-
void SetOnline(Bool_t opt) { fOnline = opt; }
54-
55-
private:
56-
// Store data for online
57-
Bool_t fOnline;
58-
59-
// Input array from previous already existing data level
60-
TClonesArray* fDataInput;
61-
62-
// Output array to new data level
63-
TClonesArray* fDataOutput;
64-
65-
public:
66-
// Class definition
67-
ClassDefOverride(NewTask, 1);
68-
};
69-
70-
#endif /* NewTask_H */
27+
// If R3B namespace is not used, the task should be named with R3BNewTask
28+
class NewTask : public FairTask
29+
{
30+
public:
31+
// Default constructor
32+
NewTask();
33+
34+
// Standard constructor
35+
explicit NewTask(const std::string& name, int iVerbose = 1);
36+
37+
// Other speical functions. Either define all these 5 functions or none of them (rule of 5).
38+
// Defining none of them is preferred (rule of 0).
39+
// ~NewTask() override;
40+
// NewTask(const NewTask&) = delete;
41+
// NewTask(NewTask&&) = delete;
42+
// NewTask& operator=(const NewTask&) = delete;
43+
// NewTask& operator=(NewTask&&) = delete;
44+
45+
// Method to setup online mode
46+
void SetOnline(bool is_online) { is_online_ = is_online; }
47+
48+
private:
49+
// NOTE: all member variables should be default initiliazed
50+
51+
// Store data for online
52+
// Naming convenction of a boolean variable should be started with is_ or has_
53+
bool is_online_ = false;
54+
55+
// Input data from previous already existing data level
56+
InputConnector<std::vector<R3BNeulandCalData>> input_data_{ "NeulandCalData" };
57+
// or
58+
// R3B::InputVectorConnector<R3BNeulandCalData> input_data_ { "NeulandCalData" };
59+
60+
// Output array to new data level
61+
OutputConnector<std::vector<R3BNeulandHit>> output_data_{ "NeulandHit" };
62+
// or
63+
// R3B::OutputVectorConnector<R3BNeulandHit> output_data_{ "NeulandHit" };
64+
65+
// virtual functions should be private
66+
67+
// Initiliazation of task at the beginning of a run
68+
InitStatus Init() override;
69+
70+
// Executed for each event
71+
void Exec(Option_t* opt) override;
72+
73+
// Load the parameter container from the runtime database
74+
void SetParContainers() override;
75+
76+
// Finish task called at the end of the run
77+
void Finish() override;
78+
79+
public:
80+
// Class definition
81+
ClassDefOverride(NewTask, 1); // NOLINT
82+
};
83+
} // namespace R3B

0 commit comments

Comments
 (0)