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