Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunInfoUnpackPRDF.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RunInfoUnpackPRDF.cc
1 #include "RunInfoUnpackPRDF.h"
2 
3 #include "PROTOTYPE4_FEM.h"
4 
6 
7 #include <phparameter/PHParameters.h>
8 
9 #include <pdbcalbase/PdbParameterMap.h>
10 
11 #include <fun4all/Fun4AllBase.h> // for Fun4AllBase::VERBOSITY_SOME
13 #include <fun4all/SubsysReco.h> // for SubsysReco
14 
15 #include <phool/PHCompositeNode.h>
16 #include <phool/PHIODataNode.h> // for PHIODataNode
17 #include <phool/PHNodeIterator.h> // for PHNodeIterator
18 #include <phool/PHObject.h> // for PHObject
19 #include <phool/getClass.h>
20 
21 #include <Event/Event.h>
22 #include <Event/EventTypes.h>
23 #include <Event/packet.h>
24 
25 #include <cmath> // for NAN
26 #include <iostream>
27 #include <string>
28 #include <utility> // for pair, make_pair
29 
30 using namespace std;
31 
32 //____________________________________
34  : SubsysReco("RunInfoUnpackPRDF")
35  , runinfo_node_name("RUN_INFO")
36 {
37 }
38 
39 //_____________________________________
41 {
42  CreateNodeTree(topNode);
44 }
45 
46 //____________________________________
48 {
49  Event *event = findNode::getClass<Event>(topNode, "PRDF");
50  if (!event)
51  {
52  if (Verbosity() >= VERBOSITY_SOME)
53  cout << "RunInfoUnpackPRDF::Process_Event - Event not found" << endl;
55  }
56 
57  // construct event info
58  EventHeaderv1 *eventheader =
59  findNode::getClass<EventHeaderv1>(topNode, "EventHeader");
60  if (eventheader)
61  {
62  eventheader->set_RunNumber(event->getRunNumber());
63  eventheader->set_EvtSequence(event->getEvtSequence());
64  eventheader->set_EvtType(event->getEvtType());
65  eventheader->set_TimeStamp(event->getTime());
66  if (Verbosity())
67  {
68  eventheader->identify();
69  }
70  }
71 
72  // search for run info
73  if (event->getEvtType() != BEGRUNEVENT)
75  else
76  {
77  if (Verbosity() >= VERBOSITY_SOME)
78  {
79  cout << "RunInfoUnpackPRDF::process_event - with BEGRUNEVENT events ";
80  event->identify();
81  }
82 
83  map<int, Packet *> packet_list;
84 
85  PHParameters Params("RunInfo");
86 
87  // special treatment for EMCal tagging packet
88  // https://wiki.bnl.gov/sPHENIX/index.php/2017_calorimeter_beam_test#What_is_new_in_the_data_structures_in_2017
89  {
90  int has_new_EMCal = 0;
91 
93  {
94  // react properly - new emcal!
95  has_new_EMCal = 1;
96  }
97 
98  Params.set_double_param("EMCAL_Is_HighEta", has_new_EMCal);
99  Params.set_int_param("EMCAL_Is_HighEta", has_new_EMCal);
100  }
101 
102  // generic packets
103  for (typ_channel_map::const_iterator it = channel_map.begin();
104  it != channel_map.end(); ++it)
105  {
106  const string &name = it->first;
107  const channel_info &info = it->second;
108 
109  if (packet_list.find(info.packet_id) == packet_list.end())
110  {
111  packet_list[info.packet_id] = event->getPacket(info.packet_id);
112  }
113 
114  Packet *packet = packet_list[info.packet_id];
115 
116  if (!packet)
117  {
118  // if (Verbosity() >= VERBOSITY_SOME)
119  cout << "RunInfoUnpackPRDF::process_event - failed to locate packet "
120  << info.packet_id << " from ";
121  event->identify();
122 
123  Params.set_double_param(name, NAN);
124  continue;
125  }
126 
127  const int ivalue = packet->iValue(info.offset);
128 
129  const double dvalue = ivalue * info.calibration_const;
130 
131  if (Verbosity() >= VERBOSITY_SOME)
132  {
133  cout << "RunInfoUnpackPRDF::process_event - " << name << " = " << dvalue
134  << ", raw = " << ivalue << " @ packet " << info.packet_id
135  << ", offset " << info.offset << endl;
136  }
137 
138  Params.set_double_param(name, dvalue);
139  }
140 
141  for (map<int, Packet *>::iterator it = packet_list.begin();
142  it != packet_list.end(); ++it)
143  {
144  if (it->second)
145  delete it->second;
146  }
147 
148  Params.SaveToNodeTree(topNode, runinfo_node_name);
149 
150  if (Verbosity() >= VERBOSITY_SOME)
151  Params.Print();
152  }
154 }
155 
156 //_______________________________________
158 {
159  PHNodeIterator nodeItr(topNode);
160  // DST node
161  PHCompositeNode *run_node = static_cast<PHCompositeNode *>(
162  nodeItr.findFirst("PHCompositeNode", "RUN"));
163  if (!run_node)
164  {
165  cout << "PHComposite node created: RUN" << endl;
166  run_node = new PHCompositeNode("RUN");
167  topNode->addNode(run_node);
168  }
169 
170  PdbParameterMap *nodeparams =
171  findNode::getClass<PdbParameterMap>(run_node, runinfo_node_name);
172  if (not nodeparams)
173  {
174  run_node->addNode(new PHIODataNode<PdbParameterMap>(new PdbParameterMap(),
176  }
177 
178  // DST node
179  PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
180  nodeItr.findFirst("PHCompositeNode", "DST"));
181  if (!dst_node)
182  {
183  cout << "PHComposite node created: DST" << endl;
184  dst_node = new PHCompositeNode("DST");
185  topNode->addNode(dst_node);
186  }
187 
188  EventHeaderv1 *eventheader = new EventHeaderv1();
189  PHIODataNode<PHObject> *EventHeaderNode = new PHIODataNode<PHObject>(
190  eventheader, "EventHeader", "PHObject"); // contain PHObject
191  dst_node->addNode(EventHeaderNode);
192 }
193 
195  const std::string &name,
196  const int packet_id,
197  const unsigned int offset,
198  const double calibration_const
199 
200 )
201 {
202  channel_map.insert(
203  make_pair(name, channel_info(packet_id, offset, calibration_const)));
204 }