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 |
|
---|
28 | int main(const int argc, const char **argv)
|
---|
29 | {
|
---|
30 | gLog << "==================================================" << endl;
|
---|
31 | gLog << " ReadRaw v0.1 " << endl;
|
---|
32 | gLog << " MARS - Read and print raw data file " << endl;
|
---|
33 | gLog << " Compiled on <" << __DATE__ << ">" << endl;
|
---|
34 | gLog << "==================================================" << endl;
|
---|
35 | gLog << endl;
|
---|
36 |
|
---|
37 | //
|
---|
38 | // check for the right usage of the program
|
---|
39 | //
|
---|
40 | if (argc!=2)
|
---|
41 | {
|
---|
42 | gLog << "Sorry the usage is:" << endl;
|
---|
43 | gLog << " readraw inputfile" << endl << endl;
|
---|
44 | return -1;
|
---|
45 | }
|
---|
46 |
|
---|
47 | //
|
---|
48 | // initialize ROOT (this is obligatory here)
|
---|
49 | //
|
---|
50 | TROOT simple("readraw","Mars - Read and print raw data file");
|
---|
51 |
|
---|
52 | //
|
---|
53 | // check whether the given files are OK.
|
---|
54 | //
|
---|
55 | if (gSystem->AccessPathName(argv[1], kFileExists))
|
---|
56 | {
|
---|
57 | gLog << "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 | MMcEvt *evtmc = new MMcEvt() ;
|
---|
68 | MMcTrig *trigmc = new MMcTrig() ;
|
---|
69 |
|
---|
70 | //
|
---|
71 | // open the file
|
---|
72 | //
|
---|
73 | gLog << " Open the file " << endl ;
|
---|
74 | TFile input(argv[1], "READ");
|
---|
75 |
|
---|
76 | //
|
---|
77 | // open the Run Header and read in
|
---|
78 | //
|
---|
79 | gLog << " Check the RunHeader " << endl ;
|
---|
80 | TTree *runtree = (TTree*) input.Get("RunHeaders") ;
|
---|
81 |
|
---|
82 | if (!runtree)
|
---|
83 | {
|
---|
84 | gLog << endl
|
---|
85 | << " WARNING: This file has NO RunHeader "
|
---|
86 | << endl << endl ;
|
---|
87 | }
|
---|
88 | else
|
---|
89 | {
|
---|
90 | gLog << " 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 | gLog << " Check the Event Tree " << endl ;
|
---|
102 | TTree *evttree = (TTree*) input.Get("Events") ;
|
---|
103 | gLog << " Check all the Branches in the Tree " << endl ;
|
---|
104 |
|
---|
105 | //
|
---|
106 | // check the branches in the Tree
|
---|
107 | //
|
---|
108 | TIter Next(evttree->GetListOfBranches());
|
---|
109 | TBranch *branch=NULL;
|
---|
110 |
|
---|
111 | while ((branch=(TBranch*)Next()))
|
---|
112 | {
|
---|
113 | //
|
---|
114 | // Get Name of Branch
|
---|
115 | //
|
---|
116 | const char *name = branch->GetName();
|
---|
117 |
|
---|
118 | if (!strcmp(name, "MRawEvtHeader"))
|
---|
119 | evttree->GetBranch("MRawEvtHeader")->SetAddress(&evtheader);
|
---|
120 |
|
---|
121 | if (!strcmp(name, "MTime"))
|
---|
122 | evttree->GetBranch("MTime")->SetAddress(&evttime);
|
---|
123 |
|
---|
124 | if (!strcmp(name, "MRawEvtData"))
|
---|
125 | evttree->GetBranch("MRawEvtData")->SetAddress(&evtdata);
|
---|
126 |
|
---|
127 | if (!strcmp(name, "MRawCrateArray"))
|
---|
128 | evttree->GetBranch("MRawCrateArray")->SetAddress(&evtcrate);
|
---|
129 |
|
---|
130 | if (!strcmp(name, "MMcTrig"))
|
---|
131 | evttree->GetBranch("MMcTrig")->SetAddress(&trigmc);
|
---|
132 |
|
---|
133 | if (!strcmp(name, "MMcEvt"))
|
---|
134 | evttree->GetBranch("MMcEvt")->SetAddress(&evtmc);
|
---|
135 | }
|
---|
136 |
|
---|
137 | //
|
---|
138 | // loop over all entries
|
---|
139 | //
|
---|
140 | Int_t nent = (Int_t)evttree->GetEntries();
|
---|
141 |
|
---|
142 | gLog << endl << endl;
|
---|
143 | gLog << " Entries in Tree Data: " << dec << nent << endl;
|
---|
144 |
|
---|
145 | for (Int_t i = 0; i<nent; i++)
|
---|
146 | {
|
---|
147 | gLog << "Entry: " << i << endl;
|
---|
148 |
|
---|
149 | //
|
---|
150 | // readin event with the selected branches
|
---|
151 | //
|
---|
152 | evttree->GetEvent(i);
|
---|
153 |
|
---|
154 | evtmc->Print();
|
---|
155 |
|
---|
156 | evtheader->Print();
|
---|
157 | evttime->Print();
|
---|
158 | evtcrate->Print();
|
---|
159 | evtdata->Print();
|
---|
160 | }
|
---|
161 |
|
---|
162 | // end of small readin program
|
---|
163 |
|
---|
164 | return 0;
|
---|
165 | }
|
---|
166 |
|
---|
167 |
|
---|