ATLAS Offline Software
VectorConverter.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
6 /**
7  * @file RootConversions/VectorConverter.icc
8  * @author scott snyder <snyder@bnl.gov>
9  * @date Oct, 2009, from previous code.
10  * @brief Template for streamer converter for vector<T> -> vector<U>,
11  * assuming T is convertable to U.
12  */
13 
14 
15 namespace RootConversions {
16 
17 
18 /**
19  * @brief Constructor.
20  * @param tname The name of the vector element type T.
21  */
22 template <typename T, typename U>
23 VectorConverter<T, U>::VectorConverter (const char* tname)
24 {
25  std::string vname = "vector<";
26  vname += tname;
27  if (vname[vname.size()-1] == '>')
28  vname += ' ';
29  vname += '>';
30  m_cl = gROOT->GetClass (vname.c_str());
31 }
32 
33 
34 /**
35  * @brief Run the streamer.
36  * @param b Buffer from which to read.
37  * @param pmember Pointer to the object into which to read.
38  * @param size Number of instances to read.
39  */
40 template <typename T, typename U>
41 void VectorConverter<T, U>::operator() (TBuffer& b,
42  void* pmember,
43  Int_t size /*=0*/)
44 {
45  // This only works for reading!
46  assert (b.IsReading());
47 
48  // The transient object.
49  std::vector<U>* obj = reinterpret_cast<std::vector<U>*> (pmember);
50 
51  // We'll read into this object.
52  std::vector<T> tmp;
53 
54  while (size-- > 0) {
55  // Read into tmp and copy data to *obj.
56  tmp.clear();
57  m_cl->Streamer (&tmp, b);
58  obj->assign (tmp.begin(), tmp.end());
59  ++obj;
60  }
61 }
62 
63 
64 } // namespace RootConversions