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-2008
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MSequence
|
---|
28 | //
|
---|
29 | // This class describes a sequence. For sequences see:
|
---|
30 | // http://db.astro.uni-wuerzburg.de
|
---|
31 | //
|
---|
32 | // A sequence is a collection of runs which should be used together.
|
---|
33 | // Any run can be contained only once.
|
---|
34 | //
|
---|
35 | // Here is an example how a file describing a sequence could look like.
|
---|
36 | //
|
---|
37 | // Reading the file is based on TEnv. For more details see also
|
---|
38 | // the class reference of TEnv.
|
---|
39 | //
|
---|
40 | // ===========================================================================
|
---|
41 | //
|
---|
42 | // sequence.txt
|
---|
43 | // ------------
|
---|
44 | //
|
---|
45 | // # Sequence number (identifier) - necessary if the path
|
---|
46 | // # contains the sequence number, e.g. image files
|
---|
47 | // Sequence: 31015
|
---|
48 | //
|
---|
49 | // # Observation Period (not needed, calculated from Night)
|
---|
50 | // # Period: 18
|
---|
51 | //
|
---|
52 | // # Date of sunrise of the observation night - necessary if the path
|
---|
53 | // # contains the date, e.g. raw data
|
---|
54 | // Night: 2004-06-24
|
---|
55 | //
|
---|
56 | // # Start time of the sequence (first data run, not needed)
|
---|
57 | // Start: 2004-06-24 03:12:42
|
---|
58 | //
|
---|
59 | // # Run number of last data run in sequence (not needed)
|
---|
60 | // LastRun: 31032
|
---|
61 | //
|
---|
62 | // # Project name of data-runs of sequence (not needed)
|
---|
63 | // Project: 3EG2033+41
|
---|
64 | //
|
---|
65 | // # Source name of all runs of sequence (not needed)
|
---|
66 | // Source: 3EG2033+41
|
---|
67 | //
|
---|
68 | // # Trigger table of data-runs of sequence (not needed)
|
---|
69 | // TriggerTable: L1_4NN:L2_DEFAULT
|
---|
70 | //
|
---|
71 | // # HV Setting table of data-runs of sequence (not needed)
|
---|
72 | // HvSettings: HVSettings_FF36q
|
---|
73 | //
|
---|
74 | // # Total number of data-events in sequence (not needed)
|
---|
75 | // NumEvents: 250914
|
---|
76 | //
|
---|
77 | // # Brightest light condition of the contained runs (not needed)
|
---|
78 | // LightCondition: Twilight
|
---|
79 | //
|
---|
80 | // # Whether this is MC data or not (necessary in case of MCs if
|
---|
81 | // # default paths should be used)
|
---|
82 | // MonteCarlo: Yes
|
---|
83 | //
|
---|
84 | // # List of all runs of this sequence (not needed)
|
---|
85 | // Runs: 31015:31017 31018 31019.0 31019.3 31019.5:7 31020+ 31021::3
|
---|
86 | //
|
---|
87 | // # List of all calibration runs of this sequence (necessary if accessed)
|
---|
88 | // CalRuns: 31015 31016 31017
|
---|
89 | // # List of pedestal runs belonging to the calibration runs of this sequence (necessary if accessed)
|
---|
90 | // PedRuns: 31018
|
---|
91 | // # List of all data runs belonging to this sequence (necessary)
|
---|
92 | // DatRuns: 31019.0 31019.3 31019:5:7 31020+ 31021::3
|
---|
93 | //
|
---|
94 | // Run00031020: :3 7:9 15
|
---|
95 | //
|
---|
96 | // # Just for fun ;-) (not needed, but helpful)
|
---|
97 | // Comment: This is a template for a sequence file
|
---|
98 | //
|
---|
99 | // ===========================================================================
|
---|
100 | //
|
---|
101 | // Runs are devided into file since run 1000000. These Run-/Filenumbers
|
---|
102 | // are given by a dot. X.Y means Run X, File Y.
|
---|
103 | //
|
---|
104 | // In the Runs, CalRuns, PedRuns and DatRuns tag you can use
|
---|
105 | // several abbreviationa:
|
---|
106 | //
|
---|
107 | // 31015:31017 means 31015.0 31016.0 31017.0
|
---|
108 | // 31018 means 31018.0
|
---|
109 | // 31019.3 means 31019.3
|
---|
110 | // 31019.5:7 means 31019.5 31019.6 31019.7
|
---|
111 | // 31020+ means file list for run 21020 given below
|
---|
112 | // 31021::3 means 31021.0 31021.1 31021.2 31021.3
|
---|
113 | //
|
---|
114 | // For the run-list defined above (note the number must have 8 digits,
|
---|
115 | // for example 'Run00031020') you can also use abbreviations:
|
---|
116 | //
|
---|
117 | // :3 means 0 1 2 3
|
---|
118 | // 7:9 means 7 8 9
|
---|
119 | //
|
---|
120 | // ===========================================================================
|
---|
121 | //
|
---|
122 | // For special cases you can also setup a sequence directly from a macro,
|
---|
123 | // for example:
|
---|
124 | //
|
---|
125 | // MDirIter pediter, datiter, caliter;
|
---|
126 | //
|
---|
127 | // MSequence seq;
|
---|
128 | // seq.SetNight("2004-07-06");
|
---|
129 | // seq.AddRun(31751, 'P');
|
---|
130 | // seq.AddRun(31752, 'C');
|
---|
131 | // seq.AddRuns(31753, 31764, 'D');
|
---|
132 | // seq.SetupPedRuns(pediter);
|
---|
133 | // seq.SetupCalRuns(caliter);
|
---|
134 | // seq.SetupDatRuns(datiter);
|
---|
135 | //
|
---|
136 | // or
|
---|
137 | //
|
---|
138 | // MDirIter iter;
|
---|
139 | //
|
---|
140 | // MSequence seq;
|
---|
141 | // seq.SetNight("2004-07-06");
|
---|
142 | // seq.AddFiles(31753, 0, 120);
|
---|
143 | // seq.GetRuns(iter);
|
---|
144 | // seq.SetupPedRuns(iter, "/mypath", "[DPC]");
|
---|
145 | //
|
---|
146 | //
|
---|
147 | // ===========================================================================
|
---|
148 | //
|
---|
149 | // ToDO:
|
---|
150 | // * Default paths could be moved into the global .rootrc
|
---|
151 | //
|
---|
152 | // ===========================================================================
|
---|
153 | //
|
---|
154 | //
|
---|
155 | // Class Version 2:
|
---|
156 | // ----------------
|
---|
157 | // + fMonteCarlo
|
---|
158 | //
|
---|
159 | // Class Version 3:
|
---|
160 | // ----------------
|
---|
161 | // + fComment
|
---|
162 | //
|
---|
163 | // Class Version 4:
|
---|
164 | // ----------------
|
---|
165 | // + fExclRuns
|
---|
166 | //
|
---|
167 | // Class Version 5:
|
---|
168 | // ----------------
|
---|
169 | // + fRunsSub
|
---|
170 | // + fDatRunsSub
|
---|
171 | // + fPedRunsSub
|
---|
172 | // + fCalRunsSub
|
---|
173 | // + fExclRunsSub
|
---|
174 | //
|
---|
175 | // Class Version 6:
|
---|
176 | // ----------------
|
---|
177 | // + fTelescope
|
---|
178 | //
|
---|
179 | /////////////////////////////////////////////////////////////////////////////
|
---|
180 | #include "MSequenceSQL.h"
|
---|
181 |
|
---|
182 | #include <stdlib.h>
|
---|
183 | #include <errno.h>
|
---|
184 |
|
---|
185 | #include <fstream>
|
---|
186 |
|
---|
187 | #include <TEnv.h>
|
---|
188 | #include <TPRegexp.h>
|
---|
189 | #include <TSystem.h> // TSystem::ExpandPath
|
---|
190 |
|
---|
191 | #include "MLog.h"
|
---|
192 | #include "MLogManip.h"
|
---|
193 |
|
---|
194 | #include "MEnv.h"
|
---|
195 | #include "MJob.h"
|
---|
196 | #include "MAstro.h"
|
---|
197 | #include "MString.h"
|
---|
198 | #include "MDirIter.h"
|
---|
199 |
|
---|
200 | ClassImp(MSequence);
|
---|
201 |
|
---|
202 | using namespace std;
|
---|
203 |
|
---|
204 | // --------------------------------------------------------------------------
|
---|
205 | //
|
---|
206 | // This adds an run/file entry to the data/sub arrays. If it is already
|
---|
207 | // contained a waring is printed.
|
---|
208 | //
|
---|
209 | void MSequence::AddEntry(Int_t run, Int_t file, TArrayI &data, TArrayI &sub) const
|
---|
210 | {
|
---|
211 | const Int_t n = data.GetSize();
|
---|
212 |
|
---|
213 | // skip already existing entries
|
---|
214 | if (IsContained(data, sub, run, file))
|
---|
215 | {
|
---|
216 | *fLog << warn << "WARNING - File " << run << "." << file << " already in list... skipped." << endl;
|
---|
217 | return;
|
---|
218 | }
|
---|
219 |
|
---|
220 | if (run<1000000 && file>0)
|
---|
221 | *fLog << warn << "WARNING - Run number " << run << "<" << "1,000,000 but file " << file << ">0..." << endl;
|
---|
222 |
|
---|
223 | // set new entry
|
---|
224 | data.Set(n+1);
|
---|
225 | sub.Set(n+1);
|
---|
226 |
|
---|
227 | data[n] = run;
|
---|
228 | sub[n] = file;
|
---|
229 | }
|
---|
230 |
|
---|
231 | // --------------------------------------------------------------------------
|
---|
232 | //
|
---|
233 | // Evaluate a token in thr Run string. Add the coresponding run/files
|
---|
234 | // with AddEntry
|
---|
235 | //
|
---|
236 | void MSequence::EvalEntry(const TEnv *env, const TString &prefix, const TString &num, TArrayI &data, TArrayI &sub) const
|
---|
237 | {
|
---|
238 | // Split entry into run and file
|
---|
239 | const Int_t run = num.Atoi();
|
---|
240 |
|
---|
241 | // Syntax error forbidden by construction
|
---|
242 | const Ssiz_t p1 = num.First('.');
|
---|
243 | const Ssiz_t p2 = num.Last(':');
|
---|
244 |
|
---|
245 | // ---------------------------------------------------------------
|
---|
246 |
|
---|
247 | const Int_t n1 = atoi(num.Data()+p1+1);
|
---|
248 | const Int_t n2 = atoi(num.Data()+p2+1);
|
---|
249 |
|
---|
250 | // ---------------------------------------------------------------
|
---|
251 | // p1>=0 && p2<0 (. but no :) run.n1 run.file1
|
---|
252 | if (p1>=0 && p2<0)
|
---|
253 | {
|
---|
254 | AddEntry(run, n1, data, sub);
|
---|
255 | return;
|
---|
256 | }
|
---|
257 |
|
---|
258 | // ---------------------------------------------------------------
|
---|
259 | // p1>=0 && p2>=0 (. and :) run:n1:n2 run.file1-run.file2
|
---|
260 | if (p1>=0 && p2>=0)
|
---|
261 | {
|
---|
262 | if (n2<n1)
|
---|
263 | {
|
---|
264 | *fLog << warn << "WARNING - Invalid range '" << num << "'... ignored." << endl;
|
---|
265 | return;
|
---|
266 | }
|
---|
267 |
|
---|
268 | for (int i=n1; i<=n2; i++)
|
---|
269 | AddEntry(run, i, data, sub);
|
---|
270 | return;
|
---|
271 | }
|
---|
272 |
|
---|
273 | // ---------------------------------------------------------------
|
---|
274 | // p1<0 && p2>=0 (no . but :) n1:n2 run1-run2
|
---|
275 | if (p1<0 && p2>=0)
|
---|
276 | {
|
---|
277 | if (n2<run)
|
---|
278 | {
|
---|
279 | *fLog << warn << "WARNING - Invalid range in '" << num << "'... ignored." << endl;
|
---|
280 | return;
|
---|
281 | }
|
---|
282 |
|
---|
283 | for (int i=run; i<=n2; i++)
|
---|
284 | AddEntry(i, 0, data, sub);
|
---|
285 | return;
|
---|
286 | }
|
---|
287 |
|
---|
288 | // ---------------------------------------------------------------
|
---|
289 | // p0<0 and p1<0 (no . and no :) run run
|
---|
290 |
|
---|
291 | if (!num.EndsWith("+"))
|
---|
292 | {
|
---|
293 | AddEntry(run, 0, data, sub);
|
---|
294 | return;
|
---|
295 | }
|
---|
296 |
|
---|
297 | if (!env)
|
---|
298 | return;
|
---|
299 |
|
---|
300 | TPRegexp regexp("([0-9]*:[0-9]+|[0-9]+(:[0-9]*)?)( +|$)");
|
---|
301 |
|
---|
302 | TString files = GetEnvValue3(*env, prefix, "Run%d", run);
|
---|
303 | if (files.IsNull())
|
---|
304 | {
|
---|
305 | AddEntry(run, 0, data, sub);
|
---|
306 | return;
|
---|
307 | }
|
---|
308 |
|
---|
309 | while (!files.IsNull())
|
---|
310 | {
|
---|
311 | const TString num = files(regexp);
|
---|
312 | if (num.IsNull())
|
---|
313 | {
|
---|
314 | *fLog << warn << "WARNING - File in run " << run << " is NaN (not a number): '" << files << "'" << endl;
|
---|
315 | break;
|
---|
316 | }
|
---|
317 |
|
---|
318 | const Ssiz_t p1 = num.First(':');
|
---|
319 | if (p1>=0)
|
---|
320 | {
|
---|
321 | const Int_t n1 = atoi(num.Data());
|
---|
322 | const Int_t n2 = atoi(num.Data()+p1+1);
|
---|
323 |
|
---|
324 | if (n2<n1)
|
---|
325 | {
|
---|
326 | *fLog << warn << "WARNING - Invalid range in '" << num << "'... ignored." << endl;
|
---|
327 | return;
|
---|
328 | }
|
---|
329 |
|
---|
330 | // FIXME: n2==0 || n2<n1
|
---|
331 | for (int i=n1; i<=n2; i++)
|
---|
332 | AddEntry(run, i, data, sub);
|
---|
333 | }
|
---|
334 | else
|
---|
335 | {
|
---|
336 | const Int_t file = atoi(num.Data());
|
---|
337 | AddEntry(run, file, data, sub);
|
---|
338 | }
|
---|
339 |
|
---|
340 | files.Remove(0, files.First(num)+num.Length());
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | // --------------------------------------------------------------------------
|
---|
345 | //
|
---|
346 | // Interprete the TString and add the run/files to the arrays.
|
---|
347 | // Run/files which are twice in the list are only added once. In this case
|
---|
348 | // a warning is emitted.
|
---|
349 | //
|
---|
350 | void MSequence::Split(TString &runs, TArrayI &data, TArrayI &sub, const TEnv *env, const TString prefix) const
|
---|
351 | {
|
---|
352 | TPRegexp regexp("^[0-9]+([+]|(:|[.]([0-9]*:)?)[0-9]+)?( +|$)");
|
---|
353 |
|
---|
354 | data.Set(0);
|
---|
355 | sub.Set(0);
|
---|
356 |
|
---|
357 | runs.ReplaceAll("\t", " ");
|
---|
358 | runs = runs.Strip(TString::kBoth);
|
---|
359 |
|
---|
360 | while (!runs.IsNull())
|
---|
361 | {
|
---|
362 | const TString num = runs(regexp);
|
---|
363 | if (num.IsNull())
|
---|
364 | {
|
---|
365 | *fLog << warn << "WARNING - Run syntax error: '" << runs << "'" << endl;
|
---|
366 | break;
|
---|
367 | }
|
---|
368 |
|
---|
369 | EvalEntry(env, prefix, num.Strip(TString::kTrailing), data, sub);
|
---|
370 |
|
---|
371 | runs.Remove(0, runs.First(num)+num.Length());
|
---|
372 | }
|
---|
373 |
|
---|
374 | SortArrays(data, sub);
|
---|
375 | }
|
---|
376 |
|
---|
377 | // --------------------------------------------------------------------------
|
---|
378 | //
|
---|
379 | // Get the String from the TEnv file prefixed by prefix-name.
|
---|
380 | // Intepret the string using Split which adds the run/files to the arrays.
|
---|
381 | //
|
---|
382 | void MSequence::Split(const TEnv &env, const TString &prefix, const char *name, TArrayI &data, TArrayI &sub) const
|
---|
383 | {
|
---|
384 | TString str = GetEnvValue2(env, prefix, name, "");
|
---|
385 | Split(str, data, sub, &env, prefix);
|
---|
386 | }
|
---|
387 |
|
---|
388 | TString MSequence::InflateFilePath(const MTime &night, Bool_t mc)
|
---|
389 | {
|
---|
390 | TString rc = GetStandardPath(mc);
|
---|
391 | rc += "rawfiles/";
|
---|
392 | rc += night.GetStringFmt("%Y/%m/%d/");
|
---|
393 | return rc;
|
---|
394 | }
|
---|
395 |
|
---|
396 | TString MSequence::InflateFilePath(const MTime &night, UShort_t tel, Int_t run, Int_t file, Int_t type)
|
---|
397 | {
|
---|
398 | return InflateFilePath(night)+InflateFileName(night, tel, run, file, type);
|
---|
399 | }
|
---|
400 |
|
---|
401 | // --------------------------------------------------------------------------
|
---|
402 | //
|
---|
403 | // Compile path from the given path name and expand it. If it IsNull()
|
---|
404 | // the path is compiled as standard path from tha datacenter). The
|
---|
405 | // returned path will end with a "/".
|
---|
406 | //
|
---|
407 | TString MSequence::GetPathName(TString d, FileType_t type) const
|
---|
408 | {
|
---|
409 | // Setup path
|
---|
410 | if (d.IsNull())
|
---|
411 | {
|
---|
412 | d = GetStandardPath();
|
---|
413 | switch (type&kFilePaths)
|
---|
414 | {
|
---|
415 | case kRaw: // rawdata
|
---|
416 | case kRoot: // mcdata
|
---|
417 | d += "rawfiles/";
|
---|
418 | if (!fNight)
|
---|
419 | *fLog << "WARNING - No Night-resource... path not supported." << endl;
|
---|
420 | d += fNight.GetStringFmt("%Y/%m/%d");
|
---|
421 | break;
|
---|
422 | case kReport:
|
---|
423 | d += "../subsystemdata/cc/";
|
---|
424 | d += fNight.GetStringFmt("%Y/%m/%d");
|
---|
425 | break;
|
---|
426 | case kCalibrated:
|
---|
427 | d += MString::Format("callisto/%04d/%08d", fSequence/10000, fSequence);
|
---|
428 | break;
|
---|
429 | case kImages:
|
---|
430 | d += MString::Format("star/%04d/%08d", fSequence/10000, fSequence);
|
---|
431 | break;
|
---|
432 | }
|
---|
433 | }
|
---|
434 | else
|
---|
435 | gSystem->ExpandPathName(d);
|
---|
436 |
|
---|
437 | if (!d.EndsWith("/"))
|
---|
438 | d += '/';
|
---|
439 |
|
---|
440 | return d;
|
---|
441 | }
|
---|
442 |
|
---|
443 | // --------------------------------------------------------------------------
|
---|
444 | //
|
---|
445 | // Compile FileName according to night, tel, run, file and type.
|
---|
446 | //
|
---|
447 | TString MSequence::InflateFileName(const MTime &night, UShort_t tel, Int_t run, Int_t file, Int_t type)
|
---|
448 | {
|
---|
449 | const char *id="_";
|
---|
450 | switch ((RunType_t)(type&kRunType))
|
---|
451 | {
|
---|
452 | case kDat:
|
---|
453 | id = "D";
|
---|
454 | break;
|
---|
455 | case kPed:
|
---|
456 | id = "P";
|
---|
457 | break;
|
---|
458 | case kCal:
|
---|
459 | id = "C";
|
---|
460 | break;
|
---|
461 | case kAll:
|
---|
462 | id = "[PCD]";
|
---|
463 | break;
|
---|
464 | case kCalib:
|
---|
465 | id = "Y";
|
---|
466 | break;
|
---|
467 | case kImage:
|
---|
468 | id = "I";
|
---|
469 | break;
|
---|
470 | case kExcl:
|
---|
471 | break;
|
---|
472 | }
|
---|
473 |
|
---|
474 | // Is report file?
|
---|
475 | const Bool_t isrep = type&kReport;
|
---|
476 |
|
---|
477 | // Calculate limit for transition from 5-digit to 8-digit numbers
|
---|
478 | const Int_t limit = isrep ? 39373 : 35487;
|
---|
479 |
|
---|
480 | // ------------- Create file name --------------
|
---|
481 | TString n;
|
---|
482 |
|
---|
483 | if (night)
|
---|
484 | n += night.GetStringFmt("%Y%m%d_");
|
---|
485 |
|
---|
486 | // This is for MCs (FIXME!!!!)
|
---|
487 | if (run<0)
|
---|
488 | n += MString::Format("%08d", -run);
|
---|
489 | else
|
---|
490 | {
|
---|
491 | if (tel>0)
|
---|
492 | n += MString::Format("M%d_", tel);
|
---|
493 |
|
---|
494 | // R. DeLosReyes and T. Bretz
|
---|
495 | // Changes to read the DAQ numbering format. Changes takes place
|
---|
496 | // between runs 35487 and 00035488 (2004_08_30)
|
---|
497 | n += MString::Format(run>limit ? "%08d" : "%05d", run);
|
---|
498 |
|
---|
499 | if (tel>0)
|
---|
500 | n += MString::Format(".%03d", file);
|
---|
501 | }
|
---|
502 |
|
---|
503 | n += "_";
|
---|
504 | n += id;
|
---|
505 | n += "_*";
|
---|
506 |
|
---|
507 | if (tel==0 && run>=0)
|
---|
508 | n += isrep ? "_S" : "_E";
|
---|
509 |
|
---|
510 | switch (type&kFileType)
|
---|
511 | {
|
---|
512 | case kRaw: // MC // DATA
|
---|
513 | n += run<0 ? ".root" : ".raw.?g?z?"; // TPRegexp: (\.gz)?
|
---|
514 | break;
|
---|
515 | case kReport:
|
---|
516 | n += ".rep"; // TPRegexp: (\.gz)?
|
---|
517 | break;
|
---|
518 | default:
|
---|
519 | n += ".root";
|
---|
520 | break;
|
---|
521 | }
|
---|
522 |
|
---|
523 | return n;
|
---|
524 | }
|
---|
525 |
|
---|
526 | // --------------------------------------------------------------------------
|
---|
527 | //
|
---|
528 | // Return the expression describing the file-name for the file defined
|
---|
529 | // by i-th entry of the the given arrays. The file type identifier is
|
---|
530 | // defined by type. The source name is replaced by a wildcard and
|
---|
531 | // the extension is defined by the type as well.
|
---|
532 | //
|
---|
533 | TString MSequence::GetFileRegexp(UInt_t i, const TArrayI &arr, const TArrayI &sub, FileType_t type) const
|
---|
534 | {
|
---|
535 | if (i>=(UInt_t)arr.GetSize())
|
---|
536 | return "";
|
---|
537 |
|
---|
538 | return InflateFileName(fNight, arr[i]>999999?fTelescope:0, fMonteCarlo?-arr[i]:arr[i], sub.GetSize()>0?sub[i]:0, type);
|
---|
539 | }
|
---|
540 |
|
---|
541 | // --------------------------------------------------------------------------
|
---|
542 | //
|
---|
543 | // Get the filename from the dirctory and the file-regexp.
|
---|
544 | // return "" if file is not accessible or the regular expression is not
|
---|
545 | // unambiguous.
|
---|
546 | //
|
---|
547 | TString MSequence::FindFile(const TString &d, const TString &f) const
|
---|
548 | {
|
---|
549 | // Check existance and accessibility of file
|
---|
550 | MDirIter file(d, f, 0);
|
---|
551 |
|
---|
552 | TString name = file();
|
---|
553 | gSystem->ExpandPathName(name);
|
---|
554 | if (gSystem->AccessPathName(name, kFileExists))
|
---|
555 | {
|
---|
556 | *fLog << err;
|
---|
557 | *fLog << "ERROR - File " << d << f << " not accessible!" << endl;
|
---|
558 | return "";
|
---|
559 | }
|
---|
560 | if (!file().IsNull())
|
---|
561 | {
|
---|
562 | *fLog << err;
|
---|
563 | *fLog << "ERROR - Searching for file " << d << f << " gave more than one result!" << endl;
|
---|
564 | return "";
|
---|
565 | }
|
---|
566 |
|
---|
567 | return name;
|
---|
568 | }
|
---|
569 |
|
---|
570 | // --------------------------------------------------------------------------
|
---|
571 | //
|
---|
572 | // Set the path accoring to type (if fDataPath=path=0), fDataPath
|
---|
573 | // (if path=0) or path.
|
---|
574 | // Returns accessability of the path.
|
---|
575 | //
|
---|
576 | Bool_t MSequence::FindPath(TString &path, FileType_t type) const
|
---|
577 | {
|
---|
578 | if (path.IsNull())
|
---|
579 | path = fDataPath;
|
---|
580 |
|
---|
581 | const Bool_t def = path.IsNull();
|
---|
582 |
|
---|
583 | path = GetPathName(path, type);
|
---|
584 |
|
---|
585 | return def;
|
---|
586 | }
|
---|
587 |
|
---|
588 | // --------------------------------------------------------------------------
|
---|
589 | //
|
---|
590 | // Add the entries from the arrays to the MDirIter
|
---|
591 | //
|
---|
592 | UInt_t MSequence::GetRuns(MDirIter &iter, const TArrayI &arr, const TArrayI &sub, FileType_t type, TString path) const
|
---|
593 | {
|
---|
594 | const Bool_t def = FindPath(path, type);
|
---|
595 |
|
---|
596 | // For this particular case we assume that the files are added one by
|
---|
597 | // one without wildcards.
|
---|
598 | const Int_t n0 = iter.GetNumEntries();
|
---|
599 |
|
---|
600 | Int_t excluded = 0;
|
---|
601 | for (int i=0; i<arr.GetSize(); i++)
|
---|
602 | {
|
---|
603 | if (IsExcluded(arr[i], sub[i]))
|
---|
604 | {
|
---|
605 | excluded++;
|
---|
606 | continue;
|
---|
607 | }
|
---|
608 |
|
---|
609 | const TString n = GetFileRegexp(i, arr, sub, type);
|
---|
610 |
|
---|
611 | if (FindFile(path, n).IsNull())
|
---|
612 | continue;
|
---|
613 |
|
---|
614 | // Add Path/File to TIter
|
---|
615 | iter.AddDirectory(path, n, 0);
|
---|
616 | }
|
---|
617 |
|
---|
618 | // n0: The previous contents of the iter
|
---|
619 | // n1: The number of files which have been added to the iter
|
---|
620 | // n2: The number of files which should have been added from the array
|
---|
621 | const Int_t n1 = iter.GetNumEntries()-n0;
|
---|
622 | const Int_t n2 = arr.GetSize()-excluded;
|
---|
623 | if (n1==0)
|
---|
624 | {
|
---|
625 | *fLog << err;
|
---|
626 | *fLog << "ERROR - No input files for sequence #" << GetSequence() << endl;
|
---|
627 | *fLog << " read from " << GetBaseName() << endl;
|
---|
628 | *fLog << " found in" << (def?" default-path ":" ") << path << endl;
|
---|
629 | return 0;
|
---|
630 | }
|
---|
631 |
|
---|
632 | if (n1==n2)
|
---|
633 | return n1;
|
---|
634 |
|
---|
635 | *fLog << err;
|
---|
636 | *fLog << "ERROR - " << n1 << " input files for sequence #" << GetSequence() << " found in" << endl;
|
---|
637 | *fLog << " " << (def?" default-path ":" ") << path << endl;
|
---|
638 | *fLog << " but " << n2 << " files were defined in sequence file" << endl;
|
---|
639 | *fLog << " " << GetBaseName() << endl;
|
---|
640 | if (fLog->GetDebugLevel()<=4)
|
---|
641 | return 0;
|
---|
642 |
|
---|
643 | *fLog << inf << "Files which are searched for this sequence:" << endl;
|
---|
644 | iter.Print();
|
---|
645 | return 0;
|
---|
646 | }
|
---|
647 |
|
---|
648 | // --------------------------------------------------------------------------
|
---|
649 | //
|
---|
650 | // Returns "0" if file at i-th index is excluded. Get the access-path
|
---|
651 | // defined by the default or data-path (if path=0) or path.
|
---|
652 | // Get the full file-name by accessing the file.
|
---|
653 | //
|
---|
654 | TString MSequence::GetFileName(UInt_t i, const TArrayI &arr, const TArrayI &sub, FileType_t type, const char *path) const
|
---|
655 | {
|
---|
656 | if (IsExcluded(arr[i], sub[i]))
|
---|
657 | return "0";
|
---|
658 |
|
---|
659 | const TString d = FindPath(type, path);
|
---|
660 | const TString n = GetFileRegexp(i, arr, sub, type);
|
---|
661 |
|
---|
662 | return FindFile(d, n);
|
---|
663 | }
|
---|
664 |
|
---|
665 | // --------------------------------------------------------------------------
|
---|
666 | //
|
---|
667 | // Return the pointers to the arrays with the runs/files depending on the
|
---|
668 | // given type.
|
---|
669 | //
|
---|
670 | void MSequence::GetArrays(const TArrayI* &r, const TArrayI* &f, Int_t type) const
|
---|
671 | {
|
---|
672 | switch ((RunType_t)(type&(kRunType|kExcl)))
|
---|
673 | {
|
---|
674 | case kPed:
|
---|
675 | r = &fPedRuns;
|
---|
676 | f = &fPedRunsSub;
|
---|
677 | break;
|
---|
678 | case kDat:
|
---|
679 | case kImage:
|
---|
680 | case kCalib:
|
---|
681 | r = &fDatRuns;
|
---|
682 | f = &fDatRunsSub;
|
---|
683 | break;
|
---|
684 | case kCal:
|
---|
685 | r = &fCalRuns;
|
---|
686 | f = &fCalRunsSub;
|
---|
687 | break;
|
---|
688 | case kExcl:
|
---|
689 | r = &fExclRuns;
|
---|
690 | f = &fExclRunsSub;
|
---|
691 | break;
|
---|
692 | case kAll:
|
---|
693 | r = &fRuns;
|
---|
694 | f = &fRunsSub;
|
---|
695 | break;
|
---|
696 | }
|
---|
697 | }
|
---|
698 |
|
---|
699 | // --------------------------------------------------------------------------
|
---|
700 | //
|
---|
701 | // Add runs from the sequence to MDirIter. If path==0 fDataPath is
|
---|
702 | // used instead. If it is also empty the standard path of the
|
---|
703 | // data-center is assumed. If you have the runs locally use path="."
|
---|
704 | //
|
---|
705 | // Returns the number of files added.
|
---|
706 | //
|
---|
707 | // Runs which are in fExlRuns are ignored.
|
---|
708 | //
|
---|
709 | UInt_t MSequence::GetRuns(MDirIter &iter, FileType_t type, const char *path) const
|
---|
710 | {
|
---|
711 | const TArrayI *r=0, *f=0;
|
---|
712 | GetArrays(r, f, type);
|
---|
713 | return GetRuns(iter, *r, *f, type, path);
|
---|
714 | }
|
---|
715 |
|
---|
716 | // --------------------------------------------------------------------------
|
---|
717 | //
|
---|
718 | // Returns the num-th entry of FileType_t as regular expression.
|
---|
719 | // If the file is excluded return "".
|
---|
720 | // To get the number of valid entries use GetNumEntries(FileType_t)
|
---|
721 | //
|
---|
722 | // e.g.
|
---|
723 | // if (GetNumEntries(MSequence::kDat))<5)
|
---|
724 | // GetFileRegexp(3, MSequence::kRawDat);
|
---|
725 | //
|
---|
726 | TString MSequence::GetFileRegexp(UInt_t num, FileType_t type) const
|
---|
727 | {
|
---|
728 | const TArrayI *r=0, *f=0;
|
---|
729 | GetArrays(r, f, type);
|
---|
730 |
|
---|
731 | TString rc = GetFileRegexp(num, *r, *f, type);
|
---|
732 | rc.ReplaceAll(".", "\\.");
|
---|
733 | rc.ReplaceAll("*", ".*");
|
---|
734 | return rc;
|
---|
735 | }
|
---|
736 |
|
---|
737 | // --------------------------------------------------------------------------
|
---|
738 | //
|
---|
739 | // Returns the num-th entry of FileType_t as filename. To access the
|
---|
740 | // path the default is used if path IsNull, path otherwise.
|
---|
741 | // If the file could not be accessed "" is returned, if it is
|
---|
742 | // excluded "0".
|
---|
743 | // To get the number of valid entries use GetNumEntries(FileType_t)
|
---|
744 | //
|
---|
745 | // e.g.
|
---|
746 | // if (GetNumEntries(MSequence::kDat))<5)
|
---|
747 | // GetFileName(3, MSequence::kRawDat);
|
---|
748 | //
|
---|
749 | TString MSequence::GetFileName(UInt_t num, FileType_t type, const char *path) const
|
---|
750 | {
|
---|
751 | const TArrayI *r=0, *f=0;
|
---|
752 | GetArrays(r, f, type);
|
---|
753 | return GetFileName(num, *r, *f, type, path);
|
---|
754 | }
|
---|
755 |
|
---|
756 | // --------------------------------------------------------------------------
|
---|
757 | //
|
---|
758 | // Returns the num-th entry of FileType_t as filename.
|
---|
759 | // If the file could not be accessed or excluded return "".
|
---|
760 | // To get the number of valid entries use GetNumEntries(RunType_t)
|
---|
761 | //
|
---|
762 | UInt_t MSequence::GetNumEntries(RunType_t type) const
|
---|
763 | {
|
---|
764 | const TArrayI *r=0, *f=0;
|
---|
765 | GetArrays(r, f, type);
|
---|
766 | return r->GetSize();
|
---|
767 | }
|
---|
768 |
|
---|
769 | // --------------------------------------------------------------------------
|
---|
770 | //
|
---|
771 | // Returns the num-th entry of RunType_t as run- and file-number.
|
---|
772 | // Returns -1 if index is out of range, 0 if file is excluded and
|
---|
773 | // 1 in case of success.
|
---|
774 | //
|
---|
775 | // e.g.
|
---|
776 | // UInt_t run, file;
|
---|
777 | // GetFile(3, MSequence::kDat, run, file);
|
---|
778 | //
|
---|
779 | Int_t MSequence::GetFile(UInt_t i, RunType_t type, UInt_t &run, UInt_t &file) const
|
---|
780 | {
|
---|
781 | const TArrayI *r=0, *f=0;
|
---|
782 | GetArrays(r, f, type);
|
---|
783 |
|
---|
784 | if (i>=(UInt_t)r->GetSize())
|
---|
785 | return -1;
|
---|
786 |
|
---|
787 | run = (*r)[i];
|
---|
788 | file = i<(UInt_t)f->GetSize() ? (*f)[i] : 0;
|
---|
789 |
|
---|
790 | if (IsExcluded(run, file))
|
---|
791 | return 0;
|
---|
792 |
|
---|
793 | return 1;
|
---|
794 | }
|
---|
795 |
|
---|
796 | // --------------------------------------------------------------------------
|
---|
797 | //
|
---|
798 | // Add a file (run/file) to the arrays defined by RunType_t
|
---|
799 | //
|
---|
800 | void MSequence::AddFile(UInt_t run, UInt_t file, RunType_t type)
|
---|
801 | {
|
---|
802 | const TArrayI *rconst=0, *fconst=0;
|
---|
803 |
|
---|
804 | GetArrays(rconst, fconst, type);
|
---|
805 |
|
---|
806 | if (!rconst || !fconst)
|
---|
807 | {
|
---|
808 | *fLog << err << "ERROR - Invalid values returned by MSequence::GetArrays... " << run << "." << file << " ignored." << endl;
|
---|
809 | return;
|
---|
810 | }
|
---|
811 |
|
---|
812 | TArrayI &r=*const_cast<TArrayI*>(rconst);
|
---|
813 | TArrayI &f=*const_cast<TArrayI*>(fconst);
|
---|
814 |
|
---|
815 | AddEntry(run, file, r, f);
|
---|
816 |
|
---|
817 | SortArrays(r, f);
|
---|
818 | }
|
---|
819 |
|
---|
820 | // --------------------------------------------------------------------------
|
---|
821 | //
|
---|
822 | // Get LightCondition from str and convert it to LightCondition_t
|
---|
823 | //
|
---|
824 | MSequence::LightCondition_t MSequence::GetLightCondition(const TString &str) const
|
---|
825 | {
|
---|
826 | if (!str.CompareTo("n/a", TString::kIgnoreCase))
|
---|
827 | return kNA;
|
---|
828 | if (!str.CompareTo("No_Moon", TString::kIgnoreCase))
|
---|
829 | return kNoMoon;
|
---|
830 | if (!str.CompareTo("NoMoon", TString::kIgnoreCase))
|
---|
831 | return kNoMoon;
|
---|
832 | if (!str.CompareTo("Twilight", TString::kIgnoreCase))
|
---|
833 | return kTwilight;
|
---|
834 | if (!str.CompareTo("Moon", TString::kIgnoreCase))
|
---|
835 | return kMoon;
|
---|
836 | if (!str.CompareTo("Day", TString::kIgnoreCase))
|
---|
837 | return kDay;
|
---|
838 |
|
---|
839 | gLog << warn;
|
---|
840 | gLog << "WARNING - in " << GetBaseName() << ":" << endl;
|
---|
841 | gLog << " LightCondition-tag is '" << str << "' but must be n/a, no_moon, twilight, moon or day." << endl;
|
---|
842 | return kNA;
|
---|
843 | }
|
---|
844 |
|
---|
845 | // --------------------------------------------------------------------------
|
---|
846 | //
|
---|
847 | // Set the path to the data. If no path is given the data-center default
|
---|
848 | // path is used to access the files.
|
---|
849 | //
|
---|
850 | // kTRUE is returned if the path is acessible, kFALSE otherwise.
|
---|
851 | // (In case of the default path kTRUE is returned in any case)
|
---|
852 | //
|
---|
853 | Bool_t MSequence::SetDataPath(const char *path)
|
---|
854 | {
|
---|
855 | fDataPath = path;
|
---|
856 |
|
---|
857 | gSystem->ExpandPathName(fDataPath);
|
---|
858 |
|
---|
859 | const Bool_t rc = !fDataPath.IsNull() && gSystem->AccessPathName(fDataPath, kFileExists);
|
---|
860 | if (rc)
|
---|
861 | gLog << err << "ERROR - Directory '" << path << "' doesn't exist." << endl;
|
---|
862 |
|
---|
863 | return !rc;
|
---|
864 | }
|
---|
865 |
|
---|
866 | // --------------------------------------------------------------------------
|
---|
867 | //
|
---|
868 | // Read a sequence from a file. To set the location of the data (datapath)
|
---|
869 | // use SetDataPath. The sequence number given is used if no sequence
|
---|
870 | // number is found in the sequence file.
|
---|
871 | //
|
---|
872 | // If the file could not be found or accesed kFALSE is returned, kTRUE
|
---|
873 | // otherwise.
|
---|
874 | //
|
---|
875 | Bool_t MSequence::ReadFile(const char *filename, UInt_t seq)
|
---|
876 | {
|
---|
877 | fFileName = filename;
|
---|
878 |
|
---|
879 | gSystem->ExpandPathName(fFileName);
|
---|
880 |
|
---|
881 | const Bool_t rc = gSystem->AccessPathName(fFileName, kFileExists);
|
---|
882 | if (rc)
|
---|
883 | gLog << err << "ERROR - Sequence file '" << filename << "' doesn't exist." << endl;
|
---|
884 |
|
---|
885 | MEnv env(fFileName);
|
---|
886 |
|
---|
887 | fSequence = (UInt_t)env.GetValue("Sequence", (Int_t)seq);
|
---|
888 |
|
---|
889 | const TString prefix = MString::Format("Sequence%08d", fSequence);
|
---|
890 |
|
---|
891 | fTelescope = GetEnvValue2(env, prefix, "Telescope", 1);
|
---|
892 | fLastRun = GetEnvValue2(env, prefix, "LastRun", -1);
|
---|
893 | fNumEvents = GetEnvValue2(env, prefix, "NumEvents", -1);
|
---|
894 |
|
---|
895 | TString str;
|
---|
896 | str = GetEnvValue2(env, prefix, "LightCondition", "n/a");
|
---|
897 | fLightCondition = GetLightCondition(str);
|
---|
898 |
|
---|
899 | str = GetEnvValue2(env, prefix, "Start", "");
|
---|
900 | fStart.SetSqlDateTime(str);
|
---|
901 |
|
---|
902 | str = GetEnvValue2(env, prefix, "Night", "");
|
---|
903 | SetNight(str);
|
---|
904 |
|
---|
905 | fProject = GetEnvValue2(env, prefix, "Project", "");
|
---|
906 | fSource = GetEnvValue2(env, prefix, "Source", "");
|
---|
907 | fTriggerTable = GetEnvValue2(env, prefix, "TriggerTable", "");
|
---|
908 | fHvSettings = GetEnvValue2(env, prefix, "HvSettings", "");
|
---|
909 | fMonteCarlo = GetEnvValue2(env, prefix, "MonteCarlo", kFALSE);
|
---|
910 | fComment = GetEnvValue2(env, prefix, "Comment", "");
|
---|
911 |
|
---|
912 | Split(env, prefix, "Runs", fRuns, fRunsSub);
|
---|
913 | Split(env, prefix, "CalRuns", fCalRuns, fCalRunsSub);
|
---|
914 | Split(env, prefix, "PedRuns", fPedRuns, fPedRunsSub);
|
---|
915 | Split(env, prefix, "DatRuns", fDatRuns, fDatRunsSub);
|
---|
916 | Split(env, prefix, "Exclude", fExclRuns, fExclRunsSub);
|
---|
917 |
|
---|
918 | // Dummies:
|
---|
919 | env.Touch("Period");
|
---|
920 | env.Touch("ZdMin");
|
---|
921 | env.Touch("ZdMax");
|
---|
922 | env.Touch("L1TriggerTable");
|
---|
923 | env.Touch("L2TriggerTable");
|
---|
924 |
|
---|
925 | if (seq<0 && env.GetNumUntouched()>0)
|
---|
926 | {
|
---|
927 | gLog << warn << "WARNING - At least one resource in the sequence-file has not been touched!" << endl;
|
---|
928 | env.PrintUntouched();
|
---|
929 | }
|
---|
930 |
|
---|
931 | return !rc;
|
---|
932 | }
|
---|
933 |
|
---|
934 | // --------------------------------------------------------------------------
|
---|
935 | //
|
---|
936 | // Instantiate a file from either a file or the database.
|
---|
937 | //
|
---|
938 | // If not valid sequence could be created the sequence is invalidated,
|
---|
939 | // which can be queried with IsValid.
|
---|
940 | //
|
---|
941 | // see ReadFile, ReadDatabase and SetDataPath for more details.
|
---|
942 | //
|
---|
943 | MSequence::MSequence(const char *fname, const char *path, UInt_t seq)
|
---|
944 | {
|
---|
945 | // regular expression to distinguish beween a mysql-path and
|
---|
946 | // a filename from where the sequence should be retrieved
|
---|
947 | TPRegexp regexp("mysql://[a-zA-Z0-9]+:.+@[a-zA-Z0-9]+/[a-zA-Z0-9]+/([0-9]+:)?[0-9]+");
|
---|
948 |
|
---|
949 | const TString db = TString(fname)(regexp);
|
---|
950 |
|
---|
951 | const Bool_t rc1 = db.IsNull() ? ReadFile(fname, seq) : ReadDatabase(fname, seq);
|
---|
952 | const Bool_t rc2 = SetDataPath(path);
|
---|
953 |
|
---|
954 | fName = "MSequence";
|
---|
955 | fTitle = "Sequence file";
|
---|
956 |
|
---|
957 | if (!rc1 || !rc2)
|
---|
958 | fSequence = (UInt_t)-1;
|
---|
959 | }
|
---|
960 |
|
---|
961 | // --------------------------------------------------------------------------
|
---|
962 | //
|
---|
963 | // Read a sequence from the database. Give the path to the database as:
|
---|
964 | // mysql://user:password@name/database
|
---|
965 | // In this case you MUST give a sequence number.
|
---|
966 | //
|
---|
967 | // You can code the telescope and sequence number into the path and
|
---|
968 | // omit the arguments:
|
---|
969 | // mysql://user:password@name/database/[tel:]sequence
|
---|
970 | //
|
---|
971 | // The third option is to give just the sql.rc as string in the argument.
|
---|
972 | // In this case you MUST give a sequence number.
|
---|
973 | //
|
---|
974 | // If the telecope number is omitted as argument, i.e. ==0, or in the
|
---|
975 | // database path, a sequence is read from the database if the sequence
|
---|
976 | // number is unambiguous.
|
---|
977 | //
|
---|
978 | // kFALSE is returned if the final sequence is invalid, kTRUE in case of
|
---|
979 | // success.
|
---|
980 | //
|
---|
981 | Bool_t MSequence::ReadDatabase(TString name, UInt_t seq, UShort_t tel)
|
---|
982 | {
|
---|
983 | TPRegexp regexp("([0-9]+:)?[0-9]+$");
|
---|
984 |
|
---|
985 | const TString telseq = name(regexp);
|
---|
986 |
|
---|
987 | if (!telseq.IsNull())
|
---|
988 | {
|
---|
989 | const Ssiz_t p = telseq.First(':');
|
---|
990 |
|
---|
991 | const TString strtel = p<0 ? TString("") : telseq(0, p);
|
---|
992 | const TString strseq = telseq(p+1, telseq.Length());
|
---|
993 |
|
---|
994 | tel = strtel.Atoi();
|
---|
995 | seq = strseq.Atoi();
|
---|
996 |
|
---|
997 | name = gSystem->DirName(name);
|
---|
998 | }
|
---|
999 |
|
---|
1000 | *this = MSequenceSQL(name, seq, tel);
|
---|
1001 |
|
---|
1002 | return IsValid();
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | // --------------------------------------------------------------------------
|
---|
1006 | //
|
---|
1007 | // Create a sequence from the database, e.g.
|
---|
1008 | //
|
---|
1009 | // TString mysql = "mysql://MAGIC:password@vela/MyMagic";
|
---|
1010 | // Int_t sequence = 100002;
|
---|
1011 | // Int_t telescope = 1;
|
---|
1012 | //
|
---|
1013 | // MSequence seq(mysql, sequence, telescope);
|
---|
1014 | //
|
---|
1015 | // Is the telescope number is omitted (==0) the database is checked for
|
---|
1016 | // an unambiguous sequence.
|
---|
1017 | //
|
---|
1018 | // For more details see ReadDatabase and MSequenceSQL.
|
---|
1019 | //
|
---|
1020 | MSequence::MSequence(const char *fname, UInt_t seq, UShort_t tel)
|
---|
1021 | {
|
---|
1022 | const Bool_t rc = ReadDatabase(fname, seq, tel);
|
---|
1023 |
|
---|
1024 | fName = "MSequence";
|
---|
1025 | fTitle = "Sequence file";
|
---|
1026 |
|
---|
1027 | if (!rc)
|
---|
1028 | fSequence = (UInt_t)-1;
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | // --------------------------------------------------------------------------
|
---|
1032 | //
|
---|
1033 | // Some helper functions for the comparison functions
|
---|
1034 | //
|
---|
1035 | static int operator==(const TArrayI &a, const TArrayI &b)
|
---|
1036 | {
|
---|
1037 | return a.GetSize()==b.GetSize() &&
|
---|
1038 | memcmp(a.GetArray(), b.GetArray(), a.GetSize()*sizeof(Int_t));
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | static int IsNull(const TArrayI &a, const TArrayI &b)
|
---|
1042 | {
|
---|
1043 | return a==TArrayI(a.GetSize()) && b==TArrayI(b.GetSize());
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | static int Check(const TArrayI &a, const TArrayI &b)
|
---|
1047 | {
|
---|
1048 | return a==b || IsNull(a, b);
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | // --------------------------------------------------------------------------
|
---|
1052 | //
|
---|
1053 | // Here we test all things mandatory for a sequence:
|
---|
1054 | // fTelescope
|
---|
1055 | // fSequence
|
---|
1056 | // fNight
|
---|
1057 | // fMonteCarlo
|
---|
1058 | // fCalRuns
|
---|
1059 | // fCalRunsSub
|
---|
1060 | // fPedRuns
|
---|
1061 | // fPedRunsSub
|
---|
1062 | // fDatRuns
|
---|
1063 | // fDatRunsSub
|
---|
1064 | // fExclRuns
|
---|
1065 | // fExclRunsSub
|
---|
1066 | //
|
---|
1067 | Bool_t MSequence::IsCompatible(const MSequence &s) const
|
---|
1068 | {
|
---|
1069 | return // Mandatory
|
---|
1070 | fTelescope == s.fTelescope &&
|
---|
1071 | fSequence == s.fSequence &&
|
---|
1072 | fNight == s.fNight &&
|
---|
1073 |
|
---|
1074 | fMonteCarlo == s.fMonteCarlo &&
|
---|
1075 |
|
---|
1076 | fCalRuns == s.fCalRuns &&
|
---|
1077 | fPedRuns == s.fPedRuns &&
|
---|
1078 | fDatRuns == s.fDatRuns &&
|
---|
1079 | fExclRuns == s.fExclRuns &&
|
---|
1080 |
|
---|
1081 | Check(fCalRunsSub, s.fCalRunsSub) &&
|
---|
1082 | Check(fPedRunsSub, s.fPedRunsSub) &&
|
---|
1083 | Check(fDatRunsSub, s.fDatRunsSub) &&
|
---|
1084 | Check(fExclRunsSub, s.fExclRunsSub);
|
---|
1085 | }
|
---|
1086 |
|
---|
1087 | // --------------------------------------------------------------------------
|
---|
1088 | //
|
---|
1089 | // Here we test whether all values of a sequence are identical
|
---|
1090 | // IsCompaticle(s)
|
---|
1091 | // fStart
|
---|
1092 | // fLastRun
|
---|
1093 | // fNumEvents
|
---|
1094 | // fPeriod
|
---|
1095 | // fProject
|
---|
1096 | // fSource
|
---|
1097 | // fRuns
|
---|
1098 | // fHvSettings
|
---|
1099 | // fTriggerTable
|
---|
1100 | // fLightCondition
|
---|
1101 | // fRuns
|
---|
1102 | // fRunsSub
|
---|
1103 | //
|
---|
1104 | Bool_t MSequence::operator==(const MSequence &s) const
|
---|
1105 | {
|
---|
1106 | return IsCompatible(s) &&
|
---|
1107 | // Unnecessary
|
---|
1108 | fStart == s.fStart &&
|
---|
1109 | fLastRun == s.fLastRun &&
|
---|
1110 | fNumEvents == s.fNumEvents &&
|
---|
1111 | fPeriod == s.fPeriod &&
|
---|
1112 | fProject == s.fProject &&
|
---|
1113 | fSource == s.fSource &&
|
---|
1114 | fRuns == s.fRuns &&
|
---|
1115 | fHvSettings == s.fHvSettings &&
|
---|
1116 | fTriggerTable == s.fTriggerTable &&
|
---|
1117 | fLightCondition == s.fLightCondition &&
|
---|
1118 | Check(fRunsSub, s.fRunsSub);
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | // --------------------------------------------------------------------------
|
---|
1122 | //
|
---|
1123 | // Check whether the sequence has also identical source, i.e.
|
---|
1124 | // the sequence filepath and the datapath in addition to operator==
|
---|
1125 | //
|
---|
1126 | Bool_t MSequence::IsIdentical(const MSequence &s) const
|
---|
1127 | {
|
---|
1128 | return *this==s &&
|
---|
1129 | // Obsolete
|
---|
1130 | fDataPath==s.fDataPath && fFileName==s.fFileName;
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | //---------------------------------------------------------------------------
|
---|
1134 | //
|
---|
1135 | // Make sure that the name used for writing doesn't contain a full path
|
---|
1136 | //
|
---|
1137 | const char *MSequence::GetBaseName() const
|
---|
1138 | {
|
---|
1139 | return gSystem->BaseName(fFileName);
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | //---------------------------------------------------------------------------
|
---|
1143 | //
|
---|
1144 | // Make sure that the name used for writing doesn't contain a full path
|
---|
1145 | //
|
---|
1146 | const char *MSequence::GetFilePath() const
|
---|
1147 | {
|
---|
1148 | return gSystem->DirName(fFileName);
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | // --------------------------------------------------------------------------
|
---|
1152 | //
|
---|
1153 | // Find a sequence of continous numbers in f starting at pos (looking
|
---|
1154 | // only at n entries). The output is converted into sequences
|
---|
1155 | // of X (single r) and X:Y (a sequence between x and r). The function
|
---|
1156 | // returnes when position pos+n is reached
|
---|
1157 | //
|
---|
1158 | TString MSequence::GetNumSequence(Int_t pos, Int_t n, const TArrayI &f) const
|
---|
1159 | {
|
---|
1160 | TString str;
|
---|
1161 |
|
---|
1162 | Int_t p=pos;
|
---|
1163 | while (p<pos+n)
|
---|
1164 | {
|
---|
1165 | str += MString::Format(" %d", f[p]);
|
---|
1166 |
|
---|
1167 | if (p==pos+n-1)
|
---|
1168 | break;
|
---|
1169 |
|
---|
1170 | int i=0;
|
---|
1171 | while (++i<n)
|
---|
1172 | if (f[p+i]-f[p]!=i)
|
---|
1173 | break;
|
---|
1174 |
|
---|
1175 | if (i>1)
|
---|
1176 | str += MString::Format(":%d", f[p+i-1]);
|
---|
1177 |
|
---|
1178 | p += i;
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | return str;
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | // --------------------------------------------------------------------------
|
---|
1185 | //
|
---|
1186 | // Search for a sequence of continous numbers in r with f==0 starting at p.
|
---|
1187 | // A new starting p is returned. The output is converted into sequences
|
---|
1188 | // of X (single r) and X:Y (a sequence between x and r). The function
|
---|
1189 | // returnes with the next f!=0.
|
---|
1190 | //
|
---|
1191 | TString MSequence::GetNumSequence(Int_t &p, const TArrayI &r, const TArrayI &f) const
|
---|
1192 | {
|
---|
1193 | TString str;
|
---|
1194 |
|
---|
1195 | while (p<r.GetSize() && f[p]==0)
|
---|
1196 | {
|
---|
1197 | // serach for the first entry which doesn't fit
|
---|
1198 | // or has a file number which is != 0
|
---|
1199 | int i=0;
|
---|
1200 | while (p+ ++i<r.GetSize())
|
---|
1201 | if (r[p+i]-r[p]!=i || f[p+i]!=0)
|
---|
1202 | break;
|
---|
1203 |
|
---|
1204 | // None found (i-1==0)
|
---|
1205 | if (i-1==0)
|
---|
1206 | return str;
|
---|
1207 |
|
---|
1208 | // The last run found in the sequence (e.g. 5.0) is followed
|
---|
1209 | // by an identical run number but file != 0 (e.g. 5.1)
|
---|
1210 | if (p+i<f.GetSize() && r[p+i]==r[p] && f[p+i]!=0)
|
---|
1211 | i--;
|
---|
1212 |
|
---|
1213 | // Now we have to check again whether found no valid entry
|
---|
1214 | if (i-1==0)
|
---|
1215 | return str;
|
---|
1216 |
|
---|
1217 | str += MString::Format(" %d", r[p]);
|
---|
1218 | // p now points to the last entry which fits and
|
---|
1219 | // has a file number == 0
|
---|
1220 | p += i-1;
|
---|
1221 | // Only one found (i-1==1)
|
---|
1222 | // More tahn one found (i-1>1)
|
---|
1223 | str += i-1==1 ? " " : ":";
|
---|
1224 | str += MString::Format("%d", r[p]);
|
---|
1225 |
|
---|
1226 | // One step forward
|
---|
1227 | p++;
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | return str;
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | // --------------------------------------------------------------------------
|
---|
1234 | //
|
---|
1235 | // Print the runs in a compressed wa. Returns the RunXXXXXXX string
|
---|
1236 | // simplyfing the file setup
|
---|
1237 | //
|
---|
1238 | TString MSequence::PrintRuns(ostream &out, const char *pre, const char *name, const TArrayI &r, const TArrayI &f) const
|
---|
1239 | {
|
---|
1240 | if (r.GetSize()==0)
|
---|
1241 | return "";
|
---|
1242 |
|
---|
1243 | out << pre << name;
|
---|
1244 | if (f.GetSize()==0)
|
---|
1245 | const_cast<TArrayI&>(f).Set(r.GetSize());
|
---|
1246 |
|
---|
1247 | #ifdef DEBUG
|
---|
1248 | for (int i=0; i<r.GetSize(); i++)
|
---|
1249 | out << " " << r[i] << "." << f[i];
|
---|
1250 | out << endl;
|
---|
1251 | return "";
|
---|
1252 | #endif
|
---|
1253 |
|
---|
1254 | TString str;
|
---|
1255 |
|
---|
1256 | Int_t pos = 0;
|
---|
1257 | while (pos<r.GetSize())
|
---|
1258 | {
|
---|
1259 | TString rc = GetNumSequence(pos, r, f);
|
---|
1260 | if (!rc.IsNull())
|
---|
1261 | {
|
---|
1262 | out << rc;
|
---|
1263 | continue;
|
---|
1264 | }
|
---|
1265 |
|
---|
1266 | Int_t n = GetSubArray(pos, r.GetSize(), (Int_t*)r.GetArray());
|
---|
1267 | // end reached
|
---|
1268 | if (n<0)
|
---|
1269 | break;
|
---|
1270 |
|
---|
1271 | // This can happen if it is the last entry
|
---|
1272 | if (n==1)
|
---|
1273 | {
|
---|
1274 | out << " " << r[pos];
|
---|
1275 | if (f[pos]>0)
|
---|
1276 | out << "." << f[pos];
|
---|
1277 | }
|
---|
1278 | else
|
---|
1279 | {
|
---|
1280 | // Check for sequence
|
---|
1281 | Bool_t isseq = kTRUE;
|
---|
1282 | for (int i=1; i<n; i++)
|
---|
1283 | if (f[pos+i]-f[pos]!=i)
|
---|
1284 | isseq=kFALSE;
|
---|
1285 |
|
---|
1286 | if (isseq)
|
---|
1287 | {
|
---|
1288 | out << " " << r[pos] << ".";
|
---|
1289 | if (f[pos]!=0)
|
---|
1290 | out << f[pos];
|
---|
1291 | out << ":" << f[pos+n-1];
|
---|
1292 | }
|
---|
1293 | else
|
---|
1294 | {
|
---|
1295 | out << " " << r[pos] << "+";
|
---|
1296 |
|
---|
1297 | str += '\n';
|
---|
1298 | str += pre;
|
---|
1299 | str += MString::Format("Run%08d:", r[pos]);
|
---|
1300 | str += GetNumSequence(pos, n, f);
|
---|
1301 | }
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 | pos += n;
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 | out << endl;
|
---|
1308 |
|
---|
1309 | return str;
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | // --------------------------------------------------------------------------
|
---|
1313 | //
|
---|
1314 | // Print the numbers in the classical way (one run after the other)
|
---|
1315 | //
|
---|
1316 | void MSequence::PrintRunsClassic(ostream &out, const char *pre, const char *name, const TArrayI &r) const
|
---|
1317 | {
|
---|
1318 | out << pre << name;
|
---|
1319 | for (int i=0; i<r.GetSize(); i++)
|
---|
1320 | out << " " << r[i];
|
---|
1321 | out << endl;
|
---|
1322 | }
|
---|
1323 |
|
---|
1324 | // --------------------------------------------------------------------------
|
---|
1325 | //
|
---|
1326 | // Print the contents of the sequence
|
---|
1327 | //
|
---|
1328 | void MSequence::Print(ostream &out, Option_t *o) const
|
---|
1329 | {
|
---|
1330 | const TString opt(o);
|
---|
1331 |
|
---|
1332 | const TString pre = opt.Contains("prefixed") ? MString::Format("Sequence%08d.", fSequence) : "";
|
---|
1333 |
|
---|
1334 | if (!IsValid())
|
---|
1335 | {
|
---|
1336 | out << pre << "Sequence: " << fFileName << " <invalid>" << endl;
|
---|
1337 | return;
|
---|
1338 | }
|
---|
1339 | if (!fFileName.IsNull())
|
---|
1340 | out << "# FileName: " << fFileName << endl;
|
---|
1341 | if (!fDataPath.IsNull())
|
---|
1342 | out << "# DataPath: " << fDataPath << endl;
|
---|
1343 | out << endl;
|
---|
1344 | if (pre.IsNull())
|
---|
1345 | out << "Sequence: " << fSequence << endl;
|
---|
1346 | if (fTelescope!=1)
|
---|
1347 | out << "Telescope: " << fTelescope << endl;
|
---|
1348 | if (fMonteCarlo)
|
---|
1349 | out << pre << "MonteCarlo: Yes" << endl;
|
---|
1350 | if (fPeriod!=(UInt_t)-1)
|
---|
1351 | out << pre << "Period: " << fPeriod << endl;
|
---|
1352 | if (fNight!=MTime())
|
---|
1353 | out << pre << "Night: " << fNight.GetStringFmt("%Y-%m-%d") << endl;
|
---|
1354 | out << endl;
|
---|
1355 | out << pre << "LightCondition: ";
|
---|
1356 | switch (fLightCondition)
|
---|
1357 | {
|
---|
1358 | case kNA: out << "n/a" << endl; break;
|
---|
1359 | case kNoMoon: out << "NoMoon" << endl; break;
|
---|
1360 | case kTwilight: out << "Twilight" << endl; break;
|
---|
1361 | case kMoon: out << "Moon" << endl; break;
|
---|
1362 | case kDay: out << "Day" << endl; break;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | if (fStart!=MTime())
|
---|
1366 | out << pre << "Start: " << fStart.GetSqlDateTime() << endl;
|
---|
1367 | if (fLastRun>=0)
|
---|
1368 | out << pre << "LastRun: " << fLastRun << endl;
|
---|
1369 | if (fNumEvents>=0)
|
---|
1370 | out << pre << "NumEvents: " << fNumEvents << endl;
|
---|
1371 | if (!fProject.IsNull())
|
---|
1372 | out << pre << "Project: " << fProject << endl;
|
---|
1373 | if (!fSource.IsNull())
|
---|
1374 | out << pre << "Source: " << fSource << endl;
|
---|
1375 | if (!fTriggerTable.IsNull())
|
---|
1376 | out << pre << "TriggerTable: " << fTriggerTable << endl;
|
---|
1377 | if (!fHvSettings.IsNull())
|
---|
1378 | out << pre << "HvSettings: " << fHvSettings << endl;
|
---|
1379 | out << endl;
|
---|
1380 |
|
---|
1381 | TString str;
|
---|
1382 | if (!HasSubRuns() && opt.Contains("classic"))
|
---|
1383 | {
|
---|
1384 | PrintRunsClassic(out, pre, "Runs: ", fRuns);
|
---|
1385 | PrintRunsClassic(out, pre, "CalRuns: ", fCalRuns);
|
---|
1386 | PrintRunsClassic(out, pre, "PedRuns: ", fPedRuns);
|
---|
1387 | PrintRunsClassic(out, pre, "DataRuns: ", fDatRuns);
|
---|
1388 | PrintRunsClassic(out, pre, "Exclude: ", fExclRuns);
|
---|
1389 | }
|
---|
1390 | else
|
---|
1391 | {
|
---|
1392 | // FIXME: This needs more check!
|
---|
1393 | // FORBID the + syntax in "Runs"
|
---|
1394 | // Could we make "Runs" an automatic summary of all runs?
|
---|
1395 | // Should we add a check forbidding the same run in
|
---|
1396 | // Cal/Ped/Data? What about the Exclude?
|
---|
1397 | /*str +=*/ PrintRuns(out, pre, "Runs: ", fRuns, fRunsSub);
|
---|
1398 | str += PrintRuns(out, pre, "CalRuns: ", fCalRuns, fCalRunsSub);
|
---|
1399 | str += PrintRuns(out, pre, "PedRuns: ", fPedRuns, fPedRunsSub);
|
---|
1400 | str += PrintRuns(out, pre, "DatRuns: ", fDatRuns, fDatRunsSub);
|
---|
1401 | str += PrintRuns(out, pre, "Exclude: ", fExclRuns, fExclRunsSub);
|
---|
1402 | }
|
---|
1403 |
|
---|
1404 | // if (!fDataPath.IsNull())
|
---|
1405 | // out << endl << pre << "DataPath: " << fDataPath << endl;
|
---|
1406 |
|
---|
1407 | if (!str.IsNull())
|
---|
1408 | out << str << endl;
|
---|
1409 |
|
---|
1410 | out << endl;
|
---|
1411 |
|
---|
1412 | if (!fComment.IsNull())
|
---|
1413 | out << pre << "Comment: " << fComment << endl;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | // --------------------------------------------------------------------------
|
---|
1417 | //
|
---|
1418 | // Print the contents of the sequence to gLog
|
---|
1419 | //
|
---|
1420 | void MSequence::Print(Option_t *o) const
|
---|
1421 | {
|
---|
1422 | gLog << all;
|
---|
1423 | Print(gLog, o);
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | // --------------------------------------------------------------------------
|
---|
1427 | //
|
---|
1428 | // Print the contents of the sequence to the file with name filename
|
---|
1429 | //
|
---|
1430 | Bool_t MSequence::WriteFile(const char *name, const Option_t *o) const
|
---|
1431 | {
|
---|
1432 | ofstream fout(name);
|
---|
1433 | if (!fout)
|
---|
1434 | {
|
---|
1435 | gLog << err << "ERROR - Cannot open file " << name << ": ";
|
---|
1436 | gLog << strerror(errno) << endl;
|
---|
1437 | return kFALSE;
|
---|
1438 | }
|
---|
1439 |
|
---|
1440 | Print(fout, o);
|
---|
1441 |
|
---|
1442 | if (!fout)
|
---|
1443 | {
|
---|
1444 | gLog << err << "ERROR - Writing file " << name << ": ";
|
---|
1445 | gLog << strerror(errno) << endl;
|
---|
1446 | return kFALSE;
|
---|
1447 | }
|
---|
1448 |
|
---|
1449 | return kTRUE;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | // --------------------------------------------------------------------------
|
---|
1453 | //
|
---|
1454 | // check if the run/file is contained in the arrays.
|
---|
1455 | //
|
---|
1456 | Bool_t MSequence::IsContained(const TArrayI &arr, const TArrayI &sub, UInt_t run, UInt_t file) const
|
---|
1457 | {
|
---|
1458 | // Backward compatibilty
|
---|
1459 | if (sub.GetSize()==0)
|
---|
1460 | {
|
---|
1461 | for (int i=0; i<arr.GetSize(); i++)
|
---|
1462 | if (run==(UInt_t)arr[i])
|
---|
1463 | return kTRUE;
|
---|
1464 | }
|
---|
1465 | else
|
---|
1466 | {
|
---|
1467 | for (int i=0; i<arr.GetSize(); i++)
|
---|
1468 | if (run==(UInt_t)arr[i] && file==(UInt_t)sub[i])
|
---|
1469 | return kTRUE;
|
---|
1470 | }
|
---|
1471 | return kFALSE;
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | // --------------------------------------------------------------------------
|
---|
1475 | //
|
---|
1476 | // Exclude all runs which are found in the list, e.g. "100 102 105"
|
---|
1477 | //
|
---|
1478 | void MSequence::ExcludeRuns(TString runs)
|
---|
1479 | {
|
---|
1480 | // FIXME: Decode stream!!!
|
---|
1481 |
|
---|
1482 | TArrayI data, sub;
|
---|
1483 | Split(runs, data, sub);
|
---|
1484 | for (int i=0; i<data.GetSize(); i++)
|
---|
1485 | ExcludeFile(data[i], sub[i]);
|
---|
1486 | }
|
---|
1487 |
|
---|
1488 | // --------------------------------------------------------------------------
|
---|
1489 | //
|
---|
1490 | // Return the excluded runs (to be more precise:the excluded files)
|
---|
1491 | // in a string
|
---|
1492 | //
|
---|
1493 | const TString MSequence::GetExcludedRuns() const
|
---|
1494 | {
|
---|
1495 | TString rc;
|
---|
1496 | for (int i=0; i<fExclRuns.GetSize(); i++)
|
---|
1497 | {
|
---|
1498 | rc += fExclRuns[i];
|
---|
1499 | if (fExclRunsSub.GetSize()>0)
|
---|
1500 | {
|
---|
1501 | rc += ".";
|
---|
1502 | rc += fExclRunsSub[i];
|
---|
1503 | }
|
---|
1504 | rc += " ";
|
---|
1505 | }
|
---|
1506 | return rc(0, rc.Length()-1);
|
---|
1507 | }
|
---|
1508 |
|
---|
1509 | // --------------------------------------------------------------------------
|
---|
1510 | //
|
---|
1511 | // If you want to change or set the night manually.
|
---|
1512 | // The Format is
|
---|
1513 | // SetNight("yyyy-mm-dd");
|
---|
1514 | //
|
---|
1515 | void MSequence::SetNight(const char *txt)
|
---|
1516 | {
|
---|
1517 | TString night(txt);
|
---|
1518 |
|
---|
1519 | if (night.IsNull())
|
---|
1520 | {
|
---|
1521 | fNight = MTime();
|
---|
1522 | fPeriod = UInt_t(-1);
|
---|
1523 | return;
|
---|
1524 | }
|
---|
1525 |
|
---|
1526 | night += " 00:00:00";
|
---|
1527 | fNight.SetSqlDateTime(night);
|
---|
1528 |
|
---|
1529 | fPeriod = fNight.GetMagicPeriod();
|
---|
1530 | }
|
---|
1531 |
|
---|
1532 | // --------------------------------------------------------------------------
|
---|
1533 | //
|
---|
1534 | // Read a sequence from gDirectory. If the default is given we try
|
---|
1535 | // to find a sequence with name GetName. If a key with name name
|
---|
1536 | // exists in the file read this key. Otherwise loop over all keys
|
---|
1537 | // and return the first key matching the TPRegex (regular expression)
|
---|
1538 | // matching defined by the argument.
|
---|
1539 | //
|
---|
1540 | Int_t MSequence::Read(const char *name)
|
---|
1541 | {
|
---|
1542 | if (!name || !gDirectory)
|
---|
1543 | return MParContainer::Read(name);
|
---|
1544 |
|
---|
1545 | if (gDirectory->GetListOfKeys()->FindObject(name))
|
---|
1546 | return MParContainer::Read(name);
|
---|
1547 |
|
---|
1548 | TPRegexp regexp(name);
|
---|
1549 |
|
---|
1550 | TIter NextK(gDirectory->GetListOfKeys());
|
---|
1551 | TObject *key = 0;
|
---|
1552 | while ((key=NextK()))
|
---|
1553 | if (TString(key->GetName())(regexp)==key->GetName())
|
---|
1554 | return MParContainer::Read(key->GetName());
|
---|
1555 |
|
---|
1556 | *fLog << warn << "WARNING - No key in " << gDirectory->GetName() << " matching " << name << "." << endl;
|
---|
1557 | return 0;
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | // --------------------------------------------------------------------------
|
---|
1561 | //
|
---|
1562 | // If the sequence name seq is just a digit it is inflated to a full
|
---|
1563 | // path following the datacenter standard.
|
---|
1564 | //
|
---|
1565 | // Returns if file accessible or not.
|
---|
1566 | //
|
---|
1567 | Bool_t MSequence::InflateSeq(TString &seq, Bool_t ismc)
|
---|
1568 | {
|
---|
1569 | TObjArray *arr = seq.Tokenize(':');
|
---|
1570 | if (arr->GetEntries()<3)
|
---|
1571 | {
|
---|
1572 | TString num1 = (*arr)[0]->GetName();
|
---|
1573 | TString num2 = arr->GetEntries()==2 ? (*arr)[1]->GetName() : "";
|
---|
1574 |
|
---|
1575 | if (num1.IsDigit() && num2.IsDigit())
|
---|
1576 | {
|
---|
1577 | gLog << err << "ERROR - InflateSeq 'telescope:sequence' not yet implemented." << endl;
|
---|
1578 | delete arr;
|
---|
1579 | return kFALSE;
|
---|
1580 | }
|
---|
1581 |
|
---|
1582 | if (num1.IsDigit() && num2.IsNull())
|
---|
1583 | {
|
---|
1584 | const Int_t numseq = seq.Atoi();
|
---|
1585 | seq = "/magic/";
|
---|
1586 | if (ismc)
|
---|
1587 | seq += "montecarlo/";
|
---|
1588 | seq += MString::Format("sequences/%04d/sequence%08d.txt", numseq/10000, numseq);
|
---|
1589 | gLog << inf << "Inflated sequence file: " << seq << endl;
|
---|
1590 | }
|
---|
1591 | }
|
---|
1592 | delete arr;
|
---|
1593 |
|
---|
1594 | if (!gSystem->AccessPathName(seq, kFileExists))
|
---|
1595 | return kTRUE;
|
---|
1596 |
|
---|
1597 | gLog << err << "Sorry, sequence file '" << seq << "' doesn't exist." << endl;
|
---|
1598 | return kFALSE;
|
---|
1599 | }
|
---|
1600 |
|
---|
1601 | // --------------------------------------------------------------------------
|
---|
1602 | //
|
---|
1603 | // Search starting at position p in array arr and return the number
|
---|
1604 | // of elemets which are identical to the starting entry (the starting entry
|
---|
1605 | // is also counted)
|
---|
1606 | //
|
---|
1607 | Int_t MSequence::GetSubArray(Int_t p, Int_t n, Int_t *arr)
|
---|
1608 | {
|
---|
1609 | Int_t *ptr0 = arr+p;
|
---|
1610 |
|
---|
1611 | Int_t *ptr = ptr0;
|
---|
1612 | Int_t *end = arr+n;
|
---|
1613 |
|
---|
1614 | while (ptr<end && *ptr==*ptr0)
|
---|
1615 | ptr++;
|
---|
1616 |
|
---|
1617 | return ptr-ptr0;
|
---|
1618 | }
|
---|
1619 |
|
---|
1620 | // --------------------------------------------------------------------------
|
---|
1621 | //
|
---|
1622 | // Sort the array arr2 starting at position p for following entries
|
---|
1623 | // for which arr1 is equal. If not at least two entries are found which
|
---|
1624 | // can be sorted return -1.
|
---|
1625 | //
|
---|
1626 | // The absolute index of the next entry in arr1 is returned.
|
---|
1627 | //
|
---|
1628 | Int_t MSequence::SortArraySub(Int_t p, Int_t n, Int_t *arr1, Int_t *arr2)
|
---|
1629 | {
|
---|
1630 | Int_t *ptr2 = arr2+p;
|
---|
1631 |
|
---|
1632 | Int_t cnt = GetSubArray(p, n, arr1);
|
---|
1633 | if (cnt==0)
|
---|
1634 | return -1;
|
---|
1635 |
|
---|
1636 | TArrayI srt(cnt, ptr2);
|
---|
1637 | MJob::SortArray(srt);
|
---|
1638 |
|
---|
1639 | memcpy(ptr2, srt.GetArray(), srt.GetSize()*sizeof(Int_t));
|
---|
1640 |
|
---|
1641 | return p+srt.GetSize();
|
---|
1642 | }
|
---|
1643 |
|
---|
1644 | void MSequence::SortArrays(TArrayI &arr1, TArrayI &arr2)
|
---|
1645 | {
|
---|
1646 | if (arr1.GetSize()!=arr2.GetSize())
|
---|
1647 | return;
|
---|
1648 |
|
---|
1649 | TArrayI idx(arr1.GetSize());
|
---|
1650 |
|
---|
1651 | TArrayI srt1(arr1);
|
---|
1652 | TArrayI srt2(arr2);
|
---|
1653 |
|
---|
1654 | TMath::Sort(arr1.GetSize(), srt1.GetArray(), idx.GetArray(), kFALSE);
|
---|
1655 |
|
---|
1656 | for (int i=0; i<arr1.GetSize(); i++)
|
---|
1657 | {
|
---|
1658 | arr1[i] = srt1[idx[i]];
|
---|
1659 | arr2[i] = srt2[idx[i]];
|
---|
1660 | }
|
---|
1661 |
|
---|
1662 | Int_t p = 0;
|
---|
1663 | while (p>=0)
|
---|
1664 | p = SortArraySub(p, arr1.GetSize(), arr1.GetArray(), arr2.GetArray());
|
---|
1665 | }
|
---|