Skip to content

Commit

Permalink
update NewTask template
Browse files Browse the repository at this point in the history
  • Loading branch information
YanzhaoW authored and jose-luis-rs committed Oct 26, 2023
1 parent da86d62 commit d67a4f3
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 130 deletions.
139 changes: 62 additions & 77 deletions template/NewTask/base/NewTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <TClonesArray.h>
#include <TMath.h>
#include <TRandom.h>

// Fair headers
#include "FairLogger.h"
#include "FairRootManager.h"
#include "FairRunAna.h"
#include "FairRuntimeDb.h"
#include <FairLogger.h>
#include <FairRootManager.h>
#include <FairRunAna.h>
#include <FairRuntimeDb.h>

// R3B headers
#include "NewTask.h"
#include <R3BLogger.h>
#include <fmt/core.h>

// ---- 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);
119 changes: 66 additions & 53 deletions template/NewTask/base/NewTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,73 @@
* or submit itself to any jurisdiction. *
******************************************************************************/

#ifndef NEWTASK_H
#define NEWTASK_H
#pragma once

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

class TClonesArray;
#include <FairTask.h>
#include <R3BIOConnector.h>
#include <R3BNeulandCalData.h>
#include <R3BNeulandHit.h>
#include <string>

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<std::vector<R3BNeulandCalData>> input_data_{ "NeulandCalData" };
// or
// R3B::InputVectorConnector<R3BNeulandCalData> input_data_ { "NeulandCalData" };

// Output array to new data level
OutputConnector<std::vector<R3BNeulandHit>> output_data_{ "NeulandHit" };
// or
// R3B::OutputVectorConnector<R3BNeulandHit> 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

0 comments on commit d67a4f3

Please sign in to comment.