source: branches/start/MagicSoft/Mars/mraw/MRawFileWrite.cc@ 9223

Last change on this file since 9223 was 454, checked in by harald, 24 years ago
Import the first sources of the MAGIC Analysis and Reconstruction Software. T. Bretz and H. Kornmayer 20.December 2000
File size: 5.0 KB
Line 
1////////////////////////////////////////////////////////////////////////
2//
3// MRawFileWrite
4//
5// Here we write the root containers which contains the data from a
6// root binary file to a root file. See also MRawFileRead
7//
8////////////////////////////////////////////////////////////////////////
9
10#include "MRawFileWrite.h"
11
12#include <iostream.h>
13
14#include <TFile.h>
15#include <TTree.h>
16#include <TBranch.h>
17
18#include "MParList.h"
19#include "MRawRunHeader.h"
20#include "MRawEvtHeader.h"
21#include "MRawEvtData.h"
22#include "MRawCrateArray.h"
23
24ClassImp(MRawFileWrite)
25
26MRawFileWrite::MRawFileWrite(const char *fname, Option_t *opt,
27 const char *ftitle, Int_t comp,
28 const char *name, const char *title)
29{
30 *fName = name ? name : "MRawFileWrite";
31 *fTitle = title ? title : "Write task to write DAQ root files";
32
33 // FIXME: move file open to preproc!
34
35 //
36 // Open a rootfile
37 //
38 fOut = new TFile(fname, opt, ftitle, comp);
39
40 //
41 // test whether file is now open or not
42 //
43 if (!fOut->IsOpen())
44 {
45 cout << "MRawFileWrite::MRawFileWrite: ERROR: Cannot open file '";
46 cout << fname << "'" << endl;
47 }
48}
49
50Bool_t MRawFileWrite::PreProcess (MParList *pList)
51{
52 //
53 // remember the pointer to the parameter list fur further usage
54 //
55 pParList = pList;
56
57 //
58 // check if MEvtHeader exists in the Parameter list already.
59 // if not create one and add them to the list
60 //
61 fRawEvtHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
62 if (!fRawEvtHeader)
63 {
64 cout << "MRawFileWrite::PreProcess - ERROR: MRawEvtHeader not found... aborting." << endl;
65 return kFALSE;
66 }
67
68 fRawEvtData = (MRawEvtData*)pList->FindObject("MRawEvtData");
69 if (!fRawEvtData)
70 {
71 cout << "MRawFileWrite::PreProcess - ERROR: MRawEvtData not found... aborting." << endl;
72 return kFALSE;
73 }
74
75 fRawCrateArray = (MRawCrateArray*)pList->FindObject("MRawCrateArray");
76 if (!fRawCrateArray)
77 {
78 cout << "MRawFileWrite::PreProcess - ERROR: MRawCrateArray not found... aborting." << endl;
79 return kFALSE;
80 }
81
82 fRawEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
83 if (!fRawEvtTime)
84 {
85 cout << "MRawFileWrite::PreProcess - WARNING: MRawEvtTime not found... aborting." << endl;
86 return kFALSE;
87 }
88
89 fRawRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
90 if (!fRawRunHeader)
91 {
92 cout << "MRawFileWrite::PreProcess - ERROR: MRawRunHeader not found... aborting." << endl;
93 return kFALSE;
94 }
95
96 //
97 // Write the run header information to the file
98 //
99 TTree *rh = new TTree("RunHeaders", "Run headers of all runs in this file");
100 TBranch *tb = rh->Branch("MRawRunHeader", "MRawRunHeader", &fRawRunHeader, 32000, 1);
101 rh->Fill();
102 rh->Write();
103 delete tb;
104 delete rh;
105
106 //
107 // create data trees for the three types of data
108 //
109 fTData = new TTree("Data", "Normal Triggered Data");
110 fTPedestal = new TTree("Pedestal", "Pedestal Triggered Data");
111 fTCalibration = new TTree("Calibration","Calibration Triggered Data");
112
113 //
114 // create all branches which are necessary
115 //
116 fTData ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
117 fTPedestal ->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
118 fTCalibration->Branch("MTime", "MTime", &fRawEvtTime, 32000, 1);
119 fTData ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
120 fTPedestal ->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
121 fTCalibration->Branch("MRawEvtHeader", "MRawEvtHeader", &fRawEvtHeader, 32000, 1);
122 fTData ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 32000, 1);
123 fTPedestal ->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
124 fTCalibration->Branch("MRawEvtData", "MRawEvtData", &fRawEvtData, 320000, 1);
125 //fTree->Branch("MRawCrateArray", fRawCrateArray->GetArray(), 32000, 1);
126 fTData ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
127 fTPedestal ->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
128 fTCalibration->Branch("MRawCrateArray", "MRawCrateArray", &fRawCrateArray, 32000, 1);
129
130 return kTRUE;
131}
132
133Bool_t MRawFileWrite::Process()
134{
135 //
136 // get the trigger type of the actual event
137 //
138 const UShort_t type = fRawEvtHeader->GetTrigType();
139
140 //
141 // writa data to the tree. the tree is choosen by the type of the event
142 //
143 switch (type)
144 {
145 case 0:
146 fTData->Fill();
147 break;
148 case 1:
149 fTPedestal->Fill();
150 break;
151 case 2:
152 fTCalibration->Fill();
153 break;
154 }
155
156 return kTRUE;
157}
158
159Bool_t MRawFileWrite::PostProcess()
160{
161 //
162 // empty data stream
163 //
164 fOut->Write();
165
166 //
167 // close root file
168 //
169 fOut->Close();
170
171 //
172 // delete instance
173 //
174 delete fOut;
175
176 return kTRUE;
177}
178
Note: See TracBrowser for help on using the repository browser.