LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOClusterHandler.cc
Go to the documentation of this file.
2 
3 // -- lcio headers
4 #include "EVENT/LCIO.h"
6 #include "IOIMPL/ClusterIOImpl.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::CLUSTER ) {
17 
18  }
19 
20  //----------------------------------------------------------------------------
21 
22  void SIOClusterHandler::read( sio::read_device& device, EVENT::LCObject* objP, sio::version_type vers ) {
23  IOIMPL::ClusterIOImpl* cluster = dynamic_cast<IOIMPL::ClusterIOImpl*>(objP) ;
24  // type is bitset<32> - can't be set directly
25  int type ;
26  SIO_DATA( device , &type , 1 ) ;
27  cluster->setType( type ) ;
28  SIO_DATA( device , &(cluster->_energy) , 1 ) ;
29  if( vers > SIO_VERSION_ENCODE( 1, 51 ) ) {
30  SIO_DATA( device , &(cluster->_energyError) , 1 ) ;
31  }
32  SIO_DATA( device , cluster->_position , 3 ) ;
33  float errpos[ NERRPOS ] ;
34  SIO_DATA( device , &errpos[0] , NERRPOS ) ;
35  cluster->setPositionError( errpos ) ;
36  SIO_DATA( device , &(cluster->_theta) , 1 ) ;
37  SIO_DATA( device , &(cluster->_phi) , 1 ) ;
38  float errdir[ NERRDIR ] ;
39  SIO_DATA( device , &errdir[0] , NERRDIR ) ;
40  cluster->setDirectionError( errdir ) ;
41  int nShape ;
42  if( vers > SIO_VERSION_ENCODE(1,2) ) {
43  SIO_DATA( device , &nShape , 1 ) ;
44  }
45  else {
46  nShape = NSHAPE_OLD ;
47  }
48  cluster->_shape.resize( nShape ) ;
49  SIO_DATA( device , &(cluster->_shape[0]) ,nShape ) ;
50  if( vers > SIO_VERSION_ENCODE(1,2) ) {
51  // read PIDs
52  int nPid ;
53  SIO_DATA( device , &nPid , 1 ) ;
54  for(int i=0;i<nPid;i++) {
55  // create new Pid objects
57  SIO_DATA( device , &(pid->_likelihood) , 1 ) ;
58  SIO_DATA( device , &(pid->_type) , 1 ) ;
59  SIO_DATA( device , &(pid->_pdg) , 1 ) ;
60  SIO_DATA( device , &(pid->_algorithmType) , 1 ) ;
61  int nPara ;
62  SIO_DATA( device , &nPara , 1 ) ;
63  float aParameter ;
64  for(int j=0;j<nPara;j++) {
65  SIO_DATA( device , &aParameter , 1 ) ;
66  pid->addParameter( aParameter ) ;
67  }
68  cluster->addParticleID( pid) ;
69  }
70  }
71  else {
72  float pType[3] ;
73  SIO_DATA( device , pType , 3 ) ;
74  }
75  int nClusters ;
76  SIO_DATA( device, &nClusters , 1 ) ;
77  // fill the vector to have correct size
78  // as we are using the addresses of the elements henceforth
79  cluster->_clusters.resize( nClusters ) ;
80  for(int i=0;i<nClusters;i++) {
81  SIO_PNTR( device , &(cluster->_clusters[i] ) ) ;
82  }
83  if( IMPL::LCFlagImpl(_flag).bitSet( EVENT::LCIO::CLBIT_HITS ) ) {
84  int nHits ;
85  SIO_DATA( device, &nHits , 1 ) ;
86  cluster->_hits.resize( nHits ) ;
87  cluster->_weights.resize( nHits ) ;
88  for(int i=0;i<nHits;i++) {
89  SIO_PNTR( device , &(cluster->_hits[i] ) ) ;
90  SIO_DATA( device , &(cluster->_weights[i] ) , 1 ) ;
91  }
92  }
93  int nEnergies ;
94  SIO_DATA( device, &nEnergies , 1 ) ;
95  cluster->_subdetectorEnergies.resize( nEnergies ) ;
96  for(int i=0;i<nEnergies;i++){
97  SIO_DATA( device, &(cluster->_subdetectorEnergies[i] ) , 1 ) ;
98  }
99  // read the pointer tag
100  SIO_PTAG( device , dynamic_cast<const EVENT::Cluster*>(cluster) ) ;
101  }
102 
103  //----------------------------------------------------------------------------
104 
105  void SIOClusterHandler::write( sio::write_device& device, const EVENT::LCObject* obj ) {
106  // this is where we gave up type safety in order to
107  // simplify the API and the implementation
108  // by having a common collection of objects
109  const EVENT::Cluster* cluster = dynamic_cast<const EVENT::Cluster*>(obj) ;
110  SIO_SDATA( device, cluster->getType() ) ;
111  SIO_SDATA( device, cluster->getEnergy() ) ;
112  SIO_SDATA( device, cluster->getEnergyError() ) ;
113  SIO_DATA( device, cluster->getPosition() , 3 ) ;
114  auto& errpos = cluster->getPositionError() ;
115  for(unsigned int i=0;i<errpos.size();i++) {
116  SIO_SDATA( device, errpos[i] ) ;
117  }
118  SIO_SDATA( device, cluster->getITheta() ) ;
119  SIO_SDATA( device, cluster->getIPhi() ) ;
120  auto& errdir = cluster->getDirectionError() ;
121  for(unsigned int i=0;i<errdir.size();i++){
122  SIO_SDATA( device, errdir[i] ) ;
123  }
124  auto& shape = cluster->getShape() ;
125  int nshape = shape.size() ;
126  SIO_SDATA( device, nshape ) ;
127  for(unsigned int i=0;i<shape.size();i++){
128  SIO_SDATA( device, shape[i] ) ;
129  }
130  // write Pids
131  int nPid = cluster->getParticleIDs().size() ;
132  SIO_SDATA( device , nPid ) ;
133  for(int i=0;i<nPid;i++) {
134  auto pid = cluster->getParticleIDs()[i] ;
135  SIO_SDATA( device, pid->getLikelihood() ) ;
136  SIO_SDATA( device, pid->getType() ) ;
137  SIO_SDATA( device, pid->getPDG() ) ;
138  SIO_SDATA( device, pid->getAlgorithmType() ) ;
139  int nPara = pid->getParameters().size() ;
140  SIO_DATA( device , &nPara , 1 ) ;
141  for(int j=0;j<nPara;j++){
142  SIO_SDATA( device, pid->getParameters()[j] ) ;
143  }
144  }
145  auto& clusters = cluster->getClusters() ;
146  int nClusters = clusters.size() ;
147  SIO_DATA( device, &nClusters , 1 ) ;
148  for(int i=0;i<nClusters;i++) {
149  SIO_PNTR( device , &(clusters[i]) ) ;
150  }
151  if( IMPL::LCFlagImpl(_flag).bitSet( EVENT::LCIO::CLBIT_HITS ) ) {
152  auto& hits = cluster->getCalorimeterHits() ;
153  auto& weights = cluster->getHitContributions() ;
154  int nHits = hits.size() ;
155  SIO_DATA( device, &nHits , 1 ) ;
156  for(int i=0;i<nHits;i++){
157  SIO_PNTR( device , &(hits[i]) ) ;
158  SIO_SDATA( device , weights[i] ) ;
159  }
160  }
161  auto& subdetectorEnergies = cluster->getSubdetectorEnergies() ;
162  int nEnergies = subdetectorEnergies.size() ;
163  SIO_SDATA( device, nEnergies ) ;
164  for(int i=0;i<nEnergies;i++) {
165  SIO_SDATA( device, subdetectorEnergies[i] ) ;
166  }
167  // write a ptag in order to be able to point to clusters
168  SIO_PTAG( device , cluster ) ;
169  }
170 
171  //----------------------------------------------------------------------------
172 
174  return new IOIMPL::ClusterIOImpl() ;
175  }
176 
177 } // namespace
#define NERRDIR
Definition: ClusterImpl.h:11
The generic object that is held in an LCCollection.
Definition: LCObject.h:30
virtual float getITheta() const =0
Intrinsic direction of cluster at position: Theta.
EVENT::FloatVec _subdetectorEnergies
Definition: ClusterImpl.h:159
SIOClusterHandler()
Constructor.
void setPositionError(const EVENT::FloatVec &errpos)
Definition: ClusterImpl.cc:71
void setDirectionError(const EVENT::FloatVec &errdir)
Definition: ClusterImpl.cc:87
EVENT::FloatVec _shape
Definition: ClusterImpl.h:154
Adding stuff needed for io (friend declarations, etc.)
Definition: ClusterIOImpl.h:20
virtual const CalorimeterHitVec & getCalorimeterHits() const =0
The hits that have been combined to this cluster.
void write(sio::write_device &device, const EVENT::LCObject *obj)
Writes lcio objects to an SIO stream.
void read(sio::read_device &device, EVENT::LCObject *objP, sio::version_type vers)
Reads lcio objects from an SIO stream.
virtual const ClusterVec & getClusters() const =0
The clusters that have been combined to this cluster.
virtual const FloatVec & getHitContributions() const =0
Returns the energy contribution of the hits Runs parallel to the CalorimeterHitVec from getCalorimete...
Interface for all lcio object SIO-handlers, has to be implemented for all event entities (hits...
virtual const FloatVec & getPositionError() const =0
Covariance matrix of the position (6 Parameters)
unsigned int _flag
The collection flag.
EVENT::LCObject * create() const
Factory method to create an object of the type of the collection.
T resize(T...args)
virtual float getEnergyError() const =0
Returns the error on the energy of the cluster.
#define NERRPOS
Definition: ClusterImpl.h:10
void addParticleID(EVENT::ParticleID *pid)
Definition: ClusterImpl.cc:120
virtual const FloatVec & getDirectionError() const =0
Covariance matrix of the direction (3 Parameters).
EVENT::CalorimeterHitVec _hits
Definition: ClusterImpl.h:157
The LCIO cluster.
Definition: Cluster.h:30
virtual const ParticleIDVec & getParticleIDs() const =0
The particle Id&#39;s sorted by their likelihood.
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 const float * getPosition() const =0
Position of the cluster.
virtual int getType() const =0
Flagword that defines the type of cluster.
void setType(int type)
Definition: ClusterImpl.cc:55
T size(T...args)
void addParameter(float p)
EVENT::FloatVec _weights
Definition: ClusterImpl.h:158
virtual const FloatVec & getSubdetectorEnergies() const =0
A vector that holds the energy observed in a particular subdetectors.
virtual float getIPhi() const =0
Intrinsic direction of cluster at position: Phi.
virtual float getEnergy() const =0
Energy of the cluster.
EVENT::ClusterVec _clusters
Definition: ClusterImpl.h:156
float _position[3]
Definition: ClusterImpl.h:149
#define NSHAPE_OLD
Definition: ClusterImpl.h:13
virtual const FloatVec & getShape() const =0
Shape parameters - check/set collection parameter ClusterShapeParameters for size and names of parame...