EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicLibrary.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicLibrary.cxx
1 //
2 // AYK (ayk@bnl.gov), 2014/09/04
3 //
4 // Few common-use library routines with no particular class affiliation;
5 //
6 
7 #include <stdlib.h>
8 
9 #include <EicLibrary.h>
10 
11 // =======================================================================================
12 
13 //
14 // Basically a signature, that file name expansion is not needed at all (absolute
15 // path or a path with respect to the currect directory);
16 //
17 
18 bool IsSortOfAbsolutePath(const char *fileName)
19 {
20  if (!fileName) return false;
21 
22  // Make life easier;
23  TString str(fileName);
24 
25  return (str.BeginsWith("/") || str.BeginsWith("./") || str.BeginsWith("../"));
26 } // IsSortOfAbsolutePath()
27 
28 // ---------------------------------------------------------------------------------------
29 
30 TString ExpandedFileName(const char *prefix, const char *fileName)
31 {
32  if (!fileName) return TString("");
33 
34  // Well, I guess in this case just ignore prefix;
35  if (IsSortOfAbsolutePath(fileName)) return TString(fileName);
36 
37  TString expandedFileName(fileName);
38 
39  // Prepend prefix if given; THINK: take care to put '/' if missing?;
40  if (prefix) expandedFileName = prefix + expandedFileName;
41  //expandedFileName = TString(prefix) + (prefix[strlen(prefix)-1] == '/' ? "" : "/") +
42  // expandedFileName;
43 
44  return TString(getenv("VMCWORKDIR")) + "/" + expandedFileName;
45 } // ExpandedFileName()
46 
47 // ---------------------------------------------------------------------------------------
48 
49 TString ExpandedFileName(const char *fileName)
50 {
51  return ExpandedFileName(0, fileName);
52 } // ExpandedFileName()
53 
54 // =======================================================================================