source: tags/Mars-V0.8.1/mfileio/MReadCurrents.cc

Last change on this file was 2377, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 5.6 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): Thomas Bretz, 5/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MReadCurrents
28//
29// Input Containers:
30// -/-
31//
32// Output Containers:
33// MCerPhotEvt
34//
35/////////////////////////////////////////////////////////////////////////////
36#include "MReadCurrents.h"
37
38#include <stdlib.h> // atoi
39#include <fstream>
40
41#include <TList.h>
42#include <TSystem.h>
43
44#include "MTime.h"
45#include "MCurrents.h"
46
47#include "MLog.h"
48#include "MLogManip.h"
49
50#include "MParList.h"
51
52ClassImp(MReadCurrents);
53
54using namespace std;
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//
62MReadCurrents::MReadCurrents(const char *fname,
63 const char *name,
64 const char *title)
65 : fIn(NULL), fNumPixel(577)
66{
67 fName = name ? name : "MReadCurrents";
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 TList;
74 fFileNames->SetOwner();
75
76 if (fname)
77 AddFile(fname);
78}
79
80// --------------------------------------------------------------------------
81//
82// Delete the filename list and the input stream if one exists.
83//
84MReadCurrents::~MReadCurrents()
85{
86 delete fFileNames;
87 if (fIn)
88 delete fIn;
89}
90
91// --------------------------------------------------------------------------
92//
93// Add this file as the last entry in the chain
94//
95Int_t MReadCurrents::AddFile(const char *txt, Int_t)
96{
97 TNamed *name = new TNamed(txt, "");
98 fFileNames->AddLast(name);
99 return 1;
100}
101
102// --------------------------------------------------------------------------
103//
104// This opens the next file in the list and deletes its name from the list.
105//
106Bool_t MReadCurrents::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 //
116 // Check for the existance of a next file to read
117 //
118 TNamed *file = (TNamed*)fFileNames->First();
119 if (!file)
120 return kFALSE;
121
122 //
123 // open the file which is the first one in the chain
124 //
125 const char *name = file->GetName();
126
127 const char *expname = gSystem->ExpandPathName(name);
128 fIn = new ifstream(expname);
129 delete [] expname;
130
131 const Bool_t noexist = !(*fIn);
132
133 if (noexist)
134 *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
135 else
136 *fLog << "Open file: '" << name << "'" << endl;
137
138 //
139 // Remove this file from the list of pending files
140 //
141 fFileNames->Remove(file);
142
143 return !noexist;
144}
145
146// --------------------------------------------------------------------------
147//
148// Open the first file in the list. Check for the output containers or create
149// them if they don't exist.
150//
151// Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
152//
153Int_t MReadCurrents::PreProcess(MParList *pList)
154{
155 //
156 // Preprocessing
157 //
158
159 //
160 // Try to open at least one (the first) file
161 //
162 if (!OpenNextFile())
163 return kFALSE;
164
165 //
166 //
167 //
168 fTime = (MTime*)pList->FindCreateObj("MTime", "MTimeCurrents");
169 if (!fTime)
170 return kFALSE;
171
172 //
173 //
174 //
175 fCurrents = (MCurrents*)pList->FindCreateObj("MCurrents");
176 if (!fCurrents)
177 return kFALSE;
178
179 // FIXME: Calculate number of events!
180
181 return kTRUE;
182}
183
184// --------------------------------------------------------------------------
185//
186// Check for the event number and depending on this number decide if
187// pedestals or event data has to be read.
188//
189// If the end of the file is reached try to open the next in the list. If
190// there is now next file stop the eventloop.
191//
192Int_t MReadCurrents::Process()
193{
194 //
195 // check if we are done. Try to open the next file in chain.
196 // If it was possible start reading. If not break the event loop
197 //
198 //
199 // "DC %s %s %02d %02d %02d %03d 577*%05d \n",
200 // status1, status2, hour, minute, second, ms,
201 // 577 * pixel_DC_readout_in_nAmp
202 //
203 TString str;
204 *fIn >> str;
205 while (!(*fIn))
206 {
207 if (!OpenNextFile())
208 return kFALSE;
209 *fIn >> str;
210 }
211 if (str!=TString("DC"))
212 {
213 *fLog << err << "DC not found in file..." << endl;
214 return kFALSE;
215 }
216
217 *fIn >> str;
218 fCurrents->SetStatus1(str);
219
220 *fIn >> str;
221 fCurrents->SetStatus2(str);
222
223 Int_t h, m, s, ms;
224 *fIn >> h >> m >> s >> ms;
225 fTime->SetTime(h, m, s, ms*1000000);
226
227 for (int i=0; i<fNumPixel; i++)
228 *fIn >> (*fCurrents)[i];
229
230 return (bool)*fIn;
231}
Note: See TracBrowser for help on using the repository browser.