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 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
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 | using namespace std;
|
---|
58 |
|
---|
59 | // --------------------------------------------------------------------------
|
---|
60 | //
|
---|
61 | // Default constructor. It opens the output file (root-file)
|
---|
62 | //
|
---|
63 | MRawFileWrite::MRawFileWrite(const char *fname,
|
---|
64 | const Option_t *opt,
|
---|
65 | const char *ftitle,
|
---|
66 | const Int_t comp,
|
---|
67 | const char *name, const char *title)
|
---|
68 | {
|
---|
69 | fName = name ? name : "MRawFileWrite";
|
---|
70 | fTitle = title ? title : "Write task to write DAQ root files";
|
---|
71 |
|
---|
72 | //
|
---|
73 | // Open a rootfile
|
---|
74 | //
|
---|
75 | TString str(fname);
|
---|
76 | if (!str.EndsWith(".root", TString::kIgnoreCase))
|
---|
77 | str += ".root";
|
---|
78 |
|
---|
79 | fOut = new TFile(str, opt, ftitle, comp);
|
---|
80 | }
|
---|
81 |
|
---|
82 | MRawFileWrite::~MRawFileWrite()
|
---|
83 | {
|
---|
84 | //
|
---|
85 | // delete instance, this also does a fOut->Close()
|
---|
86 | //
|
---|
87 | if (fOut->IsOpen())
|
---|
88 | fOut->Write();
|
---|
89 |
|
---|
90 | delete fOut;
|
---|
91 |
|
---|
92 | //
|
---|
93 | // Remark:
|
---|
94 | // - Trees are automatically deleted by the the file
|
---|
95 | // (unless file.SetDirectory(0) was called)
|
---|
96 | // - Branches are automatically deleted by the tree destructor
|
---|
97 | //
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | // --------------------------------------------------------------------------
|
---|
102 | //
|
---|
103 | // The PreProcess function checks for the following input containers:
|
---|
104 | // - MRawEvtHeader
|
---|
105 | // - MRawEvtData
|
---|
106 | // - MRawCrateArray
|
---|
107 | // - MTime
|
---|
108 | // - MRawRunHeader
|
---|
109 | // if a container isn't found the eventloop is stopped.
|
---|
110 | //
|
---|
111 | // The tree which should containe the run header is created. <RunHeaders>
|
---|
112 | // The trees which contains the Events <Events>, <PedEvents>, <CalEvents>
|
---|
113 | // are created.
|
---|
114 | //
|
---|
115 | Int_t MRawFileWrite::PreProcess (MParList *pList)
|
---|
116 | {
|
---|
117 | //
|
---|
118 | // test whether file is now open or not
|
---|
119 | //
|
---|
120 | if (!fOut->IsOpen())
|
---|
121 | {
|
---|
122 | *fLog << dbginf << "Error: Cannot open file '" << fOut->GetName() << "'" << endl;
|
---|
123 | return kFALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 | //
|
---|
127 | // remember the pointer to the parameter list fur further usage
|
---|
128 | //
|
---|
129 | pParList = pList;
|
---|
130 |
|
---|
131 | //
|
---|
132 | // check if MEvtHeader exists in the Parameter list already.
|
---|
133 | // if not create one and add them to the list
|
---|
134 | //
|
---|
135 | fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
---|
136 | if (!fRawEvtHeader)
|
---|
137 | {
|
---|
138 | *fLog << err << dbginf << "MRawEvtHeader not found... aborting." << endl;
|
---|
139 | return kFALSE;
|
---|
140 | }
|
---|
141 |
|
---|
142 | fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
143 | if (!fRawEvtData)
|
---|
144 | {
|
---|
145 | *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
|
---|
146 | return kFALSE;
|
---|
147 | }
|
---|
148 |
|
---|
149 | fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
|
---|
150 | if (!fRawCrateArray)
|
---|
151 | {
|
---|
152 | *fLog << err << dbginf << "MRawCrateArray not found... aborting." << endl;
|
---|
153 | return kFALSE;
|
---|
154 | }
|
---|
155 |
|
---|
156 | fTime = (MTime*)pList->FindObject("MTime");
|
---|
157 | if (!fTime)
|
---|
158 | {
|
---|
159 | *fLog << err << dbginf << "MTime not found... aborting." << endl;
|
---|
160 | return kFALSE;
|
---|
161 | }
|
---|
162 |
|
---|
163 | fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
164 | if (!fRawRunHeader)
|
---|
165 | {
|
---|
166 | *fLog << err << dbginf << "MRawRunHeader not found... aborting." << endl;
|
---|
167 | return kFALSE;
|
---|
168 | }
|
---|
169 |
|
---|
170 | //
|
---|
171 | // Remark:
|
---|
172 | // - Trees are automatically deleted by the the file
|
---|
173 | // (unless file.SetDirectory(0) was called)
|
---|
174 | // - Branches are automatically deleted by the tree destructor
|
---|
175 | //
|
---|
176 | fTRunHeader = new TTree("RunHeaders", "Run headers of all runs in this file");
|
---|
177 | fTRunHeader->Branch("MRawRunHeader.", "MRawRunHeader", &fRawRunHeader, 32000);
|
---|
178 |
|
---|
179 | //
|
---|
180 | // create data trees for the three types of data
|
---|
181 | //
|
---|
182 | fTData = new TTree("Events", "Normal Triggered Events");
|
---|
183 | fTPedestal = new TTree("Pedestals", "Pedestal Triggered Events");
|
---|
184 | fTCalibration = new TTree("Calibration", "Calibration Triggered Events");
|
---|
185 |
|
---|
186 | //
|
---|
187 | // From the root dicumentation:
|
---|
188 | //
|
---|
189 | // Note that calling TTree::AutoSave too frequently (or similarly calling
|
---|
190 | // TTree::SetAutoSave with a small value) is an expensive operation.
|
---|
191 | // You should make tests for your own application to find a compromize
|
---|
192 | // between speed and the quantity of information you may loose in case of
|
---|
193 | // a job crash.
|
---|
194 | //
|
---|
195 | // In case your program crashes before closing the file holding this tree,
|
---|
196 | // the file will be automatically recovered when you will connect the file
|
---|
197 | // in UPDATE mode.
|
---|
198 | // The Tree will be recovered at the status corresponding to the last AutoSave.
|
---|
199 | //
|
---|
200 | fTData ->SetAutoSave(2000000000); // 2GB
|
---|
201 | fTPedestal ->SetAutoSave(2000000000); // 2GB
|
---|
202 | fTCalibration->SetAutoSave(2000000000); // 2GB
|
---|
203 |
|
---|
204 | //
|
---|
205 | // create all branches which are necessary
|
---|
206 | //
|
---|
207 | // FIXME: Can we calculate a good buffer size out of the event size?
|
---|
208 | // using splitlevel=0 sppeds up writing by a factor of 5-10%
|
---|
209 | fTData ->Branch("MTime.", "MTime", &fTime, 32000);
|
---|
210 | fTPedestal ->Branch("MTime.", "MTime", &fTime, 32000);
|
---|
211 | fTCalibration->Branch("MTime.", "MTime", &fTime, 32000);
|
---|
212 | fTData ->Branch("MRawEvtHeader.", "MRawEvtHeader", &fRawEvtHeader, 32000);
|
---|
213 | fTPedestal ->Branch("MRawEvtHeader.", "MRawEvtHeader", &fRawEvtHeader, 32000);
|
---|
214 | fTCalibration->Branch("MRawEvtHeader.", "MRawEvtHeader", &fRawEvtHeader, 32000);
|
---|
215 | fTData ->Branch("MRawEvtData.", "MRawEvtData", &fRawEvtData, 320000);
|
---|
216 | fTPedestal ->Branch("MRawEvtData.", "MRawEvtData", &fRawEvtData, 320000);
|
---|
217 | fTCalibration->Branch("MRawEvtData.", "MRawEvtData", &fRawEvtData, 320000);
|
---|
218 | //fTree->Branch("MRawCrateArray", fRawCrateArray->GetArray(), 32000, 1);
|
---|
219 | fTData ->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
|
---|
220 | fTPedestal ->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
|
---|
221 | fTCalibration->Branch("MRawCrateArray.", "MRawCrateArray", &fRawCrateArray, 32000);
|
---|
222 |
|
---|
223 | return kTRUE;
|
---|
224 | }
|
---|
225 |
|
---|
226 | // --------------------------------------------------------------------------
|
---|
227 | //
|
---|
228 | // Write the run header information to the file
|
---|
229 | //
|
---|
230 | Bool_t MRawFileWrite::ReInit(MParList *pList)
|
---|
231 | {
|
---|
232 | fTRunHeader->Fill();
|
---|
233 | return kTRUE;
|
---|
234 | }
|
---|
235 |
|
---|
236 | // --------------------------------------------------------------------------
|
---|
237 | //
|
---|
238 | // Gets the trigger type from the run header to decide into which tree the
|
---|
239 | // event should be filled in and fills it into this tree.
|
---|
240 | //
|
---|
241 | Int_t MRawFileWrite::Process()
|
---|
242 | {
|
---|
243 | //
|
---|
244 | // get the trigger type of the actual event
|
---|
245 | //
|
---|
246 | const UShort_t type = fRawEvtHeader->GetTrigType();
|
---|
247 |
|
---|
248 | //
|
---|
249 | // writa data to the tree. the tree is choosen by the type of the event
|
---|
250 | //
|
---|
251 | switch (type)
|
---|
252 | {
|
---|
253 | case MRawEvtHeader::kTTEvent:
|
---|
254 | fTData->Fill();
|
---|
255 | return kTRUE;
|
---|
256 |
|
---|
257 | case MRawEvtHeader::kTTPedestal:
|
---|
258 | fTPedestal->Fill();
|
---|
259 | return kTRUE;
|
---|
260 |
|
---|
261 | case MRawEvtHeader::kTTCalibration:
|
---|
262 | fTCalibration->Fill();
|
---|
263 | return kTRUE;
|
---|
264 | }
|
---|
265 |
|
---|
266 | *fLog << warn << dbginf << "Got wrong number for the trigger type: " << type;
|
---|
267 | *fLog << " - skipped" << endl;
|
---|
268 |
|
---|
269 | return kCONTINUE;
|
---|
270 | }
|
---|
271 |
|
---|