ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
GETFileChecker.cxx
Go to the documentation of this file.
1 // =================================================
2 // GETFileChecker Class
3 //
4 // Description:
5 // Check if the file exists or not
6 //
7 // Genie Jhang ( geniejhang@majimak.com )
8 // 2015. 09. 01
9 // =================================================
10 
11 // GETDecoder
12 #include "GETFileChecker.h"
13 
14 // ROOT
15 #include <TObjArray.h>
16 #include <TObjString.h>
17 #include <TString.h>
18 #include <TSystem.h>
19 // STL
20 #include <iostream>
21 
22 TString GETFileChecker::CheckFile(TString filename)
23 {
24  if (filename(0, 1) == "~")
25  filename.Replace(0, 1, gSystem->HomeDirectory());
26 
27  TString nextData = filename;
28 
29  TObjArray *pathElements = nullptr;
30  pathElements = nextData.Tokenize("/");
31 
32  Int_t numElements = pathElements->GetLast();
33 
34  TString path = "";
35  if (numElements == 0)
36  path = gSystem->pwd();
37  else {
38  if (filename(0, 1) == "/")
39  path.Append("/");
40 
41  for (Int_t i = 0; i < numElements; i++) {
42  path.Append(((TObjString *)pathElements->At(i))->GetString());
43  path.Append("/");
44  }
45  }
46 
47  TString tempDataFile = ((TObjString *)pathElements->Last())->GetString();
48  delete pathElements;
49 
50  nextData = gSystem->Which(path, tempDataFile);
51  if (!nextData.EqualTo("")) {
52  std::cout << "== [GETFileChecker] File exist: " << filename << std::endl;
53 
54  return nextData.Data();
55  } else {
56  std::cout << "== [GETFileChecker] File does not exist: " << filename << std::endl;
57 
58  return "";
59  }
60 
61  return "";
62 }
GETFileChecker.h
GETFileChecker::CheckFile
static TString CheckFile(TString filename)
Definition: GETFileChecker.cxx:22