Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
OTFIOManager.cxx
1/*
2 * OTFIOManager.cxx
3 *
4 * Created on: 28 maj 2022
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "OTFIOManager.h"
10
11#include "Cout.h"
12#include "InputDataInfo.h"
13
14#include "OTFSource.h"
15
16#include <TBranch.h>
17#include <TFile.h>
18#include <TList.h>
19#include <TObjString.h>
20#include <TSystem.h>
21#include <TTree.h>
22
23#include <iostream>
24
25namespace HalOTF {
26
27 IOManager::IOManager(TString name, HalOTF::Source* source, Int_t entries) :
28 Hal::IOManager(new Hal::InputDataInfo(name)),
29 fInFileName(name),
30 fOutTreeName("HalTree"),
31 fEntries(entries),
32 fInFile(nullptr),
33 fOutFile(nullptr),
34 fOutTree(nullptr),
35 fSource(source) {}
36
37 Bool_t IOManager::InitInternal() {
38 Hal::Cout::PrintInfo(fInFileName, Hal::EInfo::kLowWarning);
39 fInFile = new TFile(fInFileName, "recreate");
40 fOutFile = new TFile(fOutFileName, "recreate");
41 fOutTree = new TTree(fOutTreeName, fOutTreeName);
42 Hal::Cout::PrintInfo(Form("CREATING TREE %s", fOutTreeName.Data()), Hal::EInfo::kError);
43 fSource->RegisterOutputs(this);
44 return kTRUE;
45 }
46
47 Int_t IOManager::GetEntries() const { return fEntries; }
48
49 IOManager::~IOManager() {
50 if (fInFile) delete fInFile;
51 if (fOutFile) delete fOutFile;
52 gSystem->Exec(Form("rm %s", fInFileName.Data()));
53 }
54
55 TFile* IOManager::GetInFile() { return fInFile; }
56
57 void IOManager::RegisterInternal(const char* name, const char* /*folderName*/, TNamed* obj, Bool_t toFile) {
58 if (toFile) { fOutTree->Branch(name, obj); }
59 }
60
61 void IOManager::RegisterInternal(const char* name, const char* /*Foldername*/, TCollection* obj, Bool_t toFile) {
62 if (toFile) { fOutTree->Branch(name, obj); }
63 }
64
65 void IOManager::SetInChain(TChain* /*tempChain*/, Int_t /*ident*/) {}
66
67 Int_t IOManager::GetEntry(Int_t i, Int_t /*flag*/) {
68 if (i < fEntries) {
69 if (fSource) fSource->GetEvent();
70 return 1;
71 }
72 return -1;
73 }
74
75 void IOManager::FillTree() { fOutTree->Fill(); }
76
77 void IOManager::CloseManager() {
78 fOutTree->Write();
79 fOutFile->Close();
80 }
81
82} // namespace HalOTF
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370