Skip to content

Commit afee20a

Browse files
committed
Add streamer for std::vector<o2::tpc::PadFlags>
1 parent d449a51 commit afee20a

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

DataFormats/Detectors/TPC/include/DataFormatsTPC/Defs.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,23 @@ typename Enum<T>::Iterator end(Enum<T>)
182182
}
183183
} // namespace o2::tpc
184184

185+
#ifdef __CLING__
186+
#include "DataFormatsTPC/VectorPadFlagsStreamer.h"
187+
188+
struct VectorPadFlagsStreamerInit {
189+
VectorPadFlagsStreamerInit()
190+
{
191+
auto cls = TClass::GetClass("std::vector<o2::tpc::PadFlags>");
192+
if (cls) {
193+
cls->AdoptStreamer(new VectorPadFlagsStreamer());
194+
} else {
195+
throw std::runtime_error("VectorPadFlagsStreamerInit: Class not found!");
196+
}
197+
}
198+
};
199+
200+
static VectorPadFlagsStreamerInit _vectorPadFlagsStreamerInit;
201+
202+
#endif // __CLING__
203+
185204
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef O2_DATAFORMATSTPC_VECTORPAD_FLAGSSTREAMER_H_
13+
#define O2_DATAFORMATSTPC_VECTORPAD_FLAGSSTREAMER_H_
14+
15+
#include "DataFormatsTPC/Defs.h"
16+
#include <TClassStreamer.h>
17+
#include <TBuffer.h>
18+
#include <vector>
19+
20+
class VectorPadFlagsStreamer : public TClassStreamer
21+
{
22+
public:
23+
void operator()(TBuffer& R__b, void* objp) override
24+
{
25+
std::vector<o2::tpc::PadFlags>* obj = static_cast<std::vector<o2::tpc::PadFlags>*>(objp);
26+
if (R__b.IsReading()) {
27+
std::vector<int> R__stl;
28+
R__stl.clear();
29+
int R__n;
30+
R__b >> R__n;
31+
R__stl.reserve(R__n);
32+
for (int R__i = 0; R__i < R__n; R__i++) {
33+
Int_t readtemp;
34+
R__b >> readtemp;
35+
R__stl.push_back(readtemp);
36+
}
37+
auto data = reinterpret_cast<unsigned short*>(R__stl.data());
38+
for (int i = 0; i < R__n; ++i) {
39+
obj->push_back(static_cast<o2::tpc::PadFlags>(data[i]));
40+
}
41+
} else {
42+
// We always save things with the old format.
43+
R__b << (int)obj->size() / 2;
44+
for (size_t i = 0; i < obj->size(); i++) {
45+
R__b << (short)obj->at(i);
46+
}
47+
}
48+
}
49+
};
50+
51+
#endif // O2_DATAFORMATSTPC_VECTORPAD_FLAGSSTREAMER_H_

0 commit comments

Comments
 (0)