source: trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc@ 1583

Last change on this file since 1583 was 1108, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 8.3 KB
Line 
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@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
55ClassImp(MRawFileWrite);
56
57// --------------------------------------------------------------------------
58//
59// Default constructor. It opens the output file (root-file)
60//
61MRawFileWrite::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
76MRawFileWrite::~MRawFileWrite()
77{
78 //
79 // delete instance, this also does a fOut->Close()
80 //
81 if (fOut->IsOpen())
82 fOut->Write();
83
84 delete fOut;
85
86 //
87 // Remark:
88 // - Trees are automatically deleted by the the file
89 // (unless file.SetDirectory(0) was called)
90 // - Branches are automatically deleted by the tree destructor
91 //
92}
93
94
95// --------------------------------------------------------------------------
96//
97// The PreProcess function checks for the following input containers:
98// - MRawEvtHeader
99// - MRawEvtData
100// - MRawCrateArray
101// - MRawEvtTime <MTime>
102// - MRawRunHeader
103// if a container isn't found the eventloop is stopped.
104//
105// The tree which should containe the run header is created. <RunHeaders>
106// The trees which contains the Events <Events>, <PedEvents>, <CalEvents>
107// are created.
108//
109Bool_t MRawFileWrite::PreProcess (MParList *pList)
110{
111 //
112 // test whether file is now open or not
113 //
114 if (!fOut->IsOpen())
115 {
116 *fLog << dbginf << "Error: Cannot open file '" << fOut->GetName() << "'" << endl;
117 return kFALSE;
118 }
119
120 //
121 // remember the pointer to the parameter list fur further usage
122 //
123 pParList = pList;
124
125 //
126 // check if MEvtHeader exists in the Parameter list already.
127 // if not create one and add them to the list
128 //
129 fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
130 if (!fRawEvtHeader)
131 {
132 *fLog << err << dbginf << "MRawEvtHeader not found... aborting." << endl;
133 return kFALSE;
134 }
135
136 fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
137 if (!fRawEvtData)
138 {
139 *fLog << err << dbginf << "MRawEvtData not found... aborting." << endl;
140 return kFALSE;
141 }
142
143 fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
144 if (!fRawCrateArray)
145 {
146 *fLog << err << dbginf << "MRawCrateArray not found... aborting." << endl;
147 return kFALSE;
148 }
149
150 fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
151 if (!fRawEvtTime)
152 {
153 *fLog << err << dbginf << "MRawEvtTime not found... aborting." << endl;
154 return kFALSE;
155 }
156
157 fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
158 if (!fRawRunHeader)
159 {
160 *fLog << err << dbginf << "MRawRunHeader not found... aborting." << endl;
161 return kFALSE;
162 }
163
164 //
165 // Remark:
166 // - Trees are automatically deleted by the the file
167 // (unless file.SetDirectory(0) was called)
168 // - Branches are automatically deleted by the tree destructor
169 //
170
171 //
172 // Write the run header information to the file
173 //
174 TTree *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
175 rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000);
176 rh->Fill();
177 //rh->Write();
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("PedEvents", "Pedestal Triggered Events");
184 fTCalibration = new TTree("CalEvents", "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", &fRawEvtTime, 32000);
210 fTPedestal ->Branch("MTime.", "MTime", &fRawEvtTime, 32000);
211 fTCalibration->Branch("MTime.", "MTime", &fRawEvtTime, 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// Gets the trigger type from the run header to decide into which tree the
229// event should be filled in and fills it into this tree.
230//
231Bool_t MRawFileWrite::Process()
232{
233 //
234 // get the trigger type of the actual event
235 //
236 const UShort_t type = fRawEvtHeader->GetTrigType();
237
238 //
239 // writa data to the tree. the tree is choosen by the type of the event
240 //
241 switch (type)
242 {
243 case kTTEvent:
244 fTData->Fill();
245 return kTRUE;
246
247 case kTTPedestal:
248 fTPedestal->Fill();
249 return kTRUE;
250
251 case kTTCalibration:
252 fTCalibration->Fill();
253 return kTRUE;
254 }
255
256 *fLog << warn << dbginf << "Got wrong number for the trigger type: " << type;
257 *fLog << " - skipped" << endl;
258
259 return kCONTINUE;
260}
261
Note: See TracBrowser for help on using the repository browser.