1 | // $Id: EsafSys.cc 2590 2006-03-17 14:21:38Z thea $ |
---|
2 | // Author: Alessandro Thea 2005/05/19 |
---|
3 | |
---|
4 | /***************************************************************************** |
---|
5 | * ESAF: Euso Simulation and Analysis Framework * |
---|
6 | * * |
---|
7 | * Id: EsafSys * |
---|
8 | * Package: Base * |
---|
9 | * Coordinator: <coordinator> * |
---|
10 | * * |
---|
11 | *****************************************************************************/ |
---|
12 | |
---|
13 | //_____________________________________________________________________________ |
---|
14 | // |
---|
15 | // EsafSys |
---|
16 | // |
---|
17 | // <extensive class description> |
---|
18 | // |
---|
19 | // Config file parameters |
---|
20 | // ====================== |
---|
21 | // |
---|
22 | // <parameter name>: <parameter description> |
---|
23 | // -Valid options: <available options> |
---|
24 | // |
---|
25 | |
---|
26 | #include "EsafSys.hh" |
---|
27 | #include <TSystem.h> |
---|
28 | |
---|
29 | EsafSys* gEsafSys(NULL); |
---|
30 | |
---|
31 | |
---|
32 | #define str(s) _QUOTE_(s) |
---|
33 | |
---|
34 | #if !defined(ESAFARCH) |
---|
35 | #warning ESAFARCH missing, assuming ESAFARCH=i686 |
---|
36 | #define ESAFARCH i686 |
---|
37 | #endif |
---|
38 | |
---|
39 | ClassImp(EsafSys) |
---|
40 | |
---|
41 | //_____________________________________________________________________________ |
---|
42 | EsafSys::EsafSys( Bool_t absolute ) { |
---|
43 | // |
---|
44 | // Constructor |
---|
45 | // |
---|
46 | |
---|
47 | |
---|
48 | fArch = str(ESAFARCH); |
---|
49 | fRootVers = ROOT_RELEASE; |
---|
50 | fCxxVers = str(ESAFCXX); |
---|
51 | |
---|
52 | if ( absolute && gSystem->Getenv("ESAFSYS") ) { |
---|
53 | fPath = gSystem->Getenv("ESAFSYS"); |
---|
54 | gSystem->ExpandPathName(fPath); |
---|
55 | } else |
---|
56 | fPath = "."; |
---|
57 | |
---|
58 | if ( fPath[fPath.Length()-1] == '/') |
---|
59 | fPath.Remove(fPath.Length()-1); |
---|
60 | |
---|
61 | CheckDirSyntax(fPath); |
---|
62 | |
---|
63 | SetAuxPath(AbsolutePath("auxilar")); |
---|
64 | SetBinPath(AbsolutePath("bin/"+fArch)); |
---|
65 | SetLibPath(AbsolutePath("lib/"+fArch)); |
---|
66 | SetOutPath(AbsolutePath("output")); |
---|
67 | SetCfgPath(AbsolutePath("config")); |
---|
68 | SetTmpPath(AbsolutePath("tmp")); |
---|
69 | } |
---|
70 | |
---|
71 | //_____________________________________________________________________________ |
---|
72 | EsafSys::EsafSys( const char* path ) { |
---|
73 | // |
---|
74 | // Constructor |
---|
75 | // |
---|
76 | fArch = str(ESAFARCH); |
---|
77 | fRootVers = ROOT_RELEASE; |
---|
78 | fCxxVers = str(ESAFCXX); |
---|
79 | |
---|
80 | fPath = path; |
---|
81 | |
---|
82 | CheckDirSyntax(fPath); |
---|
83 | |
---|
84 | SetAuxPath(AbsolutePath("auxilar")); |
---|
85 | SetBinPath(AbsolutePath("bin/"+fArch)); |
---|
86 | SetLibPath(AbsolutePath("lib/"+fArch)); |
---|
87 | SetOutPath(AbsolutePath("output")); |
---|
88 | SetCfgPath(AbsolutePath("config")); |
---|
89 | SetTmpPath(AbsolutePath("tmp")); |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | //_____________________________________________________________________________ |
---|
94 | EsafSys::~EsafSys() { |
---|
95 | // |
---|
96 | // Destructor |
---|
97 | // |
---|
98 | |
---|
99 | if ( gEsafSys == this ) |
---|
100 | gEsafSys = NULL; |
---|
101 | } |
---|
102 | |
---|
103 | //______________________________________________________________________________ |
---|
104 | const char* EsafSys::AbsolutePath( const char* path ) const { |
---|
105 | static TString str; |
---|
106 | str = path; |
---|
107 | AbsolutePath(str); |
---|
108 | return str.Data(); |
---|
109 | } |
---|
110 | |
---|
111 | //______________________________________________________________________________ |
---|
112 | TString& EsafSys::AbsolutePath( TString& path ) const { |
---|
113 | // |
---|
114 | // . => . |
---|
115 | // .. => .. |
---|
116 | // ./ => ./ |
---|
117 | // ../ => ../ |
---|
118 | // ~ => ~ |
---|
119 | // / => / |
---|
120 | // |
---|
121 | // @tmp => fTmpPath |
---|
122 | // .. |
---|
123 | // |
---|
124 | |
---|
125 | if ( path.IsNull() ) |
---|
126 | path = fPath; |
---|
127 | else if ( path[0]=='/' || path[0]=='~' || path[0]=='.') |
---|
128 | return path; |
---|
129 | else if ( path.BeginsWith("@aux" ) && !( path.Length() > 4 && path[4]!='/' ) ) |
---|
130 | path.Replace(0,4,fAuxPath); |
---|
131 | else if ( path.BeginsWith("@out" ) && !( path.Length() > 4 && path[4]!='/' ) ) |
---|
132 | path.Replace(0,4,fOutPath); |
---|
133 | else if ( path.BeginsWith("@cfg" ) && !( path.Length() > 4 && path[4]!='/' ) ) |
---|
134 | path.Replace(0,4,fCfgPath); |
---|
135 | else if ( path.BeginsWith("@tmp" ) && !( path.Length() > 4 && path[4]!='/' ) ) |
---|
136 | path.Replace(0,4,fTmpPath); |
---|
137 | else if ( fPath != "." && fPath != "./" ) |
---|
138 | path.Prepend(fPath); |
---|
139 | return path; |
---|
140 | } |
---|
141 | |
---|
142 | //______________________________________________________________________________ |
---|
143 | TString& EsafSys::CheckDirSyntax( TString& path ) const { |
---|
144 | |
---|
145 | if ( path[path.Length()-1] != '/') |
---|
146 | path += '/'; |
---|
147 | |
---|
148 | return path; |
---|
149 | } |
---|
150 | |
---|