Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
DataFormatManager.cxx
1/*
2 * DataFormatManager.cxx
3 *
4 * Created on: 23-06-2014
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "DataFormatManager.h"
11
12#include "Cout.h"
13#include "DataManager.h"
14#include "Event.h"
15
16#include <TList.h>
17#include <TObjArray.h>
18#include <TObjString.h>
19#include <TString.h>
20
21#include <vector>
22
23namespace Hal {
24 DataFormatManager* DataFormatManager::fgInstance = NULL;
25
26 DataFormatManager::DataFormatManager() : fRegisteredFormats(0), fDataFormatBuffered(nullptr), fDataFormatNonBuffered(nullptr) {
27 if (fgInstance) {
28 Cout::PrintInfo("Singleton of DataFormatManager already exist, don't use constructor of DataFormatManager",
29 EInfo::kLowWarning);
30 return;
31 } else {
32 fgInstance = this;
33 }
34 }
35
36 Event* DataFormatManager::GetNewEvent(Int_t task_id, EFormatDepth format_depth) const {
37 if (format_depth == EFormatDepth::kBuffered) {
38 return fDataFormatBuffered[task_id]->GetNewEvent();
39 } else {
40 return fDataFormatNonBuffered[task_id]->GetNewEvent();
41 }
42 }
43
44 Track* DataFormatManager::GetNewTrack(Int_t task_id, EFormatDepth format_depth) const {
45 if (format_depth == EFormatDepth::kBuffered) { return fDataFormatBuffered[task_id]->GetNewTrack(); }
46 return fDataFormatNonBuffered[task_id]->GetNewTrack();
47 }
48
49 void DataFormatManager::SetFormat(Event* format, Int_t task_id, EFormatDepth depth, Bool_t silent) {
50 if (silent) {
51 if (depth == EFormatDepth::kBuffered) {
52 fDataFormatBuffered[task_id] = format;
53 } else if (depth == EFormatDepth::kAll) {
54 fDataFormatBuffered[task_id] = format;
55 fDataFormatNonBuffered[task_id] = format;
56 } else {
57 fDataFormatNonBuffered[task_id] = format;
58 }
59 return;
60 }
61 if (task_id > fRegisteredFormats) { Cout::PrintInfo("Task id too big", EInfo::kCriticalError); }
62 switch (depth) {
63 case EFormatDepth::kBuffered: {
64 if (fDataFormatBuffered[task_id] != NULL) { Cout::PrintInfo("Overwriting format", EInfo::kLowWarning); }
65 fDataFormatBuffered[task_id] = format;
66 } break;
67 case EFormatDepth::kNonBuffered: {
68 if (fDataFormatNonBuffered[task_id] != NULL) { Cout::PrintInfo("Overwriting format", EInfo::kLowWarning); }
69 fDataFormatNonBuffered[task_id] = format;
70 } break;
71 case EFormatDepth::kAll: {
72 if (fDataFormatBuffered[task_id] != NULL) { Cout::PrintInfo("Overwriting format", EInfo::kLowWarning); }
73 if (fDataFormatNonBuffered[task_id] != NULL) { Cout::PrintInfo("Overwriting format", EInfo::kLowWarning); }
74 fDataFormatBuffered[task_id] = format;
75 fDataFormatNonBuffered[task_id] = format;
76 } break;
77 }
78 }
79
81 if (fgInstance == NULL) { fgInstance = new DataFormatManager(); }
82 return fgInstance;
83 }
84
85 TString DataFormatManager::GetFormatName(Int_t task_id, EFormatDepth format_depth) const {
86 if (format_depth == EFormatDepth::kBuffered) { return fDataFormatBuffered[task_id]->GetFormatName(); }
87 return fDataFormatNonBuffered[task_id]->GetFormatName();
88 }
89
91 DataManager* datamanager = DataManager::Instance();
92 Event* event = nullptr;
93 event = dynamic_cast<Hal::Event*>(datamanager->GetObject("HalEvent."));
94 if (event != nullptr) return event;
95 auto branchList = datamanager->GetBranchNameList();
96 for (auto branch : branchList) {
97 TObject* temp = datamanager->GetObject(branch);
98 if (dynamic_cast<Hal::Event*>(temp)) { event = (Hal::Event*) temp; }
99 }
100 return event;
101 }
102
104 for (int i = 0; i < fRegisteredFormats; i++) {
105 if (fDataFormatNonBuffered[i]) delete fDataFormatBuffered[i];
106 }
107 if (fDataFormatBuffered) delete[] fDataFormatBuffered;
108 if (fDataFormatNonBuffered) delete[] fDataFormatNonBuffered;
109 fRegisteredFormats = 0;
110 }
111
112 DataFormatManager::~DataFormatManager() {
113 for (int i = 0; i < fRegisteredFormats; i++) {
114 if (fDataFormatNonBuffered[i]) delete fDataFormatBuffered[i];
115 }
116 if (fDataFormatBuffered) delete[] fDataFormatBuffered;
117 if (fDataFormatNonBuffered) delete[] fDataFormatNonBuffered;
118 }
119
120 Bool_t DataFormatManager::FormatExist(Int_t task_id, EFormatDepth format_depth) const {
121 if (task_id == -1) {
122 return kFALSE;
123 } else {
124 if (format_depth == EFormatDepth::kBuffered) {
125 if (fDataFormatBuffered[task_id] == nullptr) return kFALSE;
126 } else {
127 if (fDataFormatNonBuffered[task_id] == nullptr) return kFALSE;
128 }
129 }
130 return kTRUE;
131 }
132
134 Event** temp1 = fDataFormatBuffered;
135 Event** temp2 = fDataFormatNonBuffered;
136 fDataFormatBuffered = new Event*[fRegisteredFormats + 1];
137 fDataFormatNonBuffered = new Event*[fRegisteredFormats + 1];
138 for (int i = 0; i < fRegisteredFormats; i++) {
139 fDataFormatBuffered[i] = temp1[i];
140 fDataFormatNonBuffered[i] = temp2[i];
141 }
142 fDataFormatBuffered[fRegisteredFormats] = NULL;
143 fDataFormatNonBuffered[fRegisteredFormats] = NULL;
144 delete[] temp1;
145 delete[] temp2;
146 return fRegisteredFormats++;
147 }
148
149 const Event* DataFormatManager::GetFormat(Int_t task_id, EFormatDepth format_depth) const {
150 if (task_id < fRegisteredFormats) {
151 if (format_depth == EFormatDepth::kBuffered) {
152 if (fDataFormatBuffered[task_id] != nullptr) return fDataFormatBuffered[task_id];
153 } else if (fDataFormatNonBuffered[task_id] != nullptr)
154 return fDataFormatNonBuffered[task_id];
155 }
156 return nullptr;
157 }
158} // namespace Hal
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
const Event * GetFormat(Int_t task_id, EFormatDepth format_depth=EFormatDepth::kAll) const
Track * GetNewTrack(Int_t task_id, EFormatDepth format_depth=EFormatDepth::kAll) const
void SetFormat(Event *format, Int_t task_id, EFormatDepth depth=EFormatDepth::kAll, Bool_t silent=kFALSE)
TString GetFormatName(Int_t task_id, EFormatDepth format_depth=EFormatDepth::kAll) const
static DataFormatManager * Instance()
Event * GetNewEvent(Int_t task_id, EFormatDepth format_depth=EFormatDepth::kAll) const
Bool_t FormatExist(Int_t task_id, EFormatDepth format_depth=EFormatDepth::kAll) const
Track * GetNewTrack() const
Definition Event.cxx:204
virtual Event * GetNewEvent() const
Definition Event.cxx:215
virtual TString GetFormatName() const
Definition Event.cxx:155