Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
FemtoSerializationInterface.cxx
1/*
2 * FemtoSerialization.cxx
3 *
4 * Created on: 17 sty 2024
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "FemtoSerializationInterface.h"
10
11#include <TH1D.h>
12#include <TH3D.h>
13
14#include <iostream>
15
16namespace Hal {
17
18 void FemtoSerializationInterface::CopyData1D(std::vector<TH1*>& list, int bin, ECopyDir dir, Bool_t error) {
19 switch (dir) {
20 case ECopyDir::kSerialize: {
21 for (auto h : list) {
22 if (error) {
23 fArray->Set(fCounter, h->GetBinError(bin));
24 fCounter++;
25 } else {
26 fArray->Set(fCounter, h->GetBinContent(bin));
27 fCounter++;
28 }
29 }
30 } break;
31 case ECopyDir::kDeserialize: {
32 for (auto h : list) {
33 if (error) {
34 h->SetBinError(bin, fArray->Get(fCounter));
35 fCounter++;
36 } else {
37 h->SetBinContent(bin, fArray->Get(fCounter));
38 fCounter++;
39 }
40 }
41 } break;
42 }
43 }
44
45 void
46 FemtoSerializationInterface::CopyData3D(std::vector<TH3*>& list, int binx, int biny, int binz, ECopyDir dir, Bool_t error) {
47 switch (dir) {
48 case ECopyDir::kSerialize: {
49 for (auto h : list) {
50 if (error) {
51 fArray->Set(fCounter++, h->GetBinError(binx, biny, binz));
52 } else {
53 fArray->Set(fCounter++, h->GetBinContent(binx, biny, binz));
54 }
55 }
56 } break;
57 case ECopyDir::kDeserialize: {
58 for (auto h : list) {
59 if (error) {
60 h->SetBinError(binx, biny, binz, fArray->Get(fCounter++));
61 } else {
62 h->SetBinContent(binx, biny, binz, fArray->Get(fCounter++));
63 }
64 }
65 } break;
66 }
67 }
68
69 void FemtoSerializationInterface::CopyDataVec(std::vector<std::vector<double>>& list, int pos, ECopyDir dir) {
70 switch (dir) {
71 case ECopyDir::kSerialize: {
72 for (auto& vec : list) {
73 fArray->Set(fCounter++, vec[pos]);
74 }
75 } break;
76 case ECopyDir::kDeserialize: {
77 for (auto& vec : list) {
78 vec[pos] = fArray->Get(fCounter++);
79 }
80 } break;
81 }
82 }
83
84 void FemtoSerializationInterface::Serialize(Int_t binLo, Int_t binHi) {
85 fBinLow = binLo;
86 fBinHi = binHi;
87 fCounter = 0;
88 if (fBinLow == -1) {
89 fBinLow = fBinStart;
90 fBinHi = fBinStop;
91 }
92 if (fBinLow == -1) { std::cout << "Cannot serialize, something is wrong with bin ranges" << std::endl; }
93 if (fDataType == EData::kUnkown) {
94 if (HaveCF())
95 fDataType = EData::kCF;
96 else if (HaveSlice())
97 fDataType = EData::kSlice;
98 }
99 ECopyDir dir = ECopyDir::kSerialize;
100 switch (fDataType) {
101 case EData::kCF: {
102 switch (fOption) {
103 case EOption::kFull: ConvertCF(dir); break;
104 case EOption::kSimple: ConvertCFSimple(dir); break;
105 }
106 } break;
107 case EData::kSlice: {
108 switch (fOption) {
109 case EOption::kFull: ConvertSlice(dir); break;
110 case EOption::kSimple: ConvertSliceSimple(dir); break;
111 }
112 } break;
113 default: break;
114 }
115 }
116
117 void FemtoSerializationInterface::ExpandArrayIfSerialize(Int_t newSize, ECopyDir dir) {
118 if (dir == ECopyDir::kSerialize) fArray->MakeBigger(newSize);
119 }
120
121 void FemtoSerializationInterface::CopyData1D2(std::vector<TH1*>& listN, std::vector<TH1*>& listD, int bin, ECopyDir dir) {
122 for (int i = 0; i < listN.size(); i++) {
123 auto nH = listN[i];
124 auto dH = listD[i];
125 if (dir == ECopyDir::kSerialize) {
126 fArray->Set(fCounter++, nH->GetBinContent(bin) / dH->GetBinContent(bin));
127 } else {
128 dH->SetBinContent(bin, fArray->Get(fCounter++));
129 dH->SetBinContent(bin, 1);
130 }
131 }
132 }
133
134 void FemtoSerializationInterface::CopyData3D2(std::vector<TH3*>& listN,
135 std::vector<TH3*>& listD,
136 int binx,
137 int biny,
138 int binz,
139 ECopyDir dir) {
140 for (int i = 0; i < listN.size(); i++) {
141 auto nH = listN[i];
142 auto dH = listD[i];
143 if (dir == ECopyDir::kSerialize) {
144 fArray->Set(fCounter++, nH->GetBinContent(binx, biny, binz) / dH->GetBinContent(binx, biny, binz));
145 } else {
146 for (int bin = fBinStart; bin <= fBinStop; bin++) {
147 nH->SetBinContent(binx, biny, binz, fArray->Get(fCounter++));
148 dH->SetBinContent(binx, biny, binz, 1);
149 }
150 }
151 }
152 }
153
154 void FemtoSerializationInterface::Deserialize(Int_t binLo, Int_t binHi) {
155 fBinLow = binLo;
156 fBinHi = binHi;
157 fCounter = 0;
158 if (fBinLow == -1) {
159 fBinLow = fBinStart;
160 fBinHi = fBinStop;
161 }
162 if (fBinLow == -1) { std::cout << "Cannot deserialize, something is wrong with bin ranges" << std::endl; }
163 if (fDataType == EData::kUnkown) {
164 if (HaveCF())
165 fDataType = EData::kCF;
166 else if (HaveSlice())
167 fDataType = EData::kSlice;
168 }
169 ECopyDir dir = ECopyDir::kDeserialize;
170 switch (fDataType) {
171 case EData::kCF: {
172 switch (fOption) {
173 case EOption::kFull: ConvertCF(dir); break;
174 case EOption::kSimple: ConvertCFSimple(dir); break;
175 }
176 } break;
177 case EData::kSlice: {
178 switch (fOption) {
179 case EOption::kFull: ConvertSlice(dir); break;
180 case EOption::kSimple: ConvertSliceSimple(dir); break;
181 }
182 } break;
183 default: break;
184 }
185 }
186
187
188 Bool_t FemtoSerializationInterface::Init() {
189 if (!HaveCF() && !HaveSlice()) {
190 std::cout << __FILE__ << " " << __LINE__ << " cannot properly without cf's or slice" << std::endl;
191 return kFALSE; // no cf, no slice
192 }
193 if (HaveCF() && HaveSlice()) {
194 std::cout << __FILE__ << " " << __LINE__ << " cannot properly use cf's and slice" << std::endl;
195 return kFALSE; // both wrong!
196 }
197 if (HaveCF()) GetBinsNo(); // have cf
198 if (!fArray) return kFALSE;
199 PostInit();
200 return kTRUE;
201 }
202
203} /* namespace Hal */
void Set(Int_t index, T val)
Definition Array.h:103
T Get(Int_t i) const
Definition Array.h:97
void MakeBigger(Int_t new_dim)
Definition Array.cxx:5
virtual void Serialize(Int_t binLo=-1, Int_t binHi=-1)