Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InttRawDataConverter.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InttRawDataConverter.cc
1 #include "InttRawDataConverter.h"
2 
3 #include <Event/Event.h>
4 #include <Event/packet.h>
5 
7 
8 #include <phool/getClass.h>
9 
10 #include <TFile.h>
11 #include <TString.h> // for Form
12 #include <TTree.h>
13 
14 #include <iostream> // for operator<<, endl, basic_ostream
15 #include <utility> // for pair
16 
17 class PHCompositeNode;
18 
20  : SubsysReco(name)
21 {
22  // Do nothing
23 }
24 
26 {
27  if (filename.empty())
28  {
29  std::cout << "InttRawDataConverter::SetOputputFile(std:: string const& filename)" << std::endl;
30  std::cout << "Argument \"filename\" is empty string" << std::endl;
31  std::cout << "No output was written" << std::endl;
32 
33  return 1;
34  }
35 
36  std::cout << "Will write to file:" << std::endl;
37  std::cout << "\t" << filename << std::endl;
38 
39  file = TFile::Open(filename.c_str(), "RECREATE");
40  if (tree)
41  {
42  tree->SetDirectory(file);
43  }
44 
45  return 0;
46 }
47 
49 {
50  if (!file)
51  {
52  std::cout << "InttRawDataConverter::WriteOputputFile()" << std::endl;
53  std::cout << "Member \"file\" is uninitialized" << std::endl;
54  std::cout << "Did you call SetOutputFile()?" << std::endl;
55  std::cout << "No output was written" << std::endl;
56  return 1;
57  }
58 
59  if (!tree)
60  {
61  std::cout << "InttRawDataConverter::WriteOputputFile()" << std::endl;
62  std::cout << "Member \"tree\" is uninitialized" << std::endl;
63  std::cout << "Did you call SetOutputFile()?" << std::endl;
64  std::cout << "No output was written" << std::endl;
65  return 1;
66  }
67 
68  file->cd();
69  tree->Write();
70  file->Write();
71  file->Close();
72  delete tree;
73 
74  return 0;
75 }
76 
78 {
79  if (tree)
80  {
81  delete tree;
82  }
83  tree = new TTree("prdf_tree", "prdf_tree");
84  if (file)
85  {
86  tree->SetDirectory(file);
87  }
88 
89  tree->Branch("n_evt", &n_evt);
90  tree->Branch("num_hits", &num_hits);
91  tree->Branch("gtm_bco", &gtm_bco);
92  tree->Branch("flx_svr", &flx_svr);
93 
94  branches =
95  {
96  {"flx_chn", nullptr},
97  {"lyr", nullptr},
98  {"ldr", nullptr},
99  {"arm", nullptr},
100  {"chp", nullptr},
101  {"chn", nullptr},
102 
103  {"flx_bco", nullptr},
104  {"adc", nullptr},
105  {"amp", nullptr},
106  };
107 
108  for (Branches_t::const_iterator itr = branches.begin(); itr != branches.end(); ++itr)
109  {
110  tree->Branch(itr->first.c_str(), itr->second, (itr->first + std::string("[num_hits]/I")).c_str());
111 //Form("%s[num_hits]/I", itr->first.c_str()));
112  }
113 
114  return 0;
115 }
116 
118 {
119  n_evt = -1;
120 
122 }
123 
125 {
126  if (!tree)
127  {
129  }
130 
131  Event* evt = findNode::getClass<Event>(topNode, "PRDF");
132  if (!evt)
133  {
135  }
136 
137  for (auto pkt_itr : InttNameSpace::Packet_Id)
138  {
139  Packet* pkt = evt->getPacket(pkt_itr.first);
140  if (!pkt)
141  {
142  continue;
143  }
144 
145  num_hits = pkt->iValue(0, "NR_HITS");
146 
147  if (Verbosity() > 20)
148  {
149  std::cout << num_hits << std::endl;
150  }
151 
152  ++n_evt; // = pkt->lValue(0, "");
153  gtm_bco = pkt->lValue(0, "BCO");
154  flx_svr = pkt_itr.second;
155 
156  for (auto& branche : branches)
157  {
158  branche.second = new Int_t[num_hits];
159  tree->GetBranch(branche.first.c_str())->SetAddress(branche.second);
160  }
161 
162  for (int n = 0; n < num_hits; ++n)
163  {
164  raw = InttNameSpace::RawFromPacket(pkt_itr.second, n, pkt);
165  branches["flx_chn"][n] = raw.felix_channel;
166 
168  branches["lyr"][n] = onl.lyr;
169  branches["ldr"][n] = onl.ldr;
170  branches["arm"][n] = onl.arm;
171  branches["chp"][n] = onl.chp;
172  branches["chn"][n] = onl.chn;
173 
174  branches["flx_bco"][n] = pkt->iValue(n, "FPHX_BCO");
175  branches["adc"][n] = pkt->iValue(n, "ADC");
176  branches["amp"][n] = pkt->iValue(n, "AMPLITUDE");
177  }
178 
179  tree->Fill();
180  for (auto& branche : branches)
181  {
182  delete[] branche.second;
183  }
184 
185  delete pkt;
186  }
187 
189 }
190 
192 {
194 }