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

Last change on this file since 738 was 717, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.7 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2// //
3// MCT1ReadAscii //
4// //
5/////////////////////////////////////////////////////////////////////////////
6
7#include "MCT1ReadAscii.h"
8
9#include <fstream.h>
10
11#include <TArrayC.h>
12
13#include "MLog.h"
14#include "MLogManip.h"
15
16#include "MParList.h"
17#include "MCerPhotEvt.h"
18#include "MPedestalCam.h"
19
20ClassImp(MCT1ReadAscii)
21
22MCT1ReadAscii::MCT1ReadAscii(const char *fname,
23 const char *name,
24 const char *title)
25{
26 *fName = name ? name : "MCT1ReadAscii";
27 *fTitle = title ? title : "Task to loop over events in CT1 ascii file";
28
29 //
30 // remember file name for opening the file in the preprocessor
31 //
32 fFileNames = new TArrayC;
33 if (fname)
34 AddFile(fname);
35}
36
37MCT1ReadAscii::~MCT1ReadAscii()
38{
39 delete fFileNames;
40 if (fIn)
41 delete fIn;
42}
43
44void MCT1ReadAscii::AddFile(const char *txt)
45{
46 //
47 // Add this file as the last entry in the chain
48 //
49 const int sz = fFileNames->GetSize();
50 const int tsz = strlen(txt)+1;
51
52 fFileNames->Set(sz+tsz);
53
54 memcpy(fFileNames->GetArray()+sz, txt, tsz);
55}
56
57Bool_t MCT1ReadAscii::OpenNextFile()
58{
59 //
60 // open the input stream and check if it is really open (file exists?)
61 //
62 if (fIn)
63 delete fIn;
64 fIn = NULL;
65
66 const int arrsz = fFileNames->GetSize();
67
68 if (arrsz<1)
69 return kFALSE;
70
71 //
72 // open the file which is the first one in the chain
73 //
74 const char *name = fFileNames->GetArray();
75
76 fIn = new ifstream(name);
77 if (!(*fIn))
78 {
79 *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
80 return kFALSE;
81 }
82
83 //
84 // remove the first entry from the chain
85 //
86 *fLog << "Open file: '" << name << "'" << endl;
87
88 //
89 // create the new char array containing the filenames to process
90 //
91 const int sz = strlen(name)+1;
92
93 char *dummy = new char[arrsz-sz];
94 memcpy(dummy, name+sz, arrsz-sz);
95
96 //
97 // dummy will be deleted by the destructor of fFileNames
98 //
99 fFileNames->Adopt(arrsz-sz, dummy);
100
101 return kTRUE;
102
103}
104
105Bool_t MCT1ReadAscii::PreProcess(MParList *pList)
106{
107 //
108 // Preprocessing
109 //
110
111 //
112 // Try to open at least one (the first) file
113 //
114 if (!OpenNextFile())
115 return kFALSE;
116
117 //
118 // look for the MCerPhotEvt class in the plist
119 //
120 fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
121 if (!fNphot)
122 return kFALSE;
123
124 //
125 // look for the pedestal class in the plist
126 //
127 fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
128 if (!fPedest)
129 return kFALSE;
130
131 fPedest->InitSize(127);
132
133 return kTRUE;
134}
135
136void MCT1ReadAscii::ReadPedestals()
137{
138 *fLog << "MCT1Pedestals::AsciiRead: Reading Pedestals..." << endl;
139
140 //
141 // skip the next 4 values
142 //
143 Float_t val;
144
145 *fIn >> val;
146 *fIn >> val;
147 *fIn >> val;
148 *fIn >> val;
149
150 //
151 // read in the next 127 numbers as the pedestals
152 //
153 for (Int_t i = 0; i<127; i++)
154 {
155 *fIn >> val;
156
157 if (val > 0.0)
158 (*fPedest)[i].SetMeanRms(val);
159 }
160}
161
162void MCT1ReadAscii::ReadData()
163{
164 //
165 // clear the list of cerphot-events
166 //
167 fNphot->Clear();
168
169 //
170 // five unsused numbers
171 //
172 Int_t val;
173
174 *fIn >> val; // ener
175 *fIn >> val; // zenang
176 *fIn >> val; // sec1
177 *fIn >> val; // sec2
178
179 //
180 // read in the number of cerenkov photons and add the 'new' pixel
181 // too the list with it's id, number of photons and error
182 //
183 for (Int_t i = 0; i<127; i++ )
184 {
185 Float_t nphot;
186
187 *fIn >> nphot;
188
189 if (nphot > 0.0)
190 fNphot->AddPixel(i, nphot, (*fPedest)[i].GetMeanRms());
191 }
192
193}
194
195Bool_t MCT1ReadAscii::Process()
196{
197 //
198 // FIXME. This function should switch between reading pedestals and
199 // reading event data by the 'switch entry'.
200 // After reading it should set the InputStreamID correctly.
201 // ( should use MPedestalCam )
202 //
203
204 //
205 // read in the event nr
206 //
207 Int_t evtnr;
208 *fIn >> evtnr;
209
210 //
211 // check if we are done. Try to open the next file in chain.
212 // If it was possible start reading. If not break the event loop
213 //
214 if (fIn->eof())
215 return OpenNextFile() ? kCONTINUE : kFALSE;
216
217 //
218 // if the first number is negativ this is a pedestal line:
219 // read in pedestals
220 //
221 // FIXME! Set InputStreamID
222
223 if (evtnr < 0)
224 {
225 ReadPedestals();
226 return kCONTINUE;
227 }
228
229 ReadData();
230
231 return kTRUE;
232}
233
Note: See TracBrowser for help on using the repository browser.