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

Last change on this file since 762 was 749, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.2 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////////////////////////////////////////////////////////////////////////
33
34#include "MRawFileWrite.h"
35
36#include <TFile.h>
37#include <TTree.h>
38#include <TBranch.h>
39
40#include "MLog.h"
41#include "MLogManip.h"
42
43#include "MParList.h"
44#include "MRawRunHeader.h"
45#include "MRawEvtHeader.h"
46#include "MRawEvtData.h"
47#include "MRawCrateArray.h"
48
49ClassImp(MRawFileWrite)
50
51MRawFileWrite::MRawFileWrite(const char *fname, Option_t *opt,
52 const char *ftitle, Int_t comp,
53 const char *name, const char *title)
54{
55 *fName = name ? name : "MRawFileWrite";
56 *fTitle = title ? title : "Write task to write DAQ root files";
57
58 // FIXME: move file open to preproc!
59
60 //
61 // Open a rootfile
62 //
63 fOut = new TFile(fname, opt, ftitle, comp);
64
65 //
66 // test whether file is now open or not
67 //
68 if (!fOut->IsOpen())
69 {
70 *fLog << "MRawFileWrite::MRawFileWrite: ERROR: Cannot open file '";
71 *fLog << fname << "'" << endl;
72 }
73}
74
75Bool_t MRawFileWrite::PreProcess (MParList *pList)
76{
77 //
78 // remember the pointer to the parameter list fur further usage
79 //
80 pParList = pList;
81
82 //
83 // check if MEvtHeader exists in the Parameter list already.
84 // if not create one and add them to the list
85 //
86 fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
87 if (!fRawEvtHeader)
88 {
89 *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtHeader not found... aborting." << endl;
90 return kFALSE;
91 }
92
93 fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
94 if (!fRawEvtData)
95 {
96 *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtData not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
101 if (!fRawCrateArray)
102 {
103 *fLog << "MRawFileWrite::PreProcess - ERROR: MRawCrateArray not found... aborting." << endl;
104 return kFALSE;
105 }
106
107 fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
108 if (!fRawEvtTime)
109 {
110 *fLog << "MRawFileWrite::PreProcess - WARNING: MRawEvtTime not found... aborting." << endl;
111 return kFALSE;
112 }
113
114 fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
115 if (!fRawRunHeader)
116 {
117 *fLog << "MRawFileWrite::PreProcess - ERROR: MRawRunHeader not found... aborting." << endl;
118 return kFALSE;
119 }
120
121 //
122 // Write the run header information to the file
123 //
124 TTree *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
125 TBranch *tb = rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000, 1);
126 rh->Fill();
127 rh->Write();
128 delete tb;
129 delete rh;
130
131 //
132 // create data trees for the three types of data
133 //
134 fTData = new TTree("Events", "Normal Triggered Events");
135 fTPedestal = new TTree("PedEvents", "Pedestal Triggered Events");
136 fTCalibration = new TTree("CalEvents", "Calibration Triggered Events");
137
138 //
139 // create all branches which are necessary
140 //
141 fTData ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
142 fTPedestal ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
143 fTCalibration->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
144 fTData ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
145 fTPedestal ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
146 fTCalibration->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
147 fTData ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 32000, 1);
148 fTPedestal ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
149 fTCalibration->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
150 //fTree->Branch("MRawCrateArray", fRawCrateArray->GetArray(), 32000, 1);
151 fTData ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
152 fTPedestal ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
153 fTCalibration->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
154
155 return kTRUE;
156}
157
158Bool_t MRawFileWrite::Process()
159{
160 //
161 // get the trigger type of the actual event
162 //
163 const UShort_t type = fRawEvtHeader->GetTrigType();
164
165 //
166 // writa data to the tree. the tree is choosen by the type of the event
167 //
168 switch (type)
169 {
170 case kTTEvent:
171 fTData->Fill();
172 return kTRUE;
173
174 case kTTPedestal:
175 fTPedestal->Fill();
176 return kTRUE;
177
178 case kTTCalibration:
179 fTCalibration->Fill();
180 return kTRUE;
181 }
182
183 *fLog << dbginf << "Got wrong number for the trigger type: " << type;
184 *fLog << " - skipping" << endl;
185
186 return kCONTINUE;
187}
188
189Bool_t MRawFileWrite::PostProcess()
190{
191 //
192 // empty data stream
193 //
194 fOut->Write();
195
196 //
197 // close root file
198 //
199 fOut->Close();
200
201 //
202 // delete instance
203 //
204 delete fOut;
205
206 return kTRUE;
207}
208
Note: See TracBrowser for help on using the repository browser.