NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
LoopHepMC.cxx
Go to the documentation of this file.
1#include "NAGASH/LoopHepMC.h"
2
3#ifdef NAGASH_HEPMC
4
5using namespace NAGASH;
6using namespace std;
7
8StatusCode LoopHepMC::OpenHepMCFile(const TString &filename)
9{
10 if (hepmctype.TString::EqualTo("Ascii") ||
11 hepmctype.TString::EqualTo("AsciiHepMC3"))
12 fReader = std::make_shared<HepMC3::ReaderAscii>(filename.TString::Data());
13 else if (hepmctype.TString::EqualTo("AsciiHepMC2"))
14 fReader = std::make_shared<HepMC3::ReaderAsciiHepMC2>(filename.TString::Data());
15 else if (hepmctype.TString::EqualTo("HEPEVT"))
16 fReader = std::make_shared<HepMC3::ReaderHEPEVT>(filename.TString::Data());
17 else if (hepmctype.TString::EqualTo("LHEF"))
18 fReader = std::make_shared<HepMC3::ReaderLHEF>(filename.TString::Data());
19 else if (hepmctype.TString::EqualTo("Root"))
20 fReader = std::make_shared<HepMC3::ReaderRoot>(filename.TString::Data());
21 else if (hepmctype.TString::EqualTo("RootTree"))
22 fReader = std::make_shared<HepMC3::ReaderRootTree>(filename.TString::Data());
23 else
24 {
25 MSGUser()->StartTitle("OpenHepMCFile");
26 MSGUser()->MSG(MSGLevel::ERROR, "HepMC Type should be Ascii(AsciiHepMC3), AsciiHepMC2, HEPEVT, LHEF, Root or RootTree ");
27 MSGUser()->EndTitle();
28 return StatusCode::FAILURE;
29 }
30 inputfilename = filename;
31
32 if (fReader == nullptr)
33 {
34 MSGUser()->StartTitle("OpenRootFile");
35 MSGUser()->MSG(MSGLevel::ERROR, "input HepMC3 file ", filename, " does not exist");
36 MSGUser()->EndTitle();
37 return StatusCode::FAILURE;
38 }
39 return StatusCode::SUCCESS;
40}
41
42StatusCode LoopHepMC::Run()
43{
44 Job::DefaultMutex.lock();
45 TimerUser()->Record("(Start Run)");
46 MSGUser()->MSG(MSGLevel::INFO, "Start Loop File ", InputFileName());
47
48 auto originlevel = MSGUser()->OutputLevel;
49 MSGUser()->OutputLevel = MSGLevel::SILENT;
50 int EvtSkip;
51 bool EvtSkipExist;
52 EvtSkip = ConfigUser()->GetPar<int>("EvtSkip", &EvtSkipExist);
53 if (!EvtSkipExist)
54 EvtSkip = 0;
55 MSGUser()->OutputLevel = originlevel;
56
57 if (EvtSkipExist && EvtSkip > 0)
58 MSGUser()->MSG(MSGLevel::INFO, "Will loop 1 event and then skip the next ", EvtSkip, " events");
59 Job::DefaultMutex.unlock();
60
61 entry = 0;
62 while (!fReader->failed())
63 {
64 fReader->read_event(evt);
65 TString num;
66 num.Form("(Execute Event %d)", entry);
67 auto titlegurad = MSGUser()->StartTitleWithGuard(num);
68 if (fReader->failed())
69 {
70 MSGUser()->MSG(MSGLevel::WARNING, "Entry ", entry, " is corrupted");
71 continue;
72 }
73 // should add StatusCode::RECOVERABLE branch
74 if (Execute() != StatusCode::SUCCESS)
75 {
76 MSGUser()->MSG(MSGLevel::ERROR, " Failed here, please check");
77 return StatusCode::FAILURE;
78 }
79 entry = entry + 1;
80 if (EvtSkipExist && EvtSkip > 0)
81 {
82 fReader->skip(EvtSkip);
83 entry = entry + EvtSkip;
84 }
85 }
86 TimerUser()->Record("(End Run)");
87
88 Job::DefaultMutex.lock();
89 TimerUser()->Duration("(Start Run)", "(End Run)");
90 fReader = nullptr;
91 Job::DefaultMutex.unlock();
92
93 return StatusCode::SUCCESS;
94}
95
96LoopHepMC::~LoopHepMC()
97{
98}
99
100#endif
StatusCode
Definition Global.h:76