NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
LoopEvent.h
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#pragma once
7
8#include "NAGASH/Global.h"
9#include "NAGASH/ConfigTool.h"
10#include "NAGASH/ResultGroup.h"
11#include "NAGASH/MSGTool.h"
12#include "NAGASH/Toolkit.h"
13#include "NAGASH/Timer.h"
14#include "NAGASH/EventVector.h"
15#include "NAGASH/Job.h"
16
17namespace NAGASH
18{
25 class LoopEvent : public Job
26 {
27 public:
30 LoopEvent(const ConfigTool &c) : Job(c) {}
31 virtual ~LoopEvent();
32
36
37 virtual StatusCode InitializeUser() = 0;
38 virtual StatusCode Execute() = 0;
39 virtual StatusCode Finalize() = 0;
40 StatusCode OpenRootFile(const TString &);
42 void SetEventVector(std::shared_ptr<EventVector> ev);
43
44 template <typename LE>
45 static StatusCode Process(const ConfigTool &, std::shared_ptr<ResultGroup>, std::shared_ptr<ResultGroup>, const TString &);
46
47 protected:
48 TTree *&RootTreeUser();
49 TFile *RootFileUser();
50 int CurrentEntry();
51 const TString &InputRootFileName();
52 std::shared_ptr<EventVector> EventVectorUser();
53
54 private:
55 TTree *fChain = nullptr;
57 TFile *infile = nullptr;
58 std::shared_ptr<EventVector> eventvector;
60 int entry = -1;
61 };
62
64 inline TTree *&LoopEvent::RootTreeUser() { return fChain; }
66 inline TFile *LoopEvent::RootFileUser() { return infile; }
68 inline int LoopEvent::CurrentEntry() { return entry; }
69 inline void LoopEvent::SetEventVector(std::shared_ptr<EventVector> ev) { eventvector = ev; }
70 inline std::shared_ptr<EventVector> LoopEvent::EventVectorUser() { return eventvector; }
72 inline const TString &LoopEvent::InputRootFileName() { return inputrootfilename; }
73
81 template <typename LE>
82 StatusCode LoopEvent::Process(const ConfigTool &config_child, std::shared_ptr<ResultGroup> result, std::shared_ptr<ResultGroup> wholeresult, const TString &inputfilename)
83 {
84 static_assert(!std::is_pointer<LE>::value, "LoopEvent::Process : type can not be a pointer");
85 static_assert(std::is_base_of<LoopEvent, LE>::value, "LoopEvent::Process : Input type must be or be inherited from LoopEvent class");
86
87 Job::DefaultMutex.lock();
88 auto childLE = std::make_shared<LE>(config_child);
89 if (childLE->OpenRootFile(inputfilename) == StatusCode::FAILURE)
90 {
91 childLE.reset();
92 Job::DefaultMutex.unlock();
94 }
95 auto msg_child = childLE->MSGUser();
96 TString threadsuffix;
97 if (childLE->JobNumber() >= 0)
98 threadsuffix.Form("(Job %d)", childLE->JobNumber());
99
100 msg_child->StartTitle("LE::InitializeData" + threadsuffix);
101 if (childLE->InitializeData() == StatusCode::FAILURE)
102 {
103 msg_child->EndTitle();
104 childLE.reset();
105 Job::DefaultMutex.unlock();
106 return StatusCode::FAILURE;
107 }
108 msg_child->EndTitle();
109
110 msg_child->StartTitle("LE::InitializeUser" + threadsuffix);
111 if (childLE->InitializeUser() == StatusCode::FAILURE)
112 {
113 msg_child->EndTitle();
114 childLE.reset();
115 Job::DefaultMutex.unlock();
116 return StatusCode::FAILURE;
117 }
118 msg_child->EndTitle();
119
120 Job::DefaultMutex.unlock();
121
122 msg_child->StartTitle("LE::Run" + threadsuffix);
123 if (childLE->Run() == StatusCode::FAILURE)
124 {
125 msg_child->EndTitle();
126 Job::DefaultMutex.lock();
127 childLE.reset();
128 Job::DefaultMutex.unlock();
129 return StatusCode::FAILURE;
130 }
131 msg_child->EndTitle();
132
133 Job::DefaultMutex.lock();
134 // Add Child Result to Mother
135 msg_child->StartTitle("LE::Finalize" + threadsuffix);
136 if (childLE->Finalize() == StatusCode::FAILURE)
137 {
138 msg_child->EndTitle();
139 childLE.reset();
140 Job::DefaultMutex.unlock();
141 return StatusCode::FAILURE;
142 }
143 msg_child->EndTitle();
144 wholeresult->Merge(childLE->ResultGroupUser());
145 childLE.reset();
146 Job::DefaultMutex.unlock();
147
148 return StatusCode::SUCCESS;
149 }
150
151} // namespace NAGASH
Some global definitions.
provide interface to config objects in NAGASH.
Definition ConfigTool.h:14
Virtual base class for all kinds of jobs inside NAGASH, handled by Analysis.
Definition Job.h:41
static std::recursive_mutex DefaultMutex
Default mutex, for multi-thread usage.
Definition Job.h:59
Virtual base class for event loops.
Definition LoopEvent.h:26
static StatusCode Process(const ConfigTool &, std::shared_ptr< ResultGroup >, std::shared_ptr< ResultGroup >, const TString &)
The function used by Analysis to process the event loop.
Definition LoopEvent.h:82
std::shared_ptr< EventVector > eventvector
Definition LoopEvent.h:58
virtual ~LoopEvent()
Definition LoopEvent.cxx:97
LoopEvent(const ConfigTool &c)
Constructor.
Definition LoopEvent.h:30
const TString & InputRootFileName()
Get the input root file name.
Definition LoopEvent.h:72
virtual StatusCode InitializeUser()=0
Initialize user-defined variables.
void SetEventVector(std::shared_ptr< EventVector > ev)
Definition LoopEvent.h:69
int CurrentEntry()
Get the current entry number in the Root TTree.
Definition LoopEvent.h:68
virtual StatusCode Finalize()=0
you can do something here after the loop for this file.
StatusCode Run()
Definition LoopEvent.cxx:38
StatusCode OpenRootFile(const TString &)
open the ROOT file with the given filename
Definition LoopEvent.cxx:12
TTree *& RootTreeUser()
Get the pointer to the used Root TTree.
Definition LoopEvent.h:64
TString inputrootfilename
Definition LoopEvent.h:59
virtual StatusCode InitializeData()=0
Initialize the input data. Most times, this function can be automatically generated using NAGASHMakeC...
std::shared_ptr< EventVector > EventVectorUser()
Definition LoopEvent.h:70
virtual StatusCode Execute()=0
Execute this function for each event.
TFile * RootFileUser()
Get the pointer to the used Root TFile.
Definition LoopEvent.h:66
StatusCode
Definition Global.h:76