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

Last change on this file since 4793 was 4732, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 6.9 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz, 8/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MSequence
28//
29// This class describes a sequence. For sequences see:
30// http://magic.astro.uni-wuerzburg.de/mars/db/queryseq.html
31//
32// A sequence is a collection of runs which should be used together.
33//
34/////////////////////////////////////////////////////////////////////////////
35#include "MSequence.h"
36
37#include <stdlib.h>
38
39#include <TEnv.h>
40#include <TRegexp.h>
41#include <TSystem.h> // TSystem::ExpandPath
42
43#include "MLog.h"
44#include "MLogManip.h"
45
46#include "MDirIter.h"
47
48ClassImp(MSequence);
49
50using namespace std;
51
52// --------------------------------------------------------------------------
53//
54// Copy the run numbers from the TString runs into the TArrayI data
55//
56void MSequence::Split(TString &runs, TArrayI &data) const
57{
58 const TRegexp regexp("[0-9]+");
59
60 data.Set(0);
61 runs = runs.Strip(TString::kTrailing);
62
63 while (!runs.IsNull())
64 {
65 TString num = runs(regexp);
66
67 const Int_t n = data.GetSize();
68 data.Set(n+1);
69 data[n] = atoi(num.Data());
70
71 runs.Remove(0, runs.First(num)+num.Length());
72 }
73}
74
75Int_t MSequence::SetupRuns(MDirIter &iter, const TArrayI &arr, const char *path, Bool_t raw) const
76{
77 TString d(path);
78
79 // Setup path
80 if (d.IsNull())
81 {
82 d = Form("/data/MAGIC/Period%03d/", fPeriod);
83 d += raw ? "rawdata/" : "rootdata/";
84 d += fNight.GetStringFmt("%Y_%m_%d");
85 }
86
87 for (int i=0; i<arr.GetSize(); i++)
88 {
89 TString n;
90
91 // Create file name
92 n = fNight.GetStringFmt("%Y%m%d_");
93 n += Form("%05d_*_E", arr[i]);
94 n += raw ? ".raw" : ".root";
95
96 // Add Path/File to TIter
97 iter.AddDirectory(d, n, 0);
98 }
99 return iter.GetNumEntries();
100}
101
102// --------------------------------------------------------------------------
103//
104// Read the file fname as setup file for the sequence.
105//
106MSequence::MSequence(const char *fname)
107{
108 fName = fname;
109 fTitle = Form("Sequence contained in file %s", fName.Data());
110
111 TEnv env(fname);
112
113 TString str;
114
115 fSequence = env.GetValue("Sequence", -1);
116 fLastRun = env.GetValue("LastRun", -1);
117 fNumEvents = env.GetValue("NumEvents", -1);
118 fPeriod = env.GetValue("Period", -1);
119
120 str = env.GetValue("Start", "");
121 fStart.SetSqlDateTime(str);
122 str = env.GetValue("Night", "");
123 str += " 00:00:00";
124 fNight.SetSqlDateTime(str);
125
126 fProject = env.GetValue("Project", "");
127 fSource = env.GetValue("Source", "");
128 fTriggerTable = env.GetValue("TriggerTable", "");
129 fHvSettings = env.GetValue("HvSettings", "");
130
131 str = env.GetValue("Runs", "");
132 Split(str, fRuns);
133 str = env.GetValue("CalRuns", "");
134 Split(str, fCalRuns);
135 str = env.GetValue("PedRuns", "");
136 Split(str, fPedRuns);
137 str = env.GetValue("DatRuns", "");
138 Split(str, fDatRuns);
139}
140
141// --------------------------------------------------------------------------
142//
143// Print the contents of the sequence
144//
145void MSequence::Print(Option_t *o) const
146{
147 gLog << all;
148 if (!IsValid())
149 {
150 gLog << "Sequence: " << fName << " <invalid>" << endl;
151 return;
152 }
153 gLog << "Sequence: " << fSequence << endl;
154 gLog << "Period: " << fPeriod << endl;
155 gLog << "Night: " << fNight << endl << endl;
156 gLog << "Start: " << fStart << endl;
157 gLog << "LastRun: " << fLastRun << endl;
158 gLog << "NumEvents: " << fNumEvents << endl;
159 gLog << "Project: " << fProject << endl;
160 gLog << "Source: " << fSource << endl;
161 gLog << "TriggerTable: " << fTriggerTable << endl;
162 gLog << "HvSettings: " << fHvSettings << endl << endl;
163 gLog << "Runs:";
164 for (int i=0; i<fRuns.GetSize(); i++)
165 gLog << " " << fRuns[i];
166 gLog << endl;
167 gLog << "CalRuns:";
168 for (int i=0; i<fCalRuns.GetSize(); i++)
169 gLog << " " << fCalRuns[i];
170 gLog << endl;
171 gLog << "PedRuns:";
172 for (int i=0; i<fPedRuns.GetSize(); i++)
173 gLog << " " << fPedRuns[i];
174 gLog << endl;
175 gLog << "DatRuns:";
176 for (int i=0; i<fDatRuns.GetSize(); i++)
177 gLog << " " << fDatRuns[i];
178 gLog << endl;
179}
180
181// --------------------------------------------------------------------------
182//
183// Add all ped runs from the sequence to MDirIter.
184// If path==0 the standard path of the data-center is assumed.
185// If you have the runs locally use path="."
186// Using raw=kTRUE you get correspodning raw-files setup.
187// Return the number of files added.
188//
189Int_t MSequence::SetupPedRuns(MDirIter &iter, const char *path, Bool_t raw) const
190{
191 return SetupRuns(iter, fPedRuns, path, raw);
192}
193
194// --------------------------------------------------------------------------
195//
196// Add all data runs from the sequence to MDirIter.
197// If path==0 the standard path of the data-center is assumed.
198// If you have the runs locally use path="."
199// Using raw=kTRUE you get correspodning raw-files setup.
200// Return the number of files added.
201//
202Int_t MSequence::SetupDatRuns(MDirIter &iter, const char *path, Bool_t raw) const
203{
204 return SetupRuns(iter, fDatRuns, path, raw);
205}
206
207// --------------------------------------------------------------------------
208//
209// Add all runs from the sequence to MDirIter.
210// If path==0 the standard path of the data-center is assumed.
211// If you have the runs locally use path="."
212// Using raw=kTRUE you get correspodning raw-files setup.
213// Return the number of files added.
214//
215Int_t MSequence::SetupAllRuns(MDirIter &iter, const char *path, Bool_t raw) const
216{
217 return SetupRuns(iter, fRuns, path, raw);
218}
219
220// --------------------------------------------------------------------------
221//
222// Add all calibration runs from the sequence to MDirIter.
223// If path==0 the standard path of the data-center is assumed.
224// If you have the runs locally use path="."
225// Using raw=kTRUE you get correspodning raw-files setup.
226// Return the number of files added.
227//
228Int_t MSequence::SetupCalRuns(MDirIter &iter, const char *path, Bool_t raw) const
229{
230 return SetupRuns(iter, fCalRuns, path, raw);
231}
Note: See TracBrowser for help on using the repository browser.