Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
tstf1tdc_main.cxx
Go to the documentation of this file.
1// Test of F1 TDC decoding
2//
3// R. Michaels, Jan 2015
4
5
6#define MYTYPE 0
7
8#include <iostream>
9#include <fstream>
10#include <cstdlib>
11#include "THaCodaFile.h"
12#include "CodaDecoder.h"
13#include "F1TDCModule.h"
14#include "TString.h"
15#include "TROOT.h"
16#include "TFile.h"
17#include "TH1.h"
18#include "TH2.h"
19
20using namespace std;
21using namespace Decoder;
22
25
26void dump(UInt_t *data, ofstream *file);
27void process(Int_t i, THaEvData *evdata, ofstream *file);
28
29int main(int /* argc */, char** /* argv */)
30{
31
32 TString filename("snippet.dat");
33
34 auto *debugfile = new ofstream;
35 debugfile->open ("oodecoder2.txt");
36 *debugfile << "Debug of OO decoder\n\n";
37
38 THaCodaFile datafile;
39 if (datafile.codaOpen(filename) != CODA_OK) {
40 cerr << "ERROR: Cannot open CODA data" << endl;
41 cerr << "Perhaps you mistyped it" << endl;
42 cerr << "... exiting." << endl;
43 exit(2);
44 }
45 auto *evdata = new CodaDecoder();
46 evdata->SetCodaVersion(datafile.getCodaVersion());
47
48 evdata->SetDebug(1);
49 evdata->SetDebugFile(debugfile);
50
51// Initialize root and output
52 TROOT fadcana("fadcroot","Hall A FADC analysis, 1st version");
53 TFile hfile("fadc.root","RECREATE","FADC data");
54
55 h1 = new TH1F("h1","snapshot 1",1020,-5,505);
56 h2 = new TH1F("h2","snapshot 2",1020,-5,505);
57 h3 = new TH1F("h3","snapshot 3",1020,-5,505);
58 h4 = new TH1F("h4","snapshot 4",1020,-5,505);
59 h5 = new TH1F("h5","snapshot 5",1020,-5,505);
60 hinteg = new TH1F("hinteg","Integral of ADC",1000,50000,120000);
61
62 // Loop over events
63 int NUMEVT=22;
64 Int_t jnum=1;
65 for (int iev=0; iev<NUMEVT; iev++) {
66 int status = datafile.codaRead();
67 if (status != CODA_OK) {
68 if ( status == EOF) {
69 *debugfile << "Normal end of file. Bye bye." << endl;
70 break;
71 } else {
72 *debugfile << hex << "ERROR: codaRread status = " << status << endl;
73 exit(status);
74 }
75 } else {
76
77 UInt_t* data = datafile.getEvBuffer();
78 dump(data, debugfile);
79
80 *debugfile << "\nAbout to Load Event "<<endl;
81 evdata->LoadEvent( data );
82 *debugfile << "\nFinished with Load Event "<<endl;
83
84 if (evdata->GetEvType() == MYTYPE) {
85 process (jnum, evdata, debugfile);
86 jnum++;
87 }
88
89 }
90 }
91
92 hfile.Write();
93 hfile.Close();
94 datafile.codaClose();
95}
96
97
98void dump( UInt_t* data, ofstream *debugfile) {
99 // Crude event dump
100 unsigned evnum = data[4];
101 unsigned len = data[0] + 1;
102 unsigned evtype = data[1]>>16;
103 *debugfile << "\n\n Event number " << dec << evnum << endl;
104 *debugfile << " length " << len << " type " << evtype << endl;
105 unsigned ipt = 0;
106 for (unsigned j=0; j<(len/5); j++) {
107 *debugfile << dec << "\n evbuffer[" << ipt << "] = ";
108 for (unsigned k=j; k<j+5; k++) {
109 *debugfile << hex << data[ipt++] << " ";
110 }
111 *debugfile << endl;
112 }
113 if (ipt < len) {
114 *debugfile << dec << "\n evbuffer[" << ipt << "] = ";
115 for (unsigned k=ipt; k<len; k++) {
116 *debugfile << hex << data[ipt++] << " ";
117 }
118 *debugfile << endl;
119 }
120}
121
122void process (Int_t iev, THaEvData *evdata, ofstream *debugfile) {
123
124 *debugfile << "\n\nHello. Now we process evdata : "<<endl;
125
126 *debugfile << "\nEvent type " << dec << evdata->GetEvType() << endl;
127 *debugfile << "Event number " << evdata->GetEvNum() << endl;
128 *debugfile << "Event length " << evdata->GetEvLength() << endl;
129 if (evdata->GetEvType() != MYTYPE) return;
130 if (evdata->IsPhysicsTrigger() ) { // triggers 1-14
131 *debugfile << "Physics trigger " << endl;
132 }
133
134 Module *fadc = evdata->GetModule(9,5);
135 *debugfile << "main: fadc ptr = "<<fadc<<endl;
136
137 if (fadc) {
138 *debugfile << "main: num events "<<fadc->GetNumEvents()<<endl;
139 *debugfile << "main: fadc mode "<<fadc->GetMode()<<endl;
140 for (unsigned i=0; i < 500; i++) {
141 *debugfile << "main: fadc data on ch. 11 "<<dec<<i<<" "<<fadc->GetData(1, 11,i)<<endl;
142 if (fadc->GetMode()==1) {
143 if (iev==5) h1->Fill(i,fadc->GetData(1,11,i));
144 if (iev==6) h2->Fill(i,fadc->GetData(1,11,i));
145 if (iev==7) h3->Fill(i,fadc->GetData(1,11,i));
146 if (iev==8) h4->Fill(i,fadc->GetData(1,11,i));
147 if (iev==9) h5->Fill(i,fadc->GetData(1,11,i));
148 }
149 if (fadc->GetMode()==2) {
150 hinteg->Fill(fadc->GetData(1,11,i),1.);
151 }
152 }
153 }
154
155 // Now we want data from a particular crate and slot.
156 // E.g. crates are 1,2,3,13,14,15 (roc numbers), Slots are 1,2,3...
157 // This is like what one might do in a detector decode() routine.
158
159 unsigned crate = 1; // for example
160 unsigned slot = 25;
161
162 // Here are raw 32-bit CODA words for this crate and slot
163 *debugfile << "Raw Data Dump for crate "<<dec<<crate<<" slot "<<slot<<endl;
164 *debugfile << "Num raw "<<evdata->GetNumRaw(crate,slot)<<endl;
165 for(unsigned hit=0; hit<evdata->GetNumRaw(crate,slot); hit++) {
166 *debugfile<<dec<<"raw["<<hit<<"] = ";
167 *debugfile<<hex<<evdata->GetRawData(crate,slot,hit)<<endl;
168 }
169 // You can alternatively let evdata print out the contents of a crate and slot:
170 *debugfile << "To print slotdata "<<crate<<" "<<slot<<endl;
171 // evdata->PrintSlotData(crate,slot);
172 *debugfile << "finished with print slot data"<<endl;
173}
int Int_t
unsigned int UInt_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 getCodaVersion()
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
UInt_t GetRawData(UInt_t crate, UInt_t slot, UInt_t hit) const
Definition THaEvData.h:288
Bool_t IsPhysicsTrigger() const
Definition THaEvData.h:348
UInt_t GetNumRaw(UInt_t crate, UInt_t slot) const
Definition THaEvData.h:280
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
int main()
STL namespace.
TFile * hfile
TH1F * h4
TH1F * hinteg
TH1F * h2
#define MYTYPE
TH1F * h3
void dump(UInt_t *data, ofstream *file)
TH1F * h1
TH1F * h5
void process(Int_t i, THaEvData *evdata, ofstream *file)