source: tags/Mars-V0.9.1/readraw.cc@ 18481

Last change on this file since 18481 was 6888, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 6.0 KB
Line 
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
25using 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
35static 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
50static 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
62void 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
71int 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 2;
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 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}
Note: See TracBrowser for help on using the repository browser.