GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
ExamineMidasFile.cxx
Go to the documentation of this file.
1
2#include <Globals.h>
3
4#include <cstdio>
5#include <map>
6#include <fstream>
7
8#include <TStopwatch.h>
9#include <TMidasFile.h>
10#include <TMidasEvent.h>
11
12void ExamineMidasFile(const char* filename)
13{
14 std::ifstream in(filename, std::ifstream::in | std::ifstream::binary);
15 if(!in.is_open()) {
16 printf("unable to open file %s\n", filename);
17 return;
18 }
19 in.seekg(0, std::ifstream::end);
20 int64_t filesize = in.tellg();
21 in.close();
22
23 TMidasFile mfile;
24 std::shared_ptr<TMidasEvent> mevent = std::make_shared<TMidasEvent>();
25 std::map<int, int> type_counter;
26
27 mfile.Open(filename);
28
29 int64_t starttime = 0;
30 int64_t stoptime = 0;
31 int currenteventnumber = 0;
32 int64_t bytesread = 0;
33
34 bool loop = true;
35
36 TStopwatch sw;
37 sw.Start();
38 if(mfile.GetOdbEvent() != nullptr) {
39 printf(DGREEN);
40 mfile.GetOdbEvent()->Print();
41 printf(RESET_COLOR);
42 starttime = mfile.GetOdbEvent()->GetTimeStamp();
43 } else {
44 printf("Failed to find any midas event!\n");
45 return;
46 }
47 while(loop) {
48 bytesread += mfile.Read(mevent);
49 switch(mevent->GetEventId()) {
50 case 0x8001: //run stop
51 printf(" \r");
52 printf(DRED);
53 mevent->Print();
54 printf(RESET_COLOR);
55 stoptime = mevent->GetTimeStamp();
56 loop = false;
57 break;
58 default:
59 type_counter[mevent->GetEventId()]++;
60 break;
61 }
62 if((++currenteventnumber % 15000) == 0) {
63 std::streamsize precision = std::cout.precision();
64 std::cout.precision(2);
65 std::cout << " Looping over event " << currenteventnumber << " have looped " << static_cast<double>(bytesread) / 1000000. << "MB/" << static_cast<double>(filesize) / 1000000. << " MB => " << std::setprecision(1) << static_cast<double>(bytesread) / 1000000 / sw.RealTime() << " MB/s \r";
66 std::cout.precision(precision);
67 sw.Continue();
68 }
69 }
70 std::streamsize precision = std::cout.precision();
71 std::cout.precision(2);
72 std::cout << " Looping over event " << currenteventnumber << " have looped " << static_cast<double>(bytesread) / 1000000. << "MB/" << static_cast<double>(filesize) / 1000000. << " MB => " << std::setprecision(1) << static_cast<double>(bytesread) / 1000000 / sw.RealTime() << " MB/s \r";
73 std::cout.precision(precision);
74 printf("\n\n");
75 printf("EventTypes Seen: \n");
76 for(auto& it : type_counter) {
77 printf("\tEventId[0x%x] = %i\n", it.first, it.second);
78 }
79 printf("\n");
80 printf("Run length = %lli seconds\n", static_cast<long long int>(stoptime - starttime));
81 printf("\n");
82}
83
84#ifndef __CINT__
85
87{
88 printf("Usage: ./ExamineMidasFile <runXXXXX.mid> \n");
89 printf("Can take multiple midas files. Currently no other options.\n");
90}
91
92int main(int argc, char** argv)
93{
94 if(argc < 2) {
95 PrintUsage();
96 return 1;
97 }
98
99 for(int x = 1; x < argc; x++) {
100 ExamineMidasFile(argv[x]);
101 }
102
103 return 0;
104}
105
106#endif
int main(int argc, char **argv)
void PrintUsage()
void ExamineMidasFile(const char *filename)
#define DRED
Definition Globals.h:18
#define DGREEN
Definition Globals.h:17
#define RESET_COLOR
Definition Globals.h:5
Reader for MIDAS .mid files.
Definition TMidasFile.h:32
bool Open(const char *filename) override
Open input file.
int Read(std::shared_ptr< TRawEvent > event) override
Read one event from the file.
std::shared_ptr< TRawEvent > GetOdbEvent() override
Definition TMidasFile.h:69