Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
tstio_main.cxx
Go to the documentation of this file.
1// Test of I/O library and codaFile class
2// R. Michaels, Jan 2000
3
4#include <iostream>
5#include <iomanip>
6#include "THaCodaFile.h"
7#include "CodaDecoder.h"
8#include "TString.h"
9
10using namespace std;
11using namespace Decoder;
12
13int main(int argc, char* argv[])
14{
15
16 if (argc < 2) {
17 cout << "Usage: tstio <choice> " << endl;
18 cout << "where choice = " << endl;
19 cout << " 1. open a file and print raw data" << endl;
20 cout << " 2. filter data from file1 to file2" << endl;
21 cout << " 3. Make a fast sum of event types" << endl;
22 exit(1);
23 }
24
25 // CODA file "snippet.dat" is a disk file of CODA data.
26 TString filename("snippet.dat");
27 THaCodaFile datafile;
28 if (datafile.codaOpen(filename) != CODA_OK) {
29 cerr << "ERROR: Cannot open CODA data" << endl;
30 cerr << "Perhaps you mistyped it" << endl;
31 cerr << "... exiting." << endl;
32 exit(2);
33 }
34
35 int Choice = atoi(argv[1]);
36 switch(Choice) {
37 case 1: {
38 // Loop over events
39
40 unsigned NUMEVT=100;
41 for (unsigned iev=0; iev<NUMEVT; iev++) {
42 int status = datafile.codaRead();
43 if (status != CODA_OK) {
44 if ( status == EOF) {
45 cout << "Normal end of file. Bye bye." << endl;
46 break;
47 } else {
48 cout << hex << "ERROR: codaRread status = " << status << endl;
49 exit(status);
50 }
51 } else {
52 UInt_t *data = datafile.getEvBuffer();
53 UInt_t len = data[0] + 1;
54 UInt_t evtype = data[1]>>16;
55 // Crude event dump
56 cout << endl<<endl<<"Event number " << dec << iev;
57 cout << " length " << len << " type " << evtype << endl;
58 CodaDecoder::hexdump((const char*)data, len);
59 }
60 }
61 break;
62 }
63
64 case 2: {
65 // Filter from file1 to file2
66
67 // Filter criteria. If no criteria, write out all events.
68 // Possible criteria are logically inclusive.
69
70 datafile.addEvTypeFilt(1); // filter this event type
71 datafile.addEvTypeFilt(5); // and this event type
72
73 // Optionally filter a list of event numbers
74 int my_event_list[] = { 4, 15, 20, 1050, 80014, 5605001 };
75 for (auto ievnum : my_event_list) {
76 datafile.addEvListFilt(ievnum);
77 }
78
79 // Max num of events to filter to output file.
80 datafile.setMaxEvFilt(20);
81
82 // Now filter
83 const char* output_file = "filter_output.dat";
84 int ret = datafile.filterToFile(output_file);
85 cout << endl << "Return status from filtering " << dec << ret << endl;
86 break;
87 }
88
89 default: {
90 // Rapidly read file and count event types
91
92 static const unsigned MAXEVTYPE = 200;
93 unsigned evtype_sum[MAXEVTYPE];
94 for (auto & isum : evtype_sum) isum = 0;
95 unsigned nevt=0;
96 cout << "Scanning " << filename << endl;
97 while (datafile.codaRead() == CODA_OK) {
98 if( (nevt%1000)==0 ) cout << "." << flush;
99 nevt++;
100 UInt_t* dbuff = datafile.getEvBuffer();
101 unsigned event_type = dbuff[1]>>16;
102 if (event_type < MAXEVTYPE) {
103 evtype_sum[event_type]++;
104 }
105 }
106 ios_base::fmtflags fmt = cout.flags();
107 cout << endl << "Summary of event types";
108 cout << endl << " Total number events read "<<dec<<nevt<<endl;
109 for (unsigned ety=0; ety<MAXEVTYPE; ety++) {
110 if (evtype_sum[ety] != 0) {
111 cout << " Event type " << setw(3) << right << ety;
112 cout << ", count = " << setw(7) << right << evtype_sum[ety] << endl;
113 }
114 }
115 cout.flags(fmt);
116 break;
117 }
118 } // switch(Choice)
119
120 datafile.codaClose();
121 return 0;
122}
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
UInt_t * getEvBuffer()
Definition THaCodaData.h:76
void addEvTypeFilt(UInt_t evtype_to_filt)
virtual Int_t codaOpen(const char *filename, Int_t mode=1)
void setMaxEvFilt(UInt_t max_event)
Int_t filterToFile(const char *output_file)
virtual Int_t codaClose()
virtual Int_t codaRead()
void addEvListFilt(UInt_t event_to_filt)
int main()
STL namespace.