Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:27

0001 #include "EventFilter/Utilities/interface/DirManager.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <iostream>
0004 
0005 namespace evf {
0006 
0007   unsigned int DirManager::findHighestRun() {
0008     DIR *dir = opendir(dir_.c_str());
0009     struct dirent *buf;
0010     int maxrun = 0;
0011     while ((buf = readdir(dir))) {
0012       std::string dirnameNum = buf->d_name;
0013       if (dirnameNum.find("run") != std::string::npos)
0014         dirnameNum = dirnameNum.substr(3, std::string::npos);
0015       if (atoi(dirnameNum.c_str()) > maxrun) {
0016         maxrun = atoi(dirnameNum.c_str());
0017       }
0018     }
0019     closedir(dir);
0020     return maxrun;
0021   }
0022 
0023   std::string DirManager::findHighestRunDir() {
0024     std::string retval = dir_ + "/";
0025     std::string tmpdir;
0026     DIR *dir = opendir(dir_.c_str());
0027     struct dirent *buf;
0028     int maxrun = 0;
0029     while ((buf = readdir(dir))) {
0030       std::string dirnameNum = buf->d_name;
0031       if (dirnameNum.find("run") != std::string::npos)
0032         dirnameNum = dirnameNum.substr(3, std::string::npos);
0033       if (atoi(dirnameNum.c_str()) > maxrun) {
0034         tmpdir = buf->d_name;
0035         maxrun = atoi(dirnameNum.c_str());
0036       }
0037     }
0038     closedir(dir);
0039     retval += tmpdir;
0040     return retval;
0041   }
0042 
0043   std::string DirManager::findRunDir(unsigned int run) {
0044     std::string retval = dir_ + "/";
0045     std::string tmpdir = "";
0046     DIR *dir = opendir(dir_.c_str());
0047     struct dirent *buf;
0048     while ((buf = readdir(dir))) {
0049       std::string dirnameNum = buf->d_name;
0050       if (dirnameNum.find("run") != std::string::npos)
0051         dirnameNum = dirnameNum.substr(3, std::string::npos);
0052       if ((unsigned int)atoi(dirnameNum.c_str()) == run) {
0053         tmpdir = buf->d_name;
0054         break;
0055       }
0056     }
0057     closedir(dir);
0058     if (tmpdir.empty())
0059       throw cms::Exception("LogicError") << "Run Directory for Run " << run << " Not Found";
0060     retval += tmpdir;
0061     return retval;
0062   }
0063 
0064   bool DirManager::checkDirEmpty(std::string &d) {
0065     int filecount = 0;
0066     DIR *dir = opendir(d.c_str());
0067     while (readdir(dir)) {
0068       filecount++;
0069     }
0070     return (filecount == 0);
0071   }
0072 }  // namespace evf