LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOTPCHitHandler.cc
Go to the documentation of this file.
1 #include "SIO/SIOTPCHitHandler.h"
2 
3 // -- lcio headers
4 #include "EVENT/TPCHit.h"
5 #include "EVENT/LCIO.h"
6 #include "IMPL/LCFlagImpl.h"
7 #include "IOIMPL/TPCHitIOImpl.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::TPCHIT ) {
17  /* nop */
18  }
19 
20  //----------------------------------------------------------------------------
21 
22  void SIOTPCHitHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
23  auto hit = dynamic_cast<IOIMPL::TPCHitIOImpl*>( objP ) ;
24  SIO_DATA( device , &(hit->_cellID) , 1 ) ;
25  SIO_DATA( device , &(hit->_time) , 1 ) ;
26  SIO_DATA( device , &(hit->_charge) , 1 ) ;
27  SIO_DATA( device , &(hit->_quality) , 1 ) ;
28  IMPL::LCFlagImpl lcflag(_flag) ;
29  if( lcflag.bitSet( EVENT::LCIO::TPCBIT_RAW ) ){
30  SIO_DATA( device , &(hit->_rawSize) , 1 ) ;
31  hit->initRawArray( hit->_rawSize ) ; // reserve enough space for raw data
32  SIO_DATA( device , hit->_rawArray , hit->_rawSize ) ;
33  }
34  if( vers > SIO_VERSION_ENCODE( 1, 2 ) ) { // the logic of the pointer bit has been inverted in v1.3
35  if( ! lcflag.bitSet( EVENT::LCIO::TPCBIT_NO_PTR ) ) {
36  SIO_PTAG( device , dynamic_cast<const EVENT::TPCHit*>(hit) ) ;
37  }
38  }
39  else {
40  if( lcflag.bitSet( EVENT::LCIO::TPCBIT_NO_PTR ) ) {
41  SIO_PTAG( device , dynamic_cast<const EVENT::TPCHit*>(hit) ) ;
42  }
43  }
44  }
45 
46  //----------------------------------------------------------------------------
47 
48  void SIOTPCHitHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
49  auto hit = dynamic_cast<const EVENT::TPCHit*>(obj) ;
50  SIO_SDATA( device, hit->getCellID() ) ;
51  SIO_SDATA( device, hit->getTime() ) ;
52  SIO_SDATA( device, hit->getCharge() ) ;
53  SIO_SDATA( device, hit->getQuality() ) ;
54  IMPL::LCFlagImpl lcflag(_flag) ;
55  if( lcflag.bitSet( EVENT::LCIO::TPCBIT_RAW ) ) {
56  SIO_SDATA( device, hit->getNRawDataWords() ) ;
57  for(int i=0;i<hit->getNRawDataWords();i++){
58  SIO_SDATA( device, hit->getRawDataWord(i) ) ;
59  }
60  }
61  // add a pointer tag for reference to TPC hits from generic hits
62  if( ! lcflag.bitSet( EVENT::LCIO::TPCBIT_NO_PTR ) ) {
63  SIO_PTAG( device , hit ) ;
64  }
65  }
66 
67  //----------------------------------------------------------------------------
68 
70  return new IOIMPL::TPCHitIOImpl() ;
71  }
72 
73 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
SIOTPCHitHandler()
Constructor.
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
EVENT::LCObject * create() const override
Factory method to create an object of the type of the collection.
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
unsigned int _flag
The collection flag.
Deprecated.
Definition: TPCHit.h:22
void write(sio::write_device &device, const EVENT::LCObject *obj) override
Writes lcio objects to 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.)
Definition: TPCHitIOImpl.h:20