source: trunk/MagicSoft/Mars/mjobs/MDataSet.cc@ 6731

Last change on this file since 6731 was 6453, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.4 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, 1/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2004-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MDataSet
28//
29// This class describes a collection of sequences.
30//
31// Such an input file looks like:
32//
33// crab.seq:
34// ---------
35// AnalysisNumber: 1
36//
37// SequencesOn: 35222
38// SequencesOff: 36817
39//
40// Sequence00035222.File: sequences/sequence035222.txt
41// Sequence00036817.File: sequences/sequence036817.txt
42//
43// Sequence00035222.Dir: /data2/wuerzburg/Crab-Analyse/images/035222
44// Sequence00036817.Dir: /data2/wuerzburg/Crab-Analyse/images/036817
45//
46// The analysis number is an artifical number used to name the output
47// files automatically if the names are not overwritten in the corresponding
48// programs.
49//
50// The sequence number are used to concatenate the filenames of the
51// sequences using the file structure used in the datacenter.
52//
53// If you have different file names you can overwrite the default file names
54// using Sequence%08d.File (make sure you have 8 digits!)
55//
56// In standard coditions (datacenter file system) paths are concatenated
57// by using the information in the sequence files (date, etc). You can
58// overwrite the directories in which the sequence-files (eg I-files) are
59// stored using Sequence%08d.Dir (make sure you have 8 digits!)
60//
61// Resource file entries are case sensitive!
62//
63// MISSING (27/01/04): The default name and paths cannot be used yet, because
64// they have to be defined soon.
65//
66/////////////////////////////////////////////////////////////////////////////
67#include "MDataSet.h"
68
69#include <stdlib.h>
70
71#include <TEnv.h>
72#include <TRegexp.h>
73#include <TSystem.h> // TSystem::ExpandPath
74
75#include "MLog.h"
76#include "MLogManip.h"
77
78#include "MRead.h"
79#include "MDirIter.h"
80#include "MSequence.h"
81
82ClassImp(MDataSet);
83
84using namespace std;
85
86// --------------------------------------------------------------------------
87//
88// Copy the run numbers from the TString runs into the TArrayI data
89//
90void MDataSet::Split(TString &runs, TArrayI &data) const
91{
92 const TRegexp regexp("[0-9]+");
93
94 data.Set(0);
95 runs = runs.Strip(TString::kTrailing);
96
97 while (!runs.IsNull())
98 {
99 TString num = runs(regexp);
100
101 const Int_t n = data.GetSize();
102 data.Set(n+1);
103 data[n] = atoi(num.Data());
104
105 runs.Remove(0, runs.First(num)+num.Length());
106 }
107}
108
109void MDataSet::ResolveSequences(TEnv &env, const TArrayI &num, TList &list) const
110{
111 for (int i=0; i<num.GetSize(); i++)
112 {
113 TString name = env.GetValue(Form("Sequence%08d.File", num[i]), "");
114 TString dir = env.GetValue(Form("Sequence%08d.Dir", num[i]), "");
115
116 if (name.IsNull())
117 {
118 // Replace with correct default name
119 name = Form("/data2/wuerzburg/sequences/sequence%08d.txt", num[i]);
120 }
121 /*
122 if (dir.IsNull())
123 {
124 // Replace with default dir
125 }
126 */
127
128 if (gSystem->AccessPathName(name, kFileExists))
129 gLog << warn << "WARNING - Sequence file '" << name << "' doesn't exist." << endl;
130
131 if (gSystem->AccessPathName(dir, kFileExists))
132 gLog << warn << "WARNING - Directory '" << dir << "' doesn't exist." << endl;
133
134 list.Add(new TNamed(name, dir));
135 }
136}
137
138// --------------------------------------------------------------------------
139//
140// Read the file fname as setup file for the sequence.
141//
142MDataSet::MDataSet(const char *fname)
143{
144 fName = fname;
145
146 const char *expname = gSystem->ExpandPathName(fname);
147
148 fTitle = Form("Sequences contained in file %s", expname);
149
150 TEnv env(expname);
151 delete [] expname;
152
153 TString str;
154
155 fNumAnalysis = env.GetValue("AnalysisNumber", -1);
156
157 str = env.GetValue("SequencesOn", "");
158 Split(str, fNumSequencesOn);
159 str = env.GetValue("SequencesOff", "");
160 Split(str, fNumSequencesOff);
161
162
163 ResolveSequences(env, fNumSequencesOn, fSequencesOn);
164 ResolveSequences(env, fNumSequencesOff, fSequencesOff);
165
166
167
168 //Print();
169 /*
170 GetFileNames(env, fSequencesOn);
171 GetFileNames(env, fSequencesOff);
172 */
173}
174
175// --------------------------------------------------------------------------
176//
177// Return '+' if both can be accessed, '-' otherwise.
178//
179void MDataSet::PrintFile(const TObject &obj)
180{
181 const Bool_t access = !gSystem->AccessPathName(obj.GetName(), kFileExists) && !gSystem->AccessPathName(obj.GetTitle(), kFileExists) ? '+' : '-';
182 gLog << " " << (access?"+":"-") << " " << obj.GetName() << " <" << obj.GetTitle() << ">" << endl;
183}
184
185// --------------------------------------------------------------------------
186//
187// Print the contents of the sequence
188//
189void MDataSet::Print(Option_t *o) const
190{
191 gLog << all;
192 if (!IsValid())
193 {
194 gLog << "Sequence: " << fName << " <invalid>" << endl;
195 return;
196 }
197 gLog << "Analysis Number: " << fNumAnalysis << endl;
198 gLog << "Sequences On: ";
199 for (int i=0; i<fNumSequencesOn.GetSize(); i++)
200 gLog << " " << fNumSequencesOn[i];
201 gLog << endl;
202 gLog << "Sequences Off: ";
203 for (int i=0; i<fNumSequencesOff.GetSize(); i++)
204 gLog << " " << fNumSequencesOff[i];
205 gLog << endl;
206
207 if (!TString(o).Contains("files", TString::kIgnoreCase))
208 return;
209
210 TObject *obj=0;
211
212 gLog << endl;
213 gLog << "On-Data Files:" << endl;
214 TIter NextOn(&fSequencesOn);
215 while ((obj=NextOn()))
216 PrintFile(*obj);
217
218 gLog << endl;
219 gLog << "Off-Data Files:" << endl;
220 TIter NextOff(&fSequencesOff);
221 while ((obj=NextOff()))
222 PrintFile(*obj);
223}
224
225Bool_t MDataSet::AddSequencesToList(const TList &list, MRead &read, char *id, Bool_t raw)
226{
227 MDirIter files;
228
229 TIter Next(const_cast<TList*>(&list));
230 TObject *o=0;
231 while ((o=Next()))
232 {
233 MSequence seq(o->GetName());
234 if (!seq.IsValid())
235 {
236 gLog << warn << "WARNING - Sequence " << o->GetName() << " invalid!" << endl;
237 return kFALSE;
238 }
239
240 const TString dir(o->GetTitle());
241 seq.SetupDatRuns(files, dir.IsNull() ? 0 : dir.Data(), id, raw);
242 }
243
244 return read.AddFiles(files)>0;
245}
246
247Bool_t MDataSet::AddFiles(MRead &read, char *id, Bool_t raw) const
248{
249 const Bool_t rc1 = AddFilesOff(read, id, raw);
250 const Bool_t rc2 = AddFilesOn(read, id, raw);
251 return rc1 && rc2;
252}
253
254Bool_t MDataSet::AddFilesOn(MRead &read, char *id, Bool_t raw) const
255{
256 return AddSequencesToList(fSequencesOn, read, id, raw);
257}
258
259Bool_t MDataSet::AddFilesOff(MRead &read, char *id, Bool_t raw) const
260{
261 return AddSequencesToList(fSequencesOff, read, id, raw);
262}
Note: See TracBrowser for help on using the repository browser.