LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOSimCalHitHandler.cc
Go to the documentation of this file.
2 
3 // -- lcio headers
4 #include "EVENT/LCIO.h"
5 #include "EVENT/MCParticle.h"
9 #include "IMPL/LCFlagImpl.h"
10 
11 // -- sio headers
12 #include <sio/io_device.h>
13 #include <sio/version.h>
14 
15 namespace SIO {
16 
18  SIOObjectHandler( EVENT::LCIO::SIMCALORIMETERHIT ) {
19  /* nop */
20  }
21 
22  //----------------------------------------------------------------------------
23 
24  void SIOSimCalHitHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
25  auto hit = dynamic_cast<IOIMPL::SimCalorimeterHitIOImpl*>( objP ) ;
27  SIO_DATA( device , &(hit->_cellID0) , 1 ) ;
28  // in v00-08 cellid1 has been stored by default
29  if( flag.bitSet( EVENT::LCIO::CHBIT_ID1 ) || ( SIO_VERSION_MAJOR(vers)==0 && SIO_VERSION_MINOR(vers)==8) ) {
30  SIO_DATA( device , &(hit->_cellID1) , 1 ) ;
31  }
32  SIO_DATA( device , &(hit->_energy) , 1 ) ;
33  if( flag.bitSet( EVENT::LCIO::CHBIT_LONG ) ) {
34  SIO_DATA( device , hit->_position , 3 ) ;
35  }
36  // read MCContributions
37  int nCon ;
38  SIO_DATA( device , &nCon , 1 ) ;
39  hit->_vec.reserve(nCon) ;
40  for(int i=0; i< nCon ; i++) {
41  auto mcCon = new IMPL::MCParticleCont ;
42  SIO_PNTR( device , &(mcCon->Particle) ) ;
43  SIO_DATA( device , &(mcCon->Energy) , 1 ) ;
44  SIO_DATA( device , &(mcCon->Time) , 1 ) ;
45  if( flag.bitSet( EVENT::LCIO::CHBIT_STEP )) {
46  if( vers > SIO_VERSION_ENCODE( 2, 10 ) ) {
47  SIO_DATA( device , &(mcCon->Length) , 1 ) ;
48  }
49  SIO_DATA( device , &(mcCon->PDG) , 1 ) ;
50  if( vers > SIO_VERSION_ENCODE( 1, 51 ) ) {
51  SIO_DATA( device , &(mcCon->StepPosition[0]) , 1 ) ;
52  SIO_DATA( device , &(mcCon->StepPosition[1]) , 1 ) ;
53  SIO_DATA( device , &(mcCon->StepPosition[2]) , 1 ) ;
54  }
55  }
56  hit->_vec.push_back( mcCon );
57  }
58  // read a pointer tag for reference to calorimeter hits
59  if( vers > SIO_VERSION_ENCODE( 1, 0) ) {
60  SIO_PTAG( device , dynamic_cast<const EVENT::SimCalorimeterHit*>(hit) ) ;
61  }
62  }
63 
64  //----------------------------------------------------------------------------
65 
66  void SIOSimCalHitHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
67  auto hit = dynamic_cast<const EVENT::SimCalorimeterHit*>(obj) ;
68  SIO_SDATA( device, hit->getCellID0() ) ;
70  if( flag.bitSet( EVENT::LCIO::CHBIT_ID1 ) ){
71  SIO_SDATA( device, hit->getCellID1() ) ;
72  }
73  SIO_SDATA( device, hit->getEnergy() ) ;
74  if( flag.bitSet( EVENT::LCIO::CHBIT_LONG ) ){
75  SIO_DATA( device, hit->getPosition() , 3 ) ;
76  }
77  // now the MCParticle contributions
78  int nMC = hit->getNMCContributions() ;
79  SIO_DATA( device, &nMC , 1 ) ;
80  for(int i=0; i<nMC ;i++) {
81  auto part = hit->getParticleCont(i) ;
82  SIO_PNTR( device , &part ) ;
83  SIO_SDATA( device, hit->getEnergyCont(i) ) ;
84  SIO_SDATA( device, hit->getTimeCont(i) ) ;
85  if( flag.bitSet( EVENT::LCIO::CHBIT_STEP ) ) {
86  SIO_SDATA( device, hit->getLengthCont(i) ) ;
87  SIO_SDATA( device, hit->getPDGCont(i) ) ;
88  float* sp = const_cast<float*> ( hit->getStepPosition(i) ) ;
89  SIO_DATA( device, sp , 3 ) ;
90  }
91  }
92  // add a pointer tag for reference to sim. calorimeter hits - added in v1.1
93  SIO_PTAG( device , hit ) ;
94  }
95 
96  //----------------------------------------------------------------------------
97 
99  return new IOIMPL::SimCalorimeterHitIOImpl() ;
100  }
101 
102 } // namespace
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
The generic simulated calorimeter hit.
EVENT::LCObject * create() const override
Factory method to create an object of the type of the collection.
virtual bool bitSet(int index) const
Returns true if bit at given index is set.
Definition: LCFlagImpl.cc:13
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.
unsigned int flag() const
Get the collection flag.
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.)