1#ifndef NAGASH_LOOPHEPMC_HEADER
2#define NAGASH_LOOPHEPMC_HEADER
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"
24 class LoopHepMC :
public Job
27 LoopHepMC(
const ConfigTool &c,
const TString &type);
35 void SetEventVector(std::shared_ptr<EventVector> ev);
37 template <
typename LE>
38 static StatusCode Process(
const ConfigTool &,
const TString &, std::shared_ptr<ResultGroup>, std::shared_ptr<ResultGroup>,
const TString &);
41 std::shared_ptr<HepMC3::Reader> ReaderUser();
43 const TString &InputFileName();
44 std::shared_ptr<EventVector> EventVectorUser();
45 HepMC3::GenEvent *EventUser();
48 std::shared_ptr<HepMC3::Reader> fReader =
nullptr;
49 int NEventsToLoop = 0;
50 std::shared_ptr<EventVector> eventvector;
51 TString inputfilename;
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; }
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)
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");
71 Job::DefaultMutex.lock();
72 auto childLE = std::make_shared<LE>(config_child, filetype);
73 if (childLE->OpenHepMCFile(inputfilename) == StatusCode::FAILURE)
76 Job::DefaultMutex.unlock();
77 return StatusCode::FAILURE;
79 auto msg_child = childLE->MSGUser();
81 if (childLE->JobNumber() >= 0)
82 threadsuffix.Form(
"(Job %d)", childLE->JobNumber());
84 msg_child->StartTitle(
"LE::InitializeData" + threadsuffix);
85 if (childLE->InitializeData() == StatusCode::FAILURE)
87 msg_child->EndTitle();
89 Job::DefaultMutex.unlock();
90 return StatusCode::FAILURE;
92 msg_child->EndTitle();
94 msg_child->StartTitle(
"LE::InitializeUser" + threadsuffix);
95 if (childLE->InitializeUser() == StatusCode::FAILURE)
97 msg_child->EndTitle();
99 Job::DefaultMutex.unlock();
100 return StatusCode::FAILURE;
102 msg_child->EndTitle();
104 Job::DefaultMutex.unlock();
106 msg_child->StartTitle(
"LE::Run" + threadsuffix);
107 if (childLE->Run() == StatusCode::FAILURE)
109 msg_child->EndTitle();
110 Job::DefaultMutex.lock();
112 Job::DefaultMutex.unlock();
113 return StatusCode::FAILURE;
115 msg_child->EndTitle();
117 Job::DefaultMutex.lock();
119 msg_child->StartTitle(
"LE::Finalize" + threadsuffix);
120 if (childLE->Finalize() == StatusCode::FAILURE)
122 msg_child->EndTitle();
124 Job::DefaultMutex.unlock();
125 return StatusCode::FAILURE;
127 msg_child->EndTitle();
128 wholeresult->Merge(childLE->ResultGroupUser());
130 Job::DefaultMutex.unlock();
132 return StatusCode::SUCCESS;