source: trunk/MagicSoft/Mars/mfileio/MReadCurrents.cc@ 2152

Last change on this file since 2152 was 2147, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 6.1 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.h>
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
54// --------------------------------------------------------------------------
55//
56// Default constructor. Creates an array which stores the file names of
57// the files which should be read. If a filename is given it is added
58// to the list.
59//
60MReadCurrents::MReadCurrents(const char *fname,
61 const char *name,
62 const char *title)
63 : fIn(NULL)
64{
65 fName = name ? name : "MReadCurrents";
66 fTitle = title ? title : "Task to loop over events in CT1 ascii file";
67
68 //
69 // remember file name for opening the file in the preprocessor
70 //
71 fFileNames = new TList;
72 fFileNames->SetOwner();
73
74 if (fname)
75 AddFile(fname);
76}
77
78// --------------------------------------------------------------------------
79//
80// Delete the filename list and the input stream if one exists.
81//
82MReadCurrents::~MReadCurrents()
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//
93Int_t MReadCurrents::AddFile(const char *txt, Int_t)
94{
95 TNamed *name = new TNamed(txt, "");
96 fFileNames->AddLast(name);
97 return 1;
98}
99
100// --------------------------------------------------------------------------
101//
102// This opens the next file in the list and deletes its name from the list.
103//
104Bool_t MReadCurrents::OpenNextFile()
105{
106 //
107 // open the input stream and check if it is really open (file exists?)
108 //
109 if (fIn)
110 delete fIn;
111 fIn = NULL;
112
113 //
114 // Check for the existance of a next file to read
115 //
116 TNamed *file = (TNamed*)fFileNames->First();
117 if (!file)
118 return kFALSE;
119
120 //
121 // open the file which is the first one in the chain
122 //
123 const char *name = file->GetName();
124
125 const char *expname = gSystem->ExpandPathName(name);
126 fIn = new ifstream(expname);
127 delete [] expname;
128
129 const Bool_t noexist = !(*fIn);
130
131 if (noexist)
132 *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
133 else
134 *fLog << "Open file: '" << name << "'" << endl;
135
136 //
137 // Remove this file from the list of pending files
138 //
139 fFileNames->Remove(file);
140
141 return !noexist;
142}
143
144// --------------------------------------------------------------------------
145//
146// Open the first file in the list. Check for the output containers or create
147// them if they don't exist.
148//
149// Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
150//
151Bool_t MReadCurrents::PreProcess(MParList *pList)
152{
153 //
154 // Preprocessing
155 //
156
157 //
158 // Try to open at least one (the first) file
159 //
160 if (!OpenNextFile())
161 return kFALSE;
162
163 //
164 //
165 //
166 fTime = (MTime*)pList->FindCreateObj("MTime", "MTimeCurrents");
167 if (!fTime)
168 return kFALSE;
169
170 //
171 //
172 //
173 fCurrents = (MCurrents*)pList->FindCreateObj("MCurrents");
174 if (!fCurrents)
175 return kFALSE;
176
177 return kTRUE;
178}
179
180// --------------------------------------------------------------------------
181//
182// Check for the event number and depending on this number decide if
183// pedestals or event data has to be read.
184//
185// If the end of the file is reached try to open the next in the list. If
186// there is now next file stop the eventloop.
187//
188Bool_t MReadCurrents::Process()
189{
190 //
191 // check if we are done. Try to open the next file in chain.
192 // If it was possible start reading. If not break the event loop
193 //
194 //
195 // "DC %s %s %02d %02d %02d %03d 577*%05d \n",
196 // status1, status2, hour, minute, second, ms,
197 // 577 * pixel_DC_readout_in_nAmp
198 //
199 TString str;
200 *fIn >> str;
201 while (!(*fIn))
202 {
203 if (!OpenNextFile())
204 return kFALSE;
205 *fIn >> str;
206 }
207 if (str!=TString("DC"))
208 {
209 *fLog << err << "DC not found in file..." << endl;
210 return kFALSE;
211 }
212
213 *fIn >> str;
214 fCurrents->SetStatus1(str);
215
216 *fIn >> str;
217 fCurrents->SetStatus2(str);
218
219 Int_t h, m, s, ms;
220 *fIn >> h >> m >> s >> ms;
221 fTime->SetTime(h, m, s, ms*1000000);
222
223 for (int i=0; i<577; i++)
224 *fIn >> (*fCurrents)[i];
225
226 return (bool)*fIn;
227}
Note: See TracBrowser for help on using the repository browser.