Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
tstoo_main.cxx
Go to the documentation of this file.
1// Test of a OO decoder
2//
3// R. Michaels, Sept 2014
4
5#include <iostream>
6#include <fstream>
7#include <cstdlib>
8#include "THaCodaFile.h"
9#include "CodaDecoder.h"
10#include "TString.h"
11
12using namespace std;
13using namespace Decoder;
14
15void dump(UInt_t *data, ofstream *file);
16void process(THaEvData *evdata, ofstream *file);
17
18int main(int /* argc */, char** /* argv */)
19{
20 TString filename("snippet.dat");
21
22 auto* debugfile = new ofstream;
23 debugfile->open ("oodecoder1.txt");
24 *debugfile << "Debug of OO decoder"<<endl<<endl;
25
26 THaCodaFile datafile;
27 if (datafile.codaOpen(filename) != CODA_OK) {
28 cerr << "ERROR: Cannot open CODA data" << endl;
29 cerr << "Perhaps you mistyped it" << endl;
30 cerr << "... exiting." << endl;
31 exit(2);
32 }
33 auto* evdata = new CodaDecoder;
34 evdata->SetCodaVersion(datafile.getCodaVersion());
35 evdata->SetDebug(1);
36 evdata->SetDebugFile(debugfile);
37
38 // Loop over events
39 int NUMEVT=10;
40 for (int iev=0; iev<NUMEVT; iev++) {
41 int status = datafile.codaRead();
42 if (status != CODA_OK) {
43 if ( status == EOF) {
44 *debugfile << "Normal end of file. Bye bye." << endl;
45 break;
46 } else {
47 *debugfile << hex << "ERROR: codaRread status = " << status << endl;
48 exit(status);
49 }
50 } else {
51
52 UInt_t *data = datafile.getEvBuffer();
53 dump(data, debugfile);
54
55 *debugfile << "\nAbout to Load Event "<<endl;
56 status = evdata->LoadEvent( data );
57 *debugfile << "\nFinished with Load Event, status = "<<status<<endl;
58 if( status != CodaDecoder::HED_OK && status != CodaDecoder::HED_WARN ) {
59 cerr << "ERROR " << status << " while decoding event " << iev
60 << ". Exiting." << endl;
61 exit(status);
62 }
63 process (evdata, debugfile);
64
65 }
66 }
67 datafile.codaClose();
68 return 0;
69}
70
71
72void dump( UInt_t* data, ofstream *debugfile)
73{
74 // Crude event dump
75 unsigned evnum = data[4];
76 unsigned len = data[0] + 1;
77 unsigned evtype = data[1]>>16;
78 *debugfile << "\n\n Event number " << dec << evnum << endl;
79 *debugfile << " length " << len << " type " << evtype << endl;
80 unsigned ipt = 0;
81 for (unsigned j=0; j<(len/5); j++) {
82 *debugfile << dec << "\n evbuffer[" << ipt << "] = ";
83 for (unsigned k=j; k<j+5; k++) {
84 *debugfile << hex << data[ipt++] << " ";
85 }
86 *debugfile << endl;
87 }
88 if (ipt < len) {
89 *debugfile << dec << "\n evbuffer[" << ipt << "] = ";
90 for (unsigned k=ipt; k<len; k++) {
91 *debugfile << hex << data[ipt++] << " ";
92 }
93 *debugfile << endl;
94 }
95}
96
97void process (THaEvData *evdata, ofstream *debugfile) {
98
99 *debugfile << "\n\nHello. Now we process evdata : "<<endl;
100
101 *debugfile << "\nEvent type " << dec << evdata->GetEvType() << endl;
102 *debugfile << "Event number " << evdata->GetEvNum() << endl;
103 *debugfile << "Event length " << evdata->GetEvLength() << endl;
104 if (evdata->IsPhysicsTrigger() ) { // triggers 1-14
105 *debugfile << "Physics trigger " << endl;
106 }
107
108// Now we want data from a particular crate and slot.
109// E.g. crates are 1,2,3,13,14,15 (roc numbers), Slots are 1,2,3...
110// This is like what one might do in a detector decode() routine.
111
112 unsigned crate = 1; // for example
113 unsigned slot = 25;
114
115// Here are raw 32-bit CODA words for this crate and slot
116 *debugfile << "Raw Data Dump for crate "<<dec<<crate<<" slot "<<slot<<endl;
117 *debugfile << "Num raw "<<evdata->GetNumRaw(crate,slot)<<endl;
118 for(unsigned hit=0; hit<evdata->GetNumRaw(crate,slot); hit++) {
119 *debugfile<<dec<<"raw["<<hit<<"] = ";
120 *debugfile<<hex<<evdata->GetRawData(crate,slot,hit)<<endl;
121 }
122// You can alternatively let evdata print out the contents of a crate and slot:
123 *debugfile << "To print slotdata "<<crate<<" "<<slot<<endl;
124 // evdata->PrintSlotData(crate,slot);
125 *debugfile << "finished with print slot data"<<endl;
126}
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
Int_t SetCodaVersion(Int_t version)
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()
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
UInt_t GetEvLength() const
Definition THaEvData.h:54
int main()
STL namespace.
void dump(UInt_t *data, ofstream *file)
void process(THaEvData *evdata, ofstream *file)