Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericUnpackPRDF.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GenericUnpackPRDF.cc
1 #include "GenericUnpackPRDF.h"
2 
3 #include "PROTOTYPE4_FEM.h"
4 #include "RawTower_Prototype4.h"
5 
6 #include <calobase/RawTower.h> // for RawTower
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerDefs.h> // for NONE
9 
10 #include <fun4all/Fun4AllBase.h> // for Fun4AllBase::VERBOSITY_SOME
12 #include <fun4all/SubsysReco.h> // for SubsysReco
13 
14 #include <phool/PHCompositeNode.h>
15 #include <phool/PHIODataNode.h> // for PHIODataNode
16 #include <phool/PHNodeIterator.h> // for PHNodeIterator
17 #include <phool/PHObject.h> // for PHObject
18 #include <phool/getClass.h>
19 
20 #include <Event/Event.h>
21 #include <Event/EventTypes.h>
22 #include <Event/packet.h>
23 
24 #include <cassert>
25 #include <cmath> // for NAN
26 #include <cstdlib> // for exit
27 #include <iostream>
28 #include <string>
29 
30 using namespace std;
31 
32 //____________________________________
34  : SubsysReco("GenericUnpackPRDF_" + detector)
35  , //
36  _detector(detector)
37  , _towers(nullptr)
38 {
39 }
40 
41 //_____________________________________
43 {
44  CreateNodeTree(topNode);
46 }
47 
48 //____________________________________
50 {
51  Event *_event = findNode::getClass<Event>(topNode, "PRDF");
52  if (!_event)
53  {
54  if (Verbosity() >= VERBOSITY_SOME)
55  cout << "GenericUnpackPRDF::Process_Event - Event not found" << endl;
57  }
58 
59  if (Verbosity() >= VERBOSITY_SOME)
60  _event->identify();
61 
62  // search for data event
63  if (_event->getEvtType() != DATAEVENT)
65 
66  map<int, Packet *> packet_list;
67 
68  for (channel_map::const_iterator it = _channel_map.begin();
69  it != _channel_map.end(); ++it)
70  {
71  const int packet_id = it->first.first;
72  const int channel = it->first.second;
73  const int tower_id = it->second;
74 
75  if (packet_list.find(packet_id) == packet_list.end())
76  {
77  packet_list[packet_id] = _event->getPacket(packet_id);
78 
79  if (packet_list[packet_id] and Verbosity() >= VERBOSITY_MORE)
80  {
81  cout << "GenericUnpackPRDF::process_event - open packet " << packet_id
82  << ":" << endl;
83  // packet_list[packet_id]->identify(cout);
84  packet_list[packet_id]->dump(cout);
85  }
86  }
87 
88  Packet *packet = packet_list[packet_id];
89 
90  if (!packet)
91  {
92  // if (Verbosity() >= VERBOSITY_SOME)
93  cout << "GenericUnpackPRDF::process_event - failed to locate packet "
94  << packet_id << endl;
95  continue;
96  }
97  assert(packet);
98 
99  // packet->setNumSamples(PROTOTYPE4_FEM::NSAMPLES);
100 
102  dynamic_cast<RawTower_Prototype4 *>(_towers->getTower(tower_id));
103  if (!tower)
104  {
105  tower = new RawTower_Prototype4();
106  tower->set_energy(NAN);
107  _towers->AddTower(tower_id, tower);
108  }
109  tower->set_HBD_channel_number(channel);
110  for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
111  {
112  tower->set_signal_samples(isamp, (packet->iValue(isamp, channel)) &
114  }
115  }
116 
117  for (map<int, Packet *>::iterator it = packet_list.begin();
118  it != packet_list.end(); ++it)
119  {
120  if (it->second)
121  delete it->second;
122  }
123 
125 }
126 
127 //_______________________________________
129 {
130  PHNodeIterator nodeItr(topNode);
131  // DST node
132  PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
133  nodeItr.findFirst("PHCompositeNode", "DST"));
134  if (!dst_node)
135  {
136  cout << "PHComposite node created: DST" << endl;
137  dst_node = new PHCompositeNode("DST");
138  topNode->addNode(dst_node);
139  }
140 
141  // DATA nodes
142  PHCompositeNode *data_node = static_cast<PHCompositeNode *>(
143  nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
144  if (!data_node)
145  {
146  if (Verbosity())
147  cout << "PHComposite node created: RAW_DATA" << endl;
148  data_node = new PHCompositeNode("RAW_DATA");
149  dst_node->addNode(data_node);
150  }
151 
152  // output as towers
154  PHIODataNode<PHObject> *towerNode =
155  new PHIODataNode<PHObject>(_towers, "TOWER_RAW_" + _detector, "PHObject");
156  data_node->addNode(towerNode);
157 }
158 
159 void GenericUnpackPRDF::add_channel(const int packet_id,
160  const int channel,
161  const int tower_id
162 )
163 {
164  channel_typ hbd_channel(packet_id, channel);
165 
166  if (_channel_map.find(hbd_channel) != _channel_map.end())
167  {
168  cout << "GenericUnpackPRDF::add_channel - packet " << packet_id
169  << ", channel " << channel << " is already registered as tower "
170  << _channel_map.find(hbd_channel)->second << endl;
171  exit(12);
172  }
173  _channel_map[hbd_channel] = tower_id;
174 }