er  dev
ERRootSourceOld.cxx
1 #include "ERRootSourceOld.h"
2 
3 #include "FairRootManager.h"
4 #include "FairRun.h"
5 
6 #include "ERHe8EventHeader.h"
7 
8 #include <iostream>
9 using namespace std;
10 
11 ERRootSourceOld::ERRootSourceOld():
12 fFile(NULL),
13 fTree(NULL),
14 fPath(""),
15 fTreeName(""),
16 fBranchName("")
17 {
18 }
19 
20 ERRootSourceOld::ERRootSourceOld(const ERRootSourceOld& source){
21 }
22 
23 ERRootSourceOld::~ERRootSourceOld(){
24 
25 }
26 
27 Bool_t ERRootSourceOld::Init(){
28  //input files opening
29  if (fPath == "")
30  Fatal("ERRootSourceOld", "No files for source ERRootSourceOld");
31  fFile = new TFile(fPath);
32  if (!fFile->IsOpen())
33  Fatal("ERRootSourceOld", "Can`t open file for source ERRootSourceOld");
34 
35  fTree = (TTree*)fFile->Get(fTreeName);
36  if (!fTree)
37  Fatal("ERRootSourceOld", "Can`t find tree in input file for source ERRootSourceOld");
38 
39  if (fRawEvents.size() == 0)
40  Fatal("ERRootSourceOld", "ERRootSourceOld without regiistered events");
41 
42  FairRun* run = FairRun::Instance();
43  ERHe8EventHeader* header = (ERHe8EventHeader*)run->GetEventHeader();
44  header->Register(fTree, fBranchName);
45 
46  for (Int_t iREvent = 0; iREvent < fRawEvents.size(); iREvent++)
47  fRawEvents[iREvent]->Register(fTree, fBranchName);
48  return kTRUE;
49 }
50 
51 Int_t ERRootSourceOld::ReadEvent(UInt_t id){
52  FairRootManager* ioman = FairRootManager::Instance();
53  if ( ! ioman ) Fatal("Init", "No FairRootManager");
54  //Проверяем есть ли еще события для обработки
55  if (fTree->GetEntriesFast() == ioman->GetEntryNr()+1)
56  return 1;
57  //cout << "ev" << ioman->GetEntryNr() << endl;
58  fTree->GetEntry(ioman->GetEntryNr());
59 
60  for (Int_t iREvent = 0; iREvent < fRawEvents.size(); iREvent++)
61  fRawEvents[iREvent]->Process();
62  return 0;
63 }
64 
65 void ERRootSourceOld::Close(){
66  if (fFile){
67  fFile->Close();
68  delete fFile;
69  }
70 }
71 
72 void ERRootSourceOld::Reset(){
73 }
74 
75 void ERRootSourceOld::SetFile(TString path, TString treeName, TString branchName){
76  fPath = path;
77  fTreeName = treeName;
78  fBranchName = branchName;
79  cout << "Input file " << path << " with tree name " << fTreeName <<" and branch name " <<
80  fBranchName << " added to source ERRootSourceOld" << endl;
81 }