CbmRoot
Loading...
Searching...
No Matches
CbmAnaTreeSource.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023-2023 Warsaw University of Technology, Warsaw
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Daniel Wielanek [committer] */
4#include "CbmAnaTreeSource.h"
5
7#include "HalCbmDetectorID.h"
8
9#include <FairLogger.h>
10#include <FairRootManager.h>
11
12#include <TBranch.h>
13#include <TChain.h>
14#include <TFile.h>
15
16#include <AnalysisTree/Configuration.hpp>
17#include <fstream>
18#include <vector>
19
20#include <Hal/InputDataInfo.h>
21
22
24
25CbmAnaTreeSource::CbmAnaTreeSource(TString inFile, TString treeName)
26 : fNFiles(1)
27 , fTreeName(treeName)
28 , fChain(nullptr)
29 , fFileName(nullptr)
30 , fATSource(nullptr)
31{
32 fFileName = new TString[1];
33 fFileName[0] = inFile;
34}
35
40
42{
43 LOG(debug) << "Init source ";
44 FairRootManager* mngr = FairRootManager::Instance();
45 fChain = new TChain(fTreeName); //new name of tree?
46
47 Hal::InputDataInfo info;
48 if (fFileName[0].EndsWith(".root")) {
49 for (int i = 0; i < fNFiles; i++) {
50 LOG(debug) << "CbmAnaTree: opening single file" << fFileName[i];
51 fChain->Add(fFileName[i]);
52 info.AddFile(fFileName[i]);
53 }
54 }
55 else { // this is long list
56 std::ifstream list;
57 list.open(fFileName[0]);
58 bool first = true;
59 do {
60 TString temp;
61 list >> temp;
62 if (temp.Length() > 1) {
63 fChain->Add(temp);
64 info.AddFile(temp);
65 if (first) {
66 first = false;
67 }
68 }
69 else {
70 break;
71 }
72 LOG(debug) << "Adding file " << temp << " to chain";
73 } while (!list.eof());
74 list.close();
75 }
76
77
78 info.AddFile(mngr->GetInFile()->GetName());
80 LOG(debug) << "load container ";
81 fATSource->LoadConf(&info);
82
83 mngr->SetInChain(fChain, -1);
84
85 auto contNames = CbmAnaTreeContainers::GetNames();
86 for (int i = 0; i < fATSource->GetSize(); i++) {
87 bool con = fATSource->fContainers[i]->ConnectToTree(fChain);
88 if (con) {
89 TString name = HalCbm::GetContainerName(contNames[i]);
90 mngr->Register(name, "AT", fATSource->fContainers[i], kFALSE);
91 }
92 }
93 return kTRUE;
94}
95
97{
98 fChain->GetEntry(unsignedInt);
99 return 0;
100}
101
103
105{
106 TString* temp = fFileName;
107 fFileName = new TString[fNFiles + 1];
108 for (int i = 0; i < fNFiles; i++) {
109 fFileName[i] = temp[i];
110 }
111 delete[] temp;
112 fFileName[fNFiles] = file;
113 fNFiles = fNFiles + 1;
114}
115
116Int_t CbmAnaTreeSource::CheckMaxEventNo(Int_t /*int1*/) { return fChain->GetEntries(); }
bool first
int Int_t
bool Bool_t
static std::vector< TString > GetNames()
virtual void AddFile(TString file)
CbmAnaTreeContainers * fATSource
virtual Int_t CheckMaxEventNo(Int_t=0)
virtual Bool_t Init()
virtual Int_t ReadEvent(UInt_t=0)
TString GetContainerName(TString name)