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

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