1 | #include <TSystem.h>
|
---|
2 |
|
---|
3 | #include <TFile.h>
|
---|
4 | #include <TTree.h>
|
---|
5 | #include <TBranch.h>
|
---|
6 |
|
---|
7 | #include "MParList.h"
|
---|
8 | #include "MTaskList.h"
|
---|
9 | #include "MEvtLoop.h"
|
---|
10 |
|
---|
11 | #include "MLog.h"
|
---|
12 | #include "MLogManip.h"
|
---|
13 |
|
---|
14 | #include "MArgs.h"
|
---|
15 | #include "MTime.h"
|
---|
16 | #include "MRawRunHeader.h"
|
---|
17 | #include "MRawEvtHeader.h"
|
---|
18 | #include "MRawEvtData.h"
|
---|
19 | #include "MRawCrateArray.h"
|
---|
20 | #include "MInputStreamID.h"
|
---|
21 |
|
---|
22 | #include "MMcEvt.hxx"
|
---|
23 | #include "MMcTrig.hxx"
|
---|
24 |
|
---|
25 | using namespace std;
|
---|
26 |
|
---|
27 | /////////////////////////////////////////////////////////////////////////////
|
---|
28 | //
|
---|
29 | // This is an demonstration how to read in a merpped root file
|
---|
30 | // This is a demonstration how to use root, not how you should
|
---|
31 | // read a merpped file!
|
---|
32 | //
|
---|
33 | /////////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | static void StartUpMessage()
|
---|
36 | {
|
---|
37 | gLog << all << endl;
|
---|
38 |
|
---|
39 | // 1 2 3 4 5
|
---|
40 | // 12345678901234567890123456789012345678901234567890
|
---|
41 | gLog << "==================================================" << endl;
|
---|
42 | gLog << " ReadRaw - MARS V" << MARSVER << endl;
|
---|
43 | gLog << " MARS - Read and print raw data files" << endl;
|
---|
44 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
---|
45 | gLog << " Using ROOT v" << ROOTVER << endl;
|
---|
46 | gLog << "==================================================" << endl;
|
---|
47 | gLog << endl;
|
---|
48 | }
|
---|
49 |
|
---|
50 | static void Usage()
|
---|
51 | {
|
---|
52 | gLog << all << endl;
|
---|
53 | gLog << "Sorry the usage is:" << endl;
|
---|
54 | gLog << " readraw [-h] [-?] [-vn] [-dec] [-a0] inputfile[.root]" << endl << endl;
|
---|
55 | gLog << " input file: Magic DAQ binary file." << endl;
|
---|
56 | gLog << " -vn: Verbosity level n [default=2]" << endl;
|
---|
57 | gLog << " -d, --dec: print data in decimal values" << endl;
|
---|
58 | gLog << " -a, --no-colors: Do not use Ansii color codes" << endl;
|
---|
59 | gLog << " -?,-h,--help: This help" << endl << endl;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void EnableBranch(TTree *t, TString name, void *ptr)
|
---|
63 | {
|
---|
64 | if (!t->GetBranch(name+"."))
|
---|
65 | return;
|
---|
66 |
|
---|
67 | t->GetBranch(name+".")->SetAddress(ptr);
|
---|
68 | gLog << " Found '" << name << "'" << endl;
|
---|
69 | }
|
---|
70 |
|
---|
71 | int main(int argc, char **argv)
|
---|
72 | {
|
---|
73 | StartUpMessage();
|
---|
74 |
|
---|
75 | // Evaluate arguments
|
---|
76 | MArgs arg(argc, argv);
|
---|
77 |
|
---|
78 | // check for the right usage of the program
|
---|
79 | if (arg.HasOption("-?") || arg.HasOption("-h") || arg.HasOption("--help") ||
|
---|
80 | arg.GetNumArguments()!=1)
|
---|
81 | {
|
---|
82 | Usage();
|
---|
83 | return -1;
|
---|
84 | }
|
---|
85 |
|
---|
86 | // Set verbosity
|
---|
87 | gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
|
---|
88 |
|
---|
89 | // Set color usage
|
---|
90 | if (arg.HasOnlyAndRemove("--no-colors") || arg.HasOnlyAndRemove("-a"))
|
---|
91 | gLog.SetNoColors();
|
---|
92 |
|
---|
93 | // Set usage of decimal values
|
---|
94 | const bool kDecimal = arg.HasOnlyAndRemove("-d") || arg.HasOnlyAndRemove("--dec");
|
---|
95 |
|
---|
96 | //
|
---|
97 | // check for unidentified options
|
---|
98 | //
|
---|
99 | if (arg.GetNumOptions()>0)
|
---|
100 | {
|
---|
101 | gLog << warn << "WARNING - unknown commandline options..." << endl;
|
---|
102 | arg.Print("options");
|
---|
103 | gLog << endl;
|
---|
104 | }
|
---|
105 |
|
---|
106 | //
|
---|
107 | // This is to make argv[i] more readable insidethe code
|
---|
108 | //
|
---|
109 | TString kNamein = arg.GetArgumentStr(0);
|
---|
110 |
|
---|
111 | if (!kNamein.EndsWith(".root"))
|
---|
112 | kNamein += ".root";
|
---|
113 |
|
---|
114 | //
|
---|
115 | // Initialize Non-GUI (batch) mode
|
---|
116 | //
|
---|
117 | gROOT->SetBatch();
|
---|
118 |
|
---|
119 | //
|
---|
120 | // check whether the given files are OK.
|
---|
121 | //
|
---|
122 | if (gSystem->AccessPathName(kNamein, kFileExists))
|
---|
123 | {
|
---|
124 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
|
---|
125 | return -1;
|
---|
126 | }
|
---|
127 |
|
---|
128 | //
|
---|
129 | // open the file
|
---|
130 | //
|
---|
131 | gLog << inf << " Open the file '" << kNamein << "'" << endl;
|
---|
132 | TFile input(kNamein, "READ");
|
---|
133 |
|
---|
134 | //
|
---|
135 | // open the Run Header and read in
|
---|
136 | //
|
---|
137 | gLog << " Check for Tree 'RunHeaders'" << endl;
|
---|
138 | TTree *runtree = (TTree*)input.Get("RunHeaders");
|
---|
139 | if (!runtree)
|
---|
140 | gLog << warn << " WARNING - This file has no Tree 'RunHeaders'" << endl << endl;
|
---|
141 | else
|
---|
142 | {
|
---|
143 | gLog << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl;
|
---|
144 |
|
---|
145 | MRawRunHeader *runheader = NULL;
|
---|
146 | runtree->GetBranch("MRawRunHeader.")->SetAddress(&runheader);
|
---|
147 | runtree->GetEvent(0);
|
---|
148 | runheader->Print();
|
---|
149 | }
|
---|
150 |
|
---|
151 | //
|
---|
152 | // open the DataTree and read in
|
---|
153 | //
|
---|
154 | gLog << inf << " Check the Tree 'Events'" << endl ;
|
---|
155 | TTree *evttree = (TTree*)input.Get("Events") ;
|
---|
156 | if (!evttree)
|
---|
157 | {
|
---|
158 | gLog << err << "Tree 'Events' not found in file... exit!" << endl;
|
---|
159 | return -1;
|
---|
160 | }
|
---|
161 |
|
---|
162 | //
|
---|
163 | // check the branches in the Tree
|
---|
164 | //
|
---|
165 | gLog << " Check all the Branches in the Tree." << endl;
|
---|
166 | gLog << endl;
|
---|
167 |
|
---|
168 | MRawEvtHeader *evtheader = NULL;
|
---|
169 | MTime *evttime = NULL;
|
---|
170 | MRawEvtData *evtdata = NULL;
|
---|
171 | MRawCrateArray *evtcrate = NULL;
|
---|
172 | MMcEvt *evtmc = NULL;
|
---|
173 | MMcTrig *trigmc = NULL;
|
---|
174 |
|
---|
175 | EnableBranch(evttree, "MRawEvtHeader", &evtheader);
|
---|
176 | EnableBranch(evttree, "MTime", &evttime);
|
---|
177 | EnableBranch(evttree, "MRawEvtData", &evtdata);
|
---|
178 | EnableBranch(evttree, "MRawCrateArray", &evtcrate);
|
---|
179 | EnableBranch(evttree, "MMcEvt", &evtmc);
|
---|
180 | EnableBranch(evttree, "MMcTrig", &trigmc);
|
---|
181 |
|
---|
182 | //
|
---|
183 | // loop over all entries
|
---|
184 | //
|
---|
185 | const Int_t nent = (Int_t)evttree->GetEntries();
|
---|
186 |
|
---|
187 | gLog << " Entries in Tree Data: " << dec << nent << endl;
|
---|
188 | gLog << endl;
|
---|
189 |
|
---|
190 | for (Int_t i = 0; i<nent; i++)
|
---|
191 | {
|
---|
192 | gLog << all << "Entry: " << i << endl;
|
---|
193 |
|
---|
194 | //
|
---|
195 | // readin event with the selected branches
|
---|
196 | //
|
---|
197 | evttree->GetEvent(i);
|
---|
198 |
|
---|
199 | if (evtmc)
|
---|
200 | evtmc->Print();
|
---|
201 | if (trigmc)
|
---|
202 | trigmc->Print("short");
|
---|
203 | if (evtheader)
|
---|
204 | evtheader->Print();
|
---|
205 | if (evttime)
|
---|
206 | evttime->Print();
|
---|
207 | if (evtcrate)
|
---|
208 | evtcrate->Print();
|
---|
209 | if (evtdata)
|
---|
210 | evtdata->Print(kDecimal?"dec":"hex");
|
---|
211 |
|
---|
212 | gLog << endl;
|
---|
213 | }
|
---|
214 |
|
---|
215 | // end of small readin program
|
---|
216 |
|
---|
217 | return 0;
|
---|
218 | }
|
---|