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

Last change on this file since 5544 was 5316, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 9.0 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
148 for (int i=0; i<arr.GetSize(); i++)
149 {
150 // R. DeLosReyes and T. Bretz
151 // Changes to read the DAQ numbering format. Changes takes place
152 // between runs 35487 and 00035488 (2004_08_30)
153 const char *fmt = arr[i]>35487 ? "%08d_%s_*_E" : "%05d_%s_*_E";
154
155 TString n;
156
157 // Create file name
158 n = fNight.GetStringFmt("%Y%m%d_");
159 n += Form(fmt, arr[i], id);
160 n += raw ? ".raw" : ".root";
161
162 // Add Path/File to TIter
163 iter.AddDirectory(d, n, 0);
164 }
165
166 return iter.GetNumEntries();
167}
168
169// --------------------------------------------------------------------------
170//
171// Read the file fname as setup file for the sequence.
172//
173MSequence::MSequence(const char *fname)
174{
175 fName = fname;
176 fTitle = Form("Sequence contained in file %s", fName.Data());
177
178 TEnv env(fname);
179
180 TString str;
181
182 fSequence = env.GetValue("Sequence", -1);
183 fLastRun = env.GetValue("LastRun", -1);
184 fNumEvents = env.GetValue("NumEvents", -1);
185 fPeriod = env.GetValue("Period", -1);
186
187 str = env.GetValue("Start", "");
188 fStart.SetSqlDateTime(str);
189 str = env.GetValue("Night", "");
190 str += " 00:00:00";
191 fNight.SetSqlDateTime(str);
192
193 fProject = env.GetValue("Project", "");
194 fSource = env.GetValue("Source", "");
195 fTriggerTable = env.GetValue("TriggerTable", "");
196 fHvSettings = env.GetValue("HvSettings", "");
197
198 str = env.GetValue("Runs", "");
199 Split(str, fRuns);
200 str = env.GetValue("CalRuns", "");
201 Split(str, fCalRuns);
202 str = env.GetValue("PedRuns", "");
203 Split(str, fPedRuns);
204 str = env.GetValue("DatRuns", "");
205 Split(str, fDatRuns);
206}
207
208// --------------------------------------------------------------------------
209//
210// Print the contents of the sequence
211//
212void MSequence::Print(Option_t *o) const
213{
214 gLog << all;
215 if (!IsValid())
216 {
217 gLog << "Sequence: " << fName << " <invalid>" << endl;
218 return;
219 }
220 gLog << "Sequence: " << fSequence << endl;
221 gLog << "Period: " << fPeriod << endl;
222 gLog << "Night: " << fNight << endl << endl;
223 gLog << "Start: " << fStart << endl;
224 gLog << "LastRun: " << fLastRun << endl;
225 gLog << "NumEvents: " << fNumEvents << endl;
226 gLog << "Project: " << fProject << endl;
227 gLog << "Source: " << fSource << endl;
228 gLog << "TriggerTable: " << fTriggerTable << endl;
229 gLog << "HvSettings: " << fHvSettings << endl << endl;
230 gLog << "Runs:";
231 for (int i=0; i<fRuns.GetSize(); i++)
232 gLog << " " << fRuns[i];
233 gLog << endl;
234 gLog << "CalRuns:";
235 for (int i=0; i<fCalRuns.GetSize(); i++)
236 gLog << " " << fCalRuns[i];
237 gLog << endl;
238 gLog << "PedRuns:";
239 for (int i=0; i<fPedRuns.GetSize(); i++)
240 gLog << " " << fPedRuns[i];
241 gLog << endl;
242 gLog << "DatRuns:";
243 for (int i=0; i<fDatRuns.GetSize(); i++)
244 gLog << " " << fDatRuns[i];
245 gLog << endl;
246}
247
248// --------------------------------------------------------------------------
249//
250// Add all ped runs from the sequence to MDirIter.
251// If path==0 the standard path of the data-center is assumed.
252// If you have the runs locally use path="."
253// Using raw=kTRUE you get correspodning raw-files setup.
254// Return the number of files added.
255//
256Int_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
257{
258 return SetupRuns(iter, fPedRuns, path, id, raw);
259}
260
261// --------------------------------------------------------------------------
262//
263// Add all data runs from the sequence to MDirIter.
264// If path==0 the standard path of the data-center is assumed.
265// If you have the runs locally use path="."
266// Using raw=kTRUE you get correspodning raw-files setup.
267// Return the number of files added.
268//
269Int_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
270{
271 return SetupRuns(iter, fDatRuns, path, id, raw);
272}
273
274// --------------------------------------------------------------------------
275//
276// Add all runs from the sequence to MDirIter.
277// If path==0 the standard path of the data-center is assumed.
278// If you have the runs locally use path="."
279// Using raw=kTRUE you get correspodning raw-files setup.
280// Return the number of files added.
281//
282Int_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
283{
284 return SetupRuns(iter, fRuns, path, id, raw);
285}
286
287// --------------------------------------------------------------------------
288//
289// Add all calibration runs from the sequence to MDirIter.
290// If path==0 the standard path of the data-center is assumed.
291// If you have the runs locally use path="."
292// Using raw=kTRUE you get correspodning raw-files setup.
293// Return the number of files added.
294//
295Int_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
296{
297 return SetupRuns(iter, fCalRuns, path, id, raw);
298}
Note: See TracBrowser for help on using the repository browser.