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 "MDirIter.h"
|
---|
133 |
|
---|
134 | ClassImp(MSequence);
|
---|
135 |
|
---|
136 | using namespace std;
|
---|
137 |
|
---|
138 | MSequence::~MSequence()
|
---|
139 | {
|
---|
140 | /*
|
---|
141 | TExMapIter iter(&fFileNames);
|
---|
142 |
|
---|
143 | Long_t key, val;
|
---|
144 |
|
---|
145 | while (iter.Next(key, val))
|
---|
146 | delete (TString*)val;
|
---|
147 | */
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | // --------------------------------------------------------------------------
|
---|
152 | //
|
---|
153 | // Copy the run numbers from the TString runs into the TArrayI data
|
---|
154 | //
|
---|
155 | void MSequence::Split(TString &runs, TArrayI &data) const
|
---|
156 | {
|
---|
157 | const TRegexp regexp("[0-9]+");
|
---|
158 |
|
---|
159 | data.Set(0);
|
---|
160 | runs = runs.Strip(TString::kTrailing);
|
---|
161 |
|
---|
162 | while (!runs.IsNull())
|
---|
163 | {
|
---|
164 | TString num = runs(regexp);
|
---|
165 |
|
---|
166 | const Int_t n = data.GetSize();
|
---|
167 | data.Set(n+1);
|
---|
168 | data[n] = atoi(num.Data());
|
---|
169 |
|
---|
170 | runs.Remove(0, runs.First(num)+num.Length());
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | UInt_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path, char *id, Bool_t raw) const
|
---|
175 | {
|
---|
176 | TString d(path);
|
---|
177 |
|
---|
178 | // Setup path
|
---|
179 | if (d.IsNull())
|
---|
180 | {
|
---|
181 | d = Form("/data/MAGIC/Period%03d/", fPeriod);
|
---|
182 | d += raw ? "rawdata/" : "rootdata/";
|
---|
183 | d += fNight.GetStringFmt("%Y_%m_%d");
|
---|
184 | }
|
---|
185 | else
|
---|
186 | gSystem->ExpandPathName(d);
|
---|
187 |
|
---|
188 | for (int i=0; i<arr.GetSize(); i++)
|
---|
189 | {
|
---|
190 | // R. DeLosReyes and T. Bretz
|
---|
191 | // Changes to read the DAQ numbering format. Changes takes place
|
---|
192 | // between runs 35487 and 00035488 (2004_08_30)
|
---|
193 | const char *fmt = arr[i]>35487 ? "%08d_%s_*_E" : "%05d_%s_*_E";
|
---|
194 |
|
---|
195 | TString n;
|
---|
196 |
|
---|
197 | // Create file name
|
---|
198 | n = fNight.GetStringFmt("%Y%m%d_");
|
---|
199 | n += Form(fmt, arr[i], id);
|
---|
200 | n += raw ? ".raw" : ".root";
|
---|
201 |
|
---|
202 | // Add Path/File to TIter
|
---|
203 | iter.AddDirectory(d, n, 0);
|
---|
204 | }
|
---|
205 |
|
---|
206 | return iter.GetNumEntries();
|
---|
207 | }
|
---|
208 |
|
---|
209 | // --------------------------------------------------------------------------
|
---|
210 | //
|
---|
211 | // Read the file fname as setup file for the sequence.
|
---|
212 | //
|
---|
213 | void MSequence::GetFileNames(TEnv &env, const TArrayI &arr)
|
---|
214 | {
|
---|
215 | /*
|
---|
216 | for (int i=0; i<arr.GetSize(); i++)
|
---|
217 | {
|
---|
218 | // Get run number
|
---|
219 | const Int_t num = arr[i];
|
---|
220 |
|
---|
221 | // Check if name already set
|
---|
222 | if (fFileNames.GetValue(num))
|
---|
223 | continue;
|
---|
224 |
|
---|
225 | TString *str = new TString(env.GetValue(Form("%d", num), ""));
|
---|
226 | fFileNames.Add(num, (Long_t)str);
|
---|
227 | }
|
---|
228 | */
|
---|
229 | }
|
---|
230 |
|
---|
231 | // --------------------------------------------------------------------------
|
---|
232 | //
|
---|
233 | // Get a file name corresponding to the run-number num, returns 0 if n/a
|
---|
234 | //
|
---|
235 | const char *MSequence::GetFileName(UInt_t num)
|
---|
236 | {
|
---|
237 | return 0;
|
---|
238 | /*
|
---|
239 | TString *str = (TString*)fFileNames.GetValue(num);
|
---|
240 | return str ? str->Data() : 0;*/
|
---|
241 | }
|
---|
242 |
|
---|
243 | // --------------------------------------------------------------------------
|
---|
244 | //
|
---|
245 | // Read the file fname as setup file for the sequence.
|
---|
246 | //
|
---|
247 | MSequence::MSequence(const char *fname)
|
---|
248 | {
|
---|
249 | fName = fname;
|
---|
250 |
|
---|
251 | const char *expname = gSystem->ExpandPathName(fname);
|
---|
252 |
|
---|
253 | fTitle = Form("Sequence contained in file %s", expname);
|
---|
254 |
|
---|
255 | TEnv env(expname);
|
---|
256 | delete [] expname;
|
---|
257 |
|
---|
258 | TString str;
|
---|
259 |
|
---|
260 | fSequence = env.GetValue("Sequence", -1);
|
---|
261 | fLastRun = env.GetValue("LastRun", -1);
|
---|
262 | fNumEvents = env.GetValue("NumEvents", -1);
|
---|
263 | fPeriod = env.GetValue("Period", -1);
|
---|
264 |
|
---|
265 | str = env.GetValue("Start", "");
|
---|
266 | fStart.SetSqlDateTime(str);
|
---|
267 | str = env.GetValue("Night", "");
|
---|
268 | str += " 00:00:00";
|
---|
269 | fNight.SetSqlDateTime(str);
|
---|
270 |
|
---|
271 | fProject = env.GetValue("Project", "");
|
---|
272 | fSource = env.GetValue("Source", "");
|
---|
273 | fTriggerTable = env.GetValue("TriggerTable", "");
|
---|
274 | fHvSettings = env.GetValue("HvSettings", "");
|
---|
275 |
|
---|
276 | str = env.GetValue("Runs", "");
|
---|
277 | Split(str, fRuns);
|
---|
278 | str = env.GetValue("CalRuns", "");
|
---|
279 | Split(str, fCalRuns);
|
---|
280 | str = env.GetValue("PedRuns", "");
|
---|
281 | Split(str, fPedRuns);
|
---|
282 | str = env.GetValue("DatRuns", "");
|
---|
283 | Split(str, fDatRuns);
|
---|
284 |
|
---|
285 | GetFileNames(env, fRuns);
|
---|
286 | GetFileNames(env, fCalRuns);
|
---|
287 | GetFileNames(env, fPedRuns);
|
---|
288 | GetFileNames(env, fDatRuns);
|
---|
289 | }
|
---|
290 |
|
---|
291 | // --------------------------------------------------------------------------
|
---|
292 | //
|
---|
293 | // Print the contents of the sequence
|
---|
294 | //
|
---|
295 | void MSequence::Print(Option_t *o) const
|
---|
296 | {
|
---|
297 | gLog << all;
|
---|
298 | if (!IsValid())
|
---|
299 | {
|
---|
300 | gLog << "Sequence: " << fName << " <invalid>" << endl;
|
---|
301 | return;
|
---|
302 | }
|
---|
303 | gLog << "Sequence: " << fSequence << endl;
|
---|
304 | gLog << "Period: " << fPeriod << endl;
|
---|
305 | gLog << "Night: " << fNight << endl << endl;
|
---|
306 | gLog << "Start: " << fStart << endl;
|
---|
307 | gLog << "LastRun: " << fLastRun << endl;
|
---|
308 | gLog << "NumEvents: " << fNumEvents << endl;
|
---|
309 | gLog << "Project: " << fProject << endl;
|
---|
310 | gLog << "Source: " << fSource << endl;
|
---|
311 | gLog << "TriggerTable: " << fTriggerTable << endl;
|
---|
312 | gLog << "HvSettings: " << fHvSettings << endl << endl;
|
---|
313 | gLog << "Runs:";
|
---|
314 | for (int i=0; i<fRuns.GetSize(); i++)
|
---|
315 | gLog << " " << fRuns[i];
|
---|
316 | gLog << endl;
|
---|
317 | gLog << "CalRuns:";
|
---|
318 | for (int i=0; i<fCalRuns.GetSize(); i++)
|
---|
319 | gLog << " " << fCalRuns[i];
|
---|
320 | gLog << endl;
|
---|
321 | gLog << "PedRuns:";
|
---|
322 | for (int i=0; i<fPedRuns.GetSize(); i++)
|
---|
323 | gLog << " " << fPedRuns[i];
|
---|
324 | gLog << endl;
|
---|
325 | gLog << "DatRuns:";
|
---|
326 | for (int i=0; i<fDatRuns.GetSize(); i++)
|
---|
327 | gLog << " " << fDatRuns[i];
|
---|
328 | gLog << endl;
|
---|
329 | }
|
---|
330 |
|
---|
331 | // --------------------------------------------------------------------------
|
---|
332 | //
|
---|
333 | // Add all ped runs from the sequence to MDirIter.
|
---|
334 | // If path==0 the standard path of the data-center is assumed.
|
---|
335 | // If you have the runs locally use path="."
|
---|
336 | // Using raw=kTRUE you get correspodning raw-files setup.
|
---|
337 | // Return the number of files added.
|
---|
338 | //
|
---|
339 | UInt_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
|
---|
340 | {
|
---|
341 | return SetupRuns(iter, fPedRuns, path, id, raw);
|
---|
342 | }
|
---|
343 |
|
---|
344 | // --------------------------------------------------------------------------
|
---|
345 | //
|
---|
346 | // Add all data runs from the sequence to MDirIter.
|
---|
347 | // If path==0 the standard path of the data-center is assumed.
|
---|
348 | // If you have the runs locally use path="."
|
---|
349 | // Using raw=kTRUE you get correspodning raw-files setup.
|
---|
350 | // Return the number of files added.
|
---|
351 | //
|
---|
352 | UInt_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
|
---|
353 | {
|
---|
354 | return SetupRuns(iter, fDatRuns, path, id, raw);
|
---|
355 | }
|
---|
356 |
|
---|
357 | // --------------------------------------------------------------------------
|
---|
358 | //
|
---|
359 | // Add all runs from the sequence to MDirIter.
|
---|
360 | // If path==0 the standard path of the data-center is assumed.
|
---|
361 | // If you have the runs locally use path="."
|
---|
362 | // Using raw=kTRUE you get correspodning raw-files setup.
|
---|
363 | // Return the number of files added.
|
---|
364 | //
|
---|
365 | UInt_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
|
---|
366 | {
|
---|
367 | return SetupRuns(iter, fRuns, path, id, raw);
|
---|
368 | }
|
---|
369 |
|
---|
370 | // --------------------------------------------------------------------------
|
---|
371 | //
|
---|
372 | // Add all calibration runs from the sequence to MDirIter.
|
---|
373 | // If path==0 the standard path of the data-center is assumed.
|
---|
374 | // If you have the runs locally use path="."
|
---|
375 | // Using raw=kTRUE you get correspodning raw-files setup.
|
---|
376 | // Return the number of files added.
|
---|
377 | //
|
---|
378 | UInt_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, char *id, Bool_t raw) const
|
---|
379 | {
|
---|
380 | return SetupRuns(iter, fCalRuns, path, id, raw);
|
---|
381 | }
|
---|
382 |
|
---|
383 | // --------------------------------------------------------------------------
|
---|
384 | //
|
---|
385 | // If you want to add runs manually, use this function.
|
---|
386 | //
|
---|
387 | UInt_t MSequence::AddRuns(UInt_t first, UInt_t last, TArrayI *runs)
|
---|
388 | {
|
---|
389 | if (last<first)
|
---|
390 | {
|
---|
391 | *fLog << warn << "MSequence::AddRuns - WARNING: Last runnumber " << last;
|
---|
392 | *fLog << " smaller than first " << first << "... ignored." << endl;
|
---|
393 | return 0;
|
---|
394 | }
|
---|
395 | if (!IsValid())
|
---|
396 | {
|
---|
397 | *fLog << inf << "Setting Sequence number to #" << first << endl;
|
---|
398 | fSequence = first;
|
---|
399 | }
|
---|
400 |
|
---|
401 | const UInt_t nall = fRuns.GetSize();
|
---|
402 | const UInt_t nrun = runs ? runs->GetSize() : 0;
|
---|
403 | const UInt_t add = last-first+1;
|
---|
404 |
|
---|
405 | fRuns.Set(nall+add);
|
---|
406 | if (runs)
|
---|
407 | runs->Set(nrun+add);
|
---|
408 |
|
---|
409 | for (UInt_t i=0; i<add; i++)
|
---|
410 | {
|
---|
411 | fRuns[nall+i] = first+i;
|
---|
412 | if (runs)
|
---|
413 | (*runs)[nrun+i] = first+i;
|
---|
414 | }
|
---|
415 | return add;
|
---|
416 | }
|
---|
417 |
|
---|
418 | // --------------------------------------------------------------------------
|
---|
419 | //
|
---|
420 | // If you want to change or set the night manually.
|
---|
421 | // The Format is
|
---|
422 | // SetNight("yyyy-mm-dd");
|
---|
423 | //
|
---|
424 | void MSequence::SetNight(const char *txt)
|
---|
425 | {
|
---|
426 | TString night(txt);
|
---|
427 | night += " 00:00:00";
|
---|
428 | fNight.SetSqlDateTime(night);
|
---|
429 |
|
---|
430 | fPeriod = MAstro::GetMagicPeriod(fNight.GetMjd());
|
---|
431 | }
|
---|