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

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