NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
LoopHepMC.h
Go to the documentation of this file.
1#ifndef NAGASH_LOOPHEPMC_HEADER
2#define NAGASH_LOOPHEPMC_HEADER
3
4#ifdef NAGASH_HEPMC
5// The following should be defined with HepMC3
6
7#include "NAGASH/ConfigTool.h"
8#include "NAGASH/MSGTool.h"
9#include "NAGASH/Job.h"
10#include "NAGASH/EventVector.h"
11
12#include "HepMC3/GenEvent.h"
13#include "HepMC3/Reader.h"
14#include "HepMC3/ReaderAscii.h"
15#include "HepMC3/ReaderAsciiHepMC2.h"
16#include "HepMC3/ReaderRoot.h"
17#include "HepMC3/ReaderRootTree.h"
18#include "HepMC3/ReaderLHEF.h"
19#include "HepMC3/ReaderHEPEVT.h"
20
21#include "TString.h"
22namespace NAGASH
23{
24 class LoopHepMC : public Job
25 {
26 public:
27 LoopHepMC(const ConfigTool &c, const TString &type);
28 virtual ~LoopHepMC();
29 virtual StatusCode InitializeData() = 0;
30 virtual StatusCode InitializeUser() = 0;
31 virtual StatusCode Execute() = 0;
32 virtual StatusCode Finalize() = 0;
33 StatusCode OpenHepMCFile(const TString &);
34 StatusCode Run();
35 void SetEventVector(std::shared_ptr<EventVector> ev);
36
37 template <typename LE>
38 static StatusCode Process(const ConfigTool &, const TString &, std::shared_ptr<ResultGroup>, std::shared_ptr<ResultGroup>, const TString &);
39
40 protected:
41 std::shared_ptr<HepMC3::Reader> ReaderUser();
42 int CurrentEntry();
43 const TString &InputFileName();
44 std::shared_ptr<EventVector> EventVectorUser();
45 HepMC3::GenEvent *EventUser();
46
47 private:
48 std::shared_ptr<HepMC3::Reader> fReader = nullptr;
49 int NEventsToLoop = 0;
50 std::shared_ptr<EventVector> eventvector;
51 TString inputfilename;
52 int entry = -1;
53 TString hepmctype;
54 HepMC3::GenEvent evt;
55 };
56
57 inline LoopHepMC::LoopHepMC(const ConfigTool &c, const TString &type) : Job(c) { hepmctype = type; }
58 inline std::shared_ptr<HepMC3::Reader> LoopHepMC::ReaderUser() { return fReader; }
59 inline int LoopHepMC::CurrentEntry() { return entry; }
60 inline void LoopHepMC::SetEventVector(std::shared_ptr<EventVector> ev) { eventvector = ev; }
61 inline std::shared_ptr<EventVector> LoopHepMC::EventVectorUser() { return eventvector; }
62 inline const TString &LoopHepMC::InputFileName() { return inputfilename; }
63 inline HepMC3::GenEvent *LoopHepMC::EventUser() { return &evt; }
64
65 template <typename LE>
66 StatusCode LoopHepMC::Process(const ConfigTool &config_child, const TString &filetype, std::shared_ptr<ResultGroup> result, std::shared_ptr<ResultGroup> wholeresult, const TString &inputfilename)
67 {
68 static_assert(!std::is_pointer<LE>::value, "LoopHepMC::Process : type can not be a pointer");
69 static_assert(std::is_base_of<LoopHepMC, LE>::value, "LoopHepMC::Process : Input type must be or be inherited from LoopHepMC class");
70
71 Job::DefaultMutex.lock();
72 auto childLE = std::make_shared<LE>(config_child, filetype);
73 if (childLE->OpenHepMCFile(inputfilename) == StatusCode::FAILURE)
74 {
75 childLE.reset();
76 Job::DefaultMutex.unlock();
77 return StatusCode::FAILURE;
78 }
79 auto msg_child = childLE->MSGUser();
80 TString threadsuffix;
81 if (childLE->JobNumber() >= 0)
82 threadsuffix.Form("(Job %d)", childLE->JobNumber());
83
84 msg_child->StartTitle("LE::InitializeData" + threadsuffix);
85 if (childLE->InitializeData() == StatusCode::FAILURE)
86 {
87 msg_child->EndTitle();
88 childLE.reset();
89 Job::DefaultMutex.unlock();
90 return StatusCode::FAILURE;
91 }
92 msg_child->EndTitle();
93
94 msg_child->StartTitle("LE::InitializeUser" + threadsuffix);
95 if (childLE->InitializeUser() == StatusCode::FAILURE)
96 {
97 msg_child->EndTitle();
98 childLE.reset();
99 Job::DefaultMutex.unlock();
100 return StatusCode::FAILURE;
101 }
102 msg_child->EndTitle();
103
104 Job::DefaultMutex.unlock();
105
106 msg_child->StartTitle("LE::Run" + threadsuffix);
107 if (childLE->Run() == StatusCode::FAILURE)
108 {
109 msg_child->EndTitle();
110 Job::DefaultMutex.lock();
111 childLE.reset();
112 Job::DefaultMutex.unlock();
113 return StatusCode::FAILURE;
114 }
115 msg_child->EndTitle();
116
117 Job::DefaultMutex.lock();
118 // Add Child Result to Mother
119 msg_child->StartTitle("LE::Finalize" + threadsuffix);
120 if (childLE->Finalize() == StatusCode::FAILURE)
121 {
122 msg_child->EndTitle();
123 childLE.reset();
124 Job::DefaultMutex.unlock();
125 return StatusCode::FAILURE;
126 }
127 msg_child->EndTitle();
128 wholeresult->Merge(childLE->ResultGroupUser());
129 childLE.reset();
130 Job::DefaultMutex.unlock();
131
132 return StatusCode::SUCCESS;
133 }
134
135} // namespace NAGASH
136
137#endif
138#endif
StatusCode
Definition Global.h:76