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 | 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 |
|
---|
321 | Bool_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 | //
|
---|
362 | void 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 | //
|
---|
443 | MDataSet::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 | //
|
---|
452 | MDataSet::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 | //
|
---|
461 | const char *MDataSet::GetBaseName() const
|
---|
462 | {
|
---|
463 | return gSystem->BaseName(fFileName);
|
---|
464 | }
|
---|
465 |
|
---|
466 | //---------------------------------------------------------------------------
|
---|
467 | //
|
---|
468 | // Return the directory of the file
|
---|
469 | //
|
---|
470 | const char *MDataSet::GetFilePath() const
|
---|
471 | {
|
---|
472 | return gSystem->DirName(fFileName);
|
---|
473 | }
|
---|
474 |
|
---|
475 | // --------------------------------------------------------------------------
|
---|
476 | //
|
---|
477 | // Return '+' if both can be accessed, '-' otherwise.
|
---|
478 | //
|
---|
479 | void MDataSet::PrintFile(ostream &out, const MSequence &seq)
|
---|
480 | {
|
---|
481 | const Char_t access =
|
---|
482 | !gSystem->AccessPathName(seq.GetFileName(), kFileExists) &&
|
---|
483 | !gSystem->AccessPathName(seq.GetDataPath(), kFileExists) ? '+' : '-';
|
---|
484 |
|
---|
485 | out << "# " << access << " " << seq.GetFileName() << " <" << seq.GetDataPath() << ">" << endl;
|
---|
486 | }
|
---|
487 |
|
---|
488 | // --------------------------------------------------------------------------
|
---|
489 | //
|
---|
490 | // Helper to print a seqeunce in Print()
|
---|
491 | //
|
---|
492 | void MDataSet::PrintSeq(ostream &out, const MSequence &seq) const
|
---|
493 | {
|
---|
494 | const Bool_t useds = seq.GetFileName()==fFileName;
|
---|
495 |
|
---|
496 | out << "Sequence" << Form("%08d", seq.GetSequence()) << ".File: " << (useds?"-":seq.GetFileName()) << endl;
|
---|
497 | out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Dir: " << seq.GetDataPath() << endl;
|
---|
498 | if (!useds && seq.GetNumExclRuns()>0)
|
---|
499 | out << "Sequence" << Form("%08d", seq.GetSequence()) << ".Exclude: " << seq.GetExcludedRuns() << endl;
|
---|
500 |
|
---|
501 | if (useds)
|
---|
502 | {
|
---|
503 | out << endl;
|
---|
504 | seq.Print(out, "prefixed");
|
---|
505 | out << endl << "# ---" << endl;
|
---|
506 | }
|
---|
507 | }
|
---|
508 |
|
---|
509 | // --------------------------------------------------------------------------
|
---|
510 | //
|
---|
511 | // Print the contents of the dataset to the ostream out
|
---|
512 | //
|
---|
513 | void MDataSet::Print(ostream &out, Option_t *o) const
|
---|
514 | {
|
---|
515 | if (!IsValid())
|
---|
516 | {
|
---|
517 | out << "Dataset: " << fFileName << " <invalid - no analysis number available>" << endl;
|
---|
518 | return;
|
---|
519 | }
|
---|
520 | out << "# Path: " << GetFilePath() << endl;
|
---|
521 | out << "# Name: " << GetBaseName() << endl;
|
---|
522 | out << endl;
|
---|
523 | out << "AnalysisNumber: " << fNumAnalysis << endl << endl;
|
---|
524 |
|
---|
525 | if (!fDataSet.IsNull())
|
---|
526 | out << "Name: " << fDataSet << endl << endl;
|
---|
527 |
|
---|
528 | out << "SequencesOn: ";
|
---|
529 | for (int i=0; i<fNumSequencesOn.GetSize(); i++)
|
---|
530 | out << " " << fNumSequencesOn[i];
|
---|
531 | out << endl;
|
---|
532 | if (fNumSequencesOff.GetSize()>0)
|
---|
533 | {
|
---|
534 | out << "SequencesOff: ";
|
---|
535 | for (int i=0; i<fNumSequencesOff.GetSize(); i++)
|
---|
536 | out << " " << fNumSequencesOff[i];
|
---|
537 | out << endl;
|
---|
538 | }
|
---|
539 |
|
---|
540 | out << endl;
|
---|
541 | if (!fNameSource.IsNull())
|
---|
542 | out << "SourceName: " << fNameSource << endl;
|
---|
543 | out << "Catalog: " << fCatalog << endl;
|
---|
544 |
|
---|
545 | out << "WobbleMode: " << (fWobbleMode?"Yes":"No") << endl << endl;
|
---|
546 | out << "MonteCarlo: " << (fMonteCarlo?"Yes":"No") << endl << endl;
|
---|
547 |
|
---|
548 | if (!fComment.IsNull())
|
---|
549 | out << "Comment: " << fComment << endl;
|
---|
550 |
|
---|
551 | if (fSequencesOn.GetEntries()>0)
|
---|
552 | out << endl;
|
---|
553 |
|
---|
554 | // FIXME: If file==fName --> print Sequence0000.content
|
---|
555 |
|
---|
556 | TIter NextOn(&fSequencesOn);
|
---|
557 | TIter NextOff(&fSequencesOff);
|
---|
558 | MSequence *seq=0;
|
---|
559 | while ((seq=(MSequence*)NextOn()))
|
---|
560 | PrintSeq(out, *seq);
|
---|
561 | if (fSequencesOff.GetEntries()>0)
|
---|
562 | out << endl;
|
---|
563 | while ((seq=(MSequence*)NextOff()))
|
---|
564 | PrintSeq(out, *seq);
|
---|
565 |
|
---|
566 | if (TString(o).Contains("files", TString::kIgnoreCase))
|
---|
567 | {
|
---|
568 | out << endl;
|
---|
569 | out << "# On-Data Files:" << endl;
|
---|
570 | NextOn.Reset();
|
---|
571 | while ((seq=(MSequence*)NextOn()))
|
---|
572 | PrintFile(out, *seq);
|
---|
573 |
|
---|
574 | out << endl;
|
---|
575 | out << "# Off-Data Files:" << endl;
|
---|
576 | NextOff.Reset();
|
---|
577 | while ((seq=(MSequence*)NextOff()))
|
---|
578 | PrintFile(out, *seq);
|
---|
579 | }
|
---|
580 | }
|
---|
581 |
|
---|
582 | // --------------------------------------------------------------------------
|
---|
583 | //
|
---|
584 | // Print the contents of the dataset to the gLog stream
|
---|
585 | //
|
---|
586 | void MDataSet::Print(Option_t *o) const
|
---|
587 | {
|
---|
588 | gLog << all;
|
---|
589 | Print(gLog, o);
|
---|
590 | }
|
---|
591 |
|
---|
592 | // --------------------------------------------------------------------------
|
---|
593 | //
|
---|
594 | // Print the contents of the dataset to the file with name filename
|
---|
595 | //
|
---|
596 | void MDataSet::WriteFile(const char *name, const Option_t *o) const
|
---|
597 | {
|
---|
598 | ofstream fout(name);
|
---|
599 | if (!fout)
|
---|
600 | {
|
---|
601 | gLog << err << "Cannot open file " << name << ": ";
|
---|
602 | gLog << strerror(errno) << endl;
|
---|
603 | return;
|
---|
604 | }
|
---|
605 |
|
---|
606 | Print(fout, o);
|
---|
607 | }
|
---|
608 |
|
---|
609 | // --------------------------------------------------------------------------
|
---|
610 | //
|
---|
611 | // Adds all sequences contained in list to the MDirIter. After adding
|
---|
612 | // everything MDirIter::Sort is called to sort all entries by name.
|
---|
613 | //
|
---|
614 | Bool_t MDataSet::AddSequencesFromList(const TList &list, MDirIter &files)
|
---|
615 | {
|
---|
616 | TIter Next(const_cast<TList*>(&list));
|
---|
617 |
|
---|
618 | MSequence *seq=0;
|
---|
619 | while ((seq=(MSequence*)Next()))
|
---|
620 | {
|
---|
621 | if (!seq->IsValid())
|
---|
622 | {
|
---|
623 | gLog << err;
|
---|
624 | gLog << "ERROR - MDataSet::AddSequencesFromList: Sequence invalid!" << endl;
|
---|
625 | gLog << " + File: " << seq->GetFileName() << endl;
|
---|
626 | gLog << " + Dir: " << seq->GetDataPath() << endl;
|
---|
627 | return kFALSE;
|
---|
628 | }
|
---|
629 |
|
---|
630 | if (seq->GetRuns(files, MSequence::kImages)<=0)
|
---|
631 | return kFALSE;
|
---|
632 | }
|
---|
633 |
|
---|
634 | // This is important in case of synchronisation, because the
|
---|
635 | // files in the sequences can be interleaved (eg W1, W2)
|
---|
636 | // Filenames MUST begin with an appropriate string which allow
|
---|
637 | // to order them correctly in time!
|
---|
638 | // files.Sort();
|
---|
639 |
|
---|
640 | if (gLog.GetDebugLevel()>4)
|
---|
641 | {
|
---|
642 | gLog << inf << "Files which are searched:" << endl;
|
---|
643 | files.Print();
|
---|
644 | }
|
---|
645 | return kTRUE;
|
---|
646 | }
|
---|
647 |
|
---|
648 | Bool_t MDataSet::AddFilesOn(MDirIter &iter) const
|
---|
649 | {
|
---|
650 | return AddSequencesFromList(fSequencesOn, iter);
|
---|
651 | }
|
---|
652 |
|
---|
653 | Bool_t MDataSet::AddFilesOff(MDirIter &iter) const
|
---|
654 | {
|
---|
655 | return AddSequencesFromList(fSequencesOff, iter);
|
---|
656 | }
|
---|
657 |
|
---|
658 | Bool_t MDataSet::AddFiles(MDirIter &iter) const
|
---|
659 | {
|
---|
660 | const Bool_t rc1 = AddFilesOff(iter);
|
---|
661 | const Bool_t rc2 = AddFilesOn(iter);
|
---|
662 | return rc1 && rc2;
|
---|
663 | }
|
---|
664 |
|
---|
665 | Bool_t MDataSet::AddFilesOn(MRead &read) const
|
---|
666 | {
|
---|
667 | MDirIter files;
|
---|
668 | if (!AddFilesOn(files))
|
---|
669 | return kFALSE;
|
---|
670 | return read.AddFiles(files)>0;
|
---|
671 | }
|
---|
672 |
|
---|
673 | Bool_t MDataSet::AddFilesOff(MRead &read) const
|
---|
674 | {
|
---|
675 | MDirIter files;
|
---|
676 | if (!AddFilesOff(files))
|
---|
677 | return kFALSE;
|
---|
678 | return read.AddFiles(files)>0;
|
---|
679 | }
|
---|
680 |
|
---|
681 | Bool_t MDataSet::AddFiles(MRead &read) const
|
---|
682 | {
|
---|
683 | const Bool_t rc1 = AddFilesOff(read);
|
---|
684 | const Bool_t rc2 = AddFilesOn(read);
|
---|
685 | return rc1 && rc2;
|
---|
686 | }
|
---|
687 |
|
---|
688 | Int_t MDataSet::AddFilesToChain(MDirIter &files, TChain &chain)
|
---|
689 | {
|
---|
690 | Int_t num=0;
|
---|
691 | while (1)
|
---|
692 | {
|
---|
693 | const TString fname = files.Next();
|
---|
694 | if (fname.IsNull())
|
---|
695 | break;
|
---|
696 |
|
---|
697 | const Int_t n = chain.Add(fname);
|
---|
698 | if (n<=0)
|
---|
699 | return kFALSE;
|
---|
700 | num += n;
|
---|
701 | }
|
---|
702 | return num;
|
---|
703 | }
|
---|
704 |
|
---|
705 | Bool_t MDataSet::AddFilesOn(TChain &chain) const
|
---|
706 | {
|
---|
707 | MDirIter files;
|
---|
708 | if (!AddSequencesFromList(fSequencesOn, files))
|
---|
709 | return kFALSE;
|
---|
710 | return AddFilesToChain(files, chain)>0;
|
---|
711 | }
|
---|
712 |
|
---|
713 | Bool_t MDataSet::AddFilesOff(TChain &chain) const
|
---|
714 | {
|
---|
715 | MDirIter files;
|
---|
716 | if (!AddSequencesFromList(fSequencesOff, files))
|
---|
717 | return kFALSE;
|
---|
718 | return AddFilesToChain(files, chain)>0;
|
---|
719 | }
|
---|
720 |
|
---|
721 | Bool_t MDataSet::AddFiles(TChain &read) const
|
---|
722 | {
|
---|
723 | const Bool_t rc1 = AddFilesOff(read);
|
---|
724 | const Bool_t rc2 = AddFilesOn(read);
|
---|
725 | return rc1 && rc2;
|
---|
726 | }
|
---|
727 |
|
---|
728 | Bool_t MDataSet::GetSourcePos(MPointingPos &pos) const
|
---|
729 | {
|
---|
730 | if (!HasSource())
|
---|
731 | {
|
---|
732 | gLog << err << "ERROR - MDataSet::GetSourcePos called, but no source available." << endl;
|
---|
733 | return kFALSE;
|
---|
734 | }
|
---|
735 |
|
---|
736 | TString catalog(fCatalog);
|
---|
737 | gSystem->ExpandPathName(catalog);
|
---|
738 |
|
---|
739 | ifstream fin(catalog);
|
---|
740 | if (!fin)
|
---|
741 | {
|
---|
742 | gLog << err << "Cannot open file " << catalog << ": ";
|
---|
743 | gLog << strerror(errno) << endl;
|
---|
744 | return kFALSE;
|
---|
745 | }
|
---|
746 |
|
---|
747 | TString ra, dec, epoch;
|
---|
748 |
|
---|
749 | Int_t n = 0;
|
---|
750 | while (1)
|
---|
751 | {
|
---|
752 | TString line;
|
---|
753 | line.ReadLine(fin);
|
---|
754 | if (!fin)
|
---|
755 | {
|
---|
756 | gLog << err << "ERROR - Source '" << fNameSource << "' not found in " << catalog << "." << endl;
|
---|
757 | return kFALSE;
|
---|
758 | }
|
---|
759 |
|
---|
760 | n++;
|
---|
761 |
|
---|
762 | TObjArray *arr = line.Tokenize(",");
|
---|
763 |
|
---|
764 | if (arr->GetEntries()<6)
|
---|
765 | {
|
---|
766 | gLog << err << "ERROR - Not enough arguments in line #" << n << " of " << catalog << endl;
|
---|
767 | delete arr;
|
---|
768 | return kFALSE;;
|
---|
769 | }
|
---|
770 |
|
---|
771 | const TString name = (*arr)[0]->GetName();
|
---|
772 |
|
---|
773 | ra = (*arr)[2]->GetName();
|
---|
774 | dec = (*arr)[3]->GetName();
|
---|
775 | epoch = (*arr)[5]->GetName();
|
---|
776 |
|
---|
777 | delete arr;
|
---|
778 |
|
---|
779 | if (name.Strip(TString::kBoth)==fNameSource)
|
---|
780 | break;
|
---|
781 | }
|
---|
782 |
|
---|
783 | if (epoch.Strip(TString::kBoth)!=(TString)"2000")
|
---|
784 | {
|
---|
785 | gLog << err << "ERROR - Epoch not 2000... not supported." << endl;
|
---|
786 | return kFALSE;
|
---|
787 | }
|
---|
788 |
|
---|
789 | Double_t r,d;
|
---|
790 | if (!MAstro::Coordinate2Angle(ra, r))
|
---|
791 | {
|
---|
792 | gLog << err << "ERROR - Interpreting right ascension: " << ra << endl;
|
---|
793 | return kFALSE;
|
---|
794 | }
|
---|
795 | if (!MAstro::Coordinate2Angle(dec, d))
|
---|
796 | {
|
---|
797 | gLog << err << "ERROR - Interpreting declination: " << dec << endl;
|
---|
798 | return kFALSE;
|
---|
799 | }
|
---|
800 |
|
---|
801 | pos.SetSkyPosition(r, d);
|
---|
802 | pos.SetTitle(fNameSource);
|
---|
803 |
|
---|
804 | return kTRUE;
|
---|
805 | }
|
---|
806 |
|
---|
807 | /*
|
---|
808 | // --------------------------------------------------------------------------
|
---|
809 | //
|
---|
810 | // Calls ReplaceAll(old, news) for all Dir-entries
|
---|
811 | //
|
---|
812 | void MDataSet::ReplaceDir(TList &list, const TString &old, const TString &news) const
|
---|
813 | {
|
---|
814 | TIter Next(&list);
|
---|
815 | TNamed *name = 0;
|
---|
816 | while ((name=(TNamed*)Next()))
|
---|
817 | {
|
---|
818 | TString dir = name->GetTitle();
|
---|
819 | dir.ReplaceAll(old, news);
|
---|
820 | name->SetTitle(dir);
|
---|
821 | }
|
---|
822 | }
|
---|
823 |
|
---|
824 | // --------------------------------------------------------------------------
|
---|
825 | //
|
---|
826 | // Calls ReplaceAll(old, news) for all File-entries
|
---|
827 | //
|
---|
828 | void MDataSet::ReplaceFile(TList &list, const TString &old, const TString &news) const
|
---|
829 | {
|
---|
830 | TIter Next(&list);
|
---|
831 | TNamed *name = 0;
|
---|
832 | while ((name=(TNamed*)Next()))
|
---|
833 | {
|
---|
834 | TString file = name->GetName();
|
---|
835 | file.ReplaceAll(old, news);
|
---|
836 | name->SetName(file);
|
---|
837 | }
|
---|
838 | }
|
---|
839 | */
|
---|