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 with ROOT v" << ROOT_RELEASE << " on <" << __DATE__ << ">" << endl;
|
---|
45 | gLog << "==================================================" << endl;
|
---|
46 | gLog << endl;
|
---|
47 | }
|
---|
48 |
|
---|
49 | static void Usage()
|
---|
50 | {
|
---|
51 | gLog << all << endl;
|
---|
52 | gLog << "Sorry the usage is:" << endl;
|
---|
53 | gLog << " readraw [-h] [-?] [-vn] [-dec] [-a0] inputfile[.root]" << endl << endl;
|
---|
54 | gLog << " input file: Magic DAQ binary file." << endl;
|
---|
55 | gLog.Usage();
|
---|
56 | gLog << " -d, --dec: print data in decimal values" << endl;
|
---|
57 | gLog << " -a, --no-colors: Do not use Ansii color codes" << endl;
|
---|
58 | gLog << " -?,-h,--help: This help" << endl << endl;
|
---|
59 | }
|
---|
60 |
|
---|
61 | void EnableBranch(TTree *t, TString name, void *ptr)
|
---|
62 | {
|
---|
63 | if (!t->GetBranch(name+"."))
|
---|
64 | return;
|
---|
65 |
|
---|
66 | t->GetBranch(name+".")->SetAddress(ptr);
|
---|
67 | gLog << " Found '" << name << "'" << endl;
|
---|
68 | }
|
---|
69 |
|
---|
70 | int main(int argc, char **argv)
|
---|
71 | {
|
---|
72 | if (!MARS::CheckRootVer())
|
---|
73 | return 0xff;
|
---|
74 |
|
---|
75 | MLog::RedirectErrorHandler(MLog::kColor);
|
---|
76 |
|
---|
77 | // Evaluate arguments
|
---|
78 | MArgs arg(argc, argv);
|
---|
79 | gLog.Setup(arg);
|
---|
80 |
|
---|
81 | StartUpMessage();
|
---|
82 |
|
---|
83 | // check for the right usage of the program
|
---|
84 | if (arg.HasOption("-?") || arg.HasOption("-h") || arg.HasOption("--help") ||
|
---|
85 | arg.GetNumArguments()!=1)
|
---|
86 | {
|
---|
87 | Usage();
|
---|
88 | return 2;
|
---|
89 | }
|
---|
90 |
|
---|
91 | arg.RemoveRootArgs();
|
---|
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 2;
|
---|
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 2;
|
---|
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 | MRawEvtData *evtdata2 = NULL;
|
---|
172 | MRawCrateArray *evtcrate = NULL;
|
---|
173 | MMcEvt *evtmc = NULL;
|
---|
174 | MMcTrig *trigmc = NULL;
|
---|
175 |
|
---|
176 | EnableBranch(evttree, "MRawEvtHeader", &evtheader);
|
---|
177 | EnableBranch(evttree, "MTime", &evttime);
|
---|
178 | EnableBranch(evttree, "MRawEvtData", &evtdata);
|
---|
179 | EnableBranch(evttree, "MRawEvtData2", &evtdata2);
|
---|
180 | EnableBranch(evttree, "MRawCrateArray", &evtcrate);
|
---|
181 | EnableBranch(evttree, "MMcEvt", &evtmc);
|
---|
182 | EnableBranch(evttree, "MMcTrig", &trigmc);
|
---|
183 |
|
---|
184 | //
|
---|
185 | // loop over all entries
|
---|
186 | //
|
---|
187 | const Int_t nent = (Int_t)evttree->GetEntries();
|
---|
188 |
|
---|
189 | gLog << " Entries in Tree Data: " << dec << nent << endl;
|
---|
190 | gLog << endl;
|
---|
191 |
|
---|
192 | for (Int_t i = 0; i<nent; i++)
|
---|
193 | {
|
---|
194 | gLog << all << "Entry: " << i << endl;
|
---|
195 |
|
---|
196 | //
|
---|
197 | // readin event with the selected branches
|
---|
198 | //
|
---|
199 | evttree->GetEvent(i);
|
---|
200 |
|
---|
201 | if (evtmc)
|
---|
202 | evtmc->Print();
|
---|
203 | if (trigmc)
|
---|
204 | trigmc->Print("short");
|
---|
205 | if (evtheader)
|
---|
206 | evtheader->Print();
|
---|
207 | if (evttime)
|
---|
208 | evttime->Print();
|
---|
209 | if (evtcrate)
|
---|
210 | evtcrate->Print();
|
---|
211 | if (evtdata)
|
---|
212 | evtdata->Print(kDecimal?"dec":"hex");
|
---|
213 | if (evtdata2)
|
---|
214 | evtdata2->Print(kDecimal?"dec":"hex");
|
---|
215 |
|
---|
216 | gLog << endl;
|
---|
217 | }
|
---|
218 |
|
---|
219 | // end of small readin program
|
---|
220 |
|
---|
221 | return 0;
|
---|
222 | }
|
---|