source: tags/Mars-V0.10/readraw.cc@ 18088

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