source: trunk/MagicSoft/Mars/mjobs/MSequence.cc@ 7062

Last change on this file since 7062 was 6964, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 15.6 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, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MSequence
28//
29// This class describes a sequence. For sequences see:
30// http://magic.astro.uni-wuerzburg.de/mars/db/queryseq.html
31//
32// A sequence is a collection of runs which should be used together.
33//
34// Here is an example how a file describing a sequence could look like:
35//
36// ===========================================================================
37//
38// sequence.txt
39// ------------
40//
41// # Sequence number (identifier)
42// Sequence: 31015
43// # Observation Period (used to get the path-names)
44// Period: 18
45// # Date of sunrise of the observation night
46// Night: 2004-06-24
47//
48// # Start time of the sequence (first data run)
49// Start: 2004-06-24 03:12:42
50// # Run number of last data run in sequence
51// LastRun: 31032
52// # Project name of data-runs of sequence
53// Project: 3EG2033+41
54// # Source name of all runs of sequence
55// Source: 3EG2033+41
56// # Trigger table of data-runs of sequence
57// TriggerTable: L1_4NN:L2_DEFAULT
58// # HV Setting table of data-runs of sequence
59// HvSettings: HVSettings_FF36q
60// # Total number of data-events in sequence
61// NumEvents: 250914
62//
63// # List of all runs of this sequence
64// Runs: 31015 31016 31017 31018 31019 31020 31021 31022 31023 31024 31025 31026 31027 31028 31029 31030 31031 31032
65//
66// # List of all calibration runs of this sequence
67// CalRuns: 31015 31016 31017
68// # List of pedestal runs belonging to the calibration runs of this sequence
69// PedRuns: 31018
70// # List of all data runs belonging to this sequence
71// DatRuns: 31019 31020 31022 31023 31024 31025 31027 31028 31030 31032
72//
73// # List of run types of all runs
74// 31015: C
75// 31016: C
76// 31017: C
77// 31018: P
78// 31019: D
79// 31020: D
80// 31021: P
81// 31022: D
82// 31023: D
83// 31024: D
84// 31025: D
85// 31026: P
86// 31027: D
87// 31028: D
88// 31029: P
89// 31030: D
90// 31031: P
91// 31032: D
92//
93// ===========================================================================
94//
95// For special cases you can also setup a sequence directly from a macro,
96// for example:
97//
98// MDirIter pediter, datiter, caliter;
99//
100// MSequence seq;
101// seq.SetNight("2004-07-06");
102// seq.AddPedRuns(31751);
103// seq.AddCalRuns(31752);
104// seq.AddDatRuns(31753, 31764);
105// seq.SetupPedRuns(pediter);
106// seq.SetupCalRuns(caliter);
107// seq.SetupDatRuns(datiter);
108//
109// or
110//
111// MDirIter iter;
112//
113// MSequence seq;
114// seq.SetNight("2004-07-06");
115// seq.AddRuns(31753, 31764);
116// seq.SetupRuns(iter);
117// seq.SetupPedRuns(iter, "/mypath", "[DPC]");
118//
119/////////////////////////////////////////////////////////////////////////////
120#include "MSequence.h"
121
122#include <stdlib.h>
123
124#include <TEnv.h>
125#include <TRegexp.h>
126#include <TSystem.h> // TSystem::ExpandPath
127
128#include "MLog.h"
129#include "MLogManip.h"
130
131#include "MAstro.h"
132#include "MString.h"
133#include "MDirIter.h"
134
135ClassImp(MSequence);
136
137using namespace std;
138
139MSequence::~MSequence()
140{
141 /*
142 TExMapIter iter(&fFileNames);
143
144 Long_t key, val;
145
146 while (iter.Next(key, val))
147 delete (TString*)val;
148 */
149}
150
151
152// --------------------------------------------------------------------------
153//
154// Copy the run numbers from the TString runs into the TArrayI data
155//
156void MSequence::Split(TString &runs, TArrayI &data) const
157{
158 const TRegexp regexp("[0-9]+");
159
160 data.Set(0);
161 runs = runs.Strip(TString::kTrailing);
162
163 while (!runs.IsNull())
164 {
165 TString num = runs(regexp);
166
167 const Int_t n = data.GetSize();
168 data.Set(n+1);
169 data[n] = atoi(num.Data());
170
171 runs.Remove(0, runs.First(num)+num.Length());
172 }
173}
174/*
175UInt_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path, char *id, Bool_t raw) const
176{
177 TString d(path);
178
179 // Setup path
180 if (d.IsNull())
181 {
182 d = GetStandardPath();
183 d += raw ? "rawfiles/" : "merpp/";
184 d += fNight.GetStringFmt("%Y/%m/%d");
185 }
186 else
187 gSystem->ExpandPathName(d);
188
189 for (int i=0; i<arr.GetSize(); i++)
190 {
191 // R. DeLosReyes and T. Bretz
192 // Changes to read the DAQ numbering format. Changes takes place
193 // between runs 35487 and 00035488 (2004_08_30)
194 const char *fmt = arr[i]>35487 ? "%08d_%s_*_E" : "%05d_%s_*_E";
195
196 TString n;
197
198 // Create file name
199 n = fNight.GetStringFmt("%Y%m%d_");
200 n += Form(fmt, arr[i], id);
201 n += raw ? ".raw" : ".root";
202
203 // Add Path/File to TIter
204 iter.AddDirectory(d, n, 0);
205 }
206
207 return iter.GetNumEntries();
208}
209*/
210UInt_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, FileType_t type, const char *path) const
211{
212 TString d(path);
213
214 // Setup path
215 if (d.IsNull())
216 {
217 d = GetStandardPath();
218 switch (type)
219 {
220 case kRawDat:
221 case kRawPed:
222 case kRawCal:
223 case kRawAll:
224 d += "rawfiles/";
225 d += fNight.GetStringFmt("%Y/%m/%d");
226 break;
227 case kRootDat:
228 case kRootPed:
229 case kRootCal:
230 case kRootAll:
231 d += "merpp/";
232 d += fNight.GetStringFmt("%Y/%m/%d");
233 break;
234 case kCalibrated:
235 d += Form("callisto/%04d/%08d/", fSequence/10000, fSequence);
236 break;
237 case kImages:
238 d += Form("star/%04d/%08d/", fSequence/10000, fSequence);
239 break;
240 }
241 }
242 else
243 gSystem->ExpandPathName(d);
244
245 for (int i=0; i<arr.GetSize(); i++)
246 {
247 // R. DeLosReyes and T. Bretz
248 // Changes to read the DAQ numbering format. Changes takes place
249 // between runs 35487 and 00035488 (2004_08_30)
250 const char *fmt = arr[i]>35487 ? "%08d_%s_*_E" : "%05d_%s_*_E";
251
252 TString n;
253 char *id="_";
254 switch (type)
255 {
256 case kRawDat:
257 case kRootDat:
258 id = "D";
259 break;
260 case kRawPed:
261 case kRootPed:
262 id = "P";
263 break;
264 case kRawCal:
265 case kRootCal:
266 id = "C";
267 break;
268 case kRawAll:
269 case kRootAll:
270 id = "[PCD]";
271 break;
272 case kCalibrated:
273 id = "Y";
274 break;
275 case kImages:
276 id = "I";
277 break;
278 }
279
280 // Create file name
281 n = fNight.GetStringFmt("%Y%m%d_");
282 n += Form(fmt, arr[i], id);
283
284 switch (type)
285 {
286 case kRawDat:
287 case kRawPed:
288 case kRawCal:
289 case kRawAll:
290 n += ".raw";
291 break;
292 default:
293 n += ".root";
294 }
295
296 // Add Path/File to TIter
297 iter.AddDirectory(d, n, 0);
298 }
299
300 return iter.GetNumEntries();
301}
302
303// --------------------------------------------------------------------------
304//
305// Read the file fname as setup file for the sequence.
306//
307void MSequence::GetFileNames(TEnv &env, const TArrayI &arr)
308{
309 /*
310 for (int i=0; i<arr.GetSize(); i++)
311 {
312 // Get run number
313 const Int_t num = arr[i];
314
315 // Check if name already set
316 if (fFileNames.GetValue(num))
317 continue;
318
319 TString *str = new TString(env.GetValue(Form("%d", num), ""));
320 fFileNames.Add(num, (Long_t)str);
321 }
322 */
323}
324
325// --------------------------------------------------------------------------
326//
327// Get a file name corresponding to the run-number num, returns 0 if n/a
328//
329const char *MSequence::GetFileName(UInt_t num)
330{
331 return 0;
332 /*
333 TString *str = (TString*)fFileNames.GetValue(num);
334 return str ? str->Data() : 0;*/
335}
336
337MSequence::LightCondition_t MSequence::ReadLightCondition(TEnv &env) const
338{
339 TString str = env.GetValue("LightCondition", "n/a");
340 if (!str.CompareTo("n/a", TString::kIgnoreCase))
341 return kNA;
342 if (!str.CompareTo("NoMoon", TString::kIgnoreCase))
343 return kNoMoon;
344 if (!str.CompareTo("Twilight", TString::kIgnoreCase))
345 return kTwilight;
346 if (!str.CompareTo("Moon", TString::kIgnoreCase))
347 return kMoon;
348
349 gLog << warn << "MSequence: LightCondition-tag not n/a, nomoon, twilight or moon." << endl;
350 return kNA;
351}
352
353// --------------------------------------------------------------------------
354//
355// Read the file fname as setup file for the sequence.
356//
357MSequence::MSequence(const char *fname)
358{
359 fName = fname;
360
361 const char *expname = gSystem->ExpandPathName(fname);
362
363 fTitle = Form("Sequence contained in file %s", expname);
364
365 TEnv env(expname);
366 delete [] expname;
367
368 TString str;
369
370 fSequence = env.GetValue("Sequence", -1);
371 fLastRun = env.GetValue("LastRun", -1);
372 fNumEvents = env.GetValue("NumEvents", -1);
373 fPeriod = env.GetValue("Period", -1);
374
375 fLightCondition = ReadLightCondition(env);
376
377 str = env.GetValue("Start", "");
378 fStart.SetSqlDateTime(str);
379 str = env.GetValue("Night", "");
380 str += " 00:00:00";
381 fNight.SetSqlDateTime(str);
382
383 fProject = env.GetValue("Project", "");
384 fSource = env.GetValue("Source", "");
385 fTriggerTable = env.GetValue("TriggerTable", "");
386 fHvSettings = env.GetValue("HvSettings", "");
387
388 str = env.GetValue("Runs", "");
389 Split(str, fRuns);
390 str = env.GetValue("CalRuns", "");
391 Split(str, fCalRuns);
392 str = env.GetValue("PedRuns", "");
393 Split(str, fPedRuns);
394 str = env.GetValue("DatRuns", "");
395 Split(str, fDatRuns);
396
397 GetFileNames(env, fRuns);
398 GetFileNames(env, fCalRuns);
399 GetFileNames(env, fPedRuns);
400 GetFileNames(env, fDatRuns);
401}
402
403// --------------------------------------------------------------------------
404//
405// Print the contents of the sequence
406//
407void MSequence::Print(Option_t *o) const
408{
409 gLog << all;
410 if (!IsValid())
411 {
412 gLog << "Sequence: " << fName << " <invalid>" << endl;
413 return;
414 }
415 gLog << "Sequence: " << fSequence << endl;
416 gLog << "Period: " << fPeriod << endl;
417 gLog << "Night: " << fNight << endl << endl;
418 gLog << "LightCondition: ";
419 switch (fLightCondition)
420 {
421 case kNA: gLog << "n/a" << endl; break;
422 case kNoMoon: gLog << "NoMoon" << endl; break;
423 case kTwilight: gLog << "Twilight" << endl; break;
424 case kMoon: gLog << "Moon" << endl; break;
425 }
426 gLog << "Start: " << fStart << endl;
427 gLog << "LastRun: " << fLastRun << endl;
428 gLog << "NumEvents: " << fNumEvents << endl;
429 gLog << "Project: " << fProject << endl;
430 gLog << "Source: " << fSource << endl;
431 gLog << "TriggerTable: " << fTriggerTable << endl;
432 gLog << "HvSettings: " << fHvSettings << endl << endl;
433 gLog << "Runs:";
434 for (int i=0; i<fRuns.GetSize(); i++)
435 gLog << " " << fRuns[i];
436 gLog << endl;
437 gLog << "CalRuns:";
438 for (int i=0; i<fCalRuns.GetSize(); i++)
439 gLog << " " << fCalRuns[i];
440 gLog << endl;
441 gLog << "PedRuns:";
442 for (int i=0; i<fPedRuns.GetSize(); i++)
443 gLog << " " << fPedRuns[i];
444 gLog << endl;
445 gLog << "DatRuns:";
446 for (int i=0; i<fDatRuns.GetSize(); i++)
447 gLog << " " << fDatRuns[i];
448 gLog << endl;
449}
450
451// --------------------------------------------------------------------------
452//
453// Add all ped runs from the sequence to MDirIter.
454// If path==0 the standard path of the data-center is assumed.
455// If you have the runs locally use path="."
456// Using raw=kTRUE you get correspodning raw-files setup.
457// Return the number of files added.
458UInt_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, Bool_t raw) const
459{
460 return SetupRuns(iter, fPedRuns, raw?kRawPed:kRootPed, path);
461}
462
463// --------------------------------------------------------------------------
464//
465// Add all data runs from the sequence to MDirIter.
466// If path==0 the standard path of the data-center is assumed.
467// If you have the runs locally use path="."
468// Using raw=kTRUE you get correspodning raw-files setup.
469// Return the number of files added.
470//
471UInt_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, Bool_t raw) const
472{
473 return SetupRuns(iter, fDatRuns, raw?kRawDat:kRootDat, path);
474}
475
476// --------------------------------------------------------------------------
477//
478// Add all runs from the sequence to MDirIter.
479// If path==0 the standard path of the data-center is assumed.
480// If you have the runs locally use path="."
481// Using raw=kTRUE you get correspodning raw-files setup.
482// Return the number of files added.
483//
484UInt_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, Bool_t raw) const
485{
486 return SetupRuns(iter, fRuns, raw?kRawAll:kRootAll, path);
487}
488
489// --------------------------------------------------------------------------
490//
491// Add all calibration runs from the sequence to MDirIter.
492// If path==0 the standard path of the data-center is assumed.
493// If you have the runs locally use path="."
494// Using raw=kTRUE you get correspodning raw-files setup.
495// Return the number of files added.
496//
497UInt_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, Bool_t raw) const
498{
499 return SetupRuns(iter, fCalRuns, raw?kRawCal:kRootCal, path);
500}
501
502// --------------------------------------------------------------------------
503//
504// Add all data runs from the sequence to MDirIter.
505// If path==0 the standard path of the data-center is assumed.
506// If you have the runs locally use path="."
507// Using raw=kTRUE you get correspodning raw-files setup.
508// Return the number of files added.
509//
510UInt_t MSequence::SetupDatRuns(MDirIter &iter, FileType_t type, const char *path) const
511{
512 return SetupRuns(iter, fDatRuns, type, path);
513}
514
515// --------------------------------------------------------------------------
516//
517// If you want to add runs manually, use this function.
518//
519UInt_t MSequence::AddRuns(UInt_t first, UInt_t last, TArrayI *runs)
520{
521 if (last<first)
522 {
523 *fLog << warn << "MSequence::AddRuns - WARNING: Last runnumber " << last;
524 *fLog << " smaller than first " << first << "... ignored." << endl;
525 return 0;
526 }
527 if (!IsValid())
528 {
529 *fLog << inf << "Setting Sequence number to #" << first << endl;
530 fSequence = first;
531 }
532
533 const UInt_t nall = fRuns.GetSize();
534 const UInt_t nrun = runs ? runs->GetSize() : 0;
535 const UInt_t add = last-first+1;
536
537 fRuns.Set(nall+add);
538 if (runs)
539 runs->Set(nrun+add);
540
541 for (UInt_t i=0; i<add; i++)
542 {
543 fRuns[nall+i] = first+i;
544 if (runs)
545 (*runs)[nrun+i] = first+i;
546 }
547 return add;
548}
549
550// --------------------------------------------------------------------------
551//
552// If you want to change or set the night manually.
553// The Format is
554// SetNight("yyyy-mm-dd");
555//
556void MSequence::SetNight(const char *txt)
557{
558 TString night(txt);
559 night += " 00:00:00";
560 fNight.SetSqlDateTime(night);
561
562 fPeriod = MAstro::GetMagicPeriod(fNight.GetMjd());
563}
Note: See TracBrowser for help on using the repository browser.