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

Last change on this file since 6906 was 6906, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 15.5 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 break;
226 case kRootDat:
227 case kRootPed:
228 case kRootCal:
229 case kRootAll:
230 d += "merpp/";
231 break;
232 case kCalibrated:
233 d += "callisto/";
234 break;
235 case kImages:
236 d += "star/";
237 break;
238 }
239 d += fNight.GetStringFmt("%Y/%m/%d");
240 }
241 else
242 gSystem->ExpandPathName(d);
243
244 for (int i=0; i<arr.GetSize(); i++)
245 {
246 // R. DeLosReyes and T. Bretz
247 // Changes to read the DAQ numbering format. Changes takes place
248 // between runs 35487 and 00035488 (2004_08_30)
249 const char *fmt = arr[i]>35487 ? "%08d_%s_*_E" : "%05d_%s_*_E";
250
251 TString n;
252 char *id="_";
253 switch (type)
254 {
255 case kRawDat:
256 case kRootDat:
257 id = "D";
258 break;
259 case kRawPed:
260 case kRootPed:
261 id = "P";
262 break;
263 case kRawCal:
264 case kRootCal:
265 id = "C";
266 break;
267 case kRawAll:
268 case kRootAll:
269 id = "[PCD]";
270 break;
271 case kCalibrated:
272 id = "Y";
273 break;
274 case kImages:
275 id = "I";
276 break;
277 }
278
279 // Create file name
280 n = fNight.GetStringFmt("%Y%m%d_");
281 n += Form(fmt, arr[i], id);
282
283 switch (type)
284 {
285 case kRawDat:
286 case kRawPed:
287 case kRawCal:
288 case kRawAll:
289 n += ".raw";
290 break;
291 default:
292 n += ".root";
293 }
294
295 // Add Path/File to TIter
296 iter.AddDirectory(d, n, 0);
297 }
298
299 return iter.GetNumEntries();
300}
301
302// --------------------------------------------------------------------------
303//
304// Read the file fname as setup file for the sequence.
305//
306void MSequence::GetFileNames(TEnv &env, const TArrayI &arr)
307{
308 /*
309 for (int i=0; i<arr.GetSize(); i++)
310 {
311 // Get run number
312 const Int_t num = arr[i];
313
314 // Check if name already set
315 if (fFileNames.GetValue(num))
316 continue;
317
318 TString *str = new TString(env.GetValue(Form("%d", num), ""));
319 fFileNames.Add(num, (Long_t)str);
320 }
321 */
322}
323
324// --------------------------------------------------------------------------
325//
326// Get a file name corresponding to the run-number num, returns 0 if n/a
327//
328const char *MSequence::GetFileName(UInt_t num)
329{
330 return 0;
331 /*
332 TString *str = (TString*)fFileNames.GetValue(num);
333 return str ? str->Data() : 0;*/
334}
335
336MSequence::LightCondition_t MSequence::ReadLightCondition(TEnv &env) const
337{
338 TString str = env.GetValue("LightCondition", "n/a");
339 if (!str.CompareTo("n/a", TString::kIgnoreCase))
340 return kNA;
341 if (!str.CompareTo("NoMoon", TString::kIgnoreCase))
342 return kNoMoon;
343 if (!str.CompareTo("Twilight", TString::kIgnoreCase))
344 return kTwilight;
345 if (!str.CompareTo("Moon", TString::kIgnoreCase))
346 return kMoon;
347
348 gLog << warn << "MSequence: LightCondition-tag not n/a, nomoon, twilight or moon." << endl;
349 return kNA;
350}
351
352// --------------------------------------------------------------------------
353//
354// Read the file fname as setup file for the sequence.
355//
356MSequence::MSequence(const char *fname)
357{
358 fName = fname;
359
360 const char *expname = gSystem->ExpandPathName(fname);
361
362 fTitle = Form("Sequence contained in file %s", expname);
363
364 TEnv env(expname);
365 delete [] expname;
366
367 TString str;
368
369 fSequence = env.GetValue("Sequence", -1);
370 fLastRun = env.GetValue("LastRun", -1);
371 fNumEvents = env.GetValue("NumEvents", -1);
372 fPeriod = env.GetValue("Period", -1);
373
374 fLightCondition = ReadLightCondition(env);
375
376 str = env.GetValue("Start", "");
377 fStart.SetSqlDateTime(str);
378 str = env.GetValue("Night", "");
379 str += " 00:00:00";
380 fNight.SetSqlDateTime(str);
381
382 fProject = env.GetValue("Project", "");
383 fSource = env.GetValue("Source", "");
384 fTriggerTable = env.GetValue("TriggerTable", "");
385 fHvSettings = env.GetValue("HvSettings", "");
386
387 str = env.GetValue("Runs", "");
388 Split(str, fRuns);
389 str = env.GetValue("CalRuns", "");
390 Split(str, fCalRuns);
391 str = env.GetValue("PedRuns", "");
392 Split(str, fPedRuns);
393 str = env.GetValue("DatRuns", "");
394 Split(str, fDatRuns);
395
396 GetFileNames(env, fRuns);
397 GetFileNames(env, fCalRuns);
398 GetFileNames(env, fPedRuns);
399 GetFileNames(env, fDatRuns);
400}
401
402// --------------------------------------------------------------------------
403//
404// Print the contents of the sequence
405//
406void MSequence::Print(Option_t *o) const
407{
408 gLog << all;
409 if (!IsValid())
410 {
411 gLog << "Sequence: " << fName << " <invalid>" << endl;
412 return;
413 }
414 gLog << "Sequence: " << fSequence << endl;
415 gLog << "Period: " << fPeriod << endl;
416 gLog << "Night: " << fNight << endl << endl;
417 gLog << "LightCondition: ";
418 switch (fLightCondition)
419 {
420 case kNA: gLog << "n/a" << endl; break;
421 case kNoMoon: gLog << "NoMoon" << endl; break;
422 case kTwilight: gLog << "Twilight" << endl; break;
423 case kMoon: gLog << "Moon" << endl; break;
424 }
425 gLog << "Start: " << fStart << endl;
426 gLog << "LastRun: " << fLastRun << endl;
427 gLog << "NumEvents: " << fNumEvents << endl;
428 gLog << "Project: " << fProject << endl;
429 gLog << "Source: " << fSource << endl;
430 gLog << "TriggerTable: " << fTriggerTable << endl;
431 gLog << "HvSettings: " << fHvSettings << endl << endl;
432 gLog << "Runs:";
433 for (int i=0; i<fRuns.GetSize(); i++)
434 gLog << " " << fRuns[i];
435 gLog << endl;
436 gLog << "CalRuns:";
437 for (int i=0; i<fCalRuns.GetSize(); i++)
438 gLog << " " << fCalRuns[i];
439 gLog << endl;
440 gLog << "PedRuns:";
441 for (int i=0; i<fPedRuns.GetSize(); i++)
442 gLog << " " << fPedRuns[i];
443 gLog << endl;
444 gLog << "DatRuns:";
445 for (int i=0; i<fDatRuns.GetSize(); i++)
446 gLog << " " << fDatRuns[i];
447 gLog << endl;
448}
449
450// --------------------------------------------------------------------------
451//
452// Add all ped runs from the sequence to MDirIter.
453// If path==0 the standard path of the data-center is assumed.
454// If you have the runs locally use path="."
455// Using raw=kTRUE you get correspodning raw-files setup.
456// Return the number of files added.
457UInt_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, Bool_t raw) const
458{
459 return SetupRuns(iter, fPedRuns, raw?kRawPed:kRootPed, path);
460}
461
462// --------------------------------------------------------------------------
463//
464// Add all data runs from the sequence to MDirIter.
465// If path==0 the standard path of the data-center is assumed.
466// If you have the runs locally use path="."
467// Using raw=kTRUE you get correspodning raw-files setup.
468// Return the number of files added.
469//
470UInt_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, Bool_t raw) const
471{
472 return SetupRuns(iter, fDatRuns, raw?kRawPed:kRootPed, path);
473}
474
475// --------------------------------------------------------------------------
476//
477// Add all runs from the sequence to MDirIter.
478// If path==0 the standard path of the data-center is assumed.
479// If you have the runs locally use path="."
480// Using raw=kTRUE you get correspodning raw-files setup.
481// Return the number of files added.
482//
483UInt_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, Bool_t raw) const
484{
485 return SetupRuns(iter, fRuns, raw?kRawAll:kRootAll, path);
486}
487
488// --------------------------------------------------------------------------
489//
490// Add all calibration runs from the sequence to MDirIter.
491// If path==0 the standard path of the data-center is assumed.
492// If you have the runs locally use path="."
493// Using raw=kTRUE you get correspodning raw-files setup.
494// Return the number of files added.
495//
496UInt_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, Bool_t raw) const
497{
498 return SetupRuns(iter, fCalRuns, raw?kRawCal:kRootCal, path);
499}
500
501// --------------------------------------------------------------------------
502//
503// Add all data runs from the sequence to MDirIter.
504// If path==0 the standard path of the data-center is assumed.
505// If you have the runs locally use path="."
506// Using raw=kTRUE you get correspodning raw-files setup.
507// Return the number of files added.
508//
509UInt_t MSequence::SetupDatRuns(MDirIter &iter, FileType_t type, const char *path) const
510{
511 return SetupRuns(iter, fDatRuns, type, path);
512}
513
514// --------------------------------------------------------------------------
515//
516// If you want to add runs manually, use this function.
517//
518UInt_t MSequence::AddRuns(UInt_t first, UInt_t last, TArrayI *runs)
519{
520 if (last<first)
521 {
522 *fLog << warn << "MSequence::AddRuns - WARNING: Last runnumber " << last;
523 *fLog << " smaller than first " << first << "... ignored." << endl;
524 return 0;
525 }
526 if (!IsValid())
527 {
528 *fLog << inf << "Setting Sequence number to #" << first << endl;
529 fSequence = first;
530 }
531
532 const UInt_t nall = fRuns.GetSize();
533 const UInt_t nrun = runs ? runs->GetSize() : 0;
534 const UInt_t add = last-first+1;
535
536 fRuns.Set(nall+add);
537 if (runs)
538 runs->Set(nrun+add);
539
540 for (UInt_t i=0; i<add; i++)
541 {
542 fRuns[nall+i] = first+i;
543 if (runs)
544 (*runs)[nrun+i] = first+i;
545 }
546 return add;
547}
548
549// --------------------------------------------------------------------------
550//
551// If you want to change or set the night manually.
552// The Format is
553// SetNight("yyyy-mm-dd");
554//
555void MSequence::SetNight(const char *txt)
556{
557 TString night(txt);
558 night += " 00:00:00";
559 fNight.SetSqlDateTime(night);
560
561 fPeriod = MAstro::GetMagicPeriod(fNight.GetMjd());
562}
Note: See TracBrowser for help on using the repository browser.