LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOCalHitHandler.cc
Go to the documentation of this file.
1 #include "SIO/SIOCalHitHandler.h"
2 
3 // -- lcio headers
4 #include "EVENT/LCIO.h"
5 #include "EVENT/CalorimeterHit.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::CALORIMETERHIT ) {
17  /* nop */
18  }
19 
20  //----------------------------------------------------------------------------
21 
22  void SIOCalHitHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
23  IMPL::LCFlagImpl lcFlag( _flag ) ;
24  IOIMPL::CalorimeterHitIOImpl *hit = dynamic_cast<IOIMPL::CalorimeterHitIOImpl *>(objP) ;
25  SIO_DATA( device , &(hit->_cellID0) , 1 ) ;
26  // in v00-08 cellid1 has been stored by default
27  if( lcFlag.bitSet( EVENT::LCIO::RCHBIT_ID1 ) || ( SIO_VERSION_MAJOR(vers)==0 && SIO_VERSION_MINOR(vers)==8) ) {
28  SIO_DATA( device , &(hit->_cellID1) , 1 ) ;
29  }
30  SIO_DATA( device , &(hit->_energy) , 1 ) ;
31  if( vers > SIO_VERSION_ENCODE( 1, 9 ) && lcFlag.bitSet( EVENT::LCIO::RCHBIT_ENERGY_ERROR )) {
32  SIO_DATA( device , &(hit->_energyError) , 1 ) ;
33  }
34  if( vers > SIO_VERSION_ENCODE( 1, 2) && lcFlag.bitSet( EVENT::LCIO::RCHBIT_TIME ) ) {
35  SIO_DATA( device , &(hit->_time) , 1 ) ;
36  }
37  if( lcFlag.bitSet( EVENT::LCIO::RCHBIT_LONG ) ) {
38  SIO_DATA( device , &hit->_position[0] , 3 ) ;
39  }
40  if( vers > SIO_VERSION_ENCODE( 1, 2) ) {
41  SIO_DATA( device , &(hit->_type) , 1 ) ;
42  SIO_PNTR( device , &(hit->_rawHit) ) ;
43  }
44  // read a pointer tag for future reference to calorimeter hits
45  if( vers > SIO_VERSION_ENCODE( 1, 2) ) { // the logic of the pointer bit has been inverted in v1.3
46  if( ! lcFlag.bitSet( EVENT::LCIO::RCHBIT_NO_PTR ) ) {
47  SIO_PTAG( device , dynamic_cast<const EVENT::CalorimeterHit*>(hit) ) ;
48  }
49  }
50  else {
51  if( lcFlag.bitSet( EVENT::LCIO::RCHBIT_NO_PTR ) ) {
52  SIO_PTAG( device , dynamic_cast<const EVENT::CalorimeterHit*>(hit) ) ;
53  }
54  }
55  }
56 
57  //----------------------------------------------------------------------------
58 
59  void SIOCalHitHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
60  const EVENT::CalorimeterHit* hit = dynamic_cast<const EVENT::CalorimeterHit*>(obj) ;
61  IMPL::LCFlagImpl lcFlag(_flag) ;
62  SIO_SDATA( device, hit->getCellID0() ) ;
63  if( lcFlag.bitSet( EVENT::LCIO::RCHBIT_ID1 ) ) {
64  SIO_SDATA( device, hit->getCellID1() ) ;
65  }
66  SIO_SDATA( device, hit->getEnergy() ) ;
67  if( lcFlag.bitSet( EVENT::LCIO::RCHBIT_ENERGY_ERROR ) ) {
68  SIO_SDATA( device, hit->getEnergyError() ) ;
69  }
70  if( lcFlag.bitSet( EVENT::LCIO::RCHBIT_TIME ) ) {
71  SIO_SDATA( device , hit->getTime() ) ;
72  }
73  if( lcFlag.bitSet( EVENT::LCIO::RCHBIT_LONG ) ) {
74  SIO_DATA( device, hit->getPosition() , 3 ) ;
75  }
76  SIO_SDATA( device , hit->getType() ) ;
77  EVENT::LCObject *rawHit = hit->getRawHit() ;
78  SIO_PNTR( device , &rawHit ) ;
79  if( !lcFlag.bitSet( EVENT::LCIO::RCHBIT_NO_PTR ) ) {
80  SIO_PTAG( device , hit ) ;
81  }
82  }
83 
84  //----------------------------------------------------------------------------
85 
87  return new IOIMPL::CalorimeterHitIOImpl() ;
88  }
89 
90 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
virtual int getCellID0() const =0
Returns the detector specific (geometrical) cell id.
SIOCalHitHandler()
Constructor.
virtual bool bitSet(int index) const
Returns true if bit at given index is set.
Definition: LCFlagImpl.cc:13
virtual float getTime() const =0
Returns the time of the hit in [ns].
virtual LCObject * getRawHit() const =0
The RawCalorimeterHit.
virtual float getEnergyError() const =0
Returns the error of the hit energy in [GeV].
virtual int getCellID1() const =0
Returns the second detector specific (geometrical) cell id.
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
unsigned int _flag
The collection flag.
virtual const float * getPosition() const =0
Returns the position of the hit in world coordinates.
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.
Implementation of helper class to create and interpret the 32-bit flag word in LCCollections.
Definition: LCFlagImpl.h:15
Adding stuff needed for io (friend declarations, etc.)
virtual int getType() const =0
Type of hit.
void write(sio::write_device &device, const EVENT::LCObject *obj) override
Writes lcio objects to an SIO stream.
virtual float getEnergy() const =0
Returns the energy of the hit in [GeV].
The generic calorimeter hit - created from SimCalorimeterHit or RawCalorimeterHit.