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

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