LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOTrackHandler.cc
Go to the documentation of this file.
1 #include "SIO/SIOTrackHandler.h"
2 
3 // -- lcio headers
4 #include "EVENT/LCIO.h"
5 #include "IOIMPL/TrackIOImpl.h"
7 #include "IMPL/LCFlagImpl.h"
8 
9 // -- sio headers
10 #include <sio/io_device.h>
11 #include <sio/version.h>
12 
13 namespace SIO {
14 
16  SIOObjectHandler( EVENT::LCIO::TRACK ) {
17  /* nop */
18  }
19 
20  //----------------------------------------------------------------------------
21 
22  void SIOTrackHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
23  auto trk = dynamic_cast<IOIMPL::TrackIOImpl*>( objP ) ;
24  int type ;
25  SIO_DATA( device , &type , 1 ) ;
26  trk->setType( type ) ; // type is bitset<32> - can't be set directly
27  // read TrackStates
28  int nTrackStates = 1 ; // set to 1 per default for backwards compatibility
29  if( vers >= SIO_VERSION_ENCODE( 2, 0 ) ) {
30  SIO_DATA( device , &nTrackStates , 1 ) ;
31  }
32  for( int i=0 ; i<nTrackStates ; i++ ) {
33  // create new TrackState object
34  auto trackstate = new IOIMPL::TrackStateIOImpl() ;
35  if( vers >= SIO_VERSION_ENCODE( 2, 0 ) ) {
36  SIO_DATA( device , &(trackstate->_location) , 1 ) ;
37  }
38  SIO_DATA( device , &(trackstate->_d0) , 1 ) ;
39  SIO_DATA( device , &(trackstate->_phi) , 1 ) ;
40  SIO_DATA( device , &(trackstate->_omega) , 1 ) ;
41  SIO_DATA( device , &(trackstate->_z0) , 1 ) ;
42  SIO_DATA( device , &(trackstate->_tanLambda) , 1 ) ;
43  float cov[15] ;
44  SIO_DATA( device , cov , 15 ) ;
45  trackstate->setCovMatrix( cov ) ;
46  SIO_DATA( device , trackstate->_reference , 3 ) ;
47  trk->addTrackState( trackstate );
48  }
49  SIO_DATA( device , &(trk->_chi2) , 1 ) ;
50  SIO_DATA( device , &(trk->_ndf) , 1 ) ;
51  SIO_DATA( device , &(trk->_dEdx) , 1 ) ;
52  SIO_DATA( device , &(trk->_dEdxError) , 1 ) ;
53  SIO_DATA( device , &( trk->_radiusOfInnermostHit ) , 1 ) ;
54  int nHitNumbers ;
55  SIO_DATA( device, &nHitNumbers , 1 ) ;
56  trk->subdetectorHitNumbers().resize( nHitNumbers ) ;
57  for( int i=0 ; i<nHitNumbers ; i++ ) {
58  SIO_DATA( device , &(trk->_subdetectorHitNumbers[i] ), 1 ) ;
59  }
60  int nTracks ;
61  SIO_DATA( device, &nTracks , 1 ) ;
62  trk->_tracks.resize( nTracks ) ;
63  for( int i=0 ; i<nTracks ; i++ ) {
64  SIO_PNTR( device , &(trk->_tracks[i] ) ) ;
65  }
66  if( IMPL::LCFlagImpl(_flag).bitSet( EVENT::LCIO::TRBIT_HITS ) ) {
67  int nHits ;
68  SIO_DATA( device, &nHits , 1 ) ;
69  trk->_hits.resize( nHits) ;
70  for( int i=0 ; i<nHits ; i++ ) {
71  SIO_PNTR( device , &(trk->_hits[i] ) ) ;
72  }
73  }
74  // read the pointer tag
75  SIO_PTAG( device , dynamic_cast<const EVENT::Track*>(trk) ) ;
76  }
77 
78  //----------------------------------------------------------------------------
79 
80  void SIOTrackHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
81  auto trk = dynamic_cast<const EVENT::Track*>(obj) ;
82  SIO_SDATA( device, trk->getType() ) ;
83  auto trackstates = trk->getTrackStates() ;
84  int nTrackStates = trackstates.size() ;
85  SIO_DATA( device, &nTrackStates , 1 ) ;
86  for( unsigned int i=0; i<trackstates.size() ; i++ ) {
87  SIO_SDATA( device, trk->getTrackStates()[i]->getLocation() ) ;
88  SIO_SDATA( device, trk->getTrackStates()[i]->getD0() ) ;
89  SIO_SDATA( device, trk->getTrackStates()[i]->getPhi() ) ;
90  SIO_SDATA( device, trk->getTrackStates()[i]->getOmega() ) ;
91  SIO_SDATA( device, trk->getTrackStates()[i]->getZ0() ) ;
92  SIO_SDATA( device, trk->getTrackStates()[i]->getTanLambda() ) ;
93  auto cov = trk->getTrackStates()[i]->getCovMatrix() ;
94  for(unsigned int j=0; j<cov.size() ; j++ ) {
95  SIO_SDATA( device, cov[j] ) ;
96  }
97  SIO_DATA( device, trk->getTrackStates()[i]->getReferencePoint() , 3 ) ;
98  }
99  SIO_SDATA( device, trk->getChi2() ) ;
100  SIO_SDATA( device, trk->getNdf() ) ;
101  SIO_SDATA( device, trk->getdEdx() ) ;
102  SIO_SDATA( device, trk->getdEdxError() ) ;
103  SIO_SDATA( device , trk->getRadiusOfInnermostHit() ) ;
104  auto hitNums = trk->getSubdetectorHitNumbers() ;
105  int nHitNumbers = hitNums.size() ;
106  SIO_DATA( device, &nHitNumbers , 1 ) ;
107  for( int i=0 ; i<nHitNumbers ; i++ ) {
108  SIO_SDATA( device , hitNums[i] ) ;
109  }
110  auto tracks = trk->getTracks() ;
111  int nTracks = tracks.size() ;
112  SIO_DATA( device, &nTracks , 1 ) ;
113  for( int i=0 ; i<nTracks ; i++ ) {
114  SIO_PNTR( device , &(tracks[i]) ) ;
115  }
116  if( IMPL::LCFlagImpl(_flag).bitSet( EVENT::LCIO::TRBIT_HITS ) ) {
117  auto hits = trk->getTrackerHits() ;
118  int nHits = hits.size() ;
119  SIO_DATA( device, &nHits , 1 ) ;
120  for( int i=0 ; i<nHits ; i++ ) {
121  SIO_PNTR( device , &(hits[i]) ) ;
122  }
123  }
124  // write a ptag in order to be able to point to tracks
125  SIO_PTAG( device , trk ) ;
126  }
127 
128  //----------------------------------------------------------------------------
129 
131  return new IOIMPL::TrackIOImpl() ;
132  }
133 
134 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
virtual const TrackStateVec & getTrackStates() const =0
Returns track states associtated to this track.
SIOTrackHandler()
Constructor.
EVENT::LCObject * create() const override
Factory method to create an object of the type of the collection.
void write(sio::write_device &device, const EVENT::LCObject *obj) override
Writes lcio objects to an SIO stream.
Adding stuff needed for io (friend declarations, etc.)
Definition: TrackIOImpl.h:20
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
void read(sio::read_device &device, EVENT::LCObject *objP, sio::version_type vers) override
Reads lcio objects from an SIO stream.
unsigned int _flag
The collection flag.
Adding stuff needed for io (friend declarations, etc.)
The LCIO track class.
Definition: Track.h:33
Implementation of helper class to create and interpret the 32-bit flag word in LCCollections.
Definition: LCFlagImpl.h:15
T size(T...args)