BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
RawFileTools.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <sstream>
4
5std::vector<std::string> RawFileTools::wildcard_correct(const std::string& fname)
6{
7 static char pbuf[8192];
8 static const std::string lsCom("/bin/ls ");
9
10 std::vector<std::string> newfnames;
11
12 if ( ( fname.find('*', 0) != std::string::npos ) ||
13 ( fname.find('?', 0) != std::string::npos ) )
14 {
15 FILE* ftmp = popen((lsCom+fname).c_str(), "r");
16
17 std::stringstream fnstream;
18 while ( fgets(pbuf, 8192, ftmp) != NULL ) {
19 fnstream << pbuf;
20 }
21
22 std::string tfn;
23 while ( ! (fnstream>>tfn).eof() ) {
24 newfnames.push_back(tfn);
25 }
26 }
27 else {
28 newfnames.push_back(fname);
29 }
30
31 return newfnames;
32}
33
34std::vector<std::string> RawFileTools::wildcard_correct(const std::vector<std::string>& fnames)
35{
36 static char pbuf[8192];
37 static const std::string lsCom("/bin/ls ");
38
39 std::vector<std::string> newfnames;
40 std::string fname;
41 std::stringstream fnstream;
42 std::vector<std::string>::const_iterator it = fnames.begin();
43
44 while ( it != fnames.end() ) {
45 if ( ( it->find('*', 0) != std::string::npos ) ||
46 ( it->find('?', 0) != std::string::npos ) ) {
47 // list and get the wildcard files
48 std::string com = lsCom + (*it);
49 FILE* ftmp = popen(com.c_str(), "r");
50
51 fnstream.clear();
52 while ( fgets(pbuf, 8192, ftmp) != NULL ) {
53 fnstream << pbuf;
54 }
55
56 while ( ! (fnstream>>fname).eof() ) {
57 newfnames.push_back(fname);
58 }
59 }
60 else {
61 newfnames.push_back(*it);
62 }
63 ++it;
64 }
65
66 return newfnames;
67}
68
69std::string RawFileTools::fname2idxname(const std::string& fname)
70{
71 std::string::size_type pathend = fname.rfind('/', fname.length());
72 std::string idxname = (pathend != std::string::npos ) ? fname.substr(pathend+1) : fname;
73
74 idxname += ".idx";
75
76 return idxname;
77}
78
79std::string RawFileTools::itoa(int i)
80{
81 std::stringstream sstr;
82 sstr << i;
83
84 std::string str;
85 sstr >> str;
86
87 while ( str.length() < 3 ) {
88 str = std::string("0") + str;
89 }
90
91 return str;
92}
std::vector< std::string > wildcard_correct(const std::string &fname)
Definition: RawFileTools.cxx:5
std::string itoa(int i)
std::string fname2idxname(const std::string &fname)