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

Last change on this file since 575 was 547, checked in by harald, 24 years ago
Now the readraw program is also able to read in the MC data.
File size: 4.0 KB
Line 
1#include <iostream.h>
2
3#include <TSystem.h>
4
5#include "TFile.h"
6#include "TTree.h"
7#include "TBranch.h"
8
9#include "MParList.h"
10#include "MTaskList.h"
11#include "MEvtLoop.h"
12
13#include "MTime.h"
14#include "MRawRunHeader.h"
15#include "MRawEvtHeader.h"
16#include "MRawEvtData.h"
17#include "MRawCrateArray.h"
18#include "MInputStreamID.h"
19
20#include "MGMarsMain.h"
21
22/////////////////////////////////////////////////////////////////////////////
23//
24// This is an demonstration how to read in a merpped root file
25//
26/////////////////////////////////////////////////////////////////////////////
27
28int main(const int argc, const char **argv)
29{
30 cout << "==================================================" << endl ;
31 cout << " ReadRaw v0.1" << endl;
32 cout << " MARS Merging and Preprocessing Program" << endl ;
33 cout << " Compiled on <" << __DATE__ << ">" << endl ;
34 cout << "==================================================" << endl ;
35 cout << endl;
36
37 //
38 // check for the right usage of the program
39 //
40 if (argc!=2)
41 {
42 cout << "Sorry the usage is:" << endl;
43 cout << " readraw inputfile" << endl << endl;
44 return -1;
45 }
46
47 //
48 // initialize ROOT (this is obligatory here)
49 //
50 TROOT simple("Readraw","Mars - Merging and Preprocessing Program");
51
52 //
53 // check whether the given files are OK.
54 //
55 if (gSystem->AccessPathName(argv[1], kFileExists))
56 {
57 cout << "Sorry, the file '" << argv[1] << "' doesn't exist." << endl;
58 return -1;
59 }
60
61 MRawRunHeader *runheader = new MRawRunHeader();
62 MRawEvtHeader *evtheader = new MRawEvtHeader();
63 MTime *evttime = new MTime();
64 MRawEvtData *evtdata = new MRawEvtData();
65 MRawCrateArray *evtcrate = new MRawCrateArray();
66
67 //
68 // open the file
69 //
70
71 cout << " Open the file " << endl ;
72
73 TFile input(argv[1], "READ");
74
75 //
76 // open the Run Header and read in
77 //
78
79 cout << " Check the RunHeader " << endl ;
80 TTree *runtree = (TTree*) input.Get("RunHeaders") ;
81
82 if (!runtree)
83 {
84 cout << endl
85 << " WARNING: This file has NO RunHeader "
86 << endl << endl ;
87 }
88 else
89 {
90 cout << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl ;
91
92 runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
93 runtree->GetEvent(0);
94
95 runheader->Print();
96 }
97
98 //
99 // open the DataTree and read in
100 //
101
102 cout << " Check the Event Tree " << endl ;
103
104 TTree *evttree = (TTree*) input.Get("Events") ;
105
106 cout << " Check all the Branches in the Tree " << endl ;
107
108
109 // check the branches in the Tree
110
111 TIter Next(evttree->GetListOfBranches());
112 TBranch *branch=NULL;
113
114 while ( (branch=(TBranch*)Next()) )
115 {
116 //
117 // Get Name of Branch
118 //
119 const char *name = branch->GetName();
120
121 // cout << name << endl ;
122
123 if ( ! strcmp(name, "MRawEvtHeader") )
124 evttree->GetBranch("MRawEvtHeader")->SetAddress(&evtheader);
125
126 if ( ! strcmp(name, "MTime") )
127 evttree->GetBranch("MTime")->SetAddress(&evttime);
128
129 if ( ! strcmp(name, "MRawEvtData") )
130 evttree->GetBranch("MRawEvtData")->SetAddress(&evtdata);
131
132 if ( ! strcmp(name, "MRawCrateArray") )
133 evttree->GetBranch("MRawCrateArray")->SetAddress(&evtcrate);
134
135 if ( ! strcmp(name, "MMcEvt") )
136 cout << " Not able to connect to class MMcEvt yet " << endl ;
137
138 if ( ! strcmp(name, "MMcTrig") )
139 cout << " Not able to connect to class MMcTrig yet " << endl ;
140
141
142 }
143
144 // loop over all entries
145
146 Int_t nent = (Int_t)evttree->GetEntries();
147
148 cout << endl << endl
149 << " Entries in Tree Data: " << dec << nent << endl;
150
151 for (Int_t i = 0; i<nent; i++)
152 {
153 cout << "Entry: " << i << endl;
154
155 // readin event with the selected branches
156 evttree->GetEvent(i);
157
158 evtheader->Print();
159 evttime->Print();
160 evtcrate->Print();
161 evtdata->Print();
162 }
163
164 // end of small readin program
165
166 return 0;
167}
168
169
Note: See TracBrowser for help on using the repository browser.