LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOLCVecHandler.h
Go to the documentation of this file.
1 #ifndef SIO_SIOINTVECHANDLER_H
2 #define SIO_SIOINTVECHANDLER_H 1
3 
4 // -- lcio headers
5 #include "SIO/SIOObjectHandler.h"
6 #include "UTIL/LCIOTypeInfo.h"
7 #include "EVENT/LCStrVec.h"
8 #include "EVENT/LCIntVec.h"
9 #include "EVENT/LCFloatVec.h"
10 
11 // -- sio headers
12 #include <sio/io_device.h>
13 #include <sio/version.h>
14 
15 namespace SIO {
16 
17 
23  template <typename VECTYPE>
25  public:
27  SIOLCVecHandler() ;
28 
30  void read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) override ;
31 
33  void write( sio::write_device& device, const EVENT::LCObject* obj ) override ;
34 
36  EVENT::LCObject *create() const override ;
37  }; // class
38 
39  //----------------------------------------------------------------------------
40  //----------------------------------------------------------------------------
41 
45 
46  //----------------------------------------------------------------------------
47  //----------------------------------------------------------------------------
48 
49  template <typename VECTYPE>
51  SIOObjectHandler( UTIL::lctypename<VECTYPE>() ) {
52  /* nop */
53  }
54 
55  //----------------------------------------------------------------------------
56 
57  template <typename VECTYPE>
58  inline void SIOLCVecHandler<VECTYPE>::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
59  auto vec = dynamic_cast<VECTYPE*>( objP ) ;
60  // read the vector
61  // SIO_SDATA( device, vec ) ;
62 
63  int nElements ;
64  SIO_SDATA( device, nElements ) ;
65  vec->reserve( nElements ) ;
66  for( int i=0 ; i<nElements ; i++ ) {
67  typename VECTYPE::value_type x ;
68  SIO_SDATA( device , x ) ;
69  vec->push_back( x ) ;
70  }
71 
72  // pointer tag
73  if( vers > SIO_VERSION_ENCODE( 1, 2 ) ) {
74  SIO_PTAG( device , vec ) ;
75  }
76  }
77 
78  //----------------------------------------------------------------------------
79 
80  template <typename VECTYPE>
81  inline void SIOLCVecHandler<VECTYPE>::write( sio::write_device& device, const EVENT::LCObject* obj ) {
82  auto vec = dynamic_cast<const VECTYPE*>( obj ) ;
83  // write the vector
84  // SIO_SDATA( device, vec ) ;
85  int nElements = vec->size() ;
86  SIO_SDATA( device, nElements ) ;
87  for( int i=0 ; i<nElements ; i++ ) {
88  SIO_SDATA( device, (*vec)[i] ) ;
89  }
90  // pointer tag
91  SIO_PTAG( device , vec ) ;
92  }
93 
94  //----------------------------------------------------------------------------
95 
96  template <typename VECTYPE>
98  return new VECTYPE() ;
99  }
100 
101 
102 } // namespace
103 
104 #endif /* ifndef SIO_SIOINTVECHANDLER_H */
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
SIOLCVecHandler< EVENT::LCFloatVec > SIOFloatVecHandler
SIOLCVecHandler< EVENT::LCStrVec > SIOStrVecHandler
SIOLCVecHandler< EVENT::LCIntVec > SIOIntVecHandler
const char * lctypename()
Template that returns the LCIO type name as used in the LCCollctions (and files), e...
Definition: LCIOTypeInfo.h:47
void write(sio::write_device &device, const EVENT::LCObject *obj) override
Writes lcio objects to an SIO stream.
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
EVENT::LCObject * create() const override
Factory method to create an object of the type of the collection.
Implementation of SIOObjectHandler to handle IO of IntVecs.
void read(sio::read_device &device, EVENT::LCObject *objP, sio::version_type vers) override
Reads lcio objects from an SIO stream.
SIOLCVecHandler()
Constructor.