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

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