00001 #include <iostream>
00002 #include <sstream>
00003 #include <cstdio>
00004 #include <vector>
00005 #include <cstdlib>
00006
00007 #include "TFile.h"
00008 #include "TTree.h"
00009
00010 #include "include/fun.h"
00011
00012 using namespace std;
00013
00014 vector<string> getHistList()
00015 {
00016 vector<string> fnames;
00017
00018 string command(
00019 "JobOutputDir=`/bin/ls -dt1 joboutput-* 2>/dev/null | head -1`\n"
00020 "if [ -d \"${JobOutputDir}\" ]; then\n"
00021 " find ${JobOutputDir} -name hist.root\n"
00022 "fi\n"
00023 );
00024
00025 stringstream fnstream;
00026
00027 char* fnbuf = new char[1024];
00028 FILE* fstream = popen(command.c_str(), "r");
00029
00030 while ( fgets(fnbuf, 1024, fstream) != NULL ) {
00031 fnstream << fnbuf;
00032 }
00033
00034 string fname;
00035 while ( ! (fnstream>>fname).eof() ) {
00036 fnames.push_back(fname);
00037 }
00038
00039 pclose(fstream);
00040 delete [] fnbuf;
00041
00042 if ( fnames.empty() ) {
00043 cout << "WARNING: Failed to retrieve hist files in the current directory!" << endl;
00044
00045 }
00046 return fnames;
00047 }
00048
00049 vector<string> getHistList(string path)
00050 {
00051 vector<string> fnames;
00052 string newpath = path;
00053 string::size_type strl = newpath.length();
00054 if((strl>1) && ('/'==newpath[strl-1])) newpath.erase(strl-1);
00055
00056 char com1[500];
00057 sprintf(com1, "JobOutputDir=`/bin/ls -dt1 %s/joboutput-* 2>/dev/null | head -1`\n", newpath.c_str());
00058 string command1(com1);
00059 string command2(
00060 "if [ -d \"${JobOutputDir}\" ]; then\n"
00061 " find ${JobOutputDir} -name hist.root\n"
00062 "fi\n"
00063 );
00064 string command = command1 + command2;
00065 stringstream fnstream;
00066
00067 char* fnbuf = new char[1024];
00068 FILE* fstream = popen(command.c_str(), "r");
00069
00070 while ( fgets(fnbuf, 1024, fstream) != NULL ) {
00071 fnstream << fnbuf;
00072 }
00073
00074 string fname;
00075 while ( ! (fnstream>>fname).eof() ) {
00076 fnames.push_back(fname);
00077 }
00078
00079 pclose(fstream);
00080 delete [] fnbuf;
00081
00082 if ( fnames.empty() ) {
00083 cout << "ERROR: Failed to retrieve hist files!" << endl;
00084 exit(1);
00085 }
00086 return fnames;
00087 }