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

Last change on this file since 993 was 949, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 7.0 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 (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
88// --------------------------------------------------------------------------
89//
90// The PreProcess function checks for the following input containers:
91// - MRawEvtHeader
92// - MRawEvtData
93// - MRawCrateArray
94// - MRawEvtTime <MTime>
95// - MRawRunHeader
96// if a container isn't found the eventloop is stopped.
97//
98// The tree which should containe the run header is created. <RunHeaders>
99// The trees which contains the Events <Events>, <PedEvents>, <CalEvents>
100// are created.
101//
102Bool_t MRawFileWrite::PreProcess (MParList *pList)
103{
104 //
105 // test whether file is now open or not
106 //
107 if (!fOut->IsOpen())
108 {
109 *fLog << dbginf << "Error: Cannot open file '" << fOut->GetName() << "'" << endl;
110 return kFALSE;
111 }
112
113 //
114 // remember the pointer to the parameter list fur further usage
115 //
116 pParList = pList;
117
118 //
119 // check if MEvtHeader exists in the Parameter list already.
120 // if not create one and add them to the list
121 //
122 fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
123 if (!fRawEvtHeader)
124 {
125 *fLog << dbginf << "MRawEvtHeader not found... aborting." << endl;
126 return kFALSE;
127 }
128
129 fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
130 if (!fRawEvtData)
131 {
132 *fLog << dbginf << "MRawEvtData not found... aborting." << endl;
133 return kFALSE;
134 }
135
136 fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
137 if (!fRawCrateArray)
138 {
139 *fLog << dbginf << "MRawCrateArray not found... aborting." << endl;
140 return kFALSE;
141 }
142
143 fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
144 if (!fRawEvtTime)
145 {
146 *fLog << dbginf << "MRawEvtTime not found... aborting." << endl;
147 return kFALSE;
148 }
149
150 fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
151 if (!fRawRunHeader)
152 {
153 *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
154 return kFALSE;
155 }
156
157 //
158 // Write the run header information to the file
159 //
160 TTree *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
161 TBranch *tb = rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000, 1);
162 rh->Fill();
163 rh->Write();
164 delete tb;
165 delete rh;
166
167 //
168 // create data trees for the three types of data
169 //
170 fTData = new TTree("Events", "Normal Triggered Events");
171 fTPedestal = new TTree("PedEvents", "Pedestal Triggered Events");
172 fTCalibration = new TTree("CalEvents", "Calibration Triggered Events");
173
174 //
175 // create all branches which are necessary
176 //
177 fTData ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
178 fTPedestal ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
179 fTCalibration->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
180 fTData ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
181 fTPedestal ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
182 fTCalibration->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
183 fTData ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 32000, 1);
184 fTPedestal ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
185 fTCalibration->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
186 //fTree->Branch("MRawCrateArray", fRawCrateArray->GetArray(), 32000, 1);
187 fTData ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
188 fTPedestal ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
189 fTCalibration->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
190
191 return kTRUE;
192}
193
194// --------------------------------------------------------------------------
195//
196// Gets the trigger type from the run header to decide into which tree the
197// event should be filled in and fills it into this tree.
198//
199Bool_t MRawFileWrite::Process()
200{
201 //
202 // get the trigger type of the actual event
203 //
204 const UShort_t type = fRawEvtHeader->GetTrigType();
205
206 //
207 // writa data to the tree. the tree is choosen by the type of the event
208 //
209 switch (type)
210 {
211 case kTTEvent:
212 fTData->Fill();
213 return kTRUE;
214
215 case kTTPedestal:
216 fTPedestal->Fill();
217 return kTRUE;
218
219 case kTTCalibration:
220 fTCalibration->Fill();
221 return kTRUE;
222 }
223
224 *fLog << dbginf << "Got wrong number for the trigger type: " << type;
225 *fLog << " - skipping" << endl;
226
227 return kCONTINUE;
228}
229
Note: See TracBrowser for help on using the repository browser.