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

Last change on this file since 4740 was 4732, 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 TString p;
143 p = GetEnv("PathOut", "");
144 if (!p.IsNull())
145 SetPathOut(p);
146
147 p = GetEnv("PathIn", "");
148 if (!p.IsNull())
149 SetPathIn(p);
150
151 p = GetEnv("PathData", "");
152 if (!p.IsNull())
153 SetPathData(p);
154
155 SetMaxEvents(GetEnv("MaxEvents", fMaxEvents));
156 SetOverwrite(GetEnv("Overwrite", fOverwrite));
157
158 return kTRUE;
159}
160
161Bool_t MJob::SetupEnv(MEvtLoop &loop) const
162{
163 if (!fEnv)
164 return kTRUE;
165
166 return loop.ReadEnv(*fEnv, fEnvPrefix, fEnvDebug) ? kTRUE : kFALSE;
167}
Note: See TracBrowser for help on using the repository browser.