source: trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc@ 945

Last change on this file since 945 was 857, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.8 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): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
19! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
20!
21! Copyright: MAGIC Software Development, 2000-2001
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27// //
28// MCT1ReadAscii //
29// //
30// Reads a ascii file with CT1 data. The file description and some example //
31// files can be found on the Magic homepage. //
32// //
33// Input Containers: //
34// -/- //
35// //
36// Output Containers: //
37// MCerPhotEvt //
38// //
39/////////////////////////////////////////////////////////////////////////////
40
41#include "MCT1ReadAscii.h"
42
43#include <fstream.h>
44
45#include <TArrayC.h>
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MParList.h"
51#include "MCerPhotEvt.h"
52#include "MPedestalCam.h"
53
54ClassImp(MCT1ReadAscii);
55
56// --------------------------------------------------------------------------
57//
58// Default constructor. Creates an array which stores the file names of
59// the files which should be read. If a filename is given it is added
60// to the list.
61//
62MCT1ReadAscii::MCT1ReadAscii(const char *fname,
63 const char *name,
64 const char *title)
65{
66 *fName = name ? name : "MCT1ReadAscii";
67 *fTitle = title ? title : "Task to loop over events in CT1 ascii file";
68
69 //
70 // remember file name for opening the file in the preprocessor
71 //
72 fFileNames = new TArrayC;
73 if (fname)
74 AddFile(fname);
75}
76
77// --------------------------------------------------------------------------
78//
79// Delete the filename list and the input stream if one exists.
80//
81MCT1ReadAscii::~MCT1ReadAscii()
82{
83 delete fFileNames;
84 if (fIn)
85 delete fIn;
86}
87
88// --------------------------------------------------------------------------
89//
90// Add this file as the last entry in the chain
91//
92void MCT1ReadAscii::AddFile(const char *txt)
93{
94 const int sz = fFileNames->GetSize();
95 const int tsz = strlen(txt)+1;
96
97 fFileNames->Set(sz+tsz);
98
99 memcpy(fFileNames->GetArray()+sz, txt, tsz);
100}
101
102// --------------------------------------------------------------------------
103//
104// This opens the next file in the list and deletes its name from the list.
105//
106Bool_t MCT1ReadAscii::OpenNextFile()
107{
108 //
109 // open the input stream and check if it is really open (file exists?)
110 //
111 if (fIn)
112 delete fIn;
113 fIn = NULL;
114
115 const int arrsz = fFileNames->GetSize();
116
117 if (arrsz<1)
118 return kFALSE;
119
120 //
121 // open the file which is the first one in the chain
122 //
123 const char *name = fFileNames->GetArray();
124
125 fIn = new ifstream(name);
126 if (!(*fIn))
127 {
128 *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
129 return kFALSE;
130 }
131
132 //
133 // remove the first entry from the chain
134 //
135 *fLog << "Open file: '" << name << "'" << endl;
136
137 //
138 // create the new char array containing the filenames to process
139 //
140 const int sz = strlen(name)+1;
141
142 char *dummy = new char[arrsz-sz];
143 memcpy(dummy, name+sz, arrsz-sz);
144
145 //
146 // dummy will be deleted by the destructor of fFileNames
147 //
148 fFileNames->Adopt(arrsz-sz, dummy);
149
150 return kTRUE;
151
152}
153
154// --------------------------------------------------------------------------
155//
156// Open the first file in the list. Check for the output containers or create
157// them if they don't exist.
158//
159// Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
160//
161Bool_t MCT1ReadAscii::PreProcess(MParList *pList)
162{
163 //
164 // Preprocessing
165 //
166
167 //
168 // Try to open at least one (the first) file
169 //
170 if (!OpenNextFile())
171 return kFALSE;
172
173 //
174 // look for the MCerPhotEvt class in the plist
175 //
176 fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
177 if (!fNphot)
178 return kFALSE;
179
180 //
181 // look for the pedestal class in the plist
182 //
183 fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
184 if (!fPedest)
185 return kFALSE;
186
187 fPedest->InitSize(127);
188
189 return kTRUE;
190}
191
192// --------------------------------------------------------------------------
193//
194// Read apedestal entry (line) from the file
195//
196void MCT1ReadAscii::ReadPedestals()
197{
198 *fLog << "MCT1Pedestals::AsciiRead: Reading Pedestals..." << endl;
199
200 //
201 // skip the next 4 values
202 //
203 Float_t val;
204
205 *fIn >> val;
206 *fIn >> val;
207 *fIn >> val;
208 *fIn >> val;
209
210 //
211 // read in the next 127 numbers as the pedestals
212 //
213 for (Int_t i = 0; i<127; i++)
214 {
215 *fIn >> val;
216
217 if (val > 0.0)
218 (*fPedest)[i].SetMeanRms(val);
219 }
220}
221
222// --------------------------------------------------------------------------
223//
224// Read a data entry (line) from the file
225//
226void MCT1ReadAscii::ReadData()
227{
228 //
229 // clear the list of cerphot-events
230 //
231 fNphot->Clear();
232
233 //
234 // five unsused numbers
235 //
236 Int_t val;
237
238 *fIn >> val; // ener
239 *fIn >> val; // zenang
240 *fIn >> val; // sec1
241 *fIn >> val; // sec2
242
243 //
244 // read in the number of cerenkov photons and add the 'new' pixel
245 // too the list with it's id, number of photons and error
246 //
247 for (Int_t i = 0; i<127; i++ )
248 {
249 Float_t nphot;
250
251 *fIn >> nphot;
252
253 if (nphot > 0.0)
254 fNphot->AddPixel(i, nphot, (*fPedest)[i].GetMeanRms());
255 }
256
257}
258
259// --------------------------------------------------------------------------
260//
261// Check for the event number and depending on this number decide if
262// pedestals or event data has to be read.
263//
264// If the end of the file is reached try to open the next in the list. If
265// there is now next file stop the eventloop.
266//
267Bool_t MCT1ReadAscii::Process()
268{
269 //
270 // FIXME. This function should switch between reading pedestals and
271 // reading event data by the 'switch entry'.
272 // After reading it should set the InputStreamID correctly.
273 // ( should use MPedestalCam )
274 //
275
276 //
277 // read in the event nr
278 //
279 Int_t evtnr;
280 *fIn >> evtnr;
281
282 //
283 // check if we are done. Try to open the next file in chain.
284 // If it was possible start reading. If not break the event loop
285 //
286 if (fIn->eof())
287 return OpenNextFile() ? kCONTINUE : kFALSE;
288
289 //
290 // if the first number is negativ this is a pedestal line:
291 // read in pedestals
292 //
293 // FIXME! Set InputStreamID
294
295 if (evtnr < 0)
296 {
297 ReadPedestals();
298 return kCONTINUE;
299 }
300
301 ReadData();
302
303 return kTRUE;
304}
305
Note: See TracBrowser for help on using the repository browser.