ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
DataModelAthenaPool
src
PackedContainerConverter.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
10
11
12
#include "
DataModelAthenaPool/PackedContainerConverter.h
"
13
#include "
AthContainers/PackedContainer.h
"
14
#include "
RootConversions/TConverterRegistry.h
"
15
#include "TMemberStreamer.h"
16
#include "TClass.h"
17
#include "TROOT.h"
18
#include <vector>
19
#include <string>
20
#include <cassert>
21
22
23
namespace
DataModelAthenaPool
{
24
25
34
template
<
class
T,
class
ALLOC>
35
void
vectorMove
(std::vector<T, ALLOC>& src, std::vector<T, ALLOC>& dst)
36
{
37
dst.swap (src);
38
}
39
template
<
class
T,
class
U,
class
ALLOC>
40
void
vectorMove
(std::vector<T, ALLOC>& src, std::vector<U, ALLOC>& dst)
41
{
42
dst.assign (src.begin(), src.end());
43
}
44
45
49
template
<
class
T,
class
U=T,
class
ALLOC=std::allocator<T> >
50
class
PackedContainerConverter
51
:
public
TMemberStreamer
52
{
53
public
:
60
PackedContainerConverter
(
const
char
* tname,
61
const
char
* allocName =
nullptr
);
62
63
70
virtual
void
operator()
(TBuffer& b,
void
* pmember, Int_t
size
=0);
71
72
73
private
:
75
TClass*
m_cl
;
76
};
77
78
85
template
<
class
T,
class
U,
class
ALLOC>
86
PackedContainerConverter<T, U, ALLOC>::PackedContainerConverter
(
const
char
* tname,
87
const
char
* allocName
/* = nullptr*/
)
88
{
89
std::string vname =
"vector<"
;
90
vname += tname;
91
if
(allocName !=
nullptr
) {
92
vname +=
","
;
93
vname += allocName;
94
}
95
if
(vname[vname.size()-1] ==
'>'
)
96
vname +=
' '
;
97
vname +=
'>'
;
98
m_cl
= gROOT->GetClass (vname.c_str());
99
}
100
101
108
template
<
class
T,
class
U,
class
ALLOC>
109
void
PackedContainerConverter<T, U, ALLOC>::operator()
(TBuffer& b,
110
void
* pmember,
111
Int_t
size
/*=0*/
)
112
{
113
// This only works for reading!
114
assert (b.IsReading());
115
116
// The transient object.
117
SG::PackedContainer<U, ALLOC>
* obj =
118
reinterpret_cast<
SG::PackedContainer<U, ALLOC>
*
>
(pmember);
119
120
// We'll read into this object.
121
std::vector<T, ALLOC> tmp;
122
123
while
(
size
-- > 0) {
124
// Read into tmp and move data to *obj.
125
tmp.clear();
126
m_cl
->Streamer (&tmp, b);
127
vectorMove
(tmp, *obj);
128
++obj;
129
}
130
}
131
132
136
void
installPackedContainerConverters
()
137
{
138
#define CONVERTER(SRC, DST) \
139
do { \
140
TConverterRegistry::Instance()->AddStreamerConverter \
141
("vector<" #SRC ">", \
142
"SG::PackedContainer<" #DST ",allocator<" #DST "> >", \
143
new PackedContainerConverter<SRC, DST> ( #SRC)); \
144
} while (0)
145
146
#define CONVERTER1(T) CONVERTER(T,T)
147
148
#define CONVERTER2(T, ALLOC) \
149
do { \
150
TConverterRegistry::Instance()->AddStreamerConverter \
151
("vector<" #T "," #ALLOC "<" #T "> >", \
152
"SG::PackedContainer<" #T "," #ALLOC "<" #T "> >", \
153
new PackedContainerConverter<T, T, ALLOC<T> > ( #T, #ALLOC "<" #T ">" )); \
154
} while (0)
155
156
157
CONVERTER1
(
char
);
158
CONVERTER1
(
unsigned
char
);
159
CONVERTER1
(
short
);
160
CONVERTER1
(
unsigned
short
);
161
CONVERTER1
(
int
);
162
CONVERTER1
(
unsigned
int
);
163
CONVERTER1
(
float
);
164
CONVERTER1
(
double
);
165
166
CONVERTER1
(std::vector<char>);
167
CONVERTER1
(std::vector<unsigned char>);
168
CONVERTER1
(std::vector<short>);
169
CONVERTER1
(std::vector<unsigned short>);
170
CONVERTER1
(std::vector<int>);
171
CONVERTER1
(std::vector<unsigned int>);
172
CONVERTER1
(std::vector<float>);
173
CONVERTER1
(std::vector<double>);
174
175
CONVERTER1
(std::vector<std::vector<char> >);
176
CONVERTER1
(std::vector<std::vector<unsigned char> >);
177
CONVERTER1
(std::vector<std::vector<short> >);
178
CONVERTER1
(std::vector<std::vector<unsigned short> >);
179
CONVERTER1
(std::vector<std::vector<int> >);
180
CONVERTER1
(std::vector<std::vector<unsigned int> >);
181
CONVERTER1
(std::vector<std::vector<float> >);
182
CONVERTER1
(std::vector<std::vector<double> >);
183
}
184
185
186
}
// namespace DataModelAthenaPool
CONVERTER1
#define CONVERTER1(T)
PackedContainerConverter.h
Allow converting std::vector to SG::PackedContainer.
PackedContainer.h
Container to hold aux data to be stored in a packed form.
size
size_t size() const
Number of registered mappings.
TConverterRegistry.h
Registry for Root converters.
DataModelAthenaPool::PackedContainerConverter::PackedContainerConverter
PackedContainerConverter(const char *tname, const char *allocName=nullptr)
Constructor.
Definition
PackedContainerConverter.cxx:86
DataModelAthenaPool::PackedContainerConverter::m_cl
TClass * m_cl
Hold the source class.
Definition
PackedContainerConverter.cxx:75
DataModelAthenaPool::PackedContainerConverter::operator()
virtual void operator()(TBuffer &b, void *pmember, Int_t size=0)
Run the streamer.
Definition
PackedContainerConverter.cxx:109
SG::PackedContainer
Container to hold aux data to be stored in a packed form.
Definition
PackedContainer.h:50
DataModelAthenaPool
Definition
CLHEPConverters.h:20
DataModelAthenaPool::vectorMove
void vectorMove(std::vector< T, ALLOC > &src, std::vector< T, ALLOC > &dst)
Move from one vector to another.
Definition
PackedContainerConverter.cxx:35
DataModelAthenaPool::installPackedContainerConverters
void installPackedContainerConverters()
Install converters for supported instantiations.
Definition
PackedContainerConverter.cxx:136
Generated on
for ATLAS Offline Software by
1.17.0