NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
LoopEvent.cxx
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#include "NAGASH/LoopEvent.h"
7
8using namespace NAGASH;
9using namespace std;
10
12StatusCode LoopEvent::OpenRootFile(const TString &filename)
13{
14 infile = new TFile(filename, "READ");
15 inputrootfilename = filename;
16
17 if (infile == nullptr)
18 {
19 MSGUser()->StartTitle("OpenRootFile");
20 MSGUser()->MSG(MSGLevel::ERROR, "input ROOT file ", filename, " does not exist");
21 MSGUser()->EndTitle();
23 }
24
25 if (infile->IsZombie())
26 {
27 MSGUser()->StartTitle("OpenRootFile");
28 MSGUser()->MSG(MSGLevel::ERROR, "input ROOT file ", filename, " is corrupted");
29 MSGUser()->EndTitle();
30 delete infile;
31 infile = nullptr;
33 }
34
36}
37
39{
40 Job::DefaultMutex.lock();
41 TimerUser()->Record("(Start Run)");
42 MSGUser()->MSG(MSGLevel::INFO, "Start Loop File ", InputRootFileName());
43 long Nentries = RootTreeUser()->GetEntries();
44
45 auto originlevel = MSGUser()->OutputLevel;
46 MSGUser()->OutputLevel = MSGLevel::SILENT;
47 long EvtMax, EvtMin;
48 bool EvtMaxExist = true, EvtMinExist = true;
49 EvtMax = ConfigUser()->GetPar<long>("EvtMax", &EvtMaxExist);
50 EvtMin = ConfigUser()->GetPar<long>("EvtMin", &EvtMinExist);
51 if (!EvtMaxExist)
52 EvtMax = Nentries - 1;
53 if (!EvtMinExist)
54 EvtMin = 0;
55 MSGUser()->OutputLevel = originlevel;
56
57 if (EvtMin > EvtMax)
58 std::swap(EvtMin, EvtMax);
59
60 EvtMax = std::min(EvtMax, Nentries - 1);
61 EvtMin = std::max(0L, EvtMin);
62 MSGUser()->MSG(MSGLevel::INFO, "Will loop from ", EvtMin, " to ", EvtMax, " entry in the file (", Nentries, " entries in total)");
63 Job::DefaultMutex.unlock();
64
65 for (int ie = EvtMin; ie <= EvtMax; ie++)
66 {
67 entry = ie;
68 TString num;
69 num.Form("(Execute Event %d)", ie);
70 auto titlegurad = MSGUser()->StartTitleWithGuard(num);
71 if (RootTreeUser()->GetEntry(ie) <= 0)
72 {
73 MSGUser()->MSG(MSGLevel::WARNING, "Entry ", ie, " is corrupted");
74 continue;
75 }
76 // should add StatusCode::RECOVERABLE branch
78 {
79 MSGUser()->MSG(MSGLevel::ERROR, " Failed here, please check");
81 }
82 }
83 TimerUser()->Record("(End Run)");
84
85 Job::DefaultMutex.lock();
86 TimerUser()->Duration("(Start Run)", "(End Run)");
87 // fChain->PrintCacheStats();
88 delete fChain;
89 delete infile;
90 fChain = nullptr;
91 infile = nullptr;
92 Job::DefaultMutex.unlock();
93
95}
96
98{
99 if (fChain != nullptr)
100 {
101 delete fChain;
102 }
103
104 if (infile != nullptr)
105 {
106 delete infile;
107 }
108}
std::shared_ptr< ConfigTool > ConfigUser()
get the ConfigTool.
Definition Job.h:87
std::shared_ptr< MSGTool > MSGUser()
get the MSGTool.
Definition Job.h:89
static std::recursive_mutex DefaultMutex
Default mutex, for multi-thread usage.
Definition Job.h:59
std::shared_ptr< Timer > TimerUser()
get the Timer.
Definition Job.h:90
virtual ~LoopEvent()
Definition LoopEvent.cxx:97
const TString & InputRootFileName()
Get the input root file name.
Definition LoopEvent.h:72
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 Execute()=0
Execute this function for each event.
StatusCode
Definition Global.h:76