source: tags/Mars-V0.9/mjobs/MSequence.cc

Last change on this file was 6858, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 13.1 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 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
175const TString MSequence::GetStandardPath(Bool_t raw) const
176{
177 TString d("/magic/data/");
178 d += raw ? "rawfiles/" : "merpp/";
179 return d;
180}
181
182UInt_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path, char *id, Bool_t raw) const
183{
184 TString d(path);
185
186 // Setup path
187 if (d.IsNull())
188 {
189 d = GetStandardPath(raw);
190 d += fNight.GetStringFmt("%Y/%m/%d");
191 }
192 else
193 gSystem->ExpandPathName(d);
194
195 for (int i=0; i<arr.GetSize(); i++)
196 {
197 // R. DeLosReyes and T. Bretz
198 // Changes to read the DAQ numbering format. Changes takes place
199 // between runs 35487 and 00035488 (2004_08_30)
200 const char *fmt = arr[i]>35487 ? "%08d_%s_*_E" : "%05d_%s_*_E";
201
202 TString n;
203
204 // Create file name
205 n = fNight.GetStringFmt("%Y%m%d_");
206 n += Form(fmt, arr[i], id);
207 n += raw ? ".raw" : ".root";
208
209 // Add Path/File to TIter
210 iter.AddDirectory(d, n, 0);
211 }
212
213 return iter.GetNumEntries();
214}
215
216// --------------------------------------------------------------------------
217//
218// Read the file fname as setup file for the sequence.
219//
220void MSequence::GetFileNames(TEnv &env, const TArrayI &arr)
221{
222 /*
223 for (int i=0; i<arr.GetSize(); i++)
224 {
225 // Get run number
226 const Int_t num = arr[i];
227
228 // Check if name already set
229 if (fFileNames.GetValue(num))
230 continue;
231
232 TString *str = new TString(env.GetValue(Form("%d", num), ""));
233 fFileNames.Add(num, (Long_t)str);
234 }
235 */
236}
237
238// --------------------------------------------------------------------------
239//
240// Get a file name corresponding to the run-number num, returns 0 if n/a
241//
242const char *MSequence::GetFileName(UInt_t num)
243{
244 return 0;
245 /*
246 TString *str = (TString*)fFileNames.GetValue(num);
247 return str ? str->Data() : 0;*/
248}
249
250MSequence::LightCondition_t MSequence::ReadLightCondition(TEnv &env) const
251{
252 TString str = env.GetValue("LightCondition", "n/a");
253 if (!str.CompareTo("n/a", TString::kIgnoreCase))
254 return kNA;
255 if (!str.CompareTo("NoMoon", TString::kIgnoreCase))
256 return kNoMoon;
257 if (!str.CompareTo("Twilight", TString::kIgnoreCase))
258 return kTwilight;
259 if (!str.CompareTo("Moon", TString::kIgnoreCase))
260 return kMoon;
261
262 gLog << warn << "MSequence: LightCondition-tag not n/a, nomoon, twilight or moon." << endl;
263 return kNA;
264}
265
266// --------------------------------------------------------------------------
267//
268// Read the file fname as setup file for the sequence.
269//
270MSequence::MSequence(const char *fname)
271{
272 fName = fname;
273
274 const char *expname = gSystem->ExpandPathName(fname);
275
276 fTitle = Form("Sequence contained in file %s", expname);
277
278 TEnv env(expname);
279 delete [] expname;
280
281 TString str;
282
283 fSequence = env.GetValue("Sequence", -1);
284 fLastRun = env.GetValue("LastRun", -1);
285 fNumEvents = env.GetValue("NumEvents", -1);
286 fPeriod = env.GetValue("Period", -1);
287
288 fLightCondition = ReadLightCondition(env);
289
290 str = env.GetValue("Start", "");
291 fStart.SetSqlDateTime(str);
292 str = env.GetValue("Night", "");
293 str += " 00:00:00";
294 fNight.SetSqlDateTime(str);
295
296 fProject = env.GetValue("Project", "");
297 fSource = env.GetValue("Source", "");
298 fTriggerTable = env.GetValue("TriggerTable", "");
299 fHvSettings = env.GetValue("HvSettings", "");
300
301 str = env.GetValue("Runs", "");
302 Split(str, fRuns);
303 str = env.GetValue("CalRuns", "");
304 Split(str, fCalRuns);
305 str = env.GetValue("PedRuns", "");
306 Split(str, fPedRuns);
307 str = env.GetValue("DatRuns", "");
308 Split(str, fDatRuns);
309
310 GetFileNames(env, fRuns);
311 GetFileNames(env, fCalRuns);
312 GetFileNames(env, fPedRuns);
313 GetFileNames(env, fDatRuns);
314}
315
316// --------------------------------------------------------------------------
317//
318// Print the contents of the sequence
319//
320void MSequence::Print(Option_t *o) const
321{
322 gLog << all;
323 if (!IsValid())
324 {
325 gLog << "Sequence: " << fName << " <invalid>" << endl;
326 return;
327 }
328 gLog << "Sequence: " << fSequence << endl;
329 gLog << "Period: " << fPeriod << endl;
330 gLog << "Night: " << fNight << endl << endl;
331 gLog << "LightCondition: ";
332 switch (fLightCondition)
333 {
334 case kNA: gLog << "n/a" << endl; break;
335 case kNoMoon: gLog << "NoMoon" << endl; break;
336 case kTwilight: gLog << "Twilight" << endl; break;
337 case kMoon: gLog << "Moon" << endl; break;
338 }
339 gLog << "Start: " << fStart << endl;
340 gLog << "LastRun: " << fLastRun << endl;
341 gLog << "NumEvents: " << fNumEvents << endl;
342 gLog << "Project: " << fProject << endl;
343 gLog << "Source: " << fSource << endl;
344 gLog << "TriggerTable: " << fTriggerTable << endl;
345 gLog << "HvSettings: " << fHvSettings << endl << endl;
346 gLog << "Runs:";
347 for (int i=0; i<fRuns.GetSize(); i++)
348 gLog << " " << fRuns[i];
349 gLog << endl;
350 gLog << "CalRuns:";
351 for (int i=0; i<fCalRuns.GetSize(); i++)
352 gLog << " " << fCalRuns[i];
353 gLog << endl;
354 gLog << "PedRuns:";
355 for (int i=0; i<fPedRuns.GetSize(); i++)
356 gLog << " " << fPedRuns[i];
357 gLog << endl;
358 gLog << "DatRuns:";
359 for (int i=0; i<fDatRuns.GetSize(); i++)
360 gLog << " " << fDatRuns[i];
361 gLog << endl;
362}
363
364// --------------------------------------------------------------------------
365//
366// Add all ped runs from the sequence to MDirIter.
367// If path==0 the standard path of the data-center is assumed.
368// If you have the runs locally use path="."
369// Using raw=kTRUE you get correspodning raw-files setup.
370// Return the number of files added.
371//
372UInt_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
373{
374 return SetupRuns(iter, fPedRuns, path, id, raw);
375}
376
377// --------------------------------------------------------------------------
378//
379// Add all data runs from the sequence to MDirIter.
380// If path==0 the standard path of the data-center is assumed.
381// If you have the runs locally use path="."
382// Using raw=kTRUE you get correspodning raw-files setup.
383// Return the number of files added.
384//
385UInt_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
386{
387 return SetupRuns(iter, fDatRuns, path, id, raw);
388}
389
390// --------------------------------------------------------------------------
391//
392// Add all runs from the sequence to MDirIter.
393// If path==0 the standard path of the data-center is assumed.
394// If you have the runs locally use path="."
395// Using raw=kTRUE you get correspodning raw-files setup.
396// Return the number of files added.
397//
398UInt_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
399{
400 return SetupRuns(iter, fRuns, path, id, raw);
401}
402
403// --------------------------------------------------------------------------
404//
405// Add all calibration runs from the sequence to MDirIter.
406// If path==0 the standard path of the data-center is assumed.
407// If you have the runs locally use path="."
408// Using raw=kTRUE you get correspodning raw-files setup.
409// Return the number of files added.
410//
411UInt_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
412{
413 return SetupRuns(iter, fCalRuns, path, id, raw);
414}
415
416// --------------------------------------------------------------------------
417//
418// If you want to add runs manually, use this function.
419//
420UInt_t MSequence::AddRuns(UInt_t first, UInt_t last, TArrayI *runs)
421{
422 if (last<first)
423 {
424 *fLog << warn << "MSequence::AddRuns - WARNING: Last runnumber " << last;
425 *fLog << " smaller than first " << first << "... ignored." << endl;
426 return 0;
427 }
428 if (!IsValid())
429 {
430 *fLog << inf << "Setting Sequence number to #" << first << endl;
431 fSequence = first;
432 }
433
434 const UInt_t nall = fRuns.GetSize();
435 const UInt_t nrun = runs ? runs->GetSize() : 0;
436 const UInt_t add = last-first+1;
437
438 fRuns.Set(nall+add);
439 if (runs)
440 runs->Set(nrun+add);
441
442 for (UInt_t i=0; i<add; i++)
443 {
444 fRuns[nall+i] = first+i;
445 if (runs)
446 (*runs)[nrun+i] = first+i;
447 }
448 return add;
449}
450
451// --------------------------------------------------------------------------
452//
453// If you want to change or set the night manually.
454// The Format is
455// SetNight("yyyy-mm-dd");
456//
457void MSequence::SetNight(const char *txt)
458{
459 TString night(txt);
460 night += " 00:00:00";
461 fNight.SetSqlDateTime(night);
462
463 fPeriod = MAstro::GetMagicPeriod(fNight.GetMjd());
464}
Note: See TracBrowser for help on using the repository browser.