LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOTrackerHitHandler.cc
Go to the documentation of this file.
2 
3 // -- lcio headers
4 #include "EVENT/LCIO.h"
5 #include "IMPL/LCFlagImpl.h"
6 #include "EVENT/MCParticle.h"
7 #include "EVENT/TrackerHit.h"
9 
10 // -- sio headers
11 #include <sio/io_device.h>
12 #include <sio/version.h>
13 
14 namespace SIO {
15 
17  SIOObjectHandler( EVENT::LCIO::TRACKERHIT ) {
18  /* nop */
19  }
20 
21  //----------------------------------------------------------------------------
22 
23  void SIOTrackerHitHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
24  auto hit = dynamic_cast<IOIMPL::TrackerHitIOImpl*>(objP) ;
25  IMPL::LCFlagImpl lcFlag(_flag) ;
26 
27  if( vers > SIO_VERSION_ENCODE( 1, 51) ) {
28  SIO_DATA( device , &(hit->_cellID0) , 1 ) ;
29  if( lcFlag.bitSet( EVENT::LCIO::RTHBIT_ID1 ) ){
30  SIO_DATA( device , &(hit->_cellID1) , 1 ) ;
31  }
32  }
33  if( vers > SIO_VERSION_ENCODE( 1, 2) ){
34  SIO_DATA( device , &(hit->_type) , 1 ) ;
35  }
36  SIO_DATA( device , hit->_pos , 3 ) ;
37  float cov[TRKHITNCOVMATRIX] ;
38  SIO_DATA( device , &cov[0] , TRKHITNCOVMATRIX ) ;
39  hit->setCovMatrix( cov ) ;
40  SIO_DATA( device , &(hit->_EDep) , 1 ) ;
41  if( vers > SIO_VERSION_ENCODE( 1, 12 ) ) {
42  SIO_DATA( device , &(hit->_EDepError) , 1 ) ;
43  }
44  SIO_DATA( device , &(hit->_time) , 1 ) ;
45  if( vers > SIO_VERSION_ENCODE( 1, 11 ) ) {
46  SIO_DATA( device , &(hit->_quality) , 1 ) ;
47  }
48  int numberOfRawHits = 1 ;
49  if( vers > SIO_VERSION_ENCODE( 1, 2 ) ) {
50  SIO_DATA( device , &numberOfRawHits , 1 ) ;
51  }
52  hit->_rawHits.resize( numberOfRawHits ) ;
53 
54  for( int i=0 ; i<numberOfRawHits ; i++ ) {
55  SIO_PNTR( device , &(hit->_rawHits[i] ) ) ;
56  }
57  SIO_PTAG( device , dynamic_cast<const EVENT::TrackerHit*>(hit) ) ;
58  }
59 
60  //----------------------------------------------------------------------------
61 
62  void SIOTrackerHitHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
63  auto hit = dynamic_cast<const EVENT::TrackerHit*>(obj) ;
64  IMPL::LCFlagImpl lcFlag(_flag) ;
65  SIO_SDATA( device, hit->getCellID0() ) ;
66  if( lcFlag.bitSet( EVENT::LCIO::RTHBIT_ID1 ) ){
67  SIO_SDATA( device, hit->getCellID1() ) ;
68  }
69  SIO_SDATA( device , hit->getType() ) ;
70  SIO_DATA( device, hit->getPosition() , 3 ) ;
71  auto cov = hit->getCovMatrix() ;
72  for( unsigned int i=0 ; i<cov.size() ; i++ ) {
73  SIO_SDATA( device, cov[i] ) ;
74  }
75  SIO_SDATA( device, hit->getEDep() ) ;
76  SIO_SDATA( device, hit->getEDepError() ) ;
77  SIO_SDATA( device, hit->getTime() ) ;
78  SIO_SDATA( device, hit->getQuality() ) ;
79  const EVENT::LCObjectVec& rawHits = hit->getRawHits() ;
80  int nrawhits = rawHits.size() ;
81  SIO_SDATA( device, nrawhits ) ;
82  for(unsigned int i=0; i < rawHits.size() ; i++){
83  SIO_PNTR( device , &(rawHits[i]) ) ;
84  }
85  // write a ptag in order to be able to point to tracker hits in the future
86  SIO_PTAG( device , hit ) ;
87  }
88 
89 
90  //----------------------------------------------------------------------------
91 
93  return new IOIMPL::TrackerHitIOImpl() ;
94  }
95 
96 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
A generic tracker hit to be used by pattern recognition.
Definition: TrackerHit.h:26
virtual bool bitSet(int index) const
Returns true if bit at given index is set.
Definition: LCFlagImpl.cc:13
#define TRKHITNCOVMATRIX
void write(sio::write_device &device, const EVENT::LCObject *obj) override
Writes lcio objects to an SIO stream.
EVENT::LCObject * create() const override
Factory method to create an object of the type of the collection.
void read(sio::read_device &device, EVENT::LCObject *objP, sio::version_type vers) override
Reads lcio objects from an SIO stream.
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
unsigned int _flag
The collection flag.
Implementation of helper class to create and interpret the 32-bit flag word in LCCollections.
Definition: LCFlagImpl.h:15
T size(T...args)
Adding stuff needed for io (friend declarations, etc.)