LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOSimTrackHitHandler.cc
Go to the documentation of this file.
2 
3 
4 #include "EVENT/LCIO.h"
5 #include "EVENT/MCParticle.h"
6 #include "EVENT/SimTrackerHit.h"
8 #include "IMPL/LCFlagImpl.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::SIMTRACKERHIT ) {
18  /* nop */
19  }
20 
21  //----------------------------------------------------------------------------
22 
23  void SIOSimTrackHitHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
24  auto hit = dynamic_cast<IOIMPL::SimTrackerHitIOImpl*>( objP ) ;
25  IMPL::LCFlagImpl lcFlag(_flag) ;
26 
27  SIO_DATA( device , &(hit->_cellID0) , 1 ) ;
28  if( vers > SIO_VERSION_ENCODE( 1, 51) ) {
29  if( lcFlag.bitSet( EVENT::LCIO::THBIT_ID1 ) ) {
30  SIO_DATA( device , &(hit->_cellID1) , 1 ) ;
31  }
32  }
33  SIO_DATA( device , hit->_pos , 3 ) ;
34  SIO_DATA( device , &(hit->_EDep) , 1 ) ;
35  SIO_DATA( device , &(hit->_time) , 1 ) ;
36  SIO_PNTR( device , &(hit->_particle) ) ;
37  if( lcFlag.bitSet( EVENT::LCIO::THBIT_MOMENTUM ) ){
38  SIO_DATA( device , hit->_p , 3 ) ;
39  if( vers > SIO_VERSION_ENCODE( 1 , 6 ) ) {
40  SIO_DATA( device , &(hit->_pathLength) , 1 ) ;
41  }
42  }
43  if( vers > SIO_VERSION_ENCODE( 2, 7 ) ) {
44  SIO_DATA( device , &(hit->_quality) , 1 ) ;
45  }
46  // read the pointer tag in case we want to point to hits
47  if( vers > SIO_VERSION_ENCODE( 1, 0) ) {
48  SIO_PTAG( device , dynamic_cast<const EVENT::SimTrackerHit*>(hit) ) ;
49  }
50  }
51 
52  //----------------------------------------------------------------------------
53 
54  void SIOSimTrackHitHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
55  auto hit = dynamic_cast<const EVENT::SimTrackerHit*>(obj) ;
56  IMPL::LCFlagImpl lcFlag(_flag) ;
57  SIO_SDATA( device, hit->getCellID0() ) ;
58  if( lcFlag.bitSet( EVENT::LCIO::THBIT_ID1 ) ) {
59  SIO_SDATA( device, hit->getCellID1() ) ;
60  }
61  SIO_DATA( device, hit->getPosition() , 3 ) ;
62  SIO_SDATA( device, hit->getEDep() ) ;
63  SIO_SDATA( device, hit->getTime() ) ;
64  auto part = hit->getMCParticle() ;
65  SIO_PNTR( device , &part ) ;
66  if( lcFlag.bitSet( EVENT::LCIO::THBIT_MOMENTUM ) ){
67  SIO_DATA( device , hit->getMomentum() , 3 ) ;
68  SIO_SDATA( device , hit->getPathLength() ) ;
69  }
70  SIO_SDATA( device, hit->getQuality() ) ;
71  // write a ptag in order to be able to point to tracker hits - from v1.1
72  SIO_PTAG( device , hit ) ;
73  }
74 
75  //----------------------------------------------------------------------------
76 
78  return new IOIMPL::SimTrackerHitIOImpl() ;
79  }
80 
81 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
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.
virtual bool bitSet(int index) const
Returns true if bit at given index is set.
Definition: LCFlagImpl.cc:13
A generic simulated tracker hit.
Definition: SimTrackerHit.h:23
Adding stuff needed for io (friend declarations, etc.)
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