1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | ////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MRawFileWrite
|
---|
28 | //
|
---|
29 | // Here we write the root containers which contains the data from a
|
---|
30 | // root binary file to a root file. See also MRawFileRead
|
---|
31 | //
|
---|
32 | // Input Containers:
|
---|
33 | // MRawRunHeader, MRawEvtHeader, MRawEvtData, MRawCrateArray, MRawEvtTime
|
---|
34 | //
|
---|
35 | // Output Containers:
|
---|
36 | // -/-
|
---|
37 | //
|
---|
38 | ////////////////////////////////////////////////////////////////////////
|
---|
39 |
|
---|
40 | #include "MRawFileWrite.h"
|
---|
41 |
|
---|
42 | #include <TFile.h>
|
---|
43 | #include <TTree.h>
|
---|
44 | #include <TBranch.h>
|
---|
45 |
|
---|
46 | #include "MLog.h"
|
---|
47 | #include "MLogManip.h"
|
---|
48 |
|
---|
49 | #include "MParList.h"
|
---|
50 | #include "MRawRunHeader.h"
|
---|
51 | #include "MRawEvtHeader.h"
|
---|
52 | #include "MRawEvtData.h"
|
---|
53 | #include "MRawCrateArray.h"
|
---|
54 |
|
---|
55 | ClassImp(MRawFileWrite);
|
---|
56 |
|
---|
57 | // --------------------------------------------------------------------------
|
---|
58 | //
|
---|
59 | // Default constructor. It opens the output file (root-file)
|
---|
60 | //
|
---|
61 | MRawFileWrite::MRawFileWrite(const char *fname,
|
---|
62 | const Option_t *opt,
|
---|
63 | const char *ftitle,
|
---|
64 | const Int_t comp,
|
---|
65 | const char *name, const char *title)
|
---|
66 | {
|
---|
67 | *fName = name ? name : "MRawFileWrite";
|
---|
68 | *fTitle = title ? title : "Write task to write DAQ root files";
|
---|
69 |
|
---|
70 | //
|
---|
71 | // Open a rootfile
|
---|
72 | //
|
---|
73 | fOut = new TFile(fname, opt, ftitle, comp);
|
---|
74 | }
|
---|
75 |
|
---|
76 | MRawFileWrite::~MRawFileWrite()
|
---|
77 | {
|
---|
78 | //
|
---|
79 | // delete instance, this laso does a fOut->Close()
|
---|
80 | //
|
---|
81 | delete fOut;
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | // --------------------------------------------------------------------------
|
---|
86 | //
|
---|
87 | // The PreProcess function checks for the following input containers:
|
---|
88 | // - MRawEvtHeader
|
---|
89 | // - MRawEvtData
|
---|
90 | // - MRawCrateArray
|
---|
91 | // - MRawEvtTime <MTime>
|
---|
92 | // - MRawRunHeader
|
---|
93 | // if a container isn't found the eventloop is stopped.
|
---|
94 | //
|
---|
95 | // The tree which should containe the run header is created. <RunHeaders>
|
---|
96 | // The trees which contains the Events <Events>, <PedEvents>, <CalEvents>
|
---|
97 | // are created.
|
---|
98 | //
|
---|
99 | Bool_t MRawFileWrite::PreProcess (MParList *pList)
|
---|
100 | {
|
---|
101 | //
|
---|
102 | // test whether file is now open or not
|
---|
103 | //
|
---|
104 | if (!fOut->IsOpen())
|
---|
105 | {
|
---|
106 | *fLog << dbginf << "Cannot open file '" << fOut->GetName() << "'" << endl;
|
---|
107 | return kFALSE;
|
---|
108 | }
|
---|
109 |
|
---|
110 | //
|
---|
111 | // remember the pointer to the parameter list fur further usage
|
---|
112 | //
|
---|
113 | pParList = pList;
|
---|
114 |
|
---|
115 | //
|
---|
116 | // check if MEvtHeader exists in the Parameter list already.
|
---|
117 | // if not create one and add them to the list
|
---|
118 | //
|
---|
119 | fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
---|
120 | if (!fRawEvtHeader)
|
---|
121 | {
|
---|
122 | *fLog << dbginf << "MRawEvtHeader not found... aborting." << endl;
|
---|
123 | return kFALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 | fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
127 | if (!fRawEvtData)
|
---|
128 | {
|
---|
129 | *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
|
---|
134 | if (!fRawCrateArray)
|
---|
135 | {
|
---|
136 | *fLog << dbginf << "MRawCrateArray not found... aborting." << endl;
|
---|
137 | return kFALSE;
|
---|
138 | }
|
---|
139 |
|
---|
140 | fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
|
---|
141 | if (!fRawEvtTime)
|
---|
142 | {
|
---|
143 | *fLog << dbginf << "MRawEvtTime not found... aborting." << endl;
|
---|
144 | return kFALSE;
|
---|
145 | }
|
---|
146 |
|
---|
147 | fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
148 | if (!fRawRunHeader)
|
---|
149 | {
|
---|
150 | *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
|
---|
151 | return kFALSE;
|
---|
152 | }
|
---|
153 |
|
---|
154 | //
|
---|
155 | // Write the run header information to the file
|
---|
156 | //
|
---|
157 | TTree *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
|
---|
158 | TBranch *tb = rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000, 1);
|
---|
159 | rh->Fill();
|
---|
160 | rh->Write();
|
---|
161 | delete tb;
|
---|
162 | delete rh;
|
---|
163 |
|
---|
164 | //
|
---|
165 | // create data trees for the three types of data
|
---|
166 | //
|
---|
167 | fTData = new TTree("Events", "Normal Triggered Events");
|
---|
168 | fTPedestal = new TTree("PedEvents", "Pedestal Triggered Events");
|
---|
169 | fTCalibration = new TTree("CalEvents", "Calibration Triggered Events");
|
---|
170 |
|
---|
171 | //
|
---|
172 | // create all branches which are necessary
|
---|
173 | //
|
---|
174 | fTData ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
---|
175 | fTPedestal ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
---|
176 | fTCalibration->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
---|
177 | fTData ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
---|
178 | fTPedestal ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
---|
179 | fTCalibration->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
---|
180 | fTData ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 32000, 1);
|
---|
181 | fTPedestal ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
|
---|
182 | fTCalibration->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
|
---|
183 | //fTree->Branch("MRawCrateArray", fRawCrateArray->GetArray(), 32000, 1);
|
---|
184 | fTData ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
---|
185 | fTPedestal ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
---|
186 | fTCalibration->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
---|
187 |
|
---|
188 | return kTRUE;
|
---|
189 | }
|
---|
190 |
|
---|
191 | // --------------------------------------------------------------------------
|
---|
192 | //
|
---|
193 | // Gets the trigger type from the run header to decide into which tree the
|
---|
194 | // event should be filled in and fills it into this tree.
|
---|
195 | //
|
---|
196 | Bool_t MRawFileWrite::Process()
|
---|
197 | {
|
---|
198 | //
|
---|
199 | // get the trigger type of the actual event
|
---|
200 | //
|
---|
201 | const UShort_t type = fRawEvtHeader->GetTrigType();
|
---|
202 |
|
---|
203 | //
|
---|
204 | // writa data to the tree. the tree is choosen by the type of the event
|
---|
205 | //
|
---|
206 | switch (type)
|
---|
207 | {
|
---|
208 | case kTTEvent:
|
---|
209 | fTData->Fill();
|
---|
210 | return kTRUE;
|
---|
211 |
|
---|
212 | case kTTPedestal:
|
---|
213 | fTPedestal->Fill();
|
---|
214 | return kTRUE;
|
---|
215 |
|
---|
216 | case kTTCalibration:
|
---|
217 | fTCalibration->Fill();
|
---|
218 | return kTRUE;
|
---|
219 | }
|
---|
220 |
|
---|
221 | *fLog << dbginf << "Got wrong number for the trigger type: " << type;
|
---|
222 | *fLog << " - skipping" << endl;
|
---|
223 |
|
---|
224 | return kCONTINUE;
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 | // --------------------------------------------------------------------------
|
---|
229 | //
|
---|
230 | // Close the TFile object and delete it.
|
---|
231 | //
|
---|
232 | Bool_t MRawFileWrite::PostProcess()
|
---|
233 | {
|
---|
234 | //
|
---|
235 | // empty data stream
|
---|
236 | //
|
---|
237 | fOut->Write();
|
---|
238 |
|
---|
239 | return kTRUE;
|
---|
240 | }
|
---|
241 |
|
---|