Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_scanf250.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_scanf250.cc
4 // Created: Tue Oct 9 21:26:13 EDT 2018
5 // Creator: njarvis (on Linux egbert 2.6.32-696.23.1.el6.x86_64 x86_64)
6 //
7 
9 using namespace jana;
10 
11 #include <vector>
12 
13 #include "DAQ/Df250WindowRawData.h"
14 
15 #include <TTree.h>
16 #include <TBranch.h>
17 
18 
19 
20 // Routine used to create our JEventProcessor
21 #include <JANA/JApplication.h>
22 #include <JANA/JFactory.h>
23 extern "C"{
24 void InitPlugin(JApplication *app){
25  InitJANAPlugin(app);
26  app->AddProcessor(new JEventProcessor_scanf250());
27 }
28 } // "C"
29 
30 //define static local variable //declared in header file
32 
33 //------------------
34 // JEventProcessor_scanf250 (Constructor)
35 //------------------
37 {
38 
39 }
40 
41 //------------------
42 // ~JEventProcessor_scanf250 (Destructor)
43 //------------------
45 {
46 
47 }
48 
49 //------------------
50 // init
51 //------------------
53 {
54  // This is called once at program startup.
55 
56  //TTREE INTERFACE
57  //MUST DELETE WHEN FINISHED: OR ELSE DATA WON'T BE SAVED!!!
58  dTreeInterface = DTreeInterface::Create_DTreeInterface("T", "tree_scanf250.root");
59 
60  //TTREE BRANCHES
61  DTreeBranchRegister locTreeBranchRegister;
62 
63 
64 
65  locTreeBranchRegister.Register_Single<ULong64_t>("eventnum");
66  locTreeBranchRegister.Register_Single<UInt_t>("rocid");
67  locTreeBranchRegister.Register_Single<UInt_t>("slot");
68  locTreeBranchRegister.Register_Single<UInt_t>("channel");
69  locTreeBranchRegister.Register_Single<UInt_t>("itrigger");
70 
71  locTreeBranchRegister.Register_Single<UInt_t>("NSAMPLES");
72  locTreeBranchRegister.Register_FundamentalArray<UInt_t>("adc", "NSAMPLES");
73 
74 
75  //REGISTER BRANCHES
76  dTreeInterface->Create_Branches(locTreeBranchRegister);
77 
78  return NOERROR;
79 }
80 
81 //------------------
82 // brun
83 //------------------
84 jerror_t JEventProcessor_scanf250::brun(JEventLoop *eventLoop, int32_t runnumber)
85 {
86  // This is called whenever the run number changes
87  return NOERROR;
88 }
89 
90 //------------------
91 // evnt
92 //------------------
93 jerror_t JEventProcessor_scanf250::evnt(JEventLoop *loop, uint64_t eventnumber)
94 {
95  // This is called for every event. Use of common resources like writing
96  // to a file or filling a histogram should be mutex protected. Using
97  // loop->Get(...) to get reconstructed objects (and thereby activating the
98  // reconstruction algorithm) should be done outside of any mutex lock
99  // since multiple threads may call this method at the same time.
100  // Here's an example:
101  //
102  // vector<const MyDataClass*> mydataclasses;
103  // loop->Get(mydataclasses);
104  //
105  // japp->RootFillLock(this);
106  // ... fill historgrams or trees ...
107  // japp->RootFillUnLock(this);
108 
109 
110 
111 
112  vector<const Df250WindowRawData*> wrdvector;
113  loop->Get(wrdvector);
114 
115 
116  uint32_t nw = (uint32_t)wrdvector.size();
117 
118  if (nw) {
119 
120  const uint32_t NSAMPLES = 100;
121 
122  uint16_t adc[NSAMPLES]; // vector<uint16_t> samples;
123  for (uint i=0; i<NSAMPLES; i++) adc[i]=0;
124 
125 
126  for (int i=0; i<(int)nw; i++) {
127 
128  const Df250WindowRawData *wrd = wrdvector[i];
129 
130  if (wrd) {
131 
132  int ns = (int)wrd->samples.size();
133  int rocid = (int)wrd->rocid;
134 
135  // add a continue if the rocid is not wanted
136 
137  if ((rocid<11 || rocid > 22)) continue;
138 
139  for (int j=0; j<ns; j++) {
140  adc[j] = wrd->samples[j];
141  }
142 
143  dTreeFillData.Fill_Single<ULong64_t>("eventnum",eventnumber);
144  dTreeFillData.Fill_Single<UInt_t>("rocid",wrd->rocid);
145  dTreeFillData.Fill_Single<UInt_t>("slot",wrd->slot);
146  dTreeFillData.Fill_Single<UInt_t>("channel",wrd->channel);
147  dTreeFillData.Fill_Single<UInt_t>("itrigger",wrd->itrigger);
148 
149 
150 
151  size_t index = 0;
152  for (int j=0; j<(int)NSAMPLES; j++) {
153  dTreeFillData.Fill_Array<UInt_t>("adc",adc[j],index);
154  index++;
155  }
156 
157  //FILL ARRAY SIZE
158  dTreeFillData.Fill_Single<UInt_t>("NSAMPLES",index);
159 
160 
161  //FILL ARRAY SIZE
162  dTreeInterface->Fill(dTreeFillData);
163 
164  }
165 
166  }
167 
168 
169 
170  } // if (nw)
171 
172 
173  return NOERROR;
174 }
175 
176 //------------------
177 // erun
178 //------------------
180 {
181  // This is called whenever the run number changes, before it is
182  // changed to give you a chance to clean up before processing
183  // events from the next run number.
184 
185  delete dTreeInterface;
186 
187  return NOERROR;
188 }
189 
190 //------------------
191 // fini
192 //------------------
194 {
195  // Called before program exit after event processing is finished.
196  return NOERROR;
197 }
198 
jerror_t fini(void)
Called after last event of last event source has been processed.
if(locHist_BCALShowerPhiVsZ!=NULL)
void Register_Single(string locBranchName)
jerror_t init(void)
Called once at program start.
vector< uint16_t > samples
static char index(char c)
Definition: base64.cpp:115
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static DTreeInterface * Create_DTreeInterface(string locTreeName, string locFileName)
InitPlugin_t InitPlugin
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
void Register_FundamentalArray(string locBranchName, string locArraySizeName, size_t locInitialArraySize=10)
static thread_local DTreeFillData dTreeFillData
uint32_t channel
Definition: DDAQAddress.h:34
uint32_t rocid
Definition: DDAQAddress.h:32
uint32_t itrigger
Definition: DDAQAddress.h:35
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
uint32_t slot
Definition: DDAQAddress.h:33