source: tags/Mars-V0.8.2/readraw.cc@ 13259

Last change on this file since 13259 was 2456, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.4 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 [-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}
60
61void 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
70int main(int argc, const char **argv)
71{
72 StartUpMessage();
73
74 //
75 // Evaluate arguments
76 //
77 MArgs arg(argc, argv);
78
79 //
80 // Set verbosity to highest level.
81 //
82 gLog.SetDebugLevel(arg.HasOption("-v") ? arg.GetIntAndRemove("-v") : 2);
83
84 if (arg.HasOption("-a") && arg.GetIntAndRemove("-a")==0)
85 gLog.SetNoColors();
86
87 const bool kDecimal = arg.HasOption("-d") && arg.GetIntAndRemove("-d")==1;
88
89 //
90 // check for the right usage of the program
91 //
92 if (arg.GetNumArguments()!=1)
93 {
94 Usage();
95 return -1;
96 }
97
98 //
99 // This is to make argv[i] more readable insidethe code
100 //
101 TString kNamein = arg.GetArgumentStr(0);
102
103 if (!kNamein.EndsWith(".root"))
104 kNamein += ".root";
105
106 //
107 // Initialize Non-GUI (batch) mode
108 //
109 gROOT->SetBatch();
110
111 //
112 // check whether the given files are OK.
113 //
114 if (gSystem->AccessPathName(kNamein, kFileExists))
115 {
116 gLog << err << "Sorry, the input file '" << kNamein << "' doesn't exist." << endl;
117 return -1;
118 }
119
120 //
121 // open the file
122 //
123 gLog << " Open the file '" << kNamein << "'" << endl;
124 TFile input(kNamein, "READ");
125
126 //
127 // open the Run Header and read in
128 //
129 gLog << " Check for Tree 'RunHeaders'" << endl;
130 TTree *runtree = (TTree*)input.Get("RunHeaders");
131 if (!runtree)
132 gLog << " WARNING: This file has NO Tree 'RunHeaders'" << endl << endl;
133 else
134 {
135 gLog << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl;
136
137 MRawRunHeader *runheader = NULL;
138 runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
139 runtree->GetEvent(0);
140 runheader->Print();
141 }
142
143 //
144 // open the DataTree and read in
145 //
146 gLog << " Check the Tree 'Events'" << endl ;
147 TTree *evttree = (TTree*)input.Get("Events") ;
148 if (!evttree)
149 {
150 gLog << "Tree 'Events' not found in file... exit!" << endl;
151 return -1;
152 }
153
154 //
155 // check the branches in the Tree
156 //
157 gLog << " Check all the Branches in the Tree." << endl;
158 gLog << endl;
159
160 MRawEvtHeader *evtheader = NULL;
161 MTime *evttime = NULL;
162 MRawEvtData *evtdata = NULL;
163 MRawCrateArray *evtcrate = NULL;
164 MMcEvt *evtmc = NULL;
165 MMcTrig *trigmc = NULL;
166
167 EnableBranch(evttree, "MRawEvtHeader", &evtheader);
168 EnableBranch(evttree, "MTime", &evttime);
169 EnableBranch(evttree, "MRawEvtData", &evtdata);
170 EnableBranch(evttree, "MRawCrateArray", &evtcrate);
171 EnableBranch(evttree, "MMcEvt", &evtmc);
172 EnableBranch(evttree, "MMcTrig", &trigmc);
173
174 //
175 // loop over all entries
176 //
177 const Int_t nent = (Int_t)evttree->GetEntries();
178
179 gLog << endl;
180 gLog << " Entries in Tree Data: " << dec << nent << endl;
181 gLog << endl;
182
183 for (Int_t i = 0; i<nent; i++)
184 {
185 gLog << "Entry: " << i << endl;
186
187 //
188 // readin event with the selected branches
189 //
190 evttree->GetEvent(i);
191
192 if (evtmc)
193 evtmc->Print();
194 if (trigmc)
195 trigmc->Print();
196 if (evtheader)
197 evtheader->Print();
198 if (evttime)
199 evttime->Print();
200 if (evtcrate)
201 evtcrate->Print();
202 if (evtdata)
203 evtdata->Print(kDecimal?"dec":"hex");
204
205 gLog << endl;
206 }
207
208 // end of small readin program
209
210 return 0;
211}
Note: See TracBrowser for help on using the repository browser.