Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
tstfadcblk_main.cxx
Go to the documentation of this file.
1// Test of FADC decoding in multiblock mode
2//
3// R. Michaels, October 2016
4//
5
6// MYTYPE = 0 for TEDF or Bryan's, 1 for HCAL or SBS
7#define MYTYPE 0
8
9// (9,10) for TEDF, (5,5) for Bryan's fcat files, (10,3) for HCAL , (12,17) for SBS
10#define MYCRATE 5
11#define MYSLOT 5
12
13// MYCHAN = 11 for TEDF, 13 for Bryan's fcat files, 0 for HCAL
14#define MYCHAN 13
15#define DEBUG 1
16
17#include <iostream>
18#include <fstream>
19#include <cstdlib>
20#include <cstdio>
21#include "THaCodaFile.h"
22#include "CodaDecoder.h"
23#include "Fadc250Module.h"
24#include "TString.h"
25#include "TROOT.h"
26#include "TFile.h"
27#include "TH1.h"
28
29using namespace std;
30using namespace Decoder;
31
32vector <TH1F * > hsnaps;
34
37
38void dump(UInt_t *data, ofstream *file);
39void process(UInt_t trignum, THaEvData *evdata, ofstream *file);
40
41int main(int /* argc */, char** /* argv */)
42{
43 TString filename("snippet.dat"); // data file, can be a link
44
45#ifdef DEBUG
46 auto* debugfile = new ofstream;
47 debugfile->open ("oodecoder1.txt");
48 *debugfile << "Debug of OO decoder"<<endl<<endl;
49#else
50 ofstream* debugfile = nullptr;
51#endif
52
53 THaCodaFile datafile;
54 if (datafile.codaOpen(filename) != CODA_OK) {
55 cerr << "ERROR: Cannot open CODA data" << endl;
56 cerr << "Perhaps you mistyped it" << endl;
57 cerr << "... exiting." << endl;
58 exit(2);
59 }
60 auto *evdata = new CodaDecoder();
61
62 evdata->SetDebug(1);
63 evdata->SetDebugFile(debugfile);
64
65 // Initialize root and output
66 TROOT fadcana("fadcroot","Hall A FADC analysis, 1st version");
67 TFile hfile("fadc.root","RECREATE","FADC data");
68
69 char cnum[50],ctitle[80];
70 for (UInt_t i = 0; i<nsnaps; i++) {
71 sprintf(cnum,"h%d",i+1);
72 sprintf(ctitle,"snapshot %d",i+1);
73 hsnaps.push_back(new TH1F(cnum,ctitle,1020,-5,505));
74 }
75 hinteg = new TH1F("hinteg","Integral of ADC",1000,50000,120000);
76 hinteg2 = new TH1F("hinteg2","Integral of ADC",1000,0,10000);
77
78 // Loop over events
79 UInt_t NUMEVT = 50;
80 UInt_t trigcnt = 0;
81
82 for (UInt_t iev=0; iev<NUMEVT; iev++) {
83
84 if (debugfile) {
85 if (evdata->IsMultiBlockMode()) {
86 *debugfile << "Are in Multiblock mode "<<endl;
87 if (evdata->BlockIsDone()) {
88 *debugfile << "Block is done "<<endl;
89 } else {
90 *debugfile << "Block is NOT done "<<endl;
91 }
92 } else {
93 *debugfile << "Not in Multiblock mode "<<endl;
94 }
95 }
96
97
98 Bool_t to_read_file = !evdata->DataCached();
99
100 if( to_read_file ) {
101
102 cout << "CODA read --- "<<endl;
103
104 if (debugfile) *debugfile << "Read from file ? Yes "<<endl;
105
106 int status = datafile.codaRead();
107
108 if (status != CODA_OK) {
109 if ( status == EOF) {
110 cout << "Normal end of file. Bye bye." << endl;
111 break;
112 } else {
113 cout << "ERROR: codaRread status = " << status << endl;
114 exit(status);
115 }
116
117 } else {
118
119 UInt_t *data = datafile.getEvBuffer();
120 dump(data, debugfile);
121
122 cout << "LoadEvent --- "<<endl;
123
124 status = evdata->LoadEvent( data );
125
126 if( status != CodaDecoder::HED_OK && status != CodaDecoder::HED_WARN ) {
127 cerr << "ERROR: LoadEvent status = " << status
128 << " while decoding event " << iev << ". Exiting." << endl;
129 exit(status);
130 }
131 }
132
133 } else {
134
135 if (debugfile) *debugfile << "Read from file ? No "<<endl;
136
137 int status = evdata->LoadFromMultiBlock();
138
139 if( status != CodaDecoder::HED_OK && status != CodaDecoder::HED_WARN ) {
140 cerr << "ERROR: LoadFromMultiBlock status = " << status
141 << " while decoding event " << iev << ". Exiting." << endl;
142 exit(status);
143 }
144
145 }
146
147 if( evdata->GetEvType() == MYTYPE )
148 process(trigcnt++, evdata, debugfile);
149
150 }
151
152 hfile.Write();
153 hfile.Close();
154 datafile.codaClose();
155}
156
157
158void dump( UInt_t* data, ofstream *debugfile) {
159 // Crude event dump
160 if (!debugfile) return;
161 UInt_t evnum = data[4];
162 UInt_t len = data[0] + 1;
163 UInt_t evtype = data[1]>>16;
164
165 *debugfile << "\n\n Event number " << dec << evnum << endl;
166 *debugfile << " length " << len << " type " << evtype << endl;
167 UInt_t ipt = 0;
168 for (UInt_t j=0; j<(len/5); j++) {
169 *debugfile << dec << "\n evbuffer[" << ipt << "] = ";
170 for (UInt_t k=j; k<j+5; k++) {
171 *debugfile << hex << data[ipt++] << " ";
172 }
173 *debugfile << endl;
174 }
175 if (ipt < len) {
176 *debugfile << dec << "\n evbuffer[" << ipt << "] = ";
177 for (UInt_t k=ipt; k<len; k++) {
178 *debugfile << hex << data[ipt++] << " ";
179 }
180 *debugfile << endl;
181 }
182}
183
184void process (UInt_t trignum, THaEvData *evdata, ofstream *debugfile) {
185
186 if (debugfile) {
187 *debugfile << "\n\nHello. Now we process evdata : "<<endl;
188
189 *debugfile << "\nEvent type " << dec << evdata->GetEvType() << endl;
190 *debugfile << "Event number " << evdata->GetEvNum() << endl;
191 *debugfile << "Event length " << evdata->GetEvLength() << endl;
192 }
193 if (evdata->GetEvType() != MYTYPE) return;
194 if (evdata->IsPhysicsTrigger() ) { // triggers 1-14
195 if (debugfile) *debugfile << "Physics trigger " << endl;
196 }
197
198 if (use_module) { // Using data directly from the module from THaEvData
199
200 Module *fadc = evdata->GetModule(MYCRATE,MYSLOT);
201 if (debugfile) *debugfile << "main: using module, fadc ptr = "<<fadc<<endl;
202
203 if (fadc) {
204 if (debugfile) *debugfile << "main: num events "<<fadc->GetNumEvents(MYCHAN)<<endl;
205 if (debugfile) *debugfile << "main: fadc mode "<<fadc->GetMode()<<endl;
206 if (fadc->GetMode()==1 || fadc->GetMode()==8) {
207 for ( UInt_t i = 0; i < fadc->GetNumEvents(kSampleADC, MYCHAN); i++) {
208 UInt_t rdata = fadc->GetData(kSampleADC,MYCHAN, i);
209 if (debugfile) *debugfile << "main: SAMPLE fadc data on ch. "<<dec<<MYCHAN<<" "<<i<<" "<<rdata<<endl;
210 if (trignum < nsnaps) hsnaps[trignum]->Fill(i,rdata);
211 }
212 }
213 if (fadc->GetMode()==7) {
214 for ( UInt_t i = 0; i < fadc->GetNumEvents(kPulseIntegral, MYCHAN); i++) {
215 UInt_t rdata = fadc->GetData(kPulseIntegral,MYCHAN,i);
216 if (debugfile) *debugfile << "main: INTEG fadc data on ch. "<<dec<<MYCHAN<<" "<<i<<" "<<rdata<<endl;
217 hinteg->Fill(rdata);
218 hinteg2->Fill(rdata);
219 }
220 }
221 }
222
223
224 } else { // alternative is to use the THaEvData::GetData interface
225
226 if (debugfile) *debugfile << "main: using THaEvData "<<endl;
227 if (debugfile) {
228 *debugfile << "main: num hits "<< evdata->GetNumEvents(kSampleADC,MYCRATE,MYSLOT,MYCHAN)<<" "<<evdata->GetNumEvents(kPulseIntegral,MYCRATE,MYSLOT,MYCHAN)<<endl;
229 for (UInt_t jj=0; jj<10; jj++) {
230 for (UInt_t kk=0; kk<15; kk++) {
231 *debugfile << "burger "<<jj<<" "<<kk<<" "<< evdata->GetNumEvents(kSampleADC,MYCRATE,jj,kk)<<" "<<evdata->GetNumEvents(kPulseIntegral,MYCRATE,jj,kk)<<endl;
232 }
233 }
234 }
235
236
237 for (UInt_t i=0; i < evdata->GetNumEvents(kSampleADC,MYCRATE,MYSLOT,MYCHAN); i++) {
238 UInt_t rdata = evdata->GetData(kSampleADC,MYCRATE,MYSLOT,MYCHAN,i);
239 if (debugfile) *debugfile << "main: SAMPLE fadc data on ch. "<<dec<<MYCHAN<<" "<<i<<" "<<rdata<<endl;
240 if (trignum < nsnaps) hsnaps[trignum]->Fill(i,rdata);
241 }
242 for (UInt_t i=0; i < evdata->GetNumEvents(kPulseIntegral,MYCRATE,MYSLOT,MYCHAN); i++) {
244 if (debugfile) *debugfile << "main: INTEG fadc data on ch. "<<dec<<MYCHAN<<" "<<i<<" "<<rdata<<endl;
245 hinteg->Fill(rdata);
246 hinteg2->Fill(rdata);
247 }
248 }
249
250}
unsigned int UInt_t
bool Bool_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
#define CODA_OK
Definition THaCodaData.h:28
virtual UInt_t GetNumEvents(Decoder::EModuleType, UInt_t) const
Definition Module.h:75
virtual Int_t GetMode() const
Definition Module.h:80
virtual UInt_t GetData(UInt_t) const
Definition Module.h:51
UInt_t * getEvBuffer()
Definition THaCodaData.h:76
virtual Int_t codaOpen(const char *filename, Int_t mode=1)
virtual Int_t codaClose()
virtual Int_t codaRead()
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) const override
void Close(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
UInt_t GetEvType() const
Definition THaEvData.h:53
Bool_t IsPhysicsTrigger() const
Definition THaEvData.h:348
UInt_t GetNumEvents(Decoder::EModuleType type, UInt_t crate, UInt_t slot, UInt_t chan) const
Definition THaEvData.h:448
UInt_t GetEvNum() const
Definition THaEvData.h:56
virtual Decoder::Module * GetModule(UInt_t roc, UInt_t slot) const
UInt_t GetEvLength() const
Definition THaEvData.h:54
UInt_t GetData(UInt_t crate, UInt_t slot, UInt_t chan, UInt_t hit) const
Definition THaEvData.h:273
int main()
@ kSampleADC
Definition Decoder.h:57
@ kPulseIntegral
Definition Decoder.h:57
STL namespace.
TFile * hfile
#define MYSLOT
void process(UInt_t trignum, THaEvData *evdata, ofstream *file)
vector< TH1F * > hsnaps
TH1F * hinteg
#define MYCHAN
Bool_t use_module
#define MYTYPE
void dump(UInt_t *data, ofstream *file)
TH1F * hinteg2
UInt_t nsnaps
#define MYCRATE