LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOVertexHandler.cc
Go to the documentation of this file.
1 #include "SIO/SIOVertexHandler.h"
2 
3 // -- lcio headers
4 #include "EVENT/LCIO.h"
5 #include "EVENT/Vertex.h"
6 #include "IOIMPL/VertexIOImpl.h"
7 #include "IMPL/LCFlagImpl.h"
8 
9 // -- sio headers
10 #include <sio/io_device.h>
11 #include <sio/version.h>
12 
13 // -- std headers
14 #include <algorithm>
15 
16 namespace SIO {
17 
19  SIOObjectHandler( EVENT::LCIO::VERTEX ) {
20  /* nop */
21  }
22 
23  //----------------------------------------------------------------------------
24 
25  void SIOVertexHandler::initReading( sio::read_device &device, EVENT::LCCollection *collection, sio::version_type vers ) {
26  SIOObjectHandler::initReading( device, collection, vers ) ;
27  _imr.clear() ;
28  _parameters.clear() ;
29  collection->getParameters().getStringVals("_lcio.VertexAlgorithmTypes" , _parameters ) ;
30  for(unsigned int i=0; i<_parameters.size(); i++) {
31  _imr[i] = _parameters[i] ;
32  }
33  }
34 
35  //----------------------------------------------------------------------------
36 
37  void SIOVertexHandler::initWriting( sio::write_device &device, EVENT::LCCollection *collection ) {
38  _parameters.clear() ;
39  _set.clear() ;
40  for( int i=0 ; i<collection->getNumberOfElements() ; i++) {
41  auto v = dynamic_cast<EVENT::Vertex*>( collection->getElementAt( i ) ) ;
42  _set.insert(v->getAlgorithmType());
43  }
44  for( auto it=_set.begin() ; it != _set.end() ; it++ ) {
45  _parameters.push_back(*it) ;
46  }
47  collection->parameters().setValues("_lcio.VertexAlgorithmTypes", _parameters ) ;
48  SIOObjectHandler::initWriting( device, collection ) ;
49  }
50 
51  //----------------------------------------------------------------------------
52 
53  void SIOVertexHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type /*vers*/ ) {
54  auto vtx = dynamic_cast<IOIMPL::VertexIOImpl*>(objP) ;
55  SIO_DATA( device , &(vtx->_primary) , 1 ) ;
56  int algtype;
57  SIO_DATA( device , &algtype , 1 ) ;
58  vtx->setAlgorithmType( _imr[algtype] ) ;
59  SIO_DATA( device , &(vtx->_chi2) , 1 ) ;
60  SIO_DATA( device , &(vtx->_probability) , 1 ) ;
61  SIO_DATA( device , vtx->_vpos , 3 ) ;
62  float cov[VTXCOVMATRIX] ;
63  SIO_DATA( device , &cov[0] , VTXCOVMATRIX ) ;
64  vtx->setCovMatrix( cov ) ;
65  int nPara ;
66  SIO_DATA( device , &nPara , 1 ) ;
67  float aParameter ;
68  for( int i=0 ; i<nPara ; i++ ) {
69  SIO_DATA( device , &aParameter , 1 ) ;
70  vtx->addParameter( aParameter ) ;
71  }
72  //read pointer to associated reconstructed particle
73  SIO_PNTR( device , &(vtx->_aParticle) ) ;
74  // read the pointer tag
75  SIO_PTAG( device , dynamic_cast<const EVENT::Vertex*>(vtx) ) ;
76  }
77 
78  //----------------------------------------------------------------------------
79 
80  void SIOVertexHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
81  auto vtx = dynamic_cast<const EVENT::Vertex*>(obj) ;
82  SIO_SDATA( device, vtx->isPrimary() ) ;
83  SIO_SDATA( device, static_cast<int> (distance( _set.begin(),_set.find( vtx->getAlgorithmType() )))) ;
84  SIO_SDATA( device, vtx->getChi2() ) ;
85  SIO_SDATA( device, vtx->getProbability() ) ;
86  SIO_DATA( device, vtx->getPosition() , 3 ) ;
87  auto cov = vtx->getCovMatrix() ;
88  for( unsigned int i=0 ; i<cov.size() ; i++ ) {
89  SIO_SDATA( device, cov[i] ) ;
90  }
91  int nPara = vtx->getParameters().size() ;
92  SIO_DATA( device , &nPara , 1 ) ;
93  for( int i=0 ; i<nPara ; i++ ) {
94  SIO_SDATA( device, vtx->getParameters()[i] ) ;
95  }
96  //write pointer to associated reconstructed particle
97  auto recP = vtx->getAssociatedParticle() ;
98  SIO_PNTR( device , &recP ) ;
99  // write a ptag in order to be able to point to vertices
100  SIO_PTAG( device , vtx ) ;
101  }
102 
103  //----------------------------------------------------------------------------
104 
106  return new IOIMPL::VertexIOImpl() ;
107  }
108 
109 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
void initWriting(sio::write_device &device, EVENT::LCCollection *collection) override
Init collection reading.
The Vertex class for LCIO.
Definition: Vertex.h:34
SIOVertexHandler()
Constructor.
T end(T...args)
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
EVENT::StringVec _parameters
#define VTXCOVMATRIX
Definition: VertexImpl.h:9
virtual void initReading(sio::read_device &device, EVENT::LCCollection *collection, sio::version_type vers)
Init collection reading.
virtual LCObject * getElementAt(int index) const =0
Returns pointer to element at index - no range check, use getNumberOfEntries().
void initReading(sio::read_device &device, EVENT::LCCollection *collection, sio::version_type vers) override
Init collection reading.
T push_back(T...args)
virtual void initWriting(sio::write_device &device, EVENT::LCCollection *collection)
Init collection writing.
virtual LCParameters & parameters()=0
Parameters defined for this collection.
virtual void setValues(const std::string &key, const IntVec &values)=0
Set integer values for the given key.
T clear(T...args)
std::set< std::string > _set
virtual int getNumberOfElements() const =0
Returns the number of elements in the collection.
T insert(T...args)
void read(sio::read_device &device, EVENT::LCObject *objP, sio::version_type vers) override
Reads lcio objects from an SIO stream.
T find(T...args)
T size(T...args)
virtual StringVec & getStringVals(const std::string &key, StringVec &values) const =0
Adds all string values for the given key to values.
The generic collection used in LCIO.
Definition: LCCollection.h:29
T begin(T...args)
void write(sio::write_device &device, const EVENT::LCObject *obj) override
Writes lcio objects to an SIO stream.
virtual const LCParameters & getParameters() const =0
Parameters defined for this collection.
EVENT::LCObject * create() const override
Factory method to create an object of the type of the collection.
Adding stuff needed for io (friend declarations, etc.)
Definition: VertexIOImpl.h:20
std::map< int, std::string > _imr