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

Last change on this file since 6380 was 5692, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.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/////////////////////////////////////////////////////////////////////////////
96#include "MSequence.h"
97
98#include <stdlib.h>
99
100#include <TEnv.h>
101#include <TRegexp.h>
102#include <TSystem.h> // TSystem::ExpandPath
103
104#include "MLog.h"
105#include "MLogManip.h"
106
107#include "MDirIter.h"
108
109ClassImp(MSequence);
110
111using namespace std;
112
113// --------------------------------------------------------------------------
114//
115// Copy the run numbers from the TString runs into the TArrayI data
116//
117void MSequence::Split(TString &runs, TArrayI &data) const
118{
119 const TRegexp regexp("[0-9]+");
120
121 data.Set(0);
122 runs = runs.Strip(TString::kTrailing);
123
124 while (!runs.IsNull())
125 {
126 TString num = runs(regexp);
127
128 const Int_t n = data.GetSize();
129 data.Set(n+1);
130 data[n] = atoi(num.Data());
131
132 runs.Remove(0, runs.First(num)+num.Length());
133 }
134}
135
136Int_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path, char *id, Bool_t raw) const
137{
138 TString d(path);
139
140 // Setup path
141 if (d.IsNull())
142 {
143 d = Form("/data/MAGIC/Period%03d/", fPeriod);
144 d += raw ? "rawdata/" : "rootdata/";
145 d += fNight.GetStringFmt("%Y_%m_%d");
146 }
147 else
148 gSystem->ExpandPathName(d);
149
150 for (int i=0; i<arr.GetSize(); i++)
151 {
152 // R. DeLosReyes and T. Bretz
153 // Changes to read the DAQ numbering format. Changes takes place
154 // between runs 35487 and 00035488 (2004_08_30)
155 const char *fmt = arr[i]>35487 ? "%08d_%s_*_E" : "%05d_%s_*_E";
156
157 TString n;
158
159 // Create file name
160 n = fNight.GetStringFmt("%Y%m%d_");
161 n += Form(fmt, arr[i], id);
162 n += raw ? ".raw" : ".root";
163
164 // Add Path/File to TIter
165 iter.AddDirectory(d, n, 0);
166 }
167
168 return iter.GetNumEntries();
169}
170
171// --------------------------------------------------------------------------
172//
173// Read the file fname as setup file for the sequence.
174//
175MSequence::MSequence(const char *fname)
176{
177 fName = fname;
178
179 const char *expname = gSystem->ExpandPathName(fname);
180
181 fTitle = Form("Sequence contained in file %s", expname);
182
183 TEnv env(expname);
184 delete [] expname;
185
186 TString str;
187
188 fSequence = env.GetValue("Sequence", -1);
189 fLastRun = env.GetValue("LastRun", -1);
190 fNumEvents = env.GetValue("NumEvents", -1);
191 fPeriod = env.GetValue("Period", -1);
192
193 str = env.GetValue("Start", "");
194 fStart.SetSqlDateTime(str);
195 str = env.GetValue("Night", "");
196 str += " 00:00:00";
197 fNight.SetSqlDateTime(str);
198
199 fProject = env.GetValue("Project", "");
200 fSource = env.GetValue("Source", "");
201 fTriggerTable = env.GetValue("TriggerTable", "");
202 fHvSettings = env.GetValue("HvSettings", "");
203
204 str = env.GetValue("Runs", "");
205 Split(str, fRuns);
206 str = env.GetValue("CalRuns", "");
207 Split(str, fCalRuns);
208 str = env.GetValue("PedRuns", "");
209 Split(str, fPedRuns);
210 str = env.GetValue("DatRuns", "");
211 Split(str, fDatRuns);
212}
213
214// --------------------------------------------------------------------------
215//
216// Print the contents of the sequence
217//
218void MSequence::Print(Option_t *o) const
219{
220 gLog << all;
221 if (!IsValid())
222 {
223 gLog << "Sequence: " << fName << " <invalid>" << endl;
224 return;
225 }
226 gLog << "Sequence: " << fSequence << endl;
227 gLog << "Period: " << fPeriod << endl;
228 gLog << "Night: " << fNight << endl << endl;
229 gLog << "Start: " << fStart << endl;
230 gLog << "LastRun: " << fLastRun << endl;
231 gLog << "NumEvents: " << fNumEvents << endl;
232 gLog << "Project: " << fProject << endl;
233 gLog << "Source: " << fSource << endl;
234 gLog << "TriggerTable: " << fTriggerTable << endl;
235 gLog << "HvSettings: " << fHvSettings << endl << endl;
236 gLog << "Runs:";
237 for (int i=0; i<fRuns.GetSize(); i++)
238 gLog << " " << fRuns[i];
239 gLog << endl;
240 gLog << "CalRuns:";
241 for (int i=0; i<fCalRuns.GetSize(); i++)
242 gLog << " " << fCalRuns[i];
243 gLog << endl;
244 gLog << "PedRuns:";
245 for (int i=0; i<fPedRuns.GetSize(); i++)
246 gLog << " " << fPedRuns[i];
247 gLog << endl;
248 gLog << "DatRuns:";
249 for (int i=0; i<fDatRuns.GetSize(); i++)
250 gLog << " " << fDatRuns[i];
251 gLog << endl;
252}
253
254// --------------------------------------------------------------------------
255//
256// Add all ped runs from the sequence to MDirIter.
257// If path==0 the standard path of the data-center is assumed.
258// If you have the runs locally use path="."
259// Using raw=kTRUE you get correspodning raw-files setup.
260// Return the number of files added.
261//
262Int_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
263{
264 return SetupRuns(iter, fPedRuns, path, id, raw);
265}
266
267// --------------------------------------------------------------------------
268//
269// Add all data runs from the sequence to MDirIter.
270// If path==0 the standard path of the data-center is assumed.
271// If you have the runs locally use path="."
272// Using raw=kTRUE you get correspodning raw-files setup.
273// Return the number of files added.
274//
275Int_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
276{
277 return SetupRuns(iter, fDatRuns, path, id, raw);
278}
279
280// --------------------------------------------------------------------------
281//
282// Add all runs from the sequence to MDirIter.
283// If path==0 the standard path of the data-center is assumed.
284// If you have the runs locally use path="."
285// Using raw=kTRUE you get correspodning raw-files setup.
286// Return the number of files added.
287//
288Int_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
289{
290 return SetupRuns(iter, fRuns, path, id, raw);
291}
292
293// --------------------------------------------------------------------------
294//
295// Add all calibration runs from the sequence to MDirIter.
296// If path==0 the standard path of the data-center is assumed.
297// If you have the runs locally use path="."
298// Using raw=kTRUE you get correspodning raw-files setup.
299// Return the number of files added.
300//
301Int_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
302{
303 return SetupRuns(iter, fCalRuns, path, id, raw);
304}
Note: See TracBrowser for help on using the repository browser.