Class Reference for E1039 Core & Analysis Software
PHG4InEventReadBack.cc
Go to the documentation of this file.
1 #include "PHG4InEventReadBack.h"
2 #include "PHG4InEvent.h"
3 #include "PHG4Particlev1.h"
4 #include "PHG4VtxPointv1.h"
5 
9 
11 
12 #include <phool/getClass.h>
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h>
15 #include <phool/phool.h>
16 
17 #include <cstdlib>
18 #include <iostream>
19 #include <vector>
20 
21 using namespace std;
22 
24 {}
25 
26 int
28 {
29  PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode,"PHG4INEVENT");
30  if (!ineve)
31  {
32  PHNodeIterator iter( topNode );
33  PHCompositeNode *dstNode;
34  dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST" ));
35 
36  ineve = new PHG4InEvent();
37  PHIODataNode<PHObject> *newNode = new PHIODataNode<PHObject>(ineve, "PHG4INEVENT", "PHObject");
38  dstNode->addNode(newNode);
39  }
40 
42 }
43 
44 int
46 {
47  PHG4InEvent *inEvent = findNode::getClass<PHG4InEvent>(topNode,"PHG4INEVENT");
48  if (!inEvent)
49  {
50  cout << "no PHG4INEVENT node found" << endl;
52  }
53  VariableArray *vtxarray = findNode::getClass<VariableArray>(topNode,"PHG4Vtx_VarArray");
54  if (!vtxarray)
55  {
56  cout << "no PHG4Vtx_VarArray node found" << endl;
58  }
59 
60  VariableArray *particlearray = findNode::getClass<VariableArray>(topNode,"PHG4Particle_VarArray");
61  if (!particlearray)
62  {
63  cout << "no PHG4Particle_VarArray node found" << endl;
65  }
66  inEvent->Reset();
67  unsigned int size = vtxarray->get_array_size();
68  const short int *sval = vtxarray->get_array();
69  PHG4VtxPointv1 vtx;
70  while(size > 0)
71  {
72  int vtxid = *sval++;
73  size --;
75  size --;
77  size --;
79  size--;
81  size--;
82  inEvent->AddVtx(vtxid,vtx);
83  }
84 
85  size = particlearray->get_array_size();
86  sval = particlearray->get_array();
87  while(size > 0)
88  {
89  PHG4Particle *particle = new PHG4Particlev1();
90  int vtxid = *sval++;
91  size --;
92  particle->set_pid(*sval++);
93  size --;
94  particle->set_px(VariableArrayUtils::ShortBitsToFloat(*sval++));
95  size --;
96  particle->set_py(VariableArrayUtils::ShortBitsToFloat(*sval++));
97  size --;
98  particle->set_pz(VariableArrayUtils::ShortBitsToFloat(*sval++));
99  size --;
100  inEvent->AddParticle(vtxid, particle);
101  }
102  // inEvent->identify();
104 }
105 
106 int
108 {
110 }
PHBoolean addNode(PHNode *)
PHG4InEventReadBack(const std::string &name="PHG4InEventReadBack")
int process_event(PHCompositeNode *topNode)
int InitRun(PHCompositeNode *topNode)
int End(PHCompositeNode *topNode)
Called at the end of all processing.
int AddParticle(const int vtxid, PHG4Particle *particle)
Definition: PHG4InEvent.cc:63
int AddVtx(const double x, const double y, const double z, const double t)
Definition: PHG4InEvent.cc:38
void Reset()
Clear Event.
Definition: PHG4InEvent.cc:88
virtual void set_pid(const int i)
Definition: PHG4Particle.h:33
virtual void set_py(const double x)
Definition: PHG4Particle.h:35
virtual void set_px(const double x)
Definition: PHG4Particle.h:34
virtual void set_pz(const double x)
Definition: PHG4Particle.h:36
void set_y(const double r)
void set_t(const double r)
void set_z(const double r)
void set_x(const double r)
PHNode * findFirst(const std::string &, const std::string &)
static float ShortBitsToFloat(const short ival)
unsigned int get_array_size() const
Definition: VariableArray.h:18
const short int * get_array() const
Definition: VariableArray.h:17