source: trunk/Mars/mjobs/MDataSet.cc@ 15625

Last change on this file since 15625 was 9328, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 25.2 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, 1/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2004-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MDataSet
28//
29// This class describes a collection of sequences.
30//
31// Such an input file looks like:
32//
33// crab.txt:
34// ---------
35// AnalysisNumber: 1
36//
37// Name: SecondCrab
38//
39// SequencesOn: 35222 35229
40// SequencesOff: 36817
41//
42// SequencePath: /magic/sequences
43// DataPath: /magic/data/star
44//
45// Sequence00035222.File: sequences/sequence035222.txt
46// Sequence00036817.File: sequences/sequence036817.txt
47//
48// Sequence00035222.Dir: /data2/wuerzburg/Crab-Analyse/images/035222
49// Sequence00036817.Dir: /data2/wuerzburg/Crab-Analyse/images/036817
50//
51// Sequence00036817.Exclude: 36818 36819
52//
53// WobbleMode: No
54// MonteCarlo: No
55//
56// SourceName: CrabNebula
57// Catalog: /magic/datacenter/setup/magic_favorites_dc.edb
58//
59//
60// Reading the file is based on TEnv. For more details see also
61// the class reference of TEnv.
62//
63//
64// AnalysisNumber: The analysis number is an artifical number used to name
65// the output files automatically if the names are not overwritten in the
66// corresponding programs.
67//
68// SequencePath: In case it is not specified the datacenter default path is
69// used. If it is given it is the place at which the sequence files
70// are searched, if not overwritten by either a program command line
71// option (aka. a argument to the constructor) or a resource for
72// an individual sequence file. Note, that the four digits high-level
73// directories to sort the sequences are added to the given path.
74//
75// DataPath: In case it is not specified the datacenter default path is
76// used. If it is given it is the place at which the data files
77// are searched, if not overwritten by either a program command line
78// option (aka. a argument to the constructor) or a resource for
79// an individual data path. Note, that the four digits high-level
80// directories to sort the sequences are added to the given path.
81//
82// SequencesOn/Off: The sequence number are used to concatenate the filenames
83// of the sequences using the file structure used in the datacenter. Each
84// sequence can be added to the on and off data at the same time but only
85// once.
86//
87// If you have different file names you can overwrite the default file names
88// using Sequence%08d.File (make sure you have 8 digits!)
89//
90// If the file name is given as "-", e.g.
91// Sequence00035222.File: -
92// the current dataset file is read as sequence file. In this case all
93// resources defined for a sequence file should be prefixed by
94// "Sequence%08d."; if not prefixed the default without the prefix
95// is looked up. Be aware that the "Sequence" resource for sequence-files
96// (for more details see MSequence) is ignored and the already defined
97// number is used instead and thus should be identical to the sequence
98// number - which normally is not necessary.
99//
100// In standard coditions (datacenter file system) paths are concatenated
101// by using the information in the sequence files (date, etc). You can
102// overwrite the directories in which the sequence-files (eg I-files) are
103// stored using Sequence%08d.Dir (make sure you have 8 digits!)
104//
105// Using the resource Sequence%08d.Exclude you can exclude a list of
106// runs from a sequence.
107//
108// WobbleMode: This is just a flag which is passed to the program
109// end eveluated (or not) by the individual program, which takes this
110// dataset as an input. For example this is necessary in ganymed to do
111// some wobble mode special setup. If no resource is given (or it is
112// set to "auto") wobble mode if set if the datset contains no off-
113// sequences.
114//
115// MonetCarlo: This is just a flag which is passed to the program
116// end eveluated (or not) by the individual program, which takes this
117// dataset as an input. For example this tells ganymed to skip some
118// parts accessing time stamps which are not available in the MCs.
119//
120// SequencePath/DataPath: This determined were the sequences and data-files
121// are stored. The priorities are as follows:
122// 0) Build in default path: /magic/sequences /magic/data/star
123// 1) Def.path from dataset file: SequencePath DataPath
124// 2) Indiv.path from dataset file: 12345.SequencePath 12345.DataPath
125// 3) Path from command line: Argument in the constructors
126// 4) Path for an indiv. dataset: Sequences00022555.File/Dir
127//
128// Catalog: This is the xephem-style file from the central control
129// containing the observed sky positions.
130//
131// SourceName: The source name, as defined in the catalog, of the object
132// the data corresponds to.
133//
134// Name: A name is stored for your convinience
135//
136// Comment: It is just stored.
137//
138// General Remark: MDataSet doesn't implement any action on the given
139// resources. Whether a resource is used, necessary or ignored, and
140// what will happen if you change the resource is always defined by the
141// executed macro or program.
142//
143// Resource file entries are case sensitive!
144//
145//
146// Collection of datsets
147// ---------------------
148//
149// You can combine more than one datset in a file (if your program
150// supports this) Such a dataset file could look like this:
151//
152// 35222.SequencesOn: 35222
153// 35222.SequencesOff: 36817
154//
155// 65778.SequencesOn: 65778
156//
157// 12345.SequencesOn: 12345
158//
159// 12345.SequencePath: /home/nobody/specialsequences
160// 65778.DataPath: /home/nobody/specialstars
161//
162// SequencePath: /home/nobody/defaultsequences
163// DataPath: /home/nobody/defaultstars
164//
165// Sequence00035222.File: sequences/sequence035222.txt
166// Sequence00035222.Dir: /data2/wuerzburg/Crab-Analyse/images/035222
167//
168// 35222.WobbleMode: Off
169// WobbleMode: On
170//
171//
172// IMPORTANT:
173// * Run filenames must begin with a string which allows correct
174// ordering in time, otherwise synchronization might fail.
175// * Sequence filenames should also have names allowing to order them
176// in time, but it is not necessary.
177//
178//
179// ===========================================================================
180//
181// ToDO:
182// * Default paths could be moved into the global .rootrc
183//
184// ===========================================================================
185//
186//
187// Class Version 3:
188// ----------------
189// + fFileName
190// + fDataSet
191//
192// Class Version 2:
193// ----------------
194// + fMonteCarlo
195// + fWobbleMode
196// - fIsWobbleMode
197//
198/////////////////////////////////////////////////////////////////////////////
199#include "MDataSet.h"
200
201#include <string.h> // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
202#include <errno.h> // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
203
204#include <stdlib.h>
205#include <fstream>
206
207#include <TEnv.h>
208#include <TChain.h>
209#include <TRegexp.h>
210#include <TSystem.h> // TSystem::ExpandPath
211
212#include "MLog.h"
213#include "MLogManip.h"
214
215#include "MRead.h"
216#include "MJob.h"
217#include "MEnv.h"
218#include "MAstro.h"
219#include "MString.h"
220#include "MDirIter.h"
221#include "MSequence.h"
222#include "MPointingPos.h"
223
224ClassImp(MDataSet);
225
226using namespace std;
227
228const TString MDataSet::fgCatalog = "/magic/datacenter/setup/magic_favorites.edb";
229
230// --------------------------------------------------------------------------
231//
232// Copy the sequence numbers from the TString runs into the TArrayI data
233// Sequences which are twice in the list are only added once. In this case
234// a warning is emitted.
235//
236void MDataSet::Split(TString &runs, TArrayI &data) const
237{
238 const TRegexp regexp("[0-9]+");
239
240 data.Set(0);
241
242 runs.ReplaceAll("\t", " ");
243 runs = runs.Strip(TString::kBoth);
244
245 while (!runs.IsNull())
246 {
247 const TString num = runs(regexp);
248
249 if (num.IsNull())
250 {
251 *fLog << warn << "WARNING - Sequence is NaN (not a number): '" << runs << "'" << endl;
252 break;
253 }
254
255 const Int_t seq = atoi(num.Data());
256 const Int_t n = data.GetSize();
257
258 // skip already existing entries
259 int i;
260 for (i=0; i<n; i++)
261 if (data[i] == seq)
262 break;
263
264 if (i<n)
265 *fLog << warn << "WARNING - Sequence #" << seq << " already in list... skipped." << endl;
266 else
267 {
268 // set new entry
269 data.Set(n+1);
270 data[n] = seq;
271 }
272
273 // remove entry from string
274 runs.Remove(0, runs.First(num)+num.Length());
275 }
276
277 MJob::SortArray(data);
278}
279
280// --------------------------------------------------------------------------
281//
282// After resolving the sequence filename and directory either from the
283// default (/magic/data/sequences/0004/sequence00004000.txt) or from
284// the corresponding entries in the dataset file.
285// The entries are sorted by filename.
286//
287void MDataSet::ResolveSequences(const TEnv &env, const TString &prefix, const TArrayI &num, TList &list) const
288{
289 TString sequences = fPathSequences;
290 TString data = fPathDataFiles;
291
292 for (int i=0; i<num.GetSize(); i++)
293 {
294 TString name = GetEnvValue3(env, prefix, "Sequence%d.File", num[i]);
295 TString dir = GetEnvValue3(env, prefix, "Sequence%d.Dir", num[i]);
296 TString excl = GetEnvValue3(env, prefix, "Sequence%d.Exclude", num[i]);
297
298 // Set default sequence file and dir name
299 if (name.IsNull())
300 name = MString::Format("%s%04d/sequence%08d.txt", sequences.Data(), num[i]/10000, num[i]);
301 if (dir.IsNull())
302 dir = MString::Format("%s%04d/%08d", data.Data(), num[i]/10000, num[i]);
303
304 // Check if sequence information is contained in Dataset file
305 const Bool_t useds = name=="-";
306
307 // FIXME: The sequence number from the sequence file is assigned!!!
308 MSequence *seq = new MSequence(useds?fFileName:name, dir, num[i]);
309 seq->ExcludeRuns(excl);
310
311 if (seq->IsValid() && seq->GetSequence()!=(UInt_t)num[i])
312 *fLog << warn << "WARNING - Sequence number " << num[i] << " in dataset file doesn't match number " << seq->GetSequence() << " in sequence file!" << endl;
313
314 list.Add(seq);
315 }
316
317 // For the synchronization we must make sure, that all sequences are
318 // in the correct order...
319 // list.Sort();
320}
321
322Bool_t MDataSet::GetWobbleMode(const TEnv &env, const TString &prefix) const
323{
324 TString wob = GetEnvValue2(env, prefix, "WobbleMode", "auto");
325
326 wob.ToLower();
327 wob=wob.Strip(TString::kBoth);
328
329 if (wob=="auto")
330 return !HasOffSequences();
331
332 return GetEnvValue2(env, prefix, "WobbleMode", kFALSE);
333}
334
335// --------------------------------------------------------------------------
336//
337// Read a dataset from the file fname. If num is != -1 all resources are
338// prefixed with the number. This allows constrcutions like:
339//
340// 89123.SequencesOn: 1 2 3 4
341// 89130.SequencesOn: 5 6 7 8
342//
343// For one dataset:
344//
345// 89123.DataPath: /magic/data/star
346//
347// For all other datasets:
348//
349// DataPath: /magic/data/star
350//
351// For one sequence of one datasets:
352//
353// 89123.Sequence00000002.Dir: /magic/data/star
354//
355// and therefore allows storage of several datsets in one file with
356// a defaults for non specific resources.
357//
358// sequences and data are the path to the sequences (/magic/sequences)
359// and the data (/magic/data/star) respectively. Both can be overwritten
360// be a default from the dataset file or a resource for an individual
361// sequence.
362//
363void MDataSet::Init(const char *fname, const UInt_t num, TString sequences, TString &data)
364{
365 fName = "MDataSet";
366 fTitle = "DataSet file";
367
368 // Store given file name as name
369 fFileName = fname;
370
371 // Delete the stored Sequences automatically at destruction
372 fSequencesOn.SetOwner();
373 fSequencesOff.SetOwner();
374
375 // Expand the file name (eg $MARS or ~ are expanded)
376 gSystem->ExpandPathName(fFileName);
377
378 // Check its accessibility
379 const Bool_t access = !gSystem->AccessPathName(fFileName, kFileExists);
380 if (!access)
381 {
382 gLog << err << "ERROR - Dataset file " << fname << " not accessible!" << endl;
383 fNumAnalysis = (UInt_t)-1;
384 return;
385 }
386
387 // Determin the prefix to access this resource
388 const TString prefix = num==(UInt_t)-1 ? "" : MString::Format("%d", num);
389
390 // Open and read the file
391 MEnv env(fFileName);
392
393 // Get analysis number and name
394 fNumAnalysis = GetEnvValue2(env, prefix, "AnalysisNumber", (Int_t)num);
395 fDataSet = GetEnvValue2(env, prefix, "Name", GetBaseName());
396
397 // Get sequences from file
398 TString str;
399 str = GetEnvValue2(env, prefix, "SequencesOn", "");
400 Split(str, fNumSequencesOn);
401 str = GetEnvValue2(env, prefix, "SequencesOff", "");
402 Split(str, fNumSequencesOff);
403
404 // Get other resources
405 fNameSource = GetEnvValue2(env, prefix, "SourceName", "");
406 fCatalog = GetEnvValue2(env, prefix, "Catalog", fgCatalog);
407 fMonteCarlo = GetEnvValue2(env, prefix, "MonteCarlo", kFALSE);
408 fComment = GetEnvValue2(env, prefix, "Comment", "");
409
410 fWobbleMode = GetWobbleMode(env, prefix); // needs the number of off sequences
411
412 fNameSource = fNameSource.Strip(TString::kBoth);
413 fCatalog = fCatalog.Strip(TString::kBoth);
414
415 // Check for sequence and data path (GetDefPath needs the monte carlo flag)
416 const TString defpathseq = GetEnvValue2(env, prefix, "SequencePath", GetDefPathSequences());
417 const TString defpathdata = GetEnvValue2(env, prefix, "DataPath", GetDefPathDataFiles());
418
419 SetupDefaultPath(sequences, defpathseq);
420 SetupDefaultPath(data, defpathdata);
421
422 fPathSequences = sequences;
423 fPathDataFiles = data;
424
425 // Resolve sequences
426 ResolveSequences(env, prefix, fNumSequencesOn, fSequencesOn);
427 ResolveSequences(env, prefix, fNumSequencesOff, fSequencesOff);
428
429 // --- Now "touch" resources which are not yet stored in MDataSet ---
430 env.Touch("RunTime");
431
432 // --- Print "untouch" resources ---
433 if (env.GetNumUntouched()>0)
434 {
435 gLog << warn << "WARNING - At least one resource in the dataset-file has not been touched!" << endl;
436 env.PrintUntouched();
437 }
438}
439
440// --------------------------------------------------------------------------
441//
442// Constructor. See Read for more details.
443//
444MDataSet::MDataSet(const char *fname, TString sequences, TString data)
445{
446 Init(fname, (UInt_t)-1, sequences, data);
447}
448
449// --------------------------------------------------------------------------
450//
451// Constructor. See Read for more details.
452//
453MDataSet::MDataSet(const char *fname, Int_t num, TString sequences, TString data)
454{
455 Init(fname, num, sequences, data);
456}
457
458//---------------------------------------------------------------------------
459//
460// Return the name of the file
461//
462const char *MDataSet::GetBaseName() const
463{
464 return gSystem->BaseName(fFileName);
465}
466
467//---------------------------------------------------------------------------
468//
469// Return the directory of the file
470//
471const char *MDataSet::GetFilePath() const
472{
473 return gSystem->DirName(fFileName);
474}
475
476// --------------------------------------------------------------------------
477//
478// Return '+' if both can be accessed, '-' otherwise.
479//
480void MDataSet::PrintFile(ostream &out, const MSequence &seq)
481{
482 const Char_t access =
483 !gSystem->AccessPathName(seq.GetFileName(), kFileExists) &&
484 !gSystem->AccessPathName(seq.GetDataPath(), kFileExists) ? '+' : '-';
485
486 out << "# " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
487}
488
489// --------------------------------------------------------------------------
490//
491// Helper to print a seqeunce in Print()
492//
493void MDataSet::PrintSeq(ostream &out, const MSequence &seq) const
494{
495 const Bool_t useds = seq.GetFileName()==fFileName;
496
497 out << "Sequence" << MString::Format("%08d", seq.GetSequence()) << ".File: " << (useds?"-":seq.GetFileName()) << endl;
498 out << "Sequence" << MString::Format("%08d", seq.GetSequence()) << ".Dir: " << seq.GetDataPath() << endl;
499 if (!useds && seq.GetNumExclRuns()>0)
500 out << "Sequence" << MString::Format("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
501
502 if (useds)
503 {
504 out << endl;
505 seq.Print(out, "prefixed");
506 out << endl << "# ---" << endl;
507 }
508}
509
510// --------------------------------------------------------------------------
511//
512// Print the contents of the dataset to the ostream out
513//
514void MDataSet::Print(ostream &out, Option_t *o) const
515{
516 if (!IsValid())
517 {
518 out << "Dataset: " << fFileName << " <invalid - no analysis number available>" << endl;
519 return;
520 }
521 out << "# Path: " << GetFilePath() << endl;
522 out << "# Name: " << GetBaseName() << endl;
523 out << endl;
524 out << "AnalysisNumber: " << fNumAnalysis << endl << endl;
525
526 if (!fDataSet.IsNull())
527 out << "Name: " << fDataSet << endl << endl;
528
529 out << "SequencesOn: ";
530 for (int i=0; i<fNumSequencesOn.GetSize(); i++)
531 out << " " << fNumSequencesOn[i];
532 out << endl;
533 if (fNumSequencesOff.GetSize()>0)
534 {
535 out << "SequencesOff: ";
536 for (int i=0; i<fNumSequencesOff.GetSize(); i++)
537 out << " " << fNumSequencesOff[i];
538 out << endl;
539 }
540
541 out << endl;
542 if (!fNameSource.IsNull())
543 out << "SourceName: " << fNameSource << endl;
544 out << "Catalog: " << fCatalog << endl;
545
546 out << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
547 out << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
548
549 if (!fComment.IsNull())
550 out << "Comment: " << fComment << endl;
551
552 if (fSequencesOn.GetEntries()>0)
553 out << endl;
554
555 // FIXME: If file==fName --> print Sequence0000.content
556
557 TIter NextOn(&fSequencesOn);
558 TIter NextOff(&fSequencesOff);
559 MSequence *seq=0;
560 while ((seq=(MSequence*)NextOn()))
561 PrintSeq(out, *seq);
562 if (fSequencesOff.GetEntries()>0)
563 out << endl;
564 while ((seq=(MSequence*)NextOff()))
565 PrintSeq(out, *seq);
566
567 if (TString(o).Contains("files", TString::kIgnoreCase))
568 {
569 out << endl;
570 out << "# On-Data Files:" << endl;
571 NextOn.Reset();
572 while ((seq=(MSequence*)NextOn()))
573 PrintFile(out, *seq);
574
575 out << endl;
576 out << "# Off-Data Files:" << endl;
577 NextOff.Reset();
578 while ((seq=(MSequence*)NextOff()))
579 PrintFile(out, *seq);
580 }
581}
582
583// --------------------------------------------------------------------------
584//
585// Print the contents of the dataset to the gLog stream
586//
587void MDataSet::Print(Option_t *o) const
588{
589 gLog << all;
590 Print(gLog, o);
591}
592
593// --------------------------------------------------------------------------
594//
595// Print the contents of the dataset to the file with name filename
596//
597void MDataSet::WriteFile(const char *name, const Option_t *o) const
598{
599 ofstream fout(name);
600 if (!fout)
601 {
602 gLog << err << "Cannot open file " << name << ": ";
603 gLog << strerror(errno) << endl;
604 return;
605 }
606
607 Print(fout, o);
608}
609
610// --------------------------------------------------------------------------
611//
612// Adds all sequences contained in list to the MDirIter. After adding
613// everything MDirIter::Sort is called to sort all entries by name.
614//
615Bool_t MDataSet::AddSequencesFromList(const TList &list, MDirIter &files)
616{
617 TIter Next(const_cast<TList*>(&list));
618
619 MSequence *seq=0;
620 while ((seq=(MSequence*)Next()))
621 {
622 if (!seq->IsValid())
623 {
624 gLog << err;
625 gLog << "ERROR - MDataSet::AddSequencesFromList: Sequence invalid!" << endl;
626 gLog << " + File: " << seq->GetFileName() << endl;
627 gLog << " + Dir: " << seq->GetDataPath() << endl;
628 return kFALSE;
629 }
630
631 if (seq->GetRuns(files, MSequence::kImages)<=0)
632 return kFALSE;
633 }
634
635 // This is important in case of synchronisation, because the
636 // files in the sequences can be interleaved (eg W1, W2)
637 // Filenames MUST begin with an appropriate string which allow
638 // to order them correctly in time!
639 // files.Sort();
640
641 if (gLog.GetDebugLevel()>4)
642 {
643 gLog << inf << "Files which are searched:" << endl;
644 files.Print();
645 }
646 return kTRUE;
647}
648
649Bool_t MDataSet::AddFilesOn(MDirIter &iter) const
650{
651 return AddSequencesFromList(fSequencesOn, iter);
652}
653
654Bool_t MDataSet::AddFilesOff(MDirIter &iter) const
655{
656 return AddSequencesFromList(fSequencesOff, iter);
657}
658
659Bool_t MDataSet::AddFiles(MDirIter &iter) const
660{
661 const Bool_t rc1 = AddFilesOff(iter);
662 const Bool_t rc2 = AddFilesOn(iter);
663 return rc1 && rc2;
664}
665
666Bool_t MDataSet::AddFilesOn(MRead &read) const
667{
668 MDirIter files;
669 if (!AddFilesOn(files))
670 return kFALSE;
671 return read.AddFiles(files)>0;
672}
673
674Bool_t MDataSet::AddFilesOff(MRead &read) const
675{
676 MDirIter files;
677 if (!AddFilesOff(files))
678 return kFALSE;
679 return read.AddFiles(files)>0;
680}
681
682Bool_t MDataSet::AddFiles(MRead &read) const
683{
684 const Bool_t rc1 = AddFilesOff(read);
685 const Bool_t rc2 = AddFilesOn(read);
686 return rc1 && rc2;
687}
688
689Int_t MDataSet::AddFilesToChain(MDirIter &files, TChain &chain)
690{
691 Int_t num=0;
692 while (1)
693 {
694 const TString fname = files.Next();
695 if (fname.IsNull())
696 break;
697
698 const Int_t n = chain.Add(fname);
699 if (n<=0)
700 return kFALSE;
701 num += n;
702 }
703 return num;
704}
705
706Bool_t MDataSet::AddFilesOn(TChain &chain) const
707{
708 MDirIter files;
709 if (!AddSequencesFromList(fSequencesOn, files))
710 return kFALSE;
711 return AddFilesToChain(files, chain)>0;
712}
713
714Bool_t MDataSet::AddFilesOff(TChain &chain) const
715{
716 MDirIter files;
717 if (!AddSequencesFromList(fSequencesOff, files))
718 return kFALSE;
719 return AddFilesToChain(files, chain)>0;
720}
721
722Bool_t MDataSet::AddFiles(TChain &read) const
723{
724 const Bool_t rc1 = AddFilesOff(read);
725 const Bool_t rc2 = AddFilesOn(read);
726 return rc1 && rc2;
727}
728
729Bool_t MDataSet::GetSourcePos(MPointingPos &pos) const
730{
731 if (!HasSource())
732 {
733 gLog << err << "ERROR - MDataSet::GetSourcePos called, but no source available." << endl;
734 return kFALSE;
735 }
736
737 TString catalog(fCatalog);
738 gSystem->ExpandPathName(catalog);
739
740 ifstream fin(catalog);
741 if (!fin)
742 {
743 gLog << err << "Cannot open file " << catalog << ": ";
744 gLog << strerror(errno) << endl;
745 return kFALSE;
746 }
747
748 TString ra, dec, epoch;
749
750 Int_t n = 0;
751 while (1)
752 {
753 TString line;
754 line.ReadLine(fin);
755 if (!fin)
756 {
757 gLog << err << "ERROR - Source '" << fNameSource << "' not found in " << catalog << "." << endl;
758 return kFALSE;
759 }
760
761 n++;
762
763 TObjArray *arr = line.Tokenize(",");
764
765 if (arr->GetEntries()<6)
766 {
767 gLog << err << "ERROR - Not enough arguments in line #" << n << " of " << catalog << endl;
768 delete arr;
769 return kFALSE;;
770 }
771
772 const TString name = (*arr)[0]->GetName();
773
774 ra = (*arr)[2]->GetName();
775 dec = (*arr)[3]->GetName();
776 epoch = (*arr)[5]->GetName();
777
778 delete arr;
779
780 if (name.Strip(TString::kBoth)==fNameSource)
781 break;
782 }
783
784 if (epoch.Strip(TString::kBoth)!=(TString)"2000")
785 {
786 gLog << err << "ERROR - Epoch not 2000... not supported." << endl;
787 return kFALSE;
788 }
789
790 Double_t r,d;
791 if (!MAstro::Coordinate2Angle(ra, r))
792 {
793 gLog << err << "ERROR - Interpreting right ascension: " << ra << endl;
794 return kFALSE;
795 }
796 if (!MAstro::Coordinate2Angle(dec, d))
797 {
798 gLog << err << "ERROR - Interpreting declination: " << dec << endl;
799 return kFALSE;
800 }
801
802 pos.SetSkyPosition(r, d);
803 pos.SetTitle(fNameSource);
804
805 return kTRUE;
806}
807
808/*
809// --------------------------------------------------------------------------
810//
811// Calls ReplaceAll(old, news) for all Dir-entries
812//
813void MDataSet::ReplaceDir(TList &list, const TString &old, const TString &news) const
814{
815 TIter Next(&list);
816 TNamed *name = 0;
817 while ((name=(TNamed*)Next()))
818 {
819 TString dir = name->GetTitle();
820 dir.ReplaceAll(old, news);
821 name->SetTitle(dir);
822 }
823}
824
825// --------------------------------------------------------------------------
826//
827// Calls ReplaceAll(old, news) for all File-entries
828//
829void MDataSet::ReplaceFile(TList &list, const TString &old, const TString &news) const
830{
831 TIter Next(&list);
832 TNamed *name = 0;
833 while ((name=(TNamed*)Next()))
834 {
835 TString file = name->GetName();
836 file.ReplaceAll(old, news);
837 name->SetName(file);
838 }
839}
840*/
Note: See TracBrowser for help on using the repository browser.