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 |
|
---|
49 | ClassImp(MRawFileWrite)
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Default constructor. It opens the output file (root-file)
|
---|
54 | //
|
---|
55 | MRawFileWrite::MRawFileWrite(const char *fname, Option_t *opt,
|
---|
56 | const char *ftitle, Int_t comp,
|
---|
57 | const char *name, const char *title)
|
---|
58 | {
|
---|
59 | *fName = name ? name : "MRawFileWrite";
|
---|
60 | *fTitle = title ? title : "Write task to write DAQ root files";
|
---|
61 |
|
---|
62 | // FIXME: move file open to preproc!
|
---|
63 |
|
---|
64 | //
|
---|
65 | // Open a rootfile
|
---|
66 | //
|
---|
67 | fOut = new TFile(fname, opt, ftitle, comp);
|
---|
68 |
|
---|
69 | //
|
---|
70 | // test whether file is now open or not
|
---|
71 | //
|
---|
72 | if (!fOut->IsOpen())
|
---|
73 | {
|
---|
74 | *fLog << "MRawFileWrite::MRawFileWrite: ERROR: Cannot open file '";
|
---|
75 | *fLog << fname << "'" << endl;
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | // --------------------------------------------------------------------------
|
---|
80 | //
|
---|
81 | // The PreProcess function checks for the following input containers:
|
---|
82 | // - MRawEvtHeader
|
---|
83 | // - MRawEvtData
|
---|
84 | // - MRawCrateArray
|
---|
85 | // - MRawEvtTime <MTime>
|
---|
86 | // - MRawRunHeader
|
---|
87 | // if a container isn't found the eventloop is stopped.
|
---|
88 | //
|
---|
89 | // The tree which should containe the run header is created. <RunHeaders>
|
---|
90 | // The trees which contains the Events <Events>, <PedEvents>, <CalEvents>
|
---|
91 | // are created.
|
---|
92 | //
|
---|
93 | Bool_t MRawFileWrite::PreProcess (MParList *pList)
|
---|
94 | {
|
---|
95 | //
|
---|
96 | // remember the pointer to the parameter list fur further usage
|
---|
97 | //
|
---|
98 | pParList = pList;
|
---|
99 |
|
---|
100 | //
|
---|
101 | // check if MEvtHeader exists in the Parameter list already.
|
---|
102 | // if not create one and add them to the list
|
---|
103 | //
|
---|
104 | fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
|
---|
105 | if (!fRawEvtHeader)
|
---|
106 | {
|
---|
107 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtHeader not found... aborting." << endl;
|
---|
108 | return kFALSE;
|
---|
109 | }
|
---|
110 |
|
---|
111 | fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
|
---|
112 | if (!fRawEvtData)
|
---|
113 | {
|
---|
114 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawEvtData not found... aborting." << endl;
|
---|
115 | return kFALSE;
|
---|
116 | }
|
---|
117 |
|
---|
118 | fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
|
---|
119 | if (!fRawCrateArray)
|
---|
120 | {
|
---|
121 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawCrateArray not found... aborting." << endl;
|
---|
122 | return kFALSE;
|
---|
123 | }
|
---|
124 |
|
---|
125 | fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
|
---|
126 | if (!fRawEvtTime)
|
---|
127 | {
|
---|
128 | *fLog << "MRawFileWrite::PreProcess - WARNING: MRawEvtTime not found... aborting." << endl;
|
---|
129 | return kFALSE;
|
---|
130 | }
|
---|
131 |
|
---|
132 | fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
133 | if (!fRawRunHeader)
|
---|
134 | {
|
---|
135 | *fLog << "MRawFileWrite::PreProcess - ERROR: MRawRunHeader not found... aborting." << endl;
|
---|
136 | return kFALSE;
|
---|
137 | }
|
---|
138 |
|
---|
139 | //
|
---|
140 | // Write the run header information to the file
|
---|
141 | //
|
---|
142 | TTree *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
|
---|
143 | TBranch *tb = rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000, 1);
|
---|
144 | rh->Fill();
|
---|
145 | rh->Write();
|
---|
146 | delete tb;
|
---|
147 | delete rh;
|
---|
148 |
|
---|
149 | //
|
---|
150 | // create data trees for the three types of data
|
---|
151 | //
|
---|
152 | fTData = new TTree("Events", "Normal Triggered Events");
|
---|
153 | fTPedestal = new TTree("PedEvents", "Pedestal Triggered Events");
|
---|
154 | fTCalibration = new TTree("CalEvents", "Calibration Triggered Events");
|
---|
155 |
|
---|
156 | //
|
---|
157 | // create all branches which are necessary
|
---|
158 | //
|
---|
159 | fTData ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
---|
160 | fTPedestal ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
---|
161 | fTCalibration->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
|
---|
162 | fTData ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
---|
163 | fTPedestal ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
---|
164 | fTCalibration->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
|
---|
165 | fTData ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 32000, 1);
|
---|
166 | fTPedestal ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
|
---|
167 | fTCalibration->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
|
---|
168 | //fTree->Branch("MRawCrateArray", fRawCrateArray->GetArray(), 32000, 1);
|
---|
169 | fTData ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
---|
170 | fTPedestal ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
---|
171 | fTCalibration->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
|
---|
172 |
|
---|
173 | return kTRUE;
|
---|
174 | }
|
---|
175 |
|
---|
176 | // --------------------------------------------------------------------------
|
---|
177 | //
|
---|
178 | // Gets the trigger type from the run header to decide into which tree the
|
---|
179 | // event should be filled in and fills it into this tree.
|
---|
180 | //
|
---|
181 | Bool_t MRawFileWrite::Process()
|
---|
182 | {
|
---|
183 | //
|
---|
184 | // get the trigger type of the actual event
|
---|
185 | //
|
---|
186 | const UShort_t type = fRawEvtHeader->GetTrigType();
|
---|
187 |
|
---|
188 | //
|
---|
189 | // writa data to the tree. the tree is choosen by the type of the event
|
---|
190 | //
|
---|
191 | switch (type)
|
---|
192 | {
|
---|
193 | case kTTEvent:
|
---|
194 | fTData->Fill();
|
---|
195 | return kTRUE;
|
---|
196 |
|
---|
197 | case kTTPedestal:
|
---|
198 | fTPedestal->Fill();
|
---|
199 | return kTRUE;
|
---|
200 |
|
---|
201 | case kTTCalibration:
|
---|
202 | fTCalibration->Fill();
|
---|
203 | return kTRUE;
|
---|
204 | }
|
---|
205 |
|
---|
206 | *fLog << dbginf << "Got wrong number for the trigger type: " << type;
|
---|
207 | *fLog << " - skipping" << endl;
|
---|
208 |
|
---|
209 | return kCONTINUE;
|
---|
210 | }
|
---|
211 |
|
---|
212 |
|
---|
213 | // --------------------------------------------------------------------------
|
---|
214 | //
|
---|
215 | // Close the TFile object and delete it.
|
---|
216 | //
|
---|
217 | Bool_t MRawFileWrite::PostProcess()
|
---|
218 | {
|
---|
219 | //
|
---|
220 | // empty data stream
|
---|
221 | //
|
---|
222 | fOut->Write();
|
---|
223 |
|
---|
224 | //
|
---|
225 | // close root file
|
---|
226 | //
|
---|
227 | fOut->Close();
|
---|
228 |
|
---|
229 | //
|
---|
230 | // delete instance
|
---|
231 | //
|
---|
232 | delete fOut;
|
---|
233 |
|
---|
234 | return kTRUE;
|
---|
235 | }
|
---|
236 |
|
---|