Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
FemtoSerializationInterface.h
1/*
2 * FemtoSerialization.h
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#ifndef HAL_ANALYSIS_FEMTO_CORRFIT_SERIALIZATION_FEMTOSERIALIZATIONINTERFACETEMPLATE_H_
10#define HAL_ANALYSIS_FEMTO_CORRFIT_SERIALIZATION_FEMTOSERIALIZATIONINTERFACETEMPLATE_H_
11
12#include "Array.h"
13
14#include <TObject.h>
15#include <iostream>
16#include <vector>
17
21class TH1;
22class TH3;
23namespace Hal {
24 class FemtoSerializationInterface : public TObject {
25 public:
26 enum class EOption { kFull, kSimple };
27 enum class ECopyDir { kSerialize, kDeserialize };
28 enum class EData { kSlice, kCF, kUnkown };
29
30 protected:
31 Int_t fBinLow = {-1};
32 Int_t fBinHi = {-1};
33 Int_t fBinStart = {-1}; // real bin in CF
34 Int_t fBinStop = {-1}; // real bin in CF
35 Array_1<Float_t>* fArray = {nullptr};
36 EOption fOption = {EOption::kFull};
37 EData fDataType = {EData::kUnkown};
38 Int_t fCounter = {0};
39
40 virtual void ConvertCF(ECopyDir dir) = 0;
41 virtual void ConvertSlice(ECopyDir dir) = 0;
42 virtual void ConvertCFSimple(ECopyDir dir) = 0;
43 virtual void ConvertSliceSimple(ECopyDir dir) = 0;
44 virtual void PostInit() {};
45 virtual Bool_t HaveCF() const = 0;
46 virtual Bool_t HaveSlice() const = 0;
47 virtual Bool_t GetBinsNo() = 0; // calculate start/stop bin
48 void CopyData1D(std::vector<TH1*>& list, int bin, ECopyDir dir, Bool_t error = false);
49 void CopyData3D(std::vector<TH3*>& list, int binx, int biny, int binz, ECopyDir dir, Bool_t error = false);
50 void CopyData1D2(std::vector<TH1*>& listN, std::vector<TH1*>& listD, int bin, ECopyDir dir);
51 void CopyData3D2(std::vector<TH3*>& listN, std::vector<TH3*>& listD, int binx, int biny, int binz, ECopyDir dir);
52 void CopyDataVec(std::vector<std::vector<double>>& list, int pos, ECopyDir dir);
53 void ExpandArrayIfSerialize(Int_t newSize, ECopyDir dir);
54 template<typename T>
55 void CopyDataSingle(T& x, ECopyDir dir) {
56 switch (dir) {
57 case ECopyDir::kSerialize:
58 fArray->Set(fCounter, x);
59 fCounter++;
60 break;
61 case ECopyDir::kDeserialize:
62 x = fArray->Get(fCounter);
63 fCounter++;
64 break;
65 }
66 }
67 template<typename T>
68 void CopyDataPair(T& n, T& d, ECopyDir dir) {
69 switch (dir) {
70 case ECopyDir::kSerialize:
71 fArray->Set(fCounter, n / d);
72 fCounter++;
73 break;
74 case ECopyDir::kDeserialize:
75 n = fArray->Get(fCounter);
76 fCounter++;
77 d = 1;
78 break;
79 }
80 }
81
82 public:
84 void Data(EData opt) { fDataType = opt; }
85 void SetOption(EOption opt) { fOption = opt; }
86 virtual Bool_t BindCFs(TObject* cf) = 0;
87 virtual Bool_t BindSlices(TObject* slice) = 0;
88 virtual Bool_t BindArray(Array_1<Float_t>* array) {
89 fArray = array;
90 if (fArray) return kTRUE;
91 return kFALSE;
92 }
93 virtual Bool_t Init();
98 virtual void Serialize(Int_t binLo = -1, Int_t binHi = -1);
99 virtual void Deserialize(Int_t binLo = -1, Int_t binHi = -1);
100 virtual ~FemtoSerializationInterface() {};
101 ClassDef(FemtoSerializationInterface, 0);
102 };
103 template<typename T1, typename T2>
105
106 protected:
107 T1* fCF = {nullptr};
108 T2* fSlice = {nullptr};
109 Bool_t HaveCF() const final;
110 Bool_t HaveSlice() const final;
111
112 public:
114 Bool_t BindCFs(TObject* cf);
115 Bool_t BindSlices(TObject* slice);
118 };
119
120} /* namespace Hal */
121
122template<typename T1, typename T2>
124 fCF = dynamic_cast<T1*>(cf);
125 if (fCF) return kTRUE;
126 std::cout << "Can't bind " << cf->ClassName() << " to " << this->ClassName() << std::endl;
127 return kFALSE;
128}
129
130template<typename T1, typename T2>
132 fSlice = dynamic_cast<T2*>(slice);
133 if (fSlice) return kTRUE;
134 return kFALSE;
135}
136
137template<typename T1, typename T2>
139 if (fCF) return kTRUE;
140 return kFALSE;
141}
142
143template<typename T1, typename T2>
145 if (fSlice) return kTRUE;
146 return kFALSE;
147}
148
149
150#endif /* HAL_ANALYSIS_FEMTO_CORRFIT_SERIALIZATION_FEMTOSERIALIZATIONINTERFACETEMPLATE_H_ */
void Set(Int_t index, T val)
Definition Array.h:103
T Get(Int_t i) const
Definition Array.h:97
virtual void Serialize(Int_t binLo=-1, Int_t binHi=-1)