source: trunk/MagicSoft/Mars/mjobs/MJob.cc@ 4896

Last change on this file since 4896 was 4760, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 4.0 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, 2000-2004
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MJob
28//
29// A base class for jobs
30//
31/////////////////////////////////////////////////////////////////////////////
32#include "MJob.h"
33
34#include <TEnv.h>
35#include <TSystem.h>
36
37#include "MLog.h"
38#include "MLogManip.h"
39
40#include "MEvtLoop.h"
41
42ClassImp(MJob);
43
44using namespace std;
45
46// --------------------------------------------------------------------------
47//
48// Default constructor.
49//
50// Sets fRuns to 0, fExtractor to NULL, fDataCheck to kFALSE
51//
52MJob::MJob(const char *name, const char *title) : fEnv(0), fOverwrite(kFALSE), fMaxEvents(0)
53{
54 fName = name ? name : "MJob";
55 fTitle = title ? title : "Base class for jobs";
56}
57
58MJob::~MJob()
59{
60 if (fEnv)
61 delete fEnv;
62}
63
64Bool_t MJob::SetEnv(const char *env, const char *prefix)
65{
66 if (fEnv)
67 {
68 delete fEnv;
69 fEnv = 0;
70 }
71
72 const Bool_t fileexist = !gSystem->AccessPathName(env, kFileExists);
73 if (!fileexist)
74 {
75 *fLog << err << "ERROR - Resource file '" << env << "' not found... no resources applied." << endl;
76 return kFALSE;
77 }
78
79 fEnv = new TEnv(env);
80
81 fEnvPrefix = prefix;
82 if (!prefix)
83 fEnvPrefix = fName.First(' ')>0 ? fName(0, fName.First(' ')) : fName;
84
85 if (fEnvPrefix.EndsWith("."))
86 fEnvPrefix.Remove(fEnvPrefix.Length()-1);
87
88 return kTRUE;
89}
90
91void MJob::FixPath(TString &path) const
92{
93 path.ReplaceAll("\015", "");
94
95 if (path==(TString)"/")
96 return;
97
98 if (path.EndsWith("/"))
99 path.Remove(path.Length()-1);
100}
101
102void MJob::SetPathOut(const char *path)
103{
104 fPathOut = path;
105 FixPath(fPathOut);
106}
107
108void MJob::SetPathIn(const char *path)
109{
110 fPathIn = path;
111 FixPath(fPathIn);
112}
113
114void MJob::SetPathData(const char *path)
115{
116 fPathData = path;
117 FixPath(fPathData);
118}
119
120Int_t MJob::GetEnv(const char *name, Int_t dflt) const
121{
122 return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); // return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
123}
124
125Double_t MJob::GetEnv(const char *name, Double_t dflt) const
126{
127 return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); // return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
128}
129
130const char *MJob::GetEnv(const char *name, const char *dflt) const
131{
132 return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); //fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
133}
134
135Bool_t MJob::HasEnv(const char *name) const
136{
137 return IsEnvDefined(*fEnv, fEnvPrefix, name, fEnvDebug);//fEnv->Lookup(Form("%s%s", fEnvPrefix.Data(), name));
138}
139
140Bool_t MJob::CheckEnv()
141{
142 if (!fEnv)
143 return kTRUE;
144
145 TString p;
146 p = GetEnv("PathOut", "");
147 if (!p.IsNull())
148 SetPathOut(p);
149
150 p = GetEnv("PathIn", "");
151 if (!p.IsNull())
152 SetPathIn(p);
153
154 p = GetEnv("PathData", "");
155 if (!p.IsNull())
156 SetPathData(p);
157
158 SetMaxEvents(GetEnv("MaxEvents", fMaxEvents));
159 SetOverwrite(GetEnv("Overwrite", fOverwrite));
160
161 return CheckEnvLocal();
162}
163
164Bool_t MJob::SetupEnv(MEvtLoop &loop) const
165{
166 if (!fEnv)
167 return kTRUE;
168
169 return loop.ReadEnv(*fEnv, fEnvPrefix, fEnvDebug) ? kTRUE : kFALSE;
170}
Note: See TracBrowser for help on using the repository browser.