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 | // Set usage of decimal values
|
---|
92 | const bool kDecimal = arg.HasOnlyAndRemove("-d") || arg.HasOnlyAndRemove("--dec");
|
---|
93 |
|
---|
94 | //
|
---|
95 | // check for unidentified options
|
---|
96 | //
|
---|
97 | if (arg.GetNumOptions()>0)
|
---|
98 | {
|
---|
99 | gLog << warn << "WARNING - unknown commandline options..." << endl;
|
---|
100 | arg.Print("options");
|
---|
101 | gLog << endl;
|
---|
102 | }
|
---|
103 |
|
---|
104 | //
|
---|
105 | // This is to make argv[i] more readable insidethe code
|
---|
106 | //
|
---|
107 | TString kNamein = arg.GetArgumentStr(0);
|
---|
108 |
|
---|
109 | if (!kNamein.EndsWith(".root"))
|
---|
110 | kNamein += ".root";
|
---|
111 |
|
---|
112 | //
|
---|
113 | // Initialize Non-GUI (batch) mode
|
---|
114 | //
|
---|
115 | gROOT->SetBatch();
|
---|
116 |
|
---|
117 | //
|
---|
118 | // check whether the given files are OK.
|
---|
119 | //
|
---|
120 | if (gSystem->AccessPathName(kNamein, kFileExists))
|
---|
121 | {
|
---|
122 | gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
|
---|
123 | return 2;
|
---|
124 | }
|
---|
125 |
|
---|
126 | //
|
---|
127 | // open the file
|
---|
128 | //
|
---|
129 | gLog << inf << " Open the file '" << kNamein << "'" << endl;
|
---|
130 | TFile input(kNamein, "READ");
|
---|
131 |
|
---|
132 | //
|
---|
133 | // open the Run Header and read in
|
---|
134 | //
|
---|
135 | gLog << " Check for Tree 'RunHeaders'" << endl;
|
---|
136 | TTree *runtree = (TTree*)input.Get("RunHeaders");
|
---|
137 | if (!runtree)
|
---|
138 | gLog << warn << " WARNING - This file has no Tree 'RunHeaders'" << endl << endl;
|
---|
139 | else
|
---|
140 | {
|
---|
141 | gLog << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl;
|
---|
142 |
|
---|
143 | MRawRunHeader *runheader = NULL;
|
---|
144 | runtree->GetBranch("MRawRunHeader.")->SetAddress(&runheader);
|
---|
145 | runtree->GetEvent(0);
|
---|
146 | runheader->Print();
|
---|
147 | }
|
---|
148 |
|
---|
149 | //
|
---|
150 | // open the DataTree and read in
|
---|
151 | //
|
---|
152 | gLog << inf << " Check the Tree 'Events'" << endl ;
|
---|
153 | TTree *evttree = (TTree*)input.Get("Events") ;
|
---|
154 | if (!evttree)
|
---|
155 | {
|
---|
156 | gLog << err << "Tree 'Events' not found in file... exit!" << endl;
|
---|
157 | return 2;
|
---|
158 | }
|
---|
159 |
|
---|
160 | //
|
---|
161 | // check the branches in the Tree
|
---|
162 | //
|
---|
163 | gLog << " Check all the Branches in the Tree." << endl;
|
---|
164 | gLog << endl;
|
---|
165 |
|
---|
166 | MRawEvtHeader *evtheader = NULL;
|
---|
167 | MTime *evttime = NULL;
|
---|
168 | MRawEvtData *evtdata = NULL;
|
---|
169 | MRawEvtData *evtdata2 = NULL;
|
---|
170 | MRawCrateArray *evtcrate = NULL;
|
---|
171 | MMcEvt *evtmc = NULL;
|
---|
172 | MMcTrig *trigmc = NULL;
|
---|
173 |
|
---|
174 | EnableBranch(evttree, "MRawEvtHeader", &evtheader);
|
---|
175 | EnableBranch(evttree, "MTime", &evttime);
|
---|
176 | EnableBranch(evttree, "MRawEvtData", &evtdata);
|
---|
177 | EnableBranch(evttree, "MRawEvtData2", &evtdata2);
|
---|
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 | if (evtdata2)
|
---|
212 | evtdata2->Print(kDecimal?"dec":"hex");
|
---|
213 |
|
---|
214 | gLog << endl;
|
---|
215 | }
|
---|
216 |
|
---|
217 | // end of small readin program
|
---|
218 |
|
---|
219 | return 0;
|
---|
220 | }
|
---|