source: trunk/MagicSoft/Mars/manalysis/MSourcePosfromStarPos.cc@ 3293

Last change on this file since 3293 was 3274, checked in by wittek, 21 years ago
*** empty log message ***
File size: 21.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! Author(s): Wolfgang Wittek 02/2004 <mailto:wittek@mppmu.mpg.de>
18!
19! Copyright: MAGIC Software Development, 2000-2004
20!
21!
22\* ======================================================================== */
23
24/////////////////////////////////////////////////////////////////////////////
25//
26// MSourcePosfromStarPos
27//
28// This is a task which
29// - calculates the position of the source in the camera
30// from the position of a known star in the camera
31// - and puts the source position into the container MSrcPosCam
32//
33// Input :
34// ASCII file containing for each run
35// - the run number
36// - the direction (theta, phi) the telescope is pointing to in [deg]
37// - the position (xStar, yStar) of a known star in the camera in [mm]
38// - the error (dxStar, dyStar) of this position in [mm]
39//
40// Output Containers :
41// MSrcPosCam
42//
43/////////////////////////////////////////////////////////////////////////////
44#include <TList.h>
45#include <TSystem.h>
46#include <TMatrixD.h>
47
48#include <fstream>
49
50#include "MSourcePosfromStarPos.h"
51
52#include "MParList.h"
53#include "MRawRunHeader.h"
54#include "MGeomCam.h"
55#include "MSrcPosCam.h"
56#include "MMcEvt.hxx"
57
58#include "MLog.h"
59#include "MLogManip.h"
60
61ClassImp(MSourcePosfromStarPos);
62
63using namespace std;
64
65// --------------------------------------------------------------------------
66//
67// Default constructor.
68//
69MSourcePosfromStarPos::MSourcePosfromStarPos(
70 const char *name, const char *title)
71 : fIn(NULL)
72{
73 fName = name ? name : "MSourcePosfromStarPos";
74 fTitle = title ? title : "Calculate source position from star position";
75
76 fFileNames = new TList;
77 fFileNames->SetOwner();
78
79 fRuns = 0;
80 fSize = 100;
81 fStars = 1;
82
83 fRunNr.Set(fSize);
84
85 fThetaTel.Set(fSize);
86 fPhiTel.Set(fSize);
87 fdThetaTel.Set(fSize);
88 fdPhiTel.Set(fSize);
89
90 fDecStar.Set(fStars);
91 fRaStar.Set(fStars);
92 fxStar.ResizeTo(fStars,fSize);
93 fyStar.ResizeTo(fStars,fSize);
94 fdxStar.ResizeTo(fStars,fSize);
95 fdyStar.ResizeTo(fStars,fSize);
96}
97
98// --------------------------------------------------------------------------
99//
100// Delete the filename list and the input stream if one exists.
101//
102MSourcePosfromStarPos::~MSourcePosfromStarPos()
103{
104 delete fFileNames;
105 if (fIn)
106 delete fIn;
107}
108
109
110// --------------------------------------------------------------------------
111//
112// Set the sky coordinates of the source and of the star
113//
114// Input :
115// declination in units of (Deg, Min, Sec)
116// right ascension in units of (Hour, Min, Sec)
117//
118
119void MSourcePosfromStarPos::SetSourceAndStarPosition(
120 TString nameSource,
121 Double_t decSourceDeg, Double_t decSourceMin, Double_t decSourceSec,
122 Double_t raSourceHour, Double_t raSourceMin, Double_t raSourceSec,
123 TString nameStar,
124 Double_t decStarDeg, Double_t decStarMin, Double_t decStarSec,
125 Double_t raStarHour, Double_t raStarMin, Double_t raStarSec )
126{
127 *fLog << "MSourcePosfromStarPos::SetSourceAndStarPosition :" << endl;
128 *fLog << " Source : " << nameSource << " " << decSourceDeg << ":"
129 << decSourceMin << ":" << decSourceSec << endl;
130 *fLog << " Star : " << nameStar << " " << decStarDeg << ":"
131 << decStarMin << ":" << decStarSec << endl;
132
133 // convert into radians
134 fDecSource = (decSourceDeg + decSourceMin/60.0 + decSourceSec/3600.0)
135 / kRad2Deg;
136 fRaSource = (raSourceHour + raSourceMin/60.0 + raSourceSec/3600.0)
137 * 360.0 / (24.0 * kRad2Deg);
138
139 fDecStar.Set(fStars);
140 fDecStar[fStars-1] = (decStarDeg + decStarMin/60.0 + decStarSec/3600.0)
141 / kRad2Deg;
142 fRaStar[fStars-1] = (raStarHour + raStarMin/60.0 + raStarSec/3600.0)
143 * 360.0 / (24.0 * kRad2Deg);
144
145 *fLog << all << "MSourcePosfromStarPos::SetSourceAndStarPosition; fDecSource, fRaSource, fDecStar, fRaStar were set to : [radians] "
146 << fDecSource << ", " << fRaSource << ", "
147 << fDecStar[fStars-1] << ", " << fRaStar[fStars-1] << endl;
148}
149
150// --------------------------------------------------------------------------
151//
152// Set the sky coordinates of another star
153//
154// Input :
155// declination in units of (Deg, Min, Sec)
156// right ascension in units of (Hour, Min, Sec)
157//
158
159void MSourcePosfromStarPos::AddStar(
160 TString nameStar,
161 Double_t decStarDeg, Double_t decStarMin, Double_t decStarSec,
162 Double_t raStarHour, Double_t raStarMin, Double_t raStarSec )
163{
164 *fLog << "MSourcePosfromStarPos::AddStar :" << endl;
165 *fLog << " Star : " << nameStar << " " << decStarDeg << ":"
166 << decStarMin << ":" << decStarSec << endl;
167
168 // convert into radians
169 Int_t fStars = fDecStar.GetSize() + 1;
170 fDecStar.Set(fStars);
171 fDecStar[fStars-1] = (decStarDeg + decStarMin/60.0 + decStarSec/3600.0)
172 / kRad2Deg;
173 fRaStar[fStars-1] = (raStarHour + raStarMin/60.0 + raStarSec/3600.0)
174 * 360.0 / (24.0 * kRad2Deg);
175
176 *fLog << all << "MSourcePosfromStarPos::AddStar; fDecStar, fRaStar were set to : [radians] "
177 << fDecStar[fStars-1] << ", " << fRaStar[fStars-1] << endl;
178}
179
180// --------------------------------------------------------------------------
181//
182//
183Int_t MSourcePosfromStarPos::PreProcess(MParList *pList)
184{
185 MGeomCam *geom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
186 if (!geom)
187 {
188 *fLog << err << "MSourcePosfromStarPos : MGeomCam (Camera Geometry) missing in Parameter List... aborting." << endl;
189 return kFALSE;
190 }
191 fMm2Deg = geom->GetConvMm2Deg();
192 // fDistCameraReflector is the distance of the camera from the reflector center in [mm]
193 fDistCameraReflector = kRad2Deg / fMm2Deg;
194 *fLog << all << "MSourcePosfromStarPos::PreProcess; fMm2Deg, fDistCameraReflector = "
195 << fMm2Deg << ", " << fDistCameraReflector << endl;
196
197
198 fRun = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
199 if (!fRun)
200 {
201 *fLog << err << "MSourcePosfromStarPos::PreProcess; MRawRunHeader not found... aborting." << endl;
202 return kFALSE;
203 }
204
205
206 fMcEvt = (MMcEvt*)pList->FindCreateObj("MMcEvt");
207 if (!fMcEvt)
208 {
209 *fLog << err << "MSourcePosfromStarPos::PreProcess; MMcEvt not found... aborting." << endl;
210 return kFALSE;
211 }
212
213
214 fSrcPos = (MSrcPosCam*)pList->FindObject(AddSerialNumber("MSrcPosCam"));
215 if (!fSrcPos)
216 {
217 *fLog << err << "MSourcePosfromStarPos::PreProcess; MSrcPosCam not found... aborting" << endl;
218 return kFALSE;
219 }
220
221 //---------------------------------------------------------------------
222 // read all files and call ReadData() to read and store the information
223 //
224
225 while(1)
226 {
227 if (!OpenNextFile())
228 {
229 *fLog << "there is no more file to open" << endl;
230 break;
231 }
232
233 *fLog << "read data" << endl;
234 while (1)
235 {
236 if (fIn->eof())
237 {
238 *fLog << "eof encountered; open next file" << endl;
239
240 if (!OpenNextFile()) break;
241 }
242
243 // FIXME! Set InputStreamID
244
245 ReadData();
246 }
247 }
248
249 *fLog << "all data were read" << endl;
250 FixSize();
251 //-------------------------------------------------------------
252
253 return kTRUE;
254}
255
256//=========================================================================
257//
258// SourcefromStar
259//
260// this routine calculates the position of a source (for example Crab) in the camera
261// from the position of a star (for example ZetaTauri) in the camera. The latter
262// position may have been determined by analysing the DC currents in the different
263// pixels.
264//
265// Input : thetaTel, phiTel the direction the telescope is pointing to,
266// in local coordinates
267// f the distance between camera and reflector
268// decStar, raStar the position of the star in sky coordinates
269// decSource, raSource the position of the source in sky coordinates
270// xStar, yStar the position of the star in the camera
271// dxStar, dyStar error of the position of the star in the camera
272//
273// Output : xSource, ySource the calculated position of the source in the camera
274// dxSource, dySource error of the calculated position of the source in
275// the camera
276//
277// Useful formulas can be found in TDAS 00-11 and TDAS 01-05
278//
279
280void MSourcePosfromStarPos::SourcefromStar(Double_t &f,
281 TArrayD &decStar, TArrayD &raStar,
282 Double_t &decSource, Double_t &raSource,
283 Double_t &thetaTel, Double_t &phiTel,
284 TArrayD &xStar, TArrayD &yStar,
285 TArrayD &dxStar, TArrayD &dyStar,
286 Double_t &xSource, Double_t &ySource,
287 Double_t &dxSource, Double_t &dySource)
288{
289 *fLog << "MSourcePosfromStarPos::SourcefromStar : printout in degrees" << endl;
290 *fLog << " decStar, raStar = " << decStar[0]*kRad2Deg << ", "
291 << raStar[0]*kRad2Deg << endl;
292 *fLog << " decSource, raSource = " << decSource*kRad2Deg << ", "
293 << raSource*kRad2Deg << endl;
294 *fLog << " thetaTel, phiTel = " << thetaTel*kRad2Deg << ", "
295 << phiTel*kRad2Deg << endl;
296 *fLog << " xStar, yStar = " << xStar[0]*fMm2Deg << ", "
297 << yStar[0]*fMm2Deg << endl;
298
299 *fLog << "MSourcePosfromStarPos::SourcefromStar : printout in radians and mm" << endl;
300 *fLog << " decStar, raStar = " << decStar[0] << ", "
301 << raStar[0] << endl;
302 *fLog << " decSource, raSource = " << decSource << ", "
303 << raSource << endl;
304 *fLog << " thetaTel, phiTel = " << thetaTel << ", "
305 << phiTel << endl;
306 *fLog << " xStar, yStar = " << xStar[0] << ", "
307 << yStar[0] << endl;
308
309
310 // the units are assumed to be radians for theta, phi, dec and ra
311 // and mm for f, x and y
312
313
314 // calculate rotation angle alpha of sky image in camera
315 // (see TDAS 00-11, eqs. (18) and (20))
316 // a1 = cos(Lat), a3 = -sin(Lat), where Lat is the geographical latitude of La Palma
317 Double_t a1 = 0.876627;
318 Double_t a3 = -0.481171;
319
320 Double_t denom = 1./ sqrt( sin(thetaTel)*sin(phiTel) * sin(thetaTel)*sin(phiTel) +
321 ( a1*cos(thetaTel)+a3*sin(thetaTel)*cos(phiTel) ) *
322 ( a1*cos(thetaTel)+a3*sin(thetaTel)*cos(phiTel) ) );
323 Double_t cosal = - (a3 * sin(thetaTel) + a1 * cos(thetaTel) * cos(phiTel)) * denom;
324 Double_t sinal = a1 * sin(phiTel) * denom;
325
326 *fLog << "thetaTel, phiTel, cosal, sinal = " << thetaTel << ", "
327 << phiTel << ", " << cosal << ", " << sinal << endl;
328
329
330 // calculate coordinates of source in system B (see TDAS 00-11, eqs. (2))
331 Double_t xB0 = cos(decSource) * cos(raSource);
332 Double_t yB0 = cos(decSource) * sin(raSource);
333 Double_t zB0 = -sin(decSource);
334
335 *fLog << "xB0, yB0, zB0 = " << xB0 << ", " << yB0 << ", "
336 << zB0 << endl;
337
338 //-----------------------------------------------------
339 // loop over stars
340 Double_t sumx = 0.0;
341 Double_t sumy = 0.0;
342 Double_t sumwx = 0.0;
343 Double_t sumwy = 0.0;
344
345 for (Int_t i=0; i<decStar.GetSize(); i++)
346 {
347 // calculate weights
348 Double_t weightx = 1.0 / (dxStar[i]*dxStar[i]);
349 Double_t weighty = 1.0 / (dyStar[i]*dyStar[i]);
350 sumwx += weightx;
351 sumwy += weighty;
352
353 *fLog << "weightx, weighty = " << weightx << ", " << weighty << endl;
354
355 // calculate coordinates of star in system B (see TDAS 00-11, eqs. (2))
356 Double_t xB = cos(decStar[i]) * cos(raStar[i]);
357 Double_t yB = cos(decStar[i]) * sin(raStar[i]);
358 Double_t zB = -sin(decStar[i]);
359
360
361 *fLog << "xB, yB, zB = " << xB << ", " << yB << ", "
362 << zB << endl;
363
364
365 // calculate coordinates of star in a system with the basis vectors e1, e2, e3
366 // where e1 is in the direction (r0 x a)
367 // e2 is in the direction (e1 x r0)
368 // and e3 is in the direction -r0;
369 // r0 is the direction to the source
370 // and a is the earth rotation axis (pointing to the celestial north pole)
371 //
372 Double_t x = (-xB*yB0 + xB0*yB) / sqrt( xB0*xB0 + yB0*yB0 );
373 Double_t y = ( xB*xB0*zB0 + yB*yB0*zB0 - zB*(xB0*xB0 + yB0*yB0) )
374 / sqrt( xB0*xB0 + yB0*yB0 );
375 Double_t z = -(xB*xB0 + yB*yB0 + zB*zB0);
376
377 *fLog << "x, y, z = " << x << ", " << y << ", "
378 << z << endl;
379
380
381 // calculate coordinates of star in camera
382 Double_t xtilde = -f/z * (cosal*x - sinal*y);
383 Double_t ytilde = -f/z * (sinal*x + cosal*y);
384
385 *fLog << "xtilde, ytile = " << xtilde << ", " << ytilde << endl;
386
387
388 // calculate coordinates of source in camera
389 // note : in real camera signs are inverted (therefore s = -1.0)
390 Double_t s = -1.0;
391 sumx += s * (s*xStar[i] - xtilde) * weightx;
392 sumy += s * (s*yStar[i] - ytilde) * weighty;
393 }
394 //-----------------------------------------------------
395
396 xSource = sumx / sumwx;
397 ySource = sumy / sumwy;
398 dxSource = 1.0 / sqrt(sumwx);
399 dySource = 1.0 / sqrt(sumwy);
400
401 *fLog << all << "MSourcePosfromStarPos::SourcefromStar; xSource, ySource = "
402 << xSource << " +- " << dxSource << ", "
403 << ySource << " +- " << dySource << endl;
404}
405
406// --------------------------------------------------------------------------
407//
408// Get the source position and put it into MSrcPosCam
409//
410//
411Bool_t MSourcePosfromStarPos::ReInit(MParList *pList)
412{
413 //if (fDecSource == 0.0 || fRaSource == 0.0 || fStars == 0)
414 //{
415 // *fLog << err << "MSourcePosfromStarPos::ReInit; sky coordinates of star and source are not defined ... aborting"
416 // << endl;
417 //return kFALSE;
418 //}
419
420 Int_t run = fRun->GetRunNumber();
421
422 *fLog << "MSourcePosfromStarPos::ReInit; run = " << run << endl;
423
424 //-------------------------------------------------------------------
425 // search this run in the list
426 for (Int_t i=0; i<fSize; i++)
427 {
428 if (run == fRunNr[i])
429 {
430 //-----------------------------------------
431 // put the zenith angle into MMcEvt
432
433 Double_t thetarad = fThetaTel[i];
434 Double_t phirad = fPhiTel[i];
435 fMcEvt->SetTelescopeTheta(thetarad);
436 fMcEvt->SetTelescopePhi(phirad);
437 fMcEvt->SetReadyToSave();
438
439 *fLog << "theta, phi = " << thetarad*kRad2Deg << ", "
440 << phirad*kRad2Deg << endl;
441
442 //-----------------------------------------
443 // Get source position and put it into MSrcPosCam
444
445 /*
446 if (fStars > 0)
447 {
448 TArrayD xStar(fxStar.GetNrows());
449 TArrayD dxStar(fdxStar.GetNrows());
450 TArrayD yStar(fyStar.GetNrows());
451 TArrayD dyStar(fdyStar.GetNrows());
452 for (Int_t j=0; j<fxStar.GetNrows(); j++)
453 {
454 xStar[j] = fxStar(j, i);
455 dxStar[j] = fdxStar(j, i);
456 yStar[j] = fyStar(j, i);
457 dyStar[j] = fdyStar(j, i);
458 }
459
460 MSourcePosfromStarPos::SourcefromStar( fDistCameraReflector,
461 fDecStar, fRaStar, fDecSource, fRaSource,
462 fThetaTel[i], fPhiTel[i],
463 xStar, yStar,
464 dxStar, dyStar,
465 fxSource, fySource,
466 fdxSource, fdySource);
467
468 fSrcPos->SetXY(fxSource, fySource);
469
470 *fLog << all << "MSourcePosfromStarPos::ReInit; fRunNr, fxSource, fySource = "
471 << fRunNr[i] << ", " << fxSource << ", " << fySource
472 << endl;
473
474 fSrcPos->SetReadyToSave();
475 }
476 */
477
478 return kTRUE;
479 }
480 }
481 //-------------------------------------------------------------------
482 *fLog << warn << "MSourcePosfromStarPos::ReInit; no information for run number = "
483 << run << endl;
484
485 Double_t thetadeg = 90.0;
486 Double_t thetarad = thetadeg / kRad2Deg;
487 fMcEvt->SetTelescopeTheta(thetarad);
488
489 Double_t phideg = 0.0;
490 Double_t phirad = phideg / kRad2Deg;
491 fMcEvt->SetTelescopePhi(phirad);
492 fMcEvt->SetReadyToSave();
493
494 return kTRUE;
495}
496
497// --------------------------------------------------------------------------
498//
499//
500Int_t MSourcePosfromStarPos::Process()
501{
502 Int_t run = fRun->GetRunNumber();
503
504 //*fLog << "MSourcePosfromStarPos::Process; run = " << run << endl;
505
506
507 return kTRUE;
508}
509
510// --------------------------------------------------------------------------
511//
512//
513Int_t MSourcePosfromStarPos::PostProcess()
514{
515
516 return kTRUE;
517}
518
519// --------------------------------------------------------------------------
520//
521// read the data from the ASCII file and store them
522//
523void MSourcePosfromStarPos::FixSize()
524{
525 *fLog << "MSourcePosfromStarPos::FixSize; fix size of arrays : fRuns = "
526 << fRuns << endl;
527
528 fSize = fRuns;
529
530 fRunNr.Set(fSize);
531
532 fThetaTel.Set(fSize);
533 fPhiTel.Set(fSize);
534 fdThetaTel.Set(fSize);
535 fdPhiTel.Set(fSize);
536
537 fStars = fxStar.GetNrows();
538 fxStar.ResizeTo(fStars, fSize);
539 fyStar.ResizeTo(fStars, fSize);
540 fdxStar.ResizeTo(fStars, fSize);
541 fdyStar.ResizeTo(fStars, fSize);
542}
543
544// --------------------------------------------------------------------------
545//
546// read the data from the ASCII file and store them
547//
548void MSourcePosfromStarPos::ReadData()
549{
550 Float_t val;
551 Int_t ival;
552
553 // extend size of arrays if necessary
554 if ( fRuns >= (fSize-1) )
555 {
556 fSize += 100;
557
558 fRunNr.Set(fSize);
559
560 fThetaTel.Set(fSize);
561 fPhiTel.Set(fSize);
562 fdThetaTel.Set(fSize);
563 fdPhiTel.Set(fSize);
564
565 fStars = fxStar.GetNrows();
566 fxStar.ResizeTo(fStars, fSize);
567 fyStar.ResizeTo(fStars, fSize);
568 fdxStar.ResizeTo(fStars, fSize);
569 fdyStar.ResizeTo(fStars, fSize);
570 }
571
572 //-------------------
573 // read header line
574 //*fIn >> val;
575
576 //*fLog << "val =" << val << endl;
577
578 //*fIn >> val;
579 //*fIn >> val;
580 //*fIn >> val;
581 //*fIn >> val;
582 //*fIn >> val;
583 //*fIn >> val;
584 //*fIn >> val;
585 //*fIn >> val;
586 //*fIn >> val;
587 //*fIn >> val;
588 //-------------------
589
590
591 fRuns += 1;
592
593 *fIn >> ival;
594
595 *fLog << fRuns <<"th run : " << ival << endl;
596
597 fRunNr.AddAt(ival, fRuns-1);
598
599 *fLog << "check : fRuns, fRunNr[fRuns-1], fRunNr[fRuns] = " << fRuns << ", "
600 << fRunNr[fRuns-1] << ", " << fRunNr[fRuns] << endl;
601
602 // read mjdS, hmsS, mjdE, hmsE
603 *fIn >> val;
604 *fIn >> val;
605 *fIn >> val;
606 *fIn >> val;
607
608 *fIn >> val;
609 *fIn >> val;
610 *fIn >> val;
611 *fIn >> val;
612
613
614 *fIn >> val;
615 fThetaTel.AddAt(val/kRad2Deg, fRuns-1);
616 *fLog << "val, fThetaTel[fRuns-1] = " << val << ", "
617 << fThetaTel[fRuns-1] << endl;
618
619
620 *fIn >> val;
621 fPhiTel.AddAt(val/kRad2Deg, fRuns-1);
622 *fLog << "val, fPhiTel[fRuns-1] = " << val << ", "
623 << fPhiTel[fRuns-1] << endl;
624
625
626 //*fIn >> val;
627 //fdThetaTel.AddAt(val/kRad2Deg, fRuns-1);
628 //*fIn >> val;
629 //fdPhiTel.AddAt(val/kRad2Deg, fRuns-1);
630
631 // input is in [deg], convert to [mm]
632 fStars = fxStar.GetNrows();
633 for (Int_t i=0; i<fStars; i++)
634 {
635 *fIn >> val;
636 fxStar(i, fRuns-1) = val / fMm2Deg;;
637 *fLog << "val, fxStar(i, fRuns-1) = " << val << ", "
638 << fxStar(i, fRuns-1) << endl;
639
640 *fIn >> val;
641 fyStar(i, fRuns-1) = val / fMm2Deg;
642 *fLog << "val, fyStar(i, fRuns-1) = " << val << ", "
643 << fyStar(i, fRuns-1) << endl;
644
645
646 *fIn >> val;
647 //*fLog << "y=dxStar = " << val << endl;
648
649 fdxStar(i, fRuns-1) = val / fMm2Deg;
650 *fIn >> val;
651 //*fLog << "y=dyStar = " << val << endl;
652
653 fdyStar(i, fRuns-1) = val / fMm2Deg;
654 }
655
656}
657
658// --------------------------------------------------------------------------
659//
660// Add this file as the last entry in the chain
661//
662Int_t MSourcePosfromStarPos::AddFile(const char *txt, Int_t)
663{
664 TNamed *name = new TNamed(txt, "");
665 fFileNames->AddLast(name);
666
667 *fLog << "MSourcePosfromStarPos::AddFile; add file '" << txt << "'"
668 << endl;
669
670 return 1;
671}
672
673// --------------------------------------------------------------------------
674//
675// This opens the next file in the list and deletes its name from the list.
676//
677Bool_t MSourcePosfromStarPos::OpenNextFile()
678{
679 //
680 // open the input stream and check if it is really open (file exists?)
681 //
682 if (fIn)
683 delete fIn;
684 fIn = NULL;
685
686 //
687 // Check for the existence of a next file to read
688 //
689 TNamed *file = (TNamed*)fFileNames->First();
690 if (!file)
691 return kFALSE;
692
693 //
694 // open the file which is the first one in the chain
695 //
696 const char *name = file->GetName();
697
698 const char *expname = gSystem->ExpandPathName(name);
699 fIn = new ifstream(expname);
700 delete [] expname;
701
702 const Bool_t noexist = !(*fIn);
703
704 if (noexist)
705 *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
706 else
707 *fLog << "Open file: '" << name << "'" << endl;
708
709 //
710 // Remove this file from the list of pending files
711 //
712 fFileNames->Remove(file);
713
714 return !noexist;
715}
716
717// --------------------------------------------------------------------------
718
719
720
721
722
723
724
725
726
727
728
Note: See TracBrowser for help on using the repository browser.