GENIEGenerator
Loading...
Searching...
No Matches
genie::utils::system Namespace Reference

System utilities. More...

Functions

vector< string > GetAllFilesInPath (string path, string extension="")
int GenieMajorVrsNum (string tag)
int GenieMinorVrsNum (string tag)
int GenieRevisVrsNum (string tag)
bool FileExists (string filename)
bool DirectoryExists (const char *path)
string LocalTimeAsString (string format)

Detailed Description

System utilities.

Author
Costas Andreopoulos <c.andreopoulos \at cern.ch> University of Liverpool
Created:\n Oct 08, 2009
License:\n Copyright (c) 2003-2025, The GENIE Collaboration
For the full text of the license visit http://copyright.genie-mc.org

Function Documentation

◆ DirectoryExists()

bool genie::utils::system::DirectoryExists ( const char * path)

Definition at line 92 of file SystemUtils.cxx.

92 {
93
94 struct stat info;
95
96 if( stat( path, &info ) != 0 ) {
97 return false ;
98 } else if(info.st_mode & S_IFDIR) {
99 return true ;
100 } else {
101 return false ;
102 }
103}

Referenced by genie::TuneId::CheckDirectory().

◆ FileExists()

bool genie::utils::system::FileExists ( string filename)

Definition at line 80 of file SystemUtils.cxx.

81{
82 if(filename.size() == 0) return false;
83
84 bool is_accessible = ! (gSystem->AccessPathName(filename.c_str()));
85 if (is_accessible) return true;
86
87 return false;
88}

Referenced by GetCommandLineArgs(), and genie::utils::app_init::XSecTable().

◆ GenieMajorVrsNum()

int genie::utils::system::GenieMajorVrsNum ( string tag)

Definition at line 59 of file SystemUtils.cxx.

60{
61 vector<string> vrs = utils::str::Split(tag,".");
62 assert(vrs.size() == 3);
63 return atoi(vrs[0].c_str());
64}
vector< string > Split(string input, string delim)

References genie::utils::str::Split().

Referenced by ConvertToGTracker().

◆ GenieMinorVrsNum()

int genie::utils::system::GenieMinorVrsNum ( string tag)

Definition at line 66 of file SystemUtils.cxx.

67{
68 vector<string> vrs = utils::str::Split(tag,".");
69 assert(vrs.size() == 3);
70 return atoi(vrs[1].c_str());
71}

References genie::utils::str::Split().

Referenced by ConvertToGTracker().

◆ GenieRevisVrsNum()

int genie::utils::system::GenieRevisVrsNum ( string tag)

Definition at line 73 of file SystemUtils.cxx.

74{
75 vector<string> vrs = utils::str::Split(tag,".");
76 assert(vrs.size() == 3);
77 return atoi(vrs[2].c_str());
78}

References genie::utils::str::Split().

Referenced by ConvertToGTracker().

◆ GetAllFilesInPath()

vector< string > genie::utils::system::GetAllFilesInPath ( string path,
string extension = "" )

Definition at line 29 of file SystemUtils.cxx.

30{
31 vector<string> files;
32
33 DIR *dp = NULL;
34 struct dirent *dirp = NULL;
35 if((dp = opendir(path.c_str())) == NULL) {
36 LOG("System", pERROR) << "Can not open directory: " << path;
37 }
38 else {
39 while ((dirp = readdir(dp)) != NULL) {
40 string filename = path + "/" + string(dirp->d_name);
41 bool match = false;
42 if(extension.size()==0) match=true; // get all files
43 else {
44 // match extension
45 vector<string> filenamev = genie::utils::str::Split(filename,".");
46 if(filenamev.size()==0) break;
47 string file_extension = filenamev[filenamev.size()-1];
48 match = (file_extension.find(extension) != string::npos);
49 }
50 if(match) {
51 files.push_back(filename);
52 }
53 }
54 closedir(dp);
55 }
56 return files;
57}
#define pERROR
Definition Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96

References LOG, pERROR, and genie::utils::str::Split().

Referenced by GetAllInputFiles().

◆ LocalTimeAsString()

string genie::utils::system::LocalTimeAsString ( string format)

Definition at line 107 of file SystemUtils.cxx.

108{
109 time_t now = time(0);
110 tm* local_time = localtime(&now);
111
112 int yr = local_time->tm_year + 1900;
113 int mon = local_time->tm_mon + 1;
114 int day = local_time->tm_mday;
115 int hr = local_time->tm_hour + 1;
116 int min = local_time->tm_min;
117 int sec = local_time->tm_sec;
118
119 // daylight saving
120 if(local_time->tm_isdst > 0)
121 {
122 if(hr > 0) {
123 hr--;
124 }
125 else
126 if(hr == 0) {
127 hr = 23;
128 if(day > 1) {
129 day--;
130 }
131 else {
132 mon--;
133 if(mon == 1 || mon == 3 || mon == 5 ||
134 mon == 7 || mon == 8 || mon == 10 || mon == 12)
135 {
136 day = 31;
137 }
138 else
139 if(mon == 2)
140 {
141 day = 28;
142 }
143 else
144 {
145 day = 30;
146 }
147 }
148 }
149 }
150
151 string local_time_as_string =
152 Form(format.c_str(),yr,mon,day,hr,min,sec);
153
154 return local_time_as_string;
155}