source: tags/Mars-V0.9.2/readraw.cc@ 18066

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