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

Last change on this file since 17873 was 2173, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 4.1 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 "MTime.h"
13#include "MRawRunHeader.h"
14#include "MRawEvtHeader.h"
15#include "MRawEvtData.h"
16#include "MRawCrateArray.h"
17#include "MInputStreamID.h"
18
19#include "MMcEvt.hxx"
20#include "MMcTrig.hxx"
21
22using namespace std;
23
24/////////////////////////////////////////////////////////////////////////////
25//
26// This is an demonstration how to read in a merpped root file
27//
28/////////////////////////////////////////////////////////////////////////////
29
30void EnableBranch(TTree *t, TString name, void *ptr)
31{
32 if (!t->GetBranch(name+"."))
33 return;
34
35 t->GetBranch(name+".")->SetAddress(ptr);
36 gLog << " Found '" << name << "'" << endl;
37}
38
39int main(const int argc, const char **argv)
40{
41 gLog << "==================================================" << endl;
42 gLog << " ReadRaw v0.1 " << endl;
43 gLog << " MARS - Read and print raw data file " << endl;
44 gLog << " Compiled on <" << __DATE__ << ">" << endl;
45 gLog << "==================================================" << endl;
46 gLog << endl;
47
48 //
49 // check for the right usage of the program
50 //
51 if (argc!=2)
52 {
53 gLog << "Sorry the usage is:" << endl;
54 gLog << " readraw inputfile" << endl << endl;
55 return -1;
56 }
57
58 //
59 // initialize ROOT (this is obligatory here)
60 //
61 TROOT simple("readraw","Mars - Read and print raw data file");
62
63 //
64 // check whether the given files are OK.
65 //
66 if (gSystem->AccessPathName(argv[1], kFileExists))
67 {
68 gLog << "Sorry, the file '" << argv[1] << "' doesn't exist." << endl;
69 return -1;
70 }
71
72 //
73 // open the file
74 //
75 gLog << " Open the file '" << argv[1] << "'" << endl;
76 TFile input(argv[1], "READ");
77
78 //
79 // open the Run Header and read in
80 //
81 gLog << " Check for Tree 'RunHeaders'" << endl;
82 TTree *runtree = (TTree*)input.Get("RunHeaders");
83 if (!runtree)
84 gLog << " WARNING: This file has NO Tree 'RunHeaders'" << endl << endl;
85 else
86 {
87 gLog << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl;
88
89 MRawRunHeader *runheader = NULL;
90 runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
91 runtree->GetEvent(0);
92 runheader->Print();
93 }
94
95 //
96 // open the DataTree and read in
97 //
98 gLog << " Check the Tree 'Events'" << endl ;
99 TTree *evttree = (TTree*)input.Get("Events") ;
100 if (!evttree)
101 {
102 gLog << "Tree 'Events' not found in file... exit!" << endl;
103 return -1;
104 }
105
106 //
107 // check the branches in the Tree
108 //
109 gLog << " Check all the Branches in the Tree." << endl;
110 gLog << endl;
111
112 MRawEvtHeader *evtheader = NULL;
113 MTime *evttime = NULL;
114 MRawEvtData *evtdata = NULL;
115 MRawCrateArray *evtcrate = NULL;
116 MMcEvt *evtmc = NULL;
117 MMcTrig *trigmc = NULL;
118
119 EnableBranch(evttree, "MRawEvtHeader", &evtheader);
120 EnableBranch(evttree, "MTime", &evttime);
121 EnableBranch(evttree, "MRawEvtData", &evtdata);
122 EnableBranch(evttree, "MRawCrateArray", &evtcrate);
123 EnableBranch(evttree, "MMcEvt", &evtmc);
124 EnableBranch(evttree, "MMcTrig", &trigmc);
125
126 //
127 // loop over all entries
128 //
129 Int_t nent = (Int_t)evttree->GetEntries();
130
131 gLog << endl;
132 gLog << " Entries in Tree Data: " << dec << nent << endl;
133 gLog << endl;
134
135 for (Int_t i = 0; i<nent; i++)
136 {
137 gLog << "Entry: " << i << endl;
138
139 //
140 // readin event with the selected branches
141 //
142 evttree->GetEvent(i);
143
144 if (evtmc)
145 evtmc->Print();
146 if (trigmc)
147 trigmc->Print();
148 if (evtheader)
149 evtheader->Print();
150 if (evttime)
151 evttime->Print();
152 if (evtcrate)
153 evtcrate->Print();
154 if (evtdata)
155 evtdata->Print();
156 }
157
158 // end of small readin program
159
160 return 0;
161}
162
163
Note: See TracBrowser for help on using the repository browser.