source: trunk/MagicSoft/Mars/readraw.cc@ 1941

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