Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InttRawDataDecoder.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InttRawDataDecoder.cc
1 #include "InttRawDataDecoder.h"
2 #include "InttMapping.h"
3 
4 #include <Event/Event.h>
5 #include <Event/packet.h>
6 
8 #include "fun4all/SubsysReco.h" // for SubsysReco
9 
10 #include <phool/PHCompositeNode.h>
11 #include <phool/PHNodeIterator.h>
12 #include <phool/getClass.h>
13 #include <phool/phool.h> // for PHWHERE
14 
15 #include <trackbase/InttDefs.h>
16 #include <trackbase/TrkrDefs.h> // for hitkey, hitsetkey
17 #include <trackbase/TrkrHit.h>
18 #include <trackbase/TrkrHitSet.h>
21 #include <trackbase/TrkrHitv2.h>
22 
23 #include <cstdlib> // for exit
24 #include <iostream> // for operator<<, endl, cout
25 #include <map> // for map, operator!=, _Rb_tr...
26 #include <utility> // for pair
27 
29  : SubsysReco(name)
30 {
31  // Do nothing
32 }
33 
34 // Init
36 {
37  // Do nothing
39 }
40 
41 // InitRun
43 {
44  if (!topNode)
45  {
46  std::cout << "InttRawDataDecoder::InitRun(PHCompositeNode* topNode)" << std::endl;
47  std::cout << "\tCould not retrieve topNode; doing nothing" << std::endl;
48 
49  return -1;
50  }
51 
52  PHNodeIterator dst_itr(topNode);
53  PHCompositeNode* dst_node = dynamic_cast<PHCompositeNode*>(dst_itr.findFirst("PHCompositeNode", "DST"));
54  if (!dst_node)
55  {
56  if (Verbosity())
57  {
58  std::cout << "InttRawDataDecoder::InitRun(PHCompositeNode* topNode)" << std::endl;
59  }
60  if (Verbosity())
61  {
62  std::cout << "\tCould not retrieve dst_node; doing nothing" << std::endl;
63  }
64 
65  return -1;
66  }
67 
68  PHNodeIterator trkr_itr(dst_node);
69  PHCompositeNode* trkr_node = dynamic_cast<PHCompositeNode*>(trkr_itr.findFirst("PHCompositeNode", "TRKR"));
70  if (!trkr_node)
71  {
72  trkr_node = new PHCompositeNode("TRKR");
73  dst_node->addNode(trkr_node);
74  }
75 
76  TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
77  if (!trkr_hit_set_container)
78  {
79  if (Verbosity())
80  {
81  std::cout << "InttRawDataDecoder::InitRun(PHCompositeNode* topNode)" << std::endl;
82  }
83  if (Verbosity())
84  {
85  std::cout << "\tMaking TrkrHitSetContainer" << std::endl;
86  }
87 
88  trkr_hit_set_container = new TrkrHitSetContainerv1;
89  PHIODataNode<PHObject>* new_node = new PHIODataNode<PHObject>(trkr_hit_set_container, "TRKR_HITSET", "PHObject");
90  trkr_node->addNode(new_node);
91  }
92 
94 }
95 
96 // process_event
98 {
99  TrkrHitSetContainer* trkr_hit_set_container = findNode::getClass<TrkrHitSetContainer>(topNode, "TRKR_HITSET");
100  if (!trkr_hit_set_container)
101  {
102  std::cout << PHWHERE << std::endl;
103  std::cout << "InttRawDataDecoder::process_event(PHCompositeNode* topNode)" << std::endl;
104  std::cout << "Could not get \"TRKR_HITSET\" from Node Tree" << std::endl;
105  std::cout << "Exiting" << std::endl;
106  exit(1);
107 
109  }
110 
111  Event* evt = findNode::getClass<Event>(topNode, "PRDF");
112  if (!evt)
113  {
115  }
116 
117  struct InttNameSpace::RawData_s rawdata;
118  struct InttNameSpace::Offline_s offline;
119 
120  int adc = 0;
121  // int amp = 0;
122  int bco = 0;
123 
124  TrkrDefs::hitsetkey hit_set_key = 0;
125  TrkrDefs::hitkey hit_key = 0;
126  TrkrHitSetContainer::Iterator hit_set_container_itr;
127  TrkrHit* hit = nullptr;
128 
129  for (auto itr : InttNameSpace::Packet_Id)
130  {
131  Packet* p = evt->getPacket(itr.first);
132  if (!p)
133  {
134  continue;
135  }
136 
137  int N = p->iValue(0, "NR_HITS");
138  full_bco = p->lValue(0, "BCO");
139 
140  if (Verbosity() > 20)
141  {
142  std::cout << N << std::endl;
143  }
144 
145  for (int n = 0; n < N; ++n)
146  {
147  rawdata = InttNameSpace::RawFromPacket(itr.second, n, p);
148 
149  adc = p->iValue(n, "ADC");
150  // amp = p->iValue(n, "AMPLITUE");
151  bco = p->iValue(n, "FPHX_BCO");
152 
153  offline = InttNameSpace::ToOffline(rawdata);
154 
155  hit_key = InttDefs::genHitKey(offline.strip_y, offline.strip_x); // col, row <trackbase/InttDefs.h>
156  hit_set_key = InttDefs::genHitSetKey(offline.layer, offline.ladder_z, offline.ladder_phi, bco);
157 
158  hit_set_container_itr = trkr_hit_set_container->findOrAddHitSet(hit_set_key);
159  hit = hit_set_container_itr->second->getHit(hit_key);
160  if (hit)
161  {
162  continue;
163  }
164 
165  hit = new TrkrHitv2;
166  hit->setAdc(adc);
167  hit_set_container_itr->second->addHitSpecificKey(hit_key, hit);
168  }
169 
170  delete p;
171  }
172 
173  if (Verbosity() > 20)
174  {
175  std::cout << std::endl;
176  std::cout << "Identify():" << std::endl;
177  trkr_hit_set_container->identify();
178  std::cout << std::endl;
179  }
180 
182 }
183 
184 // End
186 {
187  // Do nothing
189 }