2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
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.
17 namespace RootConversions {
22 * @param tname The name of the vector element type T.
24 template <typename T, typename U>
25 VectorConverter<T, U>::VectorConverter (const char* tname)
27 std::string vname = "vector<";
29 if (vname[vname.size()-1] == '>')
32 m_cl = gROOT->GetClass (vname.c_str());
37 * @brief Run the streamer.
38 * @param b Buffer from which to read.
39 * @param pmember Pointer to the object into which to read.
40 * @param size Number of instances to read.
42 template <typename T, typename U>
43 void VectorConverter<T, U>::operator() (TBuffer& b,
47 // This only works for reading!
48 assert (b.IsReading());
50 // The transient object.
51 std::vector<U>* obj = reinterpret_cast<std::vector<U>*> (pmember);
53 // We'll read into this object.
57 // Read into tmp and copy data to *obj.
59 m_cl->Streamer (&tmp, b);
60 obj->assign (tmp.begin(), tmp.end());
66 } // namespace RootConversions