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 
4 
5 #include <pdbcalbase/PdbParameterMap.h>
6 
7 #include <phparameter/PHParameters.h>
8 
9 #include <fun4all/Fun4AllBase.h> // for Fun4AllBase::VERBOSITY_SOME
11 #include <fun4all/SubsysReco.h> // for SubsysReco
12 
13 #include <phool/PHCompositeNode.h>
14 #include <phool/PHIODataNode.h> // for PHIODataNode
15 #include <phool/PHNodeIterator.h> // for PHNodeIterator
16 #include <phool/PHObject.h> // for PHObject
17 #include <phool/getClass.h>
18 
19 #include <Event/Event.h>
20 #include <Event/EventTypes.h>
21 #include <Event/packet.h>
22 
23 #include <cmath> // for NAN
24 #include <cstddef> // for NULL
25 #include <iostream>
26 #include <string>
27 #include <utility> // for pair, make_pair
28 
29 using namespace std;
30 
32 
33 //____________________________________
35  : SubsysReco("RunInfoUnpackPRDF")
36  , runinfo_node_name("RUN_INFO")
37 {
38 }
39 
40 //_____________________________________
42 {
43  CreateNodeTree(topNode);
45 }
46 
47 //____________________________________
49 {
50  Event *event = findNode::getClass<Event>(topNode, "PRDF");
51  if (event == NULL)
52  {
53  if (Verbosity() >= VERBOSITY_SOME)
54  cout << "RunInfoUnpackPRDF::Process_Event - Event not found" << endl;
56  }
57 
58  // construct event info
59  EventHeaderv1 *eventheader =
60  findNode::getClass<EventHeaderv1>(topNode, "EventHeader");
61  if (eventheader)
62  {
63  eventheader->set_RunNumber(event->getRunNumber());
64  eventheader->set_EvtSequence(event->getEvtSequence());
65  eventheader->set_EvtType(event->getEvtType());
66  eventheader->set_TimeStamp(event->getTime());
67  if (Verbosity())
68  {
69  eventheader->identify();
70  }
71  }
72 
73  // search for run info
74  if (event->getEvtType() != BEGRUNEVENT)
75  {
77  }
78  else
79  {
80  if (Verbosity() >= VERBOSITY_SOME)
81  {
82  cout << "RunInfoUnpackPRDF::process_event - with BEGRUNEVENT events ";
83  event->identify();
84  }
85 
86  map<int, Packet *> packet_list;
87 
88  PHParameters Params("RunInfo");
89 
90  for (typ_channel_map::const_iterator it = channel_map.begin();
91  it != channel_map.end(); ++it)
92  {
93  const string &name = it->first;
94  const channel_info &info = it->second;
95 
96  if (packet_list.find(info.packet_id) == packet_list.end())
97  {
98  packet_list[info.packet_id] = event->getPacket(info.packet_id);
99  }
100 
101  Packet *packet = packet_list[info.packet_id];
102 
103  if (!packet)
104  {
105  // if (Verbosity() >= VERBOSITY_SOME)
106  cout << "RunInfoUnpackPRDF::process_event - failed to locate packet "
107  << info.packet_id << " from ";
108  event->identify();
109 
110  Params.set_double_param(name, NAN);
111  continue;
112  }
113 
114  const int ivalue = packet->iValue(info.offset);
115 
116  const double dvalue = ivalue * info.calibration_const;
117 
118  if (Verbosity() >= VERBOSITY_SOME)
119  {
120  cout << "RunInfoUnpackPRDF::process_event - " << name << " = " << dvalue
121  << ", raw = " << ivalue << " @ packet " << info.packet_id
122  << ", offset " << info.offset << endl;
123  }
124 
125  Params.set_double_param(name, dvalue);
126  }
127 
128  for (map<int, Packet *>::iterator it = packet_list.begin();
129  it != packet_list.end(); ++it)
130  {
131  delete it->second;
132  }
133 
134  Params.SaveToNodeTree(topNode, runinfo_node_name);
135 
136  if (Verbosity() >= VERBOSITY_SOME)
137  {
138  Params.Print();
139  }
140  }
142 }
143 
144 //_______________________________________
146 {
147  PHNodeIterator nodeItr(topNode);
148  // DST node
149  PHCompositeNode *run_node = static_cast<PHCompositeNode *>(
150  nodeItr.findFirst("PHCompositeNode", "RUN"));
151  if (!run_node)
152  {
153  cout << "PHComposite node created: RUN" << endl;
154  run_node = new PHCompositeNode("RUN");
155  topNode->addNode(run_node);
156  }
157 
158  PdbParameterMap *nodeparams =
159  findNode::getClass<PdbParameterMap>(run_node, runinfo_node_name);
160  if (not nodeparams)
161  {
162  run_node->addNode(new PHIODataNode<PdbParameterMap>(new PdbParameterMap(),
164  }
165 
166  // DST node
167  PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
168  nodeItr.findFirst("PHCompositeNode", "DST"));
169  if (!dst_node)
170  {
171  cout << "PHComposite node created: DST" << endl;
172  dst_node = new PHCompositeNode("DST");
173  topNode->addNode(dst_node);
174  }
175 
176  EventHeaderv1 *eventheader = new EventHeaderv1();
177  PHObjectNode_t *EventHeaderNode = new PHObjectNode_t(
178  eventheader, "EventHeader", "PHObject"); // contain PHObject
179  dst_node->addNode(EventHeaderNode);
180 }
181 
183  const std::string &name,
184  const int packet_id,
185  const unsigned int offset,
186  const double calibration_const
187 
188 )
189 {
190  channel_map.insert(
191  make_pair(name, channel_info(packet_id, offset, calibration_const)));
192 }