RootUtil::FileFinder Class Reference

#include <FileFinder.h>

List of all members.

Public Member Functions

 FileFinder ()
 ~FileFinder ()
void SetKey (const std::string &value)
void SetRunRange (int first_run, int last_run)
void SetRunPosition (int beg_pos, int length)
int SearchPath (const std::string &path)
void SetRecursiveDepth (short depth)
void SetIndexFile (const std::string &index_file)
unsigned int GetNFiles () const
std::string GetFile (int index) const
double FileSize (int index=-1) const
void Print () const

Private Member Functions

int Search (std::string path, short depth)
bool FindMatch (const std::string &file_name)
bool CheckFileName (const std::string &name, const std::string &path)
int GetRunNumber (const std::string &filename) const

Private Attributes

int fFirstRun
int fLastRun
int fRunNumberPos
int fRunNumberLen
int fRecursiveDepth
bool fUseIndex
std::vector< std::string > fKeys
std::vector< std::string > fNames
std::vector< std::string > fFiles
std::vector< std::string > fIndex

Detailed Description

Definition at line 11 of file FileFinder.h.


Constructor & Destructor Documentation

FileFinder::FileFinder (  ) 

Definition at line 12 of file FileFinder.cxx.

00013    :fFirstRun(0),
00014     fLastRun(0),
00015     fRunNumberPos(0),
00016     fRunNumberLen(0),
00017     fRecursiveDepth(1),
00018     fUseIndex(false),
00019     fKeys(),
00020     fNames(),
00021     fFiles()
00022 {    
00023 }

FileFinder::~FileFinder (  ) 

Definition at line 26 of file FileFinder.cxx.

00027 {
00028 }


Member Function Documentation

bool FileFinder::CheckFileName ( const std::string &  name,
const std::string &  path 
) [private]

Definition at line 189 of file FileFinder.cxx.

References fFiles, find(), fNames, and it.

00190 {
00191    if(find(fNames.begin(), fNames.end(), name) != fNames.end())
00192    {
00193       cerr << "Error: found duplicate files: " << endl;
00194       cerr << path << endl;
00195       
00196       for(vector<string>::const_iterator it = fFiles.begin(); it != fFiles.end(); ++it)
00197       {
00198          if(it -> find(name) != string::npos)
00199          {
00200             cerr << *it << endl;
00201          }
00202       }
00203       return false;
00204    }
00205    
00206    fNames.push_back(name);
00207    return true;
00208 }

double FileFinder::FileSize ( int  index = -1  )  const

Definition at line 247 of file FileFinder.cxx.

References fFiles, GetFile(), gSystem(), it, and size.

00248 {
00249    if(index >= 0)
00250    {
00251       const string filepath = GetFile(index);
00252       FileStat_t stat;
00253       stat.fSize = 0;
00254       if(gSystem -> GetPathInfo(filepath.c_str(), stat) == 0 && stat.fSize > 1)
00255       {
00256          return double(stat.fSize)/1048576.0;
00257       }
00258 
00259       return 0.0;
00260    }
00261       
00262    double size = 0.0;
00263    for(vector<string>::const_iterator it = fFiles.begin(); it != fFiles.end(); ++it)
00264    {
00265       FileStat_t stat;
00266       stat.fSize = 0;
00267       
00268       const string &file = *it;
00269 
00270       if(gSystem -> GetPathInfo(file.c_str(), stat) == 0 && stat.fSize > 1)
00271       {
00272          size += double(stat.fSize);
00273       }
00274    }
00275    return size/1048576.0;
00276 }

bool RootUtil::FileFinder::FindMatch ( const std::string &  file_name  )  [private]
string FileFinder::GetFile ( int  index  )  const

Definition at line 235 of file FileFinder.cxx.

References fFiles.

Referenced by FileSize().

00236 {
00237    if(index < 0 || index >= int(fFiles.size()))
00238    {
00239       cerr << "Index is out of range, returning empty string" << endl;
00240       return string();
00241    }
00242 
00243    return fFiles[index];
00244 }

unsigned int RootUtil::FileFinder::GetNFiles (  )  const [inline]

Definition at line 41 of file FileFinder.h.

References fFiles.

00041 { return fFiles.size(); }

int RootUtil::FileFinder::GetRunNumber ( const std::string &  filename  )  const [private]
void FileFinder::Print ( void   )  const

Definition at line 279 of file FileFinder.cxx.

References fFirstRun, fIndex, fKeys, fLastRun, fRecursiveDepth, fRunNumberLen, fRunNumberPos, fUseIndex, and it.

00280 {
00281    cout << "FileFinder: printing config parameters "<< endl;
00282    
00283    cout << "Recurisive depth of directory search = " << fRecursiveDepth << endl;
00284 
00285    if(!fUseIndex)
00286    {
00287       cout << "Searching for files containing the following substrings " << endl;
00288       for(vector<string>::const_iterator it = fKeys.begin(); it != fKeys.end(); ++it)
00289       {
00290          cout << "Key: " << *it << endl;
00291       }
00292    }
00293    if(fUseIndex)
00294    {
00295       cout << "Searching for the following files: " << endl;
00296       for(vector<string>::const_iterator it = fIndex.begin(); it != fIndex.end(); ++it)
00297       {
00298          cout << *it; 
00299       }
00300    }
00301    
00302    if(fFirstRun > 0 && fLastRun > fFirstRun)
00303    {
00304       cout << "File's run number must be in the range " << fFirstRun << " - " << fLastRun << endl;
00305       cout << "In file name string run number starts at " << fRunNumberPos << " position and extends for "
00306            << fRunNumberLen << " characters" << endl;
00307    }
00308 }

int RootUtil::FileFinder::Search ( std::string  path,
short  depth 
) [private]

Referenced by SearchPath().

int RootUtil::FileFinder::SearchPath ( const std::string &  path  )  [inline]

Definition at line 29 of file FileFinder.h.

References Search().

00029 { return Search(path, 0); }

void FileFinder::SetIndexFile ( const std::string &  index_file  ) 

Definition at line 154 of file FileFinder.cxx.

References fIndex, fUseIndex, and infile.

00155 {
00156    ifstream infile(index_file.c_str());
00157 
00158    if(!infile)
00159    {
00160       cerr << "Failed to open file " << index_file << endl;
00161       return;
00162    }
00163    
00164    fUseIndex = true;
00165 
00166    do
00167    {
00168       string tmp;
00169       infile >> tmp;
00170       
00171       if(infile.eof()) break;
00172 
00173       fIndex.push_back(tmp);
00174    } while(!infile.eof());
00175 }

void RootUtil::FileFinder::SetKey ( const std::string &  value  ) 
void FileFinder::SetRecursiveDepth ( short  depth  ) 

Definition at line 73 of file FileFinder.cxx.

References fRecursiveDepth.

00074 {
00075    if(depth < 1 || depth > 100)
00076    {
00077       cerr << "Invalid recursive depth setting: " << depth << endl;
00078       return;
00079    }
00080    fRecursiveDepth = depth;  
00081 }

void FileFinder::SetRunPosition ( int  beg_pos,
int  length 
)

Definition at line 60 of file FileFinder.cxx.

References fRunNumberLen, and fRunNumberPos.

00061 {
00062    if(beg_pos < 0 || length < 0)
00063    {
00064       cerr << "Invalid position = " << beg_pos << " or length = " << length << " setting" << endl;
00065       return;
00066    }
00067    
00068    fRunNumberPos = beg_pos;
00069    fRunNumberLen = length;
00070 }

void FileFinder::SetRunRange ( int  first_run,
int  last_run 
)

Definition at line 47 of file FileFinder.cxx.

References fFirstRun, and fLastRun.

00048 {
00049    if(first_run < 1 || first_run < 1 || last_run < first_run)
00050    {
00051       cerr << "Bad run numbers range: " << first_run << " - " << last_run << endl;
00052       return;
00053    }
00054    
00055    fFirstRun = first_run;
00056    fLastRun  = last_run;
00057 }


Member Data Documentation

std::vector<std::string> RootUtil::FileFinder::fFiles [private]

Definition at line 82 of file FileFinder.h.

Referenced by CheckFileName(), FileSize(), GetFile(), and GetNFiles().

Definition at line 65 of file FileFinder.h.

Referenced by Print(), and SetRunRange().

std::vector<std::string> RootUtil::FileFinder::fIndex [private]

Definition at line 85 of file FileFinder.h.

Referenced by Print(), and SetIndexFile().

std::vector<std::string> RootUtil::FileFinder::fKeys [private]

Definition at line 76 of file FileFinder.h.

Referenced by Print().

Definition at line 66 of file FileFinder.h.

Referenced by Print(), and SetRunRange().

std::vector<std::string> RootUtil::FileFinder::fNames [private]

Definition at line 79 of file FileFinder.h.

Referenced by CheckFileName().

Definition at line 71 of file FileFinder.h.

Referenced by Print(), and SetRecursiveDepth().

Definition at line 69 of file FileFinder.h.

Referenced by Print(), and SetRunPosition().

Definition at line 68 of file FileFinder.h.

Referenced by Print(), and SetRunPosition().

Definition at line 73 of file FileFinder.h.

Referenced by Print(), and SetIndexFile().


The documentation for this class was generated from the following files:

Generated on 21 Jun 2018 for loon by  doxygen 1.6.1