/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Event/RawFile/RawFile-00-00-10/src/RawFileTools.cxx

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include "RawFile/RawFileTools.h"
00004 #include <stdio.h>
00005 
00006 std::vector<std::string> RawFileTools::wildcard_correct(const std::string& fname)
00007 {
00008    static char pbuf[8192];
00009    static const std::string lsCom("/bin/ls ");
00010 
00011    std::vector<std::string> newfnames;
00012 
00013    if ( ( fname.find('*', 0) != std::string::npos ) ||
00014          ( fname.find('?', 0) != std::string::npos ) )
00015    {
00016       FILE* ftmp = popen((lsCom+fname).c_str(), "r");
00017 
00018       std::stringstream  fnstream;
00019       while ( fgets(pbuf, 8192, ftmp) != NULL ) {
00020          fnstream << pbuf;
00021       }
00022 
00023       std::string tfn;
00024       while ( ! (fnstream>>tfn).eof() ) {
00025          newfnames.push_back(tfn);
00026       }
00027    }
00028    else {
00029       newfnames.push_back(fname);
00030    }
00031 
00032    return newfnames;
00033 }
00034 
00035 std::vector<std::string> RawFileTools::wildcard_correct(const std::vector<std::string>& fnames)
00036 {
00037    static char pbuf[8192];
00038    static const std::string lsCom("/bin/ls ");
00039 
00040    std::vector<std::string> newfnames;
00041    std::string fname;
00042    std::stringstream  fnstream;
00043    std::vector<std::string>::const_iterator it = fnames.begin();
00044 
00045    while ( it != fnames.end() ) {
00046       if ( ( it->find('*', 0) != std::string::npos ) ||
00047            ( it->find('?', 0) != std::string::npos ) ) {
00048          // list and get the wildcard files
00049          std::string com = lsCom + (*it);
00050          FILE* ftmp = popen(com.c_str(), "r");
00051 
00052          fnstream.clear();
00053          while ( fgets(pbuf, 8192, ftmp) != NULL ) {
00054             fnstream << pbuf;
00055          }
00056 
00057          while ( ! (fnstream>>fname).eof() ) {
00058             newfnames.push_back(fname);
00059          }
00060       }
00061       else {
00062          newfnames.push_back(*it);
00063       }
00064       ++it;
00065    }
00066 
00067    return newfnames;
00068 }
00069 
00070 std::string RawFileTools::fname2idxname(const std::string& fname)
00071 {
00072    std::string::size_type pathend = fname.rfind('/', fname.length());
00073    std::string idxname = (pathend != std::string::npos ) ? fname.substr(pathend+1) : fname;
00074 
00075    idxname += ".idx";
00076 
00077    return idxname;
00078 }
00079 
00080 std::string RawFileTools::itoa(int i)
00081 {
00082    std::stringstream  sstr;
00083    sstr << i;
00084 
00085    std::string str;
00086    sstr >> str;
00087 
00088    while ( str.length() < 3 ) {
00089       str = std::string("0") + str;
00090    }
00091 
00092    return str;
00093 }

Generated on Tue Nov 29 22:58:36 2016 for BOSS_7.0.2 by  doxygen 1.4.7