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 "MMcEvt.hxx"
|
---|
21 | #include "MMcTrig.hxx"
|
---|
22 |
|
---|
23 | #include "MGMarsMain.h"
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // This is an demonstration how to read in a merpped root file
|
---|
28 | //
|
---|
29 | /////////////////////////////////////////////////////////////////////////////
|
---|
30 |
|
---|
31 | int main(const int argc, const char **argv)
|
---|
32 | {
|
---|
33 | cout << "==================================================" << endl ;
|
---|
34 | cout << " ReadRaw v0.1" << endl;
|
---|
35 | cout << " MARS Merging and Preprocessing Program" << endl ;
|
---|
36 | cout << " Compiled on <" << __DATE__ << ">" << endl ;
|
---|
37 | cout << "==================================================" << endl ;
|
---|
38 | cout << endl;
|
---|
39 |
|
---|
40 | //
|
---|
41 | // check for the right usage of the program
|
---|
42 | //
|
---|
43 | if (argc!=2)
|
---|
44 | {
|
---|
45 | cout << "Sorry the usage is:" << endl;
|
---|
46 | cout << " readraw inputfile" << endl << endl;
|
---|
47 | return -1;
|
---|
48 | }
|
---|
49 |
|
---|
50 | //
|
---|
51 | // initialize ROOT (this is obligatory here)
|
---|
52 | //
|
---|
53 | TROOT simple("Readraw","Mars - Merging and Preprocessing Program");
|
---|
54 |
|
---|
55 | //
|
---|
56 | // check whether the given files are OK.
|
---|
57 | //
|
---|
58 | if (gSystem->AccessPathName(argv[1], kFileExists))
|
---|
59 | {
|
---|
60 | cout << "Sorry, the file '" << argv[1] << "' doesn't exist." << endl;
|
---|
61 | return -1;
|
---|
62 | }
|
---|
63 |
|
---|
64 | MRawRunHeader *runheader = new MRawRunHeader();
|
---|
65 | MRawEvtHeader *evtheader = new MRawEvtHeader();
|
---|
66 | MTime *evttime = new MTime();
|
---|
67 | MRawEvtData *evtdata = new MRawEvtData();
|
---|
68 | MRawCrateArray *evtcrate = new MRawCrateArray();
|
---|
69 |
|
---|
70 | MMcEvt *evtmc = new MMcEvt() ;
|
---|
71 | MMcTrig *trigmc = new MMcTrig() ;
|
---|
72 |
|
---|
73 | //
|
---|
74 | // open the file
|
---|
75 | //
|
---|
76 | cout << " Open the file " << endl ;
|
---|
77 | TFile input(argv[1], "READ");
|
---|
78 |
|
---|
79 | //
|
---|
80 | // open the Run Header and read in
|
---|
81 | //
|
---|
82 | cout << " Check the RunHeader " << endl ;
|
---|
83 | TTree *runtree = (TTree*) input.Get("RunHeaders") ;
|
---|
84 |
|
---|
85 | if (!runtree)
|
---|
86 | {
|
---|
87 | cout << endl
|
---|
88 | << " WARNING: This file has NO RunHeader "
|
---|
89 | << endl << endl ;
|
---|
90 | }
|
---|
91 | else
|
---|
92 | {
|
---|
93 | cout << " Entries in Tree RunHeaders: " << dec << runtree->GetEntries() << endl ;
|
---|
94 |
|
---|
95 | runtree->GetBranch("MRawRunHeader")->SetAddress(&runheader);
|
---|
96 | runtree->GetEvent(0);
|
---|
97 |
|
---|
98 | runheader->Print();
|
---|
99 | }
|
---|
100 |
|
---|
101 | //
|
---|
102 | // open the DataTree and read in
|
---|
103 | //
|
---|
104 | cout << " Check the Event Tree " << endl ;
|
---|
105 | TTree *evttree = (TTree*) input.Get("Events") ;
|
---|
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 | if (!strcmp(name, "MRawEvtHeader"))
|
---|
122 | evttree->GetBranch("MRawEvtHeader")->SetAddress(&evtheader);
|
---|
123 |
|
---|
124 | if (!strcmp(name, "MTime"))
|
---|
125 | evttree->GetBranch("MTime")->SetAddress(&evttime);
|
---|
126 |
|
---|
127 | if (!strcmp(name, "MRawEvtData"))
|
---|
128 | evttree->GetBranch("MRawEvtData")->SetAddress(&evtdata);
|
---|
129 |
|
---|
130 | if (!strcmp(name, "MRawCrateArray"))
|
---|
131 | evttree->GetBranch("MRawCrateArray")->SetAddress(&evtcrate);
|
---|
132 |
|
---|
133 | if ( ! strcmp(name, "MMcTrig") )
|
---|
134 | evttree->GetBranch("MMcTrig")->SetAddress(&trigmc);
|
---|
135 |
|
---|
136 | if (!strcmp(name, "MMcEvt"))
|
---|
137 | evttree->GetBranch("MMcEvt")->SetAddress(&evtmc);
|
---|
138 |
|
---|
139 | }
|
---|
140 |
|
---|
141 | //
|
---|
142 | // loop over all entries
|
---|
143 | //
|
---|
144 | Int_t nent = (Int_t)evttree->GetEntries();
|
---|
145 |
|
---|
146 | cout << endl << endl;
|
---|
147 | cout << " Entries in Tree Data: " << dec << nent << endl;
|
---|
148 |
|
---|
149 | for (Int_t i = 0; i<nent; i++)
|
---|
150 | {
|
---|
151 | cout << "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 |
|
---|