diff --git a/template/NewTask/base/NewTask.cxx b/template/NewTask/base/NewTask.cxx index 2c2d4cb31..d581601c2 100644 --- a/template/NewTask/base/NewTask.cxx +++ b/template/NewTask/base/NewTask.cxx @@ -11,101 +11,86 @@ * or submit itself to any jurisdiction. * ******************************************************************************/ +// NOTE: comments below are only meant for eduational purpose. DO NOT include them in your code! + // ROOT headers -#include "TClonesArray.h" -#include "TMath.h" -#include "TRandom.h" +#include +#include +#include // Fair headers -#include "FairLogger.h" -#include "FairRootManager.h" -#include "FairRunAna.h" -#include "FairRuntimeDb.h" +#include +#include +#include +#include // R3B headers #include "NewTask.h" +#include +#include -// ---- Default constructor ------------------------------------------- -NewTask::NewTask() - : NewTask("NewTask", 1) -{ -} - -// ---- Standard Constructor ------------------------------------------ -NewTask::NewTask(const TString& name, Int_t iVerbose) - : FairTask(name, iVerbose) - , fOnline(kFALSE) -{ -} - -// ---- Destructor ---------------------------------------------------- -NewTask::~NewTask() -{ - LOG(debug) << "Destructor of NewTask"; - if (fDataInput) - delete fDataInput; -} - -// ---- Initialisation ---------------------------------------------- -void NewTask::SetParContainers() -{ - LOG(debug) << "SetParContainers of NewTask"; - // Load all necessary parameter containers from the runtime data base -} - -// ---- Init ---------------------------------------------------------- -InitStatus NewTask::Init() +namespace R3B { - LOG(info) << "NewTask::Init()"; + // ---- Standard Constructor ------------------------------------------ + NewTask::NewTask(const std::string& name, int iVerbose) + : FairTask(name.c_str(), iVerbose) + { + } - // Get a handle from the IO manager - FairRootManager* ioman = FairRootManager::Instance(); - if (!ioman) + // ---- Default constructor ------------------------------------------- + // use constructor delegation + NewTask::NewTask() + : NewTask("NewTask", 1) { - return kFATAL; } - // Get a pointer to the previous already existing data level - /* - fDataInput = (TClonesArray*) ioman->GetObject("InputDataLevelName"); - if ( ! fDataInput ) { - return kERROR; + // ---- Initialisation ---------------------------------------------- + void NewTask::SetParContainers() + { + R3BLOG(debug, "SetParContainers of NewTask"); + // Load all necessary parameter containers from the runtime data base } - */ - // Create the TClonesArray for the output data and register it - /* - fDataOutput = new TClonesArray("OutputDataLevelName", 10); - ioman->Register("OutputDataLevelName","OutputDataLevelName",fDataOutput,fOnline); - */ + // ---- Init ---------------------------------------------------------- + InitStatus NewTask::Init() + { + R3BLOG(debug, "NewTask::Init()"); - // Do whatever else is needed at the initilization stage - // Create histograms to be filled - // initialize variables + // Get a handle from the IO manager + if (auto* ioman = FairRootManager::Instance(); ioman == nullptr) + { + return kFATAL; + } - return kSUCCESS; -} + input_data_.init(); + output_data_.init(); -// ---- ReInit ------------------------------------------------------- -InitStatus NewTask::ReInit() -{ - LOG(debug) << "ReInit of NewTask"; - SetParContainers(); - return kSUCCESS; -} + // Do whatever else is needed at the initilization stage + // Create histograms to be filled + // initialize variables -// ---- Exec ---------------------------------------------------------- -void NewTask::Exec(Option_t* opt) { LOG(debug) << "Exec of NewTask"; } + return kSUCCESS; + } -// ---- Finish -------------------------------------------------------- -void NewTask::Finish() { LOG(debug) << "Finish of NewTask"; } + // ---- Exec ---------------------------------------------------------- + void NewTask::Exec(Option_t* /*opt*/) + { + R3BLOG(debug, "Exec of NewTask"); + output_data_.clear(); + + // Read input data + for (const auto& calData : input_data_) + { + // do something with calData + fmt::print("qdc value: {}", calData.GetQdc()); + + // to write data: + output_data_.get().emplace_back(); + } + } -// ---- Reset --------------------------------------------------------- -void NewTask::Reset() -{ - LOG(debug) << "Reset Data Structures"; - if (fDataOutput) - fDataOutput->Clear(); -} + // ---- Finish -------------------------------------------------------- + void NewTask::Finish() { R3BLOG(debug, "Finish of NewTask"); } +} // namespace R3B -ClassImp(NewTask); +ClassImp(R3B::NewTask); diff --git a/template/NewTask/base/NewTask.h b/template/NewTask/base/NewTask.h index 197887aab..a940983b8 100644 --- a/template/NewTask/base/NewTask.h +++ b/template/NewTask/base/NewTask.h @@ -11,60 +11,73 @@ * or submit itself to any jurisdiction. * ******************************************************************************/ -#ifndef NEWTASK_H -#define NEWTASK_H +#pragma once -#include "FairTask.h" -#include +// NOTE: comments below are only meant for eduational purpose. DO NOT include them in your code! -class TClonesArray; +#include +#include +#include +#include +#include -class NewTask : public FairTask +// namespace here is optional. +namespace R3B { - public: - // Default constructor - NewTask(); - - // Standard constructor - NewTask(const TString& name, Int_t iVerbose = 1); - - // Destructor - virtual ~NewTask(); - - // Initiliazation of task at the beginning of a run - virtual InitStatus Init() override; - - // ReInitiliazation of task when the runID changes - virtual InitStatus ReInit() override; - - // Executed for each event - virtual void Exec(Option_t* opt) override; - - // Load the parameter container from the runtime database - virtual void SetParContainers() override; - - // Finish task called at the end of the run - virtual void Finish() override; - - // Virtual method Reset - virtual void Reset(); - - // Method to setup online mode - void SetOnline(Bool_t opt) { fOnline = opt; } - - private: - // Store data for online - Bool_t fOnline; - - // Input array from previous already existing data level - TClonesArray* fDataInput; - - // Output array to new data level - TClonesArray* fDataOutput; - - public: - // Class definition - ClassDefOverride(NewTask, 1); -}; - -#endif /* NewTask_H */ + // If R3B namespace is not used, the task should be named with R3BNewTask + class NewTask : public FairTask + { + public: + // Default constructor + NewTask(); + + // Standard constructor + explicit NewTask(const std::string& name, int iVerbose = 1); + + // Other speical functions. Either define all these 5 functions or none of them (rule of 5). + // Defining none of them is preferred (rule of 0). + // ~NewTask() override; + // NewTask(const NewTask&) = delete; + // NewTask(NewTask&&) = delete; + // NewTask& operator=(const NewTask&) = delete; + // NewTask& operator=(NewTask&&) = delete; + + // Method to setup online mode + void SetOnline(bool is_online) { is_online_ = is_online; } + + private: + // NOTE: all member variables should be default initiliazed + + // Store data for online + // Naming convenction of a boolean variable should be started with is_ or has_ + bool is_online_ = false; + + // Input data from previous already existing data level + InputConnector> input_data_{ "NeulandCalData" }; + // or + // R3B::InputVectorConnector input_data_ { "NeulandCalData" }; + + // Output array to new data level + OutputConnector> output_data_{ "NeulandHit" }; + // or + // R3B::OutputVectorConnector output_data_{ "NeulandHit" }; + + // virtual functions should be private + + // Initiliazation of task at the beginning of a run + InitStatus Init() override; + + // Executed for each event + void Exec(Option_t* opt) override; + + // Load the parameter container from the runtime database + void SetParContainers() override; + + // Finish task called at the end of the run + void Finish() override; + + public: + // Class definition + ClassDefOverride(NewTask, 1); // NOLINT + }; +} // namespace R3B