Commit 6ef7e04f authored by Jérémie Dudouet's avatar Jérémie Dudouet
Browse files

Adapt BasicAFP to be able to take conf files with a list of input files

parent 8b9082ad
......@@ -67,17 +67,24 @@ Bool_t BasicAFP::NewFile()
fCurrentFile = 0x0;
std::cout << " -BasicAFP: the input file has just been closed " << fCurrentFileName << std::endl;
}
// open the first file to be ready to be run
std::string tmp = fPath;
if ( tmp.size() > 0 && !(tmp.at(tmp.size()-1) == '/') )
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << std::setfill(' ')
<< ".adf";
fCurrentFileName = filename.str();
if(fListOfIndividualFiles.size()) {
if(fCurrentFileNumber<fListOfIndividualFiles.size()) fCurrentFileName = fListOfIndividualFiles.at(fCurrentFileNumber);
else fCurrentFileName.clear();
fCurrentFileNumber++;
}
else {
// open the first file to be ready to be run
std::string tmp = fPath;
if ( tmp.size() > 0 && !(tmp.at(tmp.size()-1) == '/') )
tmp += '/';
std::ostringstream filename;
filename << tmp << fBaseForName
<< std::setfill('0') << std::setw(4) << fCurrentFileNumber++ << std::setfill(' ')
<< ".adf";
fCurrentFileName = filename.str();
}
fCurrentFile = ::fopen(fCurrentFileName.c_str(),"rb");
if ( fCurrentFile != 0x0 ) {
......@@ -92,8 +99,8 @@ Bool_t BasicAFP::NewFile()
fCurrentName = fCurrentFileName.substr(lpt+1, len-lpt-1);
ok = true;
}
else {
Log << "Could not open input file " << fCurrentFileName << nline;
else {
if(fCurrentFileName.length()) Log << "Could not open input file " << fCurrentFileName << nline;
GetFrameIO().SetStatus(BaseFrameIO::kFinished);
ok = false;
}
......@@ -176,23 +183,40 @@ void BasicAFP::process_initialise (UInt_t *error_code)
*error_code = 0u;
Log.ClearMessage(); Log.SetProcessMethod("process_initialise");
// read an input file to get the base filename and the path
std::string conffile = GetConfPath() + "BasicAFP.conf";
// read an input file to get the base filename and the path
std::string conffile = GetConfPath() + "BasicAFP.conf";
std::ifstream filein(conffile.data());
if ( filein.is_open() == true ) {
std::string pathforfiles, basename;
UInt_t starting_number;
filein >> pathforfiles >> basename >> starting_number;
if ( filein.good() ) {
fPath = pathforfiles;
fBaseForName = basename;
fCurrentFileNumber = starting_number;
std::cout << "BasicAFP::process_initialise " << pathforfiles << " " << basename << " " << starting_number << std::endl;
}
}
if ( filein.is_open() == true ) {
// check with the first line if the files are given one by one
std::string line;
std::getline(filein,line);
int nblank = std::count(line.begin(), line.end(),' ');
filein.seekg(0);
// case where a list of files is given
if(nblank==0) {
while(filein.good()) {
std::getline(filein,line);
if(line.length()) fListOfIndividualFiles.push_back(line);
}
fCurrentFileNumber = 0;
std::cout << "BasicAFP::process_initialise => list of files to process:" << std::endl;
for(auto &i: fListOfIndividualFiles) std::cout << " -- " << i << std::endl;
}
else {
std::string pathforfiles, basename;
UInt_t starting_number;
filein >> pathforfiles >> basename >> starting_number;
if ( filein.good() ) {
fPath = pathforfiles;
fBaseForName = basename;
fCurrentFileNumber = starting_number;
std::cout << "BasicAFP::process_initialise " << pathforfiles << " " << basename << " " << starting_number << std::endl;
}
}
}
filein.close();
// open the first file
......
......@@ -48,6 +48,8 @@ private:
std::string fPath;
//! base for all the files produced
std::string fBaseForName;
//! in case files are given one by one
std::vector<std::string> fListOfIndividualFiles;
//! current file
FILE *fCurrentFile;
//! current file number
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment