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 |
|
---|
223 | ClassImp(MDataSet);
|
---|
224 |
|
---|
225 | using namespace std;
|
---|
226 |
|
---|
227 | const 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 | //
|
---|
235 | void 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 | //
|
---|
286 | void 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 | const TString seqid = Form("Sequence%08d", num[i]);
|
---|
294 |
|
---|
295 | TString name = GetEnvValue2(env, prefix, Form("%s.File", seqid.Data()), "");
|
---|
296 | TString dir = GetEnvValue2(env, prefix, Form("%s.Dir", seqid.Data()), "");
|
---|
297 | TString excl = GetEnvValue2(env, prefix, Form("%s.Exclude", seqid.Data()), "");
|
---|
298 |
|
---|
299 | // Set default sequence file and dir name
|
---|
300 | if (name.IsNull())
|
---|
301 | name = Form("%s%04d/sequence%08d.txt", sequences.Data(), num[i]/10000, num[i]);
|
---|
302 | if (dir.IsNull())
|
---|
303 | dir = Form("%s%04d/%08d", data.Data(), num[i]/10000, num[i]);
|
---|
304 |
|
---|
305 | // Check if sequence information is contained in Dataset file
|
---|
306 | const Bool_t useds = name=="-";
|
---|
307 |
|
---|
308 | // FIXME: The sequence number from the sequence file is assigned!!!
|
---|
309 | MSequence *seq = new MSequence(useds?fFileName:name, dir, num[i]);
|
---|
310 | seq->ExcludeRuns(excl);
|
---|
311 |
|
---|
312 | if (seq->IsValid() && seq->GetSequence()!=(UInt_t)num[i])
|
---|
313 | *fLog << warn << "WARNING - Sequence number " << num[i] << " in dataset file doesn't match number " << seq->GetSequence() << " in sequence file!" << endl;
|
---|
314 |
|
---|
315 | list.Add(seq);
|
---|
316 | }
|
---|
317 |
|
---|
318 | // For the synchronization we must make sure, that all sequences are
|
---|
319 | // in the correct order...
|
---|
320 | // list.Sort();
|
---|
321 | }
|
---|
322 |
|
---|
323 | Bool_t MDataSet::GetWobbleMode(const TEnv &env, const TString &prefix) const
|
---|
324 | {
|
---|
325 | TString wob = GetEnvValue2(env, prefix, "WobbleMode", "auto");
|
---|
326 |
|
---|
327 | wob.ToLower();
|
---|
328 | wob=wob.Strip(TString::kBoth);
|
---|
329 |
|
---|
330 | if (wob=="auto")
|
---|
331 | return !HasOffSequences();
|
---|
332 |
|
---|
333 | return GetEnvValue2(env, prefix, "WobbleMode", kFALSE);
|
---|
334 | }
|
---|
335 |
|
---|
336 | // --------------------------------------------------------------------------
|
---|
337 | //
|
---|
338 | // Read a dataset from the file fname. If num is != -1 all resources are
|
---|
339 | // prefixed with the number. This allows constrcutions like:
|
---|
340 | //
|
---|
341 | // 89123.SequencesOn: 1 2 3 4
|
---|
342 | // 89130.SequencesOn: 5 6 7 8
|
---|
343 | //
|
---|
344 | // For one dataset:
|
---|
345 | //
|
---|
346 | // 89123.DataPath: /magic/data/star
|
---|
347 | //
|
---|
348 | // For all other datasets:
|
---|
349 | //
|
---|
350 | // DataPath: /magic/data/star
|
---|
351 | //
|
---|
352 | // For one sequence of one datasets:
|
---|
353 | //
|
---|
354 | // 89123.Sequence00000002.Dir: /magic/data/star
|
---|
355 | //
|
---|
356 | // and therefore allows storage of several datsets in one file with
|
---|
357 | // a defaults for non specific resources.
|
---|
358 | //
|
---|
359 | // sequences and data are the path to the sequences (/magic/sequences)
|
---|
360 | // and the data (/magic/data/star) respectively. Both can be overwritten
|
---|
361 | // be a default from the dataset file or a resource for an individual
|
---|
362 | // sequence.
|
---|
363 | //
|
---|
364 | void MDataSet::Init(const char *fname, const UInt_t num, TString sequences, TString &data)
|
---|
365 | {
|
---|
366 | fName = "MDataSet";
|
---|
367 | fTitle = "DataSet file";
|
---|
368 |
|
---|
369 | // Store given file name as name
|
---|
370 | fFileName = fname;
|
---|
371 |
|
---|
372 | // Delete the stored Sequences automatically at destruction
|
---|
373 | fSequencesOn.SetOwner();
|
---|
374 | fSequencesOff.SetOwner();
|
---|
375 |
|
---|
376 | // Expand the file name (eg $MARS or ~ are expanded)
|
---|
377 | gSystem->ExpandPathName(fFileName);
|
---|
378 |
|
---|
379 | // Check its accessibility
|
---|
380 | const Bool_t access = !gSystem->AccessPathName(fFileName, kFileExists);
|
---|
381 | if (!access)
|
---|
382 | {
|
---|
383 | gLog << err << "ERROR - Dataset file " << fname << " not accessible!" << endl;
|
---|
384 | fNumAnalysis = (UInt_t)-1;
|
---|
385 | return;
|
---|
386 | }
|
---|
387 |
|
---|
388 | // Determin the prefix to access this resource
|
---|
389 | const TString prefix = num==(UInt_t)-1 ? "" : Form("%d", num);
|
---|
390 |
|
---|
391 | // Open and read the file
|
---|
392 | MEnv env(fFileName);
|
---|
393 |
|
---|
394 | // Get analysis number and name
|
---|
395 | fNumAnalysis = GetEnvValue2(env, prefix, "AnalysisNumber", (Int_t)num);
|
---|
396 | fDataSet = GetEnvValue2(env, prefix, "Name", GetBaseName());
|
---|
397 |
|
---|
398 | // Get sequences from file
|
---|
399 | TString str;
|
---|
400 | str = GetEnvValue2(env, prefix, "SequencesOn", "");
|
---|
401 | Split(str, fNumSequencesOn);
|
---|
402 | str = GetEnvValue2(env, prefix, "SequencesOff", "");
|
---|
403 | Split(str, fNumSequencesOff);
|
---|
404 |
|
---|
405 | // Get other resources
|
---|
406 | fNameSource = GetEnvValue2(env, prefix, "SourceName", "");
|
---|
407 | fCatalog = GetEnvValue2(env, prefix, "Catalog", fgCatalog);
|
---|
408 | fMonteCarlo = GetEnvValue2(env, prefix, "MonteCarlo", kFALSE);
|
---|
409 | fComment = GetEnvValue2(env, prefix, "Comment", "");
|
---|
410 |
|
---|
411 | fWobbleMode = GetWobbleMode(env, prefix); // needs the number of off sequences
|
---|
412 |
|
---|
413 | fNameSource = fNameSource.Strip(TString::kBoth);
|
---|
414 | fCatalog = fCatalog.Strip(TString::kBoth);
|
---|
415 |
|
---|
416 | // Check for sequence and data path (GetDefPath needs the monte carlo flag)
|
---|
417 | const TString defpathseq = GetEnvValue2(env, prefix, "SequencePath", GetDefPathSequences());
|
---|
418 | const TString defpathdata = GetEnvValue2(env, prefix, "DataPath", GetDefPathDataFiles());
|
---|
419 |
|
---|
420 | SetupDefaultPath(sequences, defpathseq);
|
---|
421 | SetupDefaultPath(data, defpathdata);
|
---|
422 |
|
---|
423 | fPathSequences = sequences;
|
---|
424 | fPathDataFiles = data;
|
---|
425 |
|
---|
426 | // Resolve sequences
|
---|
427 | ResolveSequences(env, prefix, fNumSequencesOn, fSequencesOn);
|
---|
428 | ResolveSequences(env, prefix, fNumSequencesOff, fSequencesOff);
|
---|
429 |
|
---|
430 | // --- Now "touch" resources which are not yet stored in MDataSet ---
|
---|
431 | env.Touch("RunTime");
|
---|
432 |
|
---|
433 | // --- Print "untouch" resources ---
|
---|
434 | if (env.GetNumUntouched()>0)
|
---|
435 | {
|
---|
436 | gLog << warn << "WARNING - At least one resource in the dataset-file has not been touched!" << endl;
|
---|
437 | env.PrintUntouched();
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | // --------------------------------------------------------------------------
|
---|
442 | //
|
---|
443 | // Constructor. See Read for more details.
|
---|
444 | //
|
---|
445 | MDataSet::MDataSet(const char *fname, TString sequences, TString data)
|
---|
446 | {
|
---|
447 | Init(fname, (UInt_t)-1, sequences, data);
|
---|
448 | }
|
---|
449 |
|
---|
450 | // --------------------------------------------------------------------------
|
---|
451 | //
|
---|
452 | // Constructor. See Read for more details.
|
---|
453 | //
|
---|
454 | MDataSet::MDataSet(const char *fname, Int_t num, TString sequences, TString data)
|
---|
455 | {
|
---|
456 | Init(fname, num, sequences, data);
|
---|
457 | }
|
---|
458 |
|
---|
459 | //---------------------------------------------------------------------------
|
---|
460 | //
|
---|
461 | // Return the name of the file
|
---|
462 | //
|
---|
463 | const char *MDataSet::GetBaseName() const
|
---|
464 | {
|
---|
465 | return gSystem->BaseName(fFileName);
|
---|
466 | }
|
---|
467 |
|
---|
468 | //---------------------------------------------------------------------------
|
---|
469 | //
|
---|
470 | // Return the directory of the file
|
---|
471 | //
|
---|
472 | const char *MDataSet::GetFilePath() const
|
---|
473 | {
|
---|
474 | return gSystem->DirName(fFileName);
|
---|
475 | }
|
---|
476 |
|
---|
477 |
|
---|
478 | // --------------------------------------------------------------------------
|
---|
479 | //
|
---|
480 | // Return '+' if both can be accessed, '-' otherwise.
|
---|
481 | //
|
---|
482 | void MDataSet::PrintFile(ostream &out, const MSequence &seq)
|
---|
483 | {
|
---|
484 | const Char_t access =
|
---|
485 | !gSystem->AccessPathName(seq.GetFileName(), kFileExists) &&
|
---|
486 | !gSystem->AccessPathName(seq.GetDataPath(), kFileExists) ? '+' : '-';
|
---|
487 |
|
---|
488 | out << "# " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
|
---|
489 | }
|
---|
490 |
|
---|
491 | // --------------------------------------------------------------------------
|
---|
492 | //
|
---|
493 | // Helper to print a seqeunce in Print()
|
---|
494 | //
|
---|
495 | void MDataSet::PrintSeq(ostream &out, const MSequence &seq) const
|
---|
496 | {
|
---|
497 | const Bool_t useds = seq.GetFileName()==fFileName;
|
---|
498 |
|
---|
499 | out << "Sequence" << Form("%08d", seq.GetSequence()) << ".File: " << (useds?"-":seq.GetFileName()) << endl;
|
---|
500 | out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Dir: " << seq.GetDataPath() << endl;
|
---|
501 | if (!useds && seq.GetNumExclRuns()>0)
|
---|
502 | out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
|
---|
503 |
|
---|
504 | if (useds)
|
---|
505 | {
|
---|
506 | out << endl;
|
---|
507 | seq.Print(out, "prefixed");
|
---|
508 | out << endl << "# ---" << endl;
|
---|
509 | }
|
---|
510 | }
|
---|
511 |
|
---|
512 | // --------------------------------------------------------------------------
|
---|
513 | //
|
---|
514 | // Print the contents of the dataset to the ostream out
|
---|
515 | //
|
---|
516 | void MDataSet::Print(ostream &out, Option_t *o) const
|
---|
517 | {
|
---|
518 | if (!IsValid())
|
---|
519 | {
|
---|
520 | out << "Dataset: " << fFileName << " <invalid - no analysis number available>" << endl;
|
---|
521 | return;
|
---|
522 | }
|
---|
523 | out << "# Path: " << GetFilePath() << endl;
|
---|
524 | out << "# Name: " << GetBaseName() << endl;
|
---|
525 | out << endl;
|
---|
526 | out << "AnalysisNumber: " << fNumAnalysis << endl << endl;
|
---|
527 |
|
---|
528 | if (!fDataSet.IsNull())
|
---|
529 | out << "Name: " << fDataSet << endl << endl;
|
---|
530 |
|
---|
531 | out << "SequencesOn: ";
|
---|
532 | for (int i=0; i<fNumSequencesOn.GetSize(); i++)
|
---|
533 | out << " " << fNumSequencesOn[i];
|
---|
534 | out << endl;
|
---|
535 | if (fNumSequencesOff.GetSize()>0)
|
---|
536 | {
|
---|
537 | out << "SequencesOff: ";
|
---|
538 | for (int i=0; i<fNumSequencesOff.GetSize(); i++)
|
---|
539 | out << " " << fNumSequencesOff[i];
|
---|
540 | out << endl;
|
---|
541 | }
|
---|
542 |
|
---|
543 | out << endl;
|
---|
544 | if (!fNameSource.IsNull())
|
---|
545 | out << "SourceName: " << fNameSource << endl;
|
---|
546 | out << "Catalog: " << fCatalog << endl;
|
---|
547 |
|
---|
548 | out << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
|
---|
549 | out << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
|
---|
550 |
|
---|
551 | if (!fComment.IsNull())
|
---|
552 | out << "Comment: " << fComment << endl;
|
---|
553 |
|
---|
554 | if (fSequencesOn.GetEntries()>0)
|
---|
555 | out << endl;
|
---|
556 |
|
---|
557 | // FIXME: If file==fName --> print Sequence0000.content
|
---|
558 |
|
---|
559 | TIter NextOn(&fSequencesOn);
|
---|
560 | TIter NextOff(&fSequencesOff);
|
---|
561 | MSequence *seq=0;
|
---|
562 | while ((seq=(MSequence*)NextOn()))
|
---|
563 | PrintSeq(out, *seq);
|
---|
564 | if (fSequencesOff.GetEntries()>0)
|
---|
565 | out << endl;
|
---|
566 | while ((seq=(MSequence*)NextOff()))
|
---|
567 | PrintSeq(out, *seq);
|
---|
568 |
|
---|
569 | if (TString(o).Contains("files", TString::kIgnoreCase))
|
---|
570 | {
|
---|
571 | out << endl;
|
---|
572 | out << "# On-Data Files:" << endl;
|
---|
573 | NextOn.Reset();
|
---|
574 | while ((seq=(MSequence*)NextOn()))
|
---|
575 | PrintFile(out, *seq);
|
---|
576 |
|
---|
577 | out << endl;
|
---|
578 | out << "# Off-Data Files:" << endl;
|
---|
579 | NextOff.Reset();
|
---|
580 | while ((seq=(MSequence*)NextOff()))
|
---|
581 | PrintFile(out, *seq);
|
---|
582 |
|
---|
583 | return;
|
---|
584 | }
|
---|
585 | }
|
---|
586 |
|
---|
587 | // --------------------------------------------------------------------------
|
---|
588 | //
|
---|
589 | // Print the contents of the dataset to the gLog stream
|
---|
590 | //
|
---|
591 | void MDataSet::Print(Option_t *o) const
|
---|
592 | {
|
---|
593 | gLog << all;
|
---|
594 | Print(gLog, o);
|
---|
595 | }
|
---|
596 |
|
---|
597 | // --------------------------------------------------------------------------
|
---|
598 | //
|
---|
599 | // Print the contents of the dataset to the file with name filename
|
---|
600 | //
|
---|
601 | void MDataSet::WriteFile(const char *name, const Option_t *o) const
|
---|
602 | {
|
---|
603 | ofstream fout(name);
|
---|
604 | if (!fout)
|
---|
605 | {
|
---|
606 | gLog << err << "Cannot open file " << name << ": ";
|
---|
607 | gLog << strerror(errno) << endl;
|
---|
608 | return;
|
---|
609 | }
|
---|
610 |
|
---|
611 | Print(fout, o);
|
---|
612 | }
|
---|
613 |
|
---|
614 | // --------------------------------------------------------------------------
|
---|
615 | //
|
---|
616 | // Adds all sequences contained in list to the MDirIter. After adding
|
---|
617 | // everything MDirIter::Sort is called to sort all entries by name.
|
---|
618 | //
|
---|
619 | Bool_t MDataSet::AddSequencesFromList(const TList &list, MDirIter &files)
|
---|
620 | {
|
---|
621 | TIter Next(const_cast<TList*>(&list));
|
---|
622 |
|
---|
623 | MSequence *seq=0;
|
---|
624 | while ((seq=(MSequence*)Next()))
|
---|
625 | {
|
---|
626 | if (!seq->IsValid())
|
---|
627 | {
|
---|
628 | gLog << err;
|
---|
629 | gLog << "ERROR - MDataSet::AddSequencesFromList: Sequence invalid!" << endl;
|
---|
630 | gLog << " + File: " << seq->GetFileName() << endl;
|
---|
631 | gLog << " + Dir: " << seq->GetDataPath() << endl;
|
---|
632 | return kFALSE;
|
---|
633 | }
|
---|
634 |
|
---|
635 | if (seq->SetupDatRuns(files, MSequence::kImages)<=0)
|
---|
636 | return kFALSE;
|
---|
637 | }
|
---|
638 |
|
---|
639 | // This is important in case of synchronisation, because the
|
---|
640 | // files in the sequences can be interleaved (eg W1, W2)
|
---|
641 | // Filenames MUST begin with an appropriate string which allow
|
---|
642 | // to order them correctly in time!
|
---|
643 | // files.Sort();
|
---|
644 |
|
---|
645 | if (gLog.GetDebugLevel()>4)
|
---|
646 | {
|
---|
647 | gLog << inf << "Files which are searched:" << endl;
|
---|
648 | files.Print();
|
---|
649 | }
|
---|
650 | return kTRUE;
|
---|
651 | }
|
---|
652 |
|
---|
653 | Bool_t MDataSet::AddFilesOn(MDirIter &iter) const
|
---|
654 | {
|
---|
655 | return AddSequencesFromList(fSequencesOn, iter);
|
---|
656 | }
|
---|
657 |
|
---|
658 | Bool_t MDataSet::AddFilesOff(MDirIter &iter) const
|
---|
659 | {
|
---|
660 | return AddSequencesFromList(fSequencesOff, iter);
|
---|
661 | }
|
---|
662 |
|
---|
663 | Bool_t MDataSet::AddFiles(MDirIter &iter) const
|
---|
664 | {
|
---|
665 | const Bool_t rc1 = AddFilesOff(iter);
|
---|
666 | const Bool_t rc2 = AddFilesOn(iter);
|
---|
667 | return rc1 && rc2;
|
---|
668 | }
|
---|
669 |
|
---|
670 | Bool_t MDataSet::AddFilesOn(MRead &read) const
|
---|
671 | {
|
---|
672 | MDirIter files;
|
---|
673 | if (!AddFilesOn(files))
|
---|
674 | return kFALSE;
|
---|
675 | return read.AddFiles(files)>0;
|
---|
676 | }
|
---|
677 |
|
---|
678 | Bool_t MDataSet::AddFilesOff(MRead &read) const
|
---|
679 | {
|
---|
680 | MDirIter files;
|
---|
681 | if (!AddFilesOff(files))
|
---|
682 | return kFALSE;
|
---|
683 | return read.AddFiles(files)>0;
|
---|
684 | }
|
---|
685 |
|
---|
686 | Bool_t MDataSet::AddFiles(MRead &read) const
|
---|
687 | {
|
---|
688 | const Bool_t rc1 = AddFilesOff(read);
|
---|
689 | const Bool_t rc2 = AddFilesOn(read);
|
---|
690 | return rc1 && rc2;
|
---|
691 | }
|
---|
692 |
|
---|
693 | Int_t MDataSet::AddFilesToChain(MDirIter &files, TChain &chain)
|
---|
694 | {
|
---|
695 | Int_t num=0;
|
---|
696 | while (1)
|
---|
697 | {
|
---|
698 | const TString fname = files.Next();
|
---|
699 | if (fname.IsNull())
|
---|
700 | break;
|
---|
701 |
|
---|
702 | const Int_t n = chain.Add(fname);
|
---|
703 | if (n<=0)
|
---|
704 | return kFALSE;
|
---|
705 | num += n;
|
---|
706 | }
|
---|
707 | return num;
|
---|
708 | }
|
---|
709 |
|
---|
710 | Bool_t MDataSet::AddFilesOn(TChain &chain) const
|
---|
711 | {
|
---|
712 | MDirIter files;
|
---|
713 | if (!AddSequencesFromList(fSequencesOn, files))
|
---|
714 | return kFALSE;
|
---|
715 | return AddFilesToChain(files, chain)>0;
|
---|
716 | }
|
---|
717 |
|
---|
718 | Bool_t MDataSet::AddFilesOff(TChain &chain) const
|
---|
719 | {
|
---|
720 | MDirIter files;
|
---|
721 | if (!AddSequencesFromList(fSequencesOff, files))
|
---|
722 | return kFALSE;
|
---|
723 | return AddFilesToChain(files, chain)>0;
|
---|
724 | }
|
---|
725 |
|
---|
726 | Bool_t MDataSet::AddFiles(TChain &read) const
|
---|
727 | {
|
---|
728 | const Bool_t rc1 = AddFilesOff(read);
|
---|
729 | const Bool_t rc2 = AddFilesOn(read);
|
---|
730 | return rc1 && rc2;
|
---|
731 | }
|
---|
732 |
|
---|
733 | Bool_t MDataSet::GetSourcePos(MPointingPos &pos) const
|
---|
734 | {
|
---|
735 | if (!HasSource())
|
---|
736 | {
|
---|
737 | gLog << err << "ERROR - MDataSet::GetSourcePos called, but no source available." << endl;
|
---|
738 | return kFALSE;
|
---|
739 | }
|
---|
740 |
|
---|
741 | TString catalog(fCatalog);
|
---|
742 | gSystem->ExpandPathName(catalog);
|
---|
743 |
|
---|
744 | ifstream fin(catalog);
|
---|
745 | if (!fin)
|
---|
746 | {
|
---|
747 | gLog << err << "Cannot open file " << catalog << ": ";
|
---|
748 | gLog << strerror(errno) << endl;
|
---|
749 | return kFALSE;
|
---|
750 | }
|
---|
751 |
|
---|
752 | TString ra, dec, epoch;
|
---|
753 |
|
---|
754 | Int_t n = 0;
|
---|
755 | while (1)
|
---|
756 | {
|
---|
757 | TString line;
|
---|
758 | line.ReadLine(fin);
|
---|
759 | if (!fin)
|
---|
760 | {
|
---|
761 | gLog << err << "ERROR - Source '" << fNameSource << "' not found in " << catalog << "." << endl;
|
---|
762 | return kFALSE;
|
---|
763 | }
|
---|
764 |
|
---|
765 | n++;
|
---|
766 |
|
---|
767 | TObjArray *arr = line.Tokenize(",");
|
---|
768 |
|
---|
769 | if (arr->GetEntries()<6)
|
---|
770 | {
|
---|
771 | gLog << err << "ERROR - Not enough arguments in line #" << n << " of " << catalog << endl;
|
---|
772 | delete arr;
|
---|
773 | return kFALSE;;
|
---|
774 | }
|
---|
775 |
|
---|
776 | const TString name = (*arr)[0]->GetName();
|
---|
777 |
|
---|
778 | ra = (*arr)[2]->GetName();
|
---|
779 | dec = (*arr)[3]->GetName();
|
---|
780 | epoch = (*arr)[5]->GetName();
|
---|
781 |
|
---|
782 | delete arr;
|
---|
783 |
|
---|
784 | if (name.Strip(TString::kBoth)==fNameSource)
|
---|
785 | break;
|
---|
786 | }
|
---|
787 |
|
---|
788 | if (epoch.Strip(TString::kBoth)!=(TString)"2000")
|
---|
789 | {
|
---|
790 | gLog << err << "ERROR - Epoch not 2000... not supported." << endl;
|
---|
791 | return kFALSE;
|
---|
792 | }
|
---|
793 |
|
---|
794 | Double_t r,d;
|
---|
795 | if (!MAstro::Coordinate2Angle(ra, r))
|
---|
796 | {
|
---|
797 | gLog << err << "ERROR - Interpreting right ascension: " << ra << endl;
|
---|
798 | return kFALSE;
|
---|
799 | }
|
---|
800 | if (!MAstro::Coordinate2Angle(dec, d))
|
---|
801 | {
|
---|
802 | gLog << err << "ERROR - Interpreting declination: " << dec << endl;
|
---|
803 | return kFALSE;
|
---|
804 | }
|
---|
805 |
|
---|
806 | pos.SetSkyPosition(r, d);
|
---|
807 | pos.SetTitle(fNameSource);
|
---|
808 |
|
---|
809 | return kTRUE;
|
---|
810 | }
|
---|
811 |
|
---|
812 | /*
|
---|
813 | // --------------------------------------------------------------------------
|
---|
814 | //
|
---|
815 | // Calls ReplaceAll(old, news) for all Dir-entries
|
---|
816 | //
|
---|
817 | void MDataSet::ReplaceDir(TList &list, const TString &old, const TString &news) const
|
---|
818 | {
|
---|
819 | TIter Next(&list);
|
---|
820 | TNamed *name = 0;
|
---|
821 | while ((name=(TNamed*)Next()))
|
---|
822 | {
|
---|
823 | TString dir = name->GetTitle();
|
---|
824 | dir.ReplaceAll(old, news);
|
---|
825 | name->SetTitle(dir);
|
---|
826 | }
|
---|
827 | }
|
---|
828 |
|
---|
829 | // --------------------------------------------------------------------------
|
---|
830 | //
|
---|
831 | // Calls ReplaceAll(old, news) for all File-entries
|
---|
832 | //
|
---|
833 | void MDataSet::ReplaceFile(TList &list, const TString &old, const TString &news) const
|
---|
834 | {
|
---|
835 | TIter Next(&list);
|
---|
836 | TNamed *name = 0;
|
---|
837 | while ((name=(TNamed*)Next()))
|
---|
838 | {
|
---|
839 | TString file = name->GetName();
|
---|
840 | file.ReplaceAll(old, news);
|
---|
841 | name->SetName(file);
|
---|
842 | }
|
---|
843 | }
|
---|
844 | */
|
---|