source: trunk/MagicSoft/Mars/mjobs/MDataSet.cc@ 9204

Last change on this file since 9204 was 9186, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 25.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, 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 "MDirIter.h"
220#include "MSequence.h"
221#include "MPointingPos.h"
222
223ClassImp(MDataSet);
224
225using namespace std;
226
227const TString MDataSet::fgCatalog = "/magic/datacenter/setup/magic_favorites.edb";
228
229// --------------------------------------------------------------------------
230//
231// Copy the sequence numbers from the TString runs into the TArrayI data
232// Sequences which are twice in the list are only added once. In this case
233// a warning is emitted.
234//
235void MDataSet::Split(TString &runs, TArrayI &data) const
236{
237 const TRegexp regexp("[0-9]+");
238
239 data.Set(0);
240
241 runs.ReplaceAll("\t", " ");
242 runs = runs.Strip(TString::kBoth);
243
244 while (!runs.IsNull())
245 {
246 const TString num = runs(regexp);
247
248 if (num.IsNull())
249 {
250 *fLog << warn << "WARNING - Sequence is NaN (not a number): '" << runs << "'" << endl;
251 break;
252 }
253
254 const Int_t seq = atoi(num.Data());
255 const Int_t n = data.GetSize();
256
257 // skip already existing entries
258 int i;
259 for (i=0; i<n; i++)
260 if (data[i] == seq)
261 break;
262
263 if (i<n)
264 *fLog << warn << "WARNING - Sequence #" << seq << " already in list... skipped." << endl;
265 else
266 {
267 // set new entry
268 data.Set(n+1);
269 data[n] = seq;
270 }
271
272 // remove entry from string
273 runs.Remove(0, runs.First(num)+num.Length());
274 }
275
276 MJob::SortArray(data);
277}
278
279// --------------------------------------------------------------------------
280//
281// After resolving the sequence filename and directory either from the
282// default (/magic/data/sequences/0004/sequence00004000.txt) or from
283// the corresponding entries in the dataset file.
284// The entries are sorted by filename.
285//
286void MDataSet::ResolveSequences(const TEnv &env, const TString &prefix, const TArrayI &num, TList &list) const
287{
288 TString sequences = fPathSequences;
289 TString data = fPathDataFiles;
290
291 for (int i=0; i<num.GetSize(); i++)
292 {
293 TString name = GetEnvValue3(env, prefix, "Sequence%d.File", num[i]);
294 TString dir = GetEnvValue3(env, prefix, "Sequence%d.Dir", num[i]);
295 TString excl = GetEnvValue3(env, prefix, "Sequence%d.Exclude", num[i]);
296
297 // Set default sequence file and dir name
298 if (name.IsNull())
299 name = Form("%s%04d/sequence%08d.txt", sequences.Data(), num[i]/10000, num[i]);
300 if (dir.IsNull())
301 dir = Form("%s%04d/%08d", data.Data(), num[i]/10000, num[i]);
302
303 // Check if sequence information is contained in Dataset file
304 const Bool_t useds = name=="-";
305
306 // FIXME: The sequence number from the sequence file is assigned!!!
307 MSequence *seq = new MSequence(useds?fFileName:name, dir, num[i]);
308 seq->ExcludeRuns(excl);
309
310 if (seq->IsValid() && seq->GetSequence()!=(UInt_t)num[i])
311 *fLog << warn << "WARNING - Sequence number " << num[i] << " in dataset file doesn't match number " << seq->GetSequence() << " in sequence file!" << endl;
312
313 list.Add(seq);
314 }
315
316 // For the synchronization we must make sure, that all sequences are
317 // in the correct order...
318 // list.Sort();
319}
320
321Bool_t MDataSet::GetWobbleMode(const TEnv &env, const TString &prefix) const
322{
323 TString wob = GetEnvValue2(env, prefix, "WobbleMode", "auto");
324
325 wob.ToLower();
326 wob=wob.Strip(TString::kBoth);
327
328 if (wob=="auto")
329 return !HasOffSequences();
330
331 return GetEnvValue2(env, prefix, "WobbleMode", kFALSE);
332}
333
334// --------------------------------------------------------------------------
335//
336// Read a dataset from the file fname. If num is != -1 all resources are
337// prefixed with the number. This allows constrcutions like:
338//
339// 89123.SequencesOn: 1 2 3 4
340// 89130.SequencesOn: 5 6 7 8
341//
342// For one dataset:
343//
344// 89123.DataPath: /magic/data/star
345//
346// For all other datasets:
347//
348// DataPath: /magic/data/star
349//
350// For one sequence of one datasets:
351//
352// 89123.Sequence00000002.Dir: /magic/data/star
353//
354// and therefore allows storage of several datsets in one file with
355// a defaults for non specific resources.
356//
357// sequences and data are the path to the sequences (/magic/sequences)
358// and the data (/magic/data/star) respectively. Both can be overwritten
359// be a default from the dataset file or a resource for an individual
360// sequence.
361//
362void MDataSet::Init(const char *fname, const UInt_t num, TString sequences, TString &data)
363{
364 fName = "MDataSet";
365 fTitle = "DataSet file";
366
367 // Store given file name as name
368 fFileName = fname;
369
370 // Delete the stored Sequences automatically at destruction
371 fSequencesOn.SetOwner();
372 fSequencesOff.SetOwner();
373
374 // Expand the file name (eg $MARS or ~ are expanded)
375 gSystem->ExpandPathName(fFileName);
376
377 // Check its accessibility
378 const Bool_t access = !gSystem->AccessPathName(fFileName, kFileExists);
379 if (!access)
380 {
381 gLog << err << "ERROR - Dataset file " << fname << " not accessible!" << endl;
382 fNumAnalysis = (UInt_t)-1;
383 return;
384 }
385
386 // Determin the prefix to access this resource
387 const TString prefix = num==(UInt_t)-1 ? "" : Form("%d", num);
388
389 // Open and read the file
390 MEnv env(fFileName);
391
392 // Get analysis number and name
393 fNumAnalysis = GetEnvValue2(env, prefix, "AnalysisNumber", (Int_t)num);
394 fDataSet = GetEnvValue2(env, prefix, "Name", GetBaseName());
395
396 // Get sequences from file
397 TString str;
398 str = GetEnvValue2(env, prefix, "SequencesOn", "");
399 Split(str, fNumSequencesOn);
400 str = GetEnvValue2(env, prefix, "SequencesOff", "");
401 Split(str, fNumSequencesOff);
402
403 // Get other resources
404 fNameSource = GetEnvValue2(env, prefix, "SourceName", "");
405 fCatalog = GetEnvValue2(env, prefix, "Catalog", fgCatalog);
406 fMonteCarlo = GetEnvValue2(env, prefix, "MonteCarlo", kFALSE);
407 fComment = GetEnvValue2(env, prefix, "Comment", "");
408
409 fWobbleMode = GetWobbleMode(env, prefix); // needs the number of off sequences
410
411 fNameSource = fNameSource.Strip(TString::kBoth);
412 fCatalog = fCatalog.Strip(TString::kBoth);
413
414 // Check for sequence and data path (GetDefPath needs the monte carlo flag)
415 const TString defpathseq = GetEnvValue2(env, prefix, "SequencePath", GetDefPathSequences());
416 const TString defpathdata = GetEnvValue2(env, prefix, "DataPath", GetDefPathDataFiles());
417
418 SetupDefaultPath(sequences, defpathseq);
419 SetupDefaultPath(data, defpathdata);
420
421 fPathSequences = sequences;
422 fPathDataFiles = data;
423
424 // Resolve sequences
425 ResolveSequences(env, prefix, fNumSequencesOn, fSequencesOn);
426 ResolveSequences(env, prefix, fNumSequencesOff, fSequencesOff);
427
428 // --- Now "touch" resources which are not yet stored in MDataSet ---
429 env.Touch("RunTime");
430
431 // --- Print "untouch" resources ---
432 if (env.GetNumUntouched()>0)
433 {
434 gLog << warn << "WARNING - At least one resource in the dataset-file has not been touched!" << endl;
435 env.PrintUntouched();
436 }
437}
438
439// --------------------------------------------------------------------------
440//
441// Constructor. See Read for more details.
442//
443MDataSet::MDataSet(const char *fname, TString sequences, TString data)
444{
445 Init(fname, (UInt_t)-1, sequences, data);
446}
447
448// --------------------------------------------------------------------------
449//
450// Constructor. See Read for more details.
451//
452MDataSet::MDataSet(const char *fname, Int_t num, TString sequences, TString data)
453{
454 Init(fname, num, sequences, data);
455}
456
457//---------------------------------------------------------------------------
458//
459// Return the name of the file
460//
461const char *MDataSet::GetBaseName() const
462{
463 return gSystem->BaseName(fFileName);
464}
465
466//---------------------------------------------------------------------------
467//
468// Return the directory of the file
469//
470const char *MDataSet::GetFilePath() const
471{
472 return gSystem->DirName(fFileName);
473}
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" << Form("%08d", seq.GetSequence()) << ".File: " << (useds?"-":seq.GetFileName()) << endl;
498 out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Dir: " << seq.GetDataPath() << endl;
499 if (!useds && seq.GetNumExclRuns()>0)
500 out << "Sequence" << Form("%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 return;
582 }
583}
584
585// --------------------------------------------------------------------------
586//
587// Print the contents of the dataset to the gLog stream
588//
589void MDataSet::Print(Option_t *o) const
590{
591 gLog << all;
592 Print(gLog, o);
593}
594
595// --------------------------------------------------------------------------
596//
597// Print the contents of the dataset to the file with name filename
598//
599void MDataSet::WriteFile(const char *name, const Option_t *o) const
600{
601 ofstream fout(name);
602 if (!fout)
603 {
604 gLog << err << "Cannot open file " << name << ": ";
605 gLog << strerror(errno) << endl;
606 return;
607 }
608
609 Print(fout, o);
610}
611
612// --------------------------------------------------------------------------
613//
614// Adds all sequences contained in list to the MDirIter. After adding
615// everything MDirIter::Sort is called to sort all entries by name.
616//
617Bool_t MDataSet::AddSequencesFromList(const TList &list, MDirIter &files)
618{
619 TIter Next(const_cast<TList*>(&list));
620
621 MSequence *seq=0;
622 while ((seq=(MSequence*)Next()))
623 {
624 if (!seq->IsValid())
625 {
626 gLog << err;
627 gLog << "ERROR - MDataSet::AddSequencesFromList: Sequence invalid!" << endl;
628 gLog << " + File: " << seq->GetFileName() << endl;
629 gLog << " + Dir: " << seq->GetDataPath() << endl;
630 return kFALSE;
631 }
632
633 if (seq->GetRuns(files, MSequence::kImages)<=0)
634 return kFALSE;
635 }
636
637 // This is important in case of synchronisation, because the
638 // files in the sequences can be interleaved (eg W1, W2)
639 // Filenames MUST begin with an appropriate string which allow
640 // to order them correctly in time!
641 // files.Sort();
642
643 if (gLog.GetDebugLevel()>4)
644 {
645 gLog << inf << "Files which are searched:" << endl;
646 files.Print();
647 }
648 return kTRUE;
649}
650
651Bool_t MDataSet::AddFilesOn(MDirIter &iter) const
652{
653 return AddSequencesFromList(fSequencesOn, iter);
654}
655
656Bool_t MDataSet::AddFilesOff(MDirIter &iter) const
657{
658 return AddSequencesFromList(fSequencesOff, iter);
659}
660
661Bool_t MDataSet::AddFiles(MDirIter &iter) const
662{
663 const Bool_t rc1 = AddFilesOff(iter);
664 const Bool_t rc2 = AddFilesOn(iter);
665 return rc1 && rc2;
666}
667
668Bool_t MDataSet::AddFilesOn(MRead &read) const
669{
670 MDirIter files;
671 if (!AddFilesOn(files))
672 return kFALSE;
673 return read.AddFiles(files)>0;
674}
675
676Bool_t MDataSet::AddFilesOff(MRead &read) const
677{
678 MDirIter files;
679 if (!AddFilesOff(files))
680 return kFALSE;
681 return read.AddFiles(files)>0;
682}
683
684Bool_t MDataSet::AddFiles(MRead &read) const
685{
686 const Bool_t rc1 = AddFilesOff(read);
687 const Bool_t rc2 = AddFilesOn(read);
688 return rc1 && rc2;
689}
690
691Int_t MDataSet::AddFilesToChain(MDirIter &files, TChain &chain)
692{
693 Int_t num=0;
694 while (1)
695 {
696 const TString fname = files.Next();
697 if (fname.IsNull())
698 break;
699
700 const Int_t n = chain.Add(fname);
701 if (n<=0)
702 return kFALSE;
703 num += n;
704 }
705 return num;
706}
707
708Bool_t MDataSet::AddFilesOn(TChain &chain) const
709{
710 MDirIter files;
711 if (!AddSequencesFromList(fSequencesOn, files))
712 return kFALSE;
713 return AddFilesToChain(files, chain)>0;
714}
715
716Bool_t MDataSet::AddFilesOff(TChain &chain) const
717{
718 MDirIter files;
719 if (!AddSequencesFromList(fSequencesOff, files))
720 return kFALSE;
721 return AddFilesToChain(files, chain)>0;
722}
723
724Bool_t MDataSet::AddFiles(TChain &read) const
725{
726 const Bool_t rc1 = AddFilesOff(read);
727 const Bool_t rc2 = AddFilesOn(read);
728 return rc1 && rc2;
729}
730
731Bool_t MDataSet::GetSourcePos(MPointingPos &pos) const
732{
733 if (!HasSource())
734 {
735 gLog << err << "ERROR - MDataSet::GetSourcePos called, but no source available." << endl;
736 return kFALSE;
737 }
738
739 TString catalog(fCatalog);
740 gSystem->ExpandPathName(catalog);
741
742 ifstream fin(catalog);
743 if (!fin)
744 {
745 gLog << err << "Cannot open file " << catalog << ": ";
746 gLog << strerror(errno) << endl;
747 return kFALSE;
748 }
749
750 TString ra, dec, epoch;
751
752 Int_t n = 0;
753 while (1)
754 {
755 TString line;
756 line.ReadLine(fin);
757 if (!fin)
758 {
759 gLog << err << "ERROR - Source '" << fNameSource << "' not found in " << catalog << "." << endl;
760 return kFALSE;
761 }
762
763 n++;
764
765 TObjArray *arr = line.Tokenize(",");
766
767 if (arr->GetEntries()<6)
768 {
769 gLog << err << "ERROR - Not enough arguments in line #" << n << " of " << catalog << endl;
770 delete arr;
771 return kFALSE;;
772 }
773
774 const TString name = (*arr)[0]->GetName();
775
776 ra = (*arr)[2]->GetName();
777 dec = (*arr)[3]->GetName();
778 epoch = (*arr)[5]->GetName();
779
780 delete arr;
781
782 if (name.Strip(TString::kBoth)==fNameSource)
783 break;
784 }
785
786 if (epoch.Strip(TString::kBoth)!=(TString)"2000")
787 {
788 gLog << err << "ERROR - Epoch not 2000... not supported." << endl;
789 return kFALSE;
790 }
791
792 Double_t r,d;
793 if (!MAstro::Coordinate2Angle(ra, r))
794 {
795 gLog << err << "ERROR - Interpreting right ascension: " << ra << endl;
796 return kFALSE;
797 }
798 if (!MAstro::Coordinate2Angle(dec, d))
799 {
800 gLog << err << "ERROR - Interpreting declination: " << dec << endl;
801 return kFALSE;
802 }
803
804 pos.SetSkyPosition(r, d);
805 pos.SetTitle(fNameSource);
806
807 return kTRUE;
808}
809
810/*
811// --------------------------------------------------------------------------
812//
813// Calls ReplaceAll(old, news) for all Dir-entries
814//
815void MDataSet::ReplaceDir(TList &list, const TString &old, const TString &news) const
816{
817 TIter Next(&list);
818 TNamed *name = 0;
819 while ((name=(TNamed*)Next()))
820 {
821 TString dir = name->GetTitle();
822 dir.ReplaceAll(old, news);
823 name->SetTitle(dir);
824 }
825}
826
827// --------------------------------------------------------------------------
828//
829// Calls ReplaceAll(old, news) for all File-entries
830//
831void MDataSet::ReplaceFile(TList &list, const TString &old, const TString &news) const
832{
833 TIter Next(&list);
834 TNamed *name = 0;
835 while ((name=(TNamed*)Next()))
836 {
837 TString file = name->GetName();
838 file.ReplaceAll(old, news);
839 name->SetName(file);
840 }
841}
842*/
Note: See TracBrowser for help on using the repository browser.