Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
tdecpr_main.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// tdecpr (Test of DECoding, PRintout)
3//
4// Primitive example of decoding Hall A Data
5// R. Michaels, Feb, 2000
6
7#include <iostream>
8#include <cstdlib>
9#include "THaCodaFile.h"
10#include "CodaDecoder.h"
11#include "TString.h"
12//#include "evio.h"
13
14using namespace std;
15using namespace Decoder;
16
17int main(int /* argc */, char** /* argv */ )
18{
19
20 // int debug=0;
21 // if (argc > 1) debug=1;
22
23// CODA file "snippet.dat" is a disk file of CODA data.
24 THaCodaFile datafile; // We could also open the data using a
25 // different constructor:
26 // THaCodaFile datafile("snippet.dat");
27
28 TString filename("snippet.dat");
29 if (datafile.codaOpen(filename) != CODA_OK) {
30 cout << "ERROR: Cannot open CODA data" << endl;
31 exit(1);
32 }
33
34 auto *evdata = new CodaDecoder();
35 evdata->SetCodaVersion(datafile.getCodaVersion());
36
37// Loop over events
38
39 unsigned NUMEVT=100;
40 unsigned ievent=0;
41 for (; ievent<NUMEVT; ievent++) {
42
43 int status = datafile.codaRead();
44
45 if ( status != CODA_OK ) {
46 if ( status == EOF) {
47 cout << "This is normal end of file. Goodbye !" << endl;
48 } else {
49 cout << hex << "ERROR: codaRread status = " << status <<dec<<endl;
50 }
51 goto Finish;
52 }
53
54// load_evbuffer() must be called each event before you access evdata contents.
55// If you use the version of load_evbuffer() shown here,
56// evdata uses its private crate map (recommended).
57// Alternatively you could use load_evbuffer(int* evbuffer, haCrateMap& map)
58
59 status = evdata->LoadEvent( datafile.getEvBuffer() );
60
61 if( status != CodaDecoder::HED_OK && status != CodaDecoder::HED_WARN ) {
62 cerr << "ERROR " << status << " while decoding event " << ievent
63 << ". Exiting." << endl;
64 exit(status);
65 }
66 cout << endl << "Event type " << evdata->GetEvType() << endl;
67 cout << "Event number " << evdata->GetEvNum() << endl;
68 cout << "Event length " << evdata->GetEvLength() << endl;
69 if (evdata->IsPhysicsTrigger() ) { // triggers 1-14
70 cout << "Physics trigger " << endl;
71 }
72 if(evdata->IsScalerEvent()) cout << "Scaler `event' " << endl;
73
74// Now we want data from a particular crate and slot.
75// E.g. crates are 1,2,3,13,14,15 (roc numbers), Slots are 1,2,3...
76// This is like what one might do in a detector decode() routine.
77
78 unsigned crate = 1; // for example
79 unsigned slot = 24;
80
81// Here are raw 32-bit CODA words for this crate and slot
82 cout << "Raw Data Dump for crate "<<crate<<" slot "<<slot<<endl;
83 for(unsigned hit=0; hit<evdata->GetNumRaw(crate,slot); hit++) {
84 cout<<"raw["<<hit<<"] = ";
85 cout<<hex<<evdata->GetRawData(crate,slot,hit)<<dec<<endl;
86 }
87// You can alternatively let evdata print out the contents of a crate and slot:
88 evdata->PrintSlotData(crate,slot);
89
90 if (evdata->IsPhysicsTrigger()) {
91// Below are interpreted data, device types are ADC, TDC, or scaler.
92// One needs to know the channel number within the device
93 unsigned channel = 7; // for example
94 cout << "Device type = ";
95 cout << evdata->DevType(crate,slot) << endl;
96 for (unsigned hit=0; hit<evdata->GetNumHits(crate,slot,channel); hit++) {
97 cout << "Channel " <<channel<<" hit # "<<hit<<" ";
98 cout << "data = " << evdata->GetData(crate,slot,channel,hit)<<endl;
99 }
100// Helicity data
101 cout << "Helicity on left spectrometer "<<evdata->GetHelicity("left")<<endl;
102 cout << "Helicity on right spectrometer "<<evdata->GetHelicity("right")<<endl;
103 cout << "Helicity "<<evdata->GetHelicity()<<endl;
104 }
105
106// Scalers: Although the getData methods works if you happen
107// to know what crate & slot contain scaler data, here is
108// another way to get scalers directly from evdata
109//FIXME: needs update for Podd 1.6+
110#if 0
111 for (unsigned slot=0; slot<5; slot++) {
112 cout << endl << " scaler slot -> " << slot << endl;;
113 for (unsigned chan=0; chan<16; chan++) {
114 cout << "Scaler chan " << chan << " ";
115 cout << evdata->GetScaler("left",slot,chan);
116 cout << " " << evdata->GetScaler(7,slot,chan) << endl;
117 }
118 }
119#endif
120 } // end of event loop
121
122Finish:
123 cout<<endl<<"All done; processed "<<dec<<ievent<<" events"<<endl;
124 datafile.codaClose();
125 return 0;
126}
127
128
129
130
131
132
133
uint32_t chan
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
#define CODA_OK
Definition THaCodaData.h:28
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 main()
STL namespace.