ATLAS Offline Software
PackedContainerConverter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
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> >
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>
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>
110  void* pmember,
111  Int_t size /*=0*/)
112 {
113  // This only works for reading!
114  assert (b.IsReading());
115 
116  // The transient object.
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 
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
DataModelAthenaPool::PackedContainerConverter::operator()
virtual void operator()(TBuffer &b, void *pmember, Int_t size=0)
Run the streamer.
Definition: PackedContainerConverter.cxx:109
PackedContainer.h
Container to hold aux data to be stored in a packed form.
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
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
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
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
DataModelAthenaPool::PackedContainerConverter
Converter from std::vector<T,ALLOC> to SG::PackedContainer<U,ALLOC>.
Definition: PackedContainerConverter.cxx:52
CONVERTER1
#define CONVERTER1(T)
SG::PackedContainer
Container to hold aux data to be stored in a packed form.
Definition: PackedContainer.h:50
TConverterRegistry.h
Registry for Root converters.
PackedContainerConverter.h
Allow converting std::vector to SG::PackedContainer.
python.PyAthena.obj
obj
Definition: PyAthena.py:135