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