source: tags/Mars-V0.8.3/readraw.cc@ 10108

Last change on this file since 10108 was 2580, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.5 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 << " -a0: Do not use Ansii codes." << endl;
57 gLog << " -vn: Verbosity level n [default=2]" << endl;
58 gLog << " -d1: print data in decimal values" << endl;
59 gLog << " -?/-h: 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 //
76 // Evaluate arguments
77 //
78 MArgs arg(argc, argv);
79
80 if (arg.HasOption("-?") || arg.HasOption("-h"))
81 {
82 Usage();
83 return -1;
84 }
85
86 //
87 // Set verbosity to highest level.
88 //
89 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
90
91 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
92 gLog.SetNoColors();
93
94 const bool kDecimal = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
95
96 //
97 // check for the right usage of the program
98 //
99 if (arg.GetNumArguments()!=1)
100 {
101 Usage();
102 return -1;
103 }
104
105 //
106 // This is to make argv[i] more readable insidethe code
107 //
108 TString kNamein = arg.GetArgumentStr(0);
109
110 if (!kNamein.EndsWith(".root"))
111 kNamein += ".root";
112
113 //
114 // Initialize Non-GUI (batch) mode
115 //
116 gROOT->SetBatch();
117
118 //
119 // check whether the given files are OK.
120 //
121 if (gSystem->AccessPathName(kNamein, kFileExists))
122 {
123 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
124 return -1;
125 }
126
127 //
128 // open the file
129 //
130 gLog << " Open the file '" << kNamein << "'" << endl;
131 TFile input(kNamein, "READ");
132
133 //
134 // open the Run Header and read in
135 //
136 gLog << " Check for Tree 'RunHeaders'" << endl;
137 TTree *runtree = (TTree*)input.Get("RunHeaders");
138 if (!runtree)
139 gLog << " WARNING: This file has NO Tree 'RunHeaders'" << endl << endl;
140 else
141 {
142 gLog << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl;
143
144 MRawRunHeader *runheader = NULL;
145 runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
146 runtree->GetEvent(0);
147 runheader->Print();
148 }
149
150 //
151 // open the DataTree and read in
152 //
153 gLog << " Check the Tree 'Events'" << endl ;
154 TTree *evttree = (TTree*)input.Get("Events") ;
155 if (!evttree)
156 {
157 gLog << "Tree 'Events' not found in file... exit!" << endl;
158 return -1;
159 }
160
161 //
162 // check the branches in the Tree
163 //
164 gLog << " Check all the Branches in the Tree." << endl;
165 gLog << endl;
166
167 MRawEvtHeader *evtheader = NULL;
168 MTime *evttime = NULL;
169 MRawEvtData *evtdata = 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, "MRawCrateArray", &evtcrate);
178 EnableBranch(evttree, "MMcEvt", &evtmc);
179 EnableBranch(evttree, "MMcTrig", &trigmc);
180
181 //
182 // loop over all entries
183 //
184 const Int_t nent = (Int_t)evttree->GetEntries();
185
186 gLog << endl;
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 << "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();
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}
Note: See TracBrowser for help on using the repository browser.