source: tags/Mars-V0.9.6/readraw.cc@ 17873

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