[2] | 1 |
|
---|
| 2 | /** \class ExRootEventLoop
|
---|
| 3 | *
|
---|
| 4 | * Analysis steering class.
|
---|
| 5 | * Implements events loop and modules management.
|
---|
| 6 | *
|
---|
| 7 | * $Date: 2008-06-04 13:57:55 $
|
---|
| 8 | * $Revision: 1.1 $
|
---|
| 9 | *
|
---|
| 10 | *
|
---|
| 11 | * \author P. Demin - UCL, Louvain-la-Neuve
|
---|
| 12 | *
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | #include "ExRootAnalysis/ExRootEventLoop.h"
|
---|
| 16 | #include "ExRootAnalysis/ExRootFactory.h"
|
---|
| 17 |
|
---|
| 18 | #include "ExRootAnalysis/ExRootConfReader.h"
|
---|
| 19 | #include "ExRootAnalysis/ExRootTreeReader.h"
|
---|
| 20 | #include "ExRootAnalysis/ExRootTreeWriter.h"
|
---|
| 21 |
|
---|
| 22 | #include "ExRootAnalysis/ExRootUtilities.h"
|
---|
| 23 | #include "ExRootAnalysis/ExRootProgressBar.h"
|
---|
| 24 |
|
---|
| 25 | #include "TROOT.h"
|
---|
| 26 | #include "TClass.h"
|
---|
| 27 | #include "TSystem.h"
|
---|
| 28 | #include "TFolder.h"
|
---|
| 29 | #include "TObjArray.h"
|
---|
| 30 |
|
---|
| 31 | #include <iostream>
|
---|
| 32 |
|
---|
| 33 | #include <string.h>
|
---|
| 34 | #include <stdio.h>
|
---|
| 35 |
|
---|
| 36 | using namespace std;
|
---|
| 37 |
|
---|
| 38 | ExRootEventLoop::ExRootEventLoop() :
|
---|
| 39 | fAllEntries(0), fEventLoop(0)
|
---|
| 40 | {
|
---|
| 41 | fChains = new TObjArray;
|
---|
| 42 | fChains->SetOwner();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | //------------------------------------------------------------------------------
|
---|
| 46 |
|
---|
| 47 | ExRootEventLoop::~ExRootEventLoop()
|
---|
| 48 | {
|
---|
| 49 | delete fChains;
|
---|
| 50 | if(fEventLoop) delete fEventLoop;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | //------------------------------------------------------------------------------
|
---|
| 54 |
|
---|
| 55 | Long64_t ExRootEventLoop::GetEntries()
|
---|
| 56 | {
|
---|
| 57 | ExRootTreeReader *reader = GetTreeReader();
|
---|
| 58 | return reader ? reader->GetEntries() : 0;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | //------------------------------------------------------------------------------
|
---|
| 62 |
|
---|
| 63 | Bool_t ExRootEventLoop::ReadEvent(Long64_t entry)
|
---|
| 64 | {
|
---|
| 65 | ExRootTreeReader *reader = GetTreeReader();
|
---|
| 66 | return reader ? reader->ReadEntry(entry) : kFALSE;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | //------------------------------------------------------------------------------
|
---|
| 70 |
|
---|
| 71 | void ExRootEventLoop::Init()
|
---|
| 72 | {
|
---|
| 73 | fEventLoop = NewTask(ExRootTask::Class(), "EventLoop");
|
---|
| 74 |
|
---|
| 75 | ExRootTask *task;
|
---|
| 76 | const ExRootConfReader::ExRootTaskMap *modules = GetModules();
|
---|
| 77 | ExRootConfReader::ExRootTaskMap::const_iterator itModules;
|
---|
| 78 |
|
---|
| 79 | ExRootConfParam param = GetParam("TaskList");
|
---|
| 80 | Long_t i, size;
|
---|
| 81 | TString name;
|
---|
| 82 |
|
---|
| 83 | size = param.GetSize();
|
---|
| 84 |
|
---|
| 85 | for(i = 0; i < size; ++i)
|
---|
| 86 | {
|
---|
| 87 | name = param[i].GetString();
|
---|
| 88 | itModules = modules->find(name);
|
---|
| 89 | if(itModules != modules->end())
|
---|
| 90 | {
|
---|
| 91 | cout << itModules->second << " \t " << itModules->first << endl;
|
---|
| 92 | task = NewTask(itModules->second, itModules->first);
|
---|
| 93 | fEventLoop->Add(task);
|
---|
| 94 | }
|
---|
| 95 | else
|
---|
| 96 | {
|
---|
| 97 | cout << "** ERROR: module '" << name;
|
---|
| 98 | cout << "' is specified in TaskList but not configured.";
|
---|
| 99 | return;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | param = GetParam("InputCollection");
|
---|
| 105 | TChain *chain = 0, *firstChain = 0;
|
---|
| 106 | size = param.GetSize();
|
---|
| 107 | if(size > 0)
|
---|
| 108 | {
|
---|
| 109 | for(i = 0; i < size; ++i)
|
---|
| 110 | {
|
---|
| 111 | chain = new TChain("", "");
|
---|
| 112 | fChains->Add(chain);
|
---|
| 113 | name = param[i][0].GetString();
|
---|
| 114 | chain->SetName(name);
|
---|
| 115 | FillChain(chain, param[i][1].GetString());
|
---|
| 116 | if(i == 0)
|
---|
| 117 | {
|
---|
| 118 | firstChain = chain;
|
---|
| 119 | }
|
---|
| 120 | else
|
---|
| 121 | {
|
---|
| 122 | firstChain->AddFriend(chain, name + i);
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 | GetTreeReader()->SetTree(firstChain);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | cout << "** Calculating number of events to process. Please wait..." << endl;
|
---|
| 129 | fAllEntries = GetEntries();
|
---|
| 130 | cout << "** Chain contains " << fAllEntries << " events" << endl;
|
---|
| 131 |
|
---|
| 132 | if(fAllEntries <= 0)
|
---|
| 133 | {
|
---|
| 134 | cout << "** ERROR: cannot read any event for analysis" << endl;
|
---|
| 135 | return;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | fEventLoop->CleanTasks();
|
---|
| 139 | fEventLoop->InitSubTasks();
|
---|
| 140 |
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | //------------------------------------------------------------------------------
|
---|
| 144 |
|
---|
| 145 | void ExRootEventLoop::Process()
|
---|
| 146 | {
|
---|
| 147 | Long64_t entry;
|
---|
| 148 |
|
---|
| 149 | if(fAllEntries > 0)
|
---|
| 150 | {
|
---|
| 151 | ExRootProgressBar progressBar(fAllEntries);
|
---|
| 152 | // Loop over all events
|
---|
| 153 | for(entry = 0; entry < fAllEntries; ++entry)
|
---|
| 154 | {
|
---|
| 155 | if(!ReadEvent(entry))
|
---|
| 156 | {
|
---|
| 157 | cout << "** ERROR: cannot read event " << entry << endl;
|
---|
| 158 | break;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | Clear();
|
---|
| 162 |
|
---|
| 163 | fEventLoop->CleanTasks();
|
---|
| 164 | fEventLoop->ProcessSubTasks();
|
---|
| 165 |
|
---|
| 166 | if(fTreeWriter) fTreeWriter->Fill();
|
---|
| 167 |
|
---|
| 168 | progressBar.Update(entry);
|
---|
| 169 | }
|
---|
| 170 | progressBar.Finish();
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | //------------------------------------------------------------------------------
|
---|
| 176 |
|
---|
| 177 | void ExRootEventLoop::Finish()
|
---|
| 178 | {
|
---|
| 179 | fEventLoop->CleanTasks();
|
---|
| 180 | fEventLoop->FinishSubTasks();
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | //------------------------------------------------------------------------------
|
---|
| 184 |
|
---|
| 185 | void ExRootEventLoop::Clear()
|
---|
| 186 | {
|
---|
| 187 | if(fTreeWriter) fTreeWriter->Clear();
|
---|
| 188 | if(fFactory) fFactory->Clear();
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | //------------------------------------------------------------------------------
|
---|
| 192 |
|
---|