/* * ScanFile.cpp * * Created on: Nov 26, 2014 * Author: Hovanes Egiyan */ #include #include #include #include #include #include "boost/algorithm/string/classification.hpp" #include "ScanFile.hh" ClassImp( ScanFile ) using namespace std; ScanFile::ScanFile( const string fName ) : TObject(), fileName( fName ), fileStream( 0 ), bufferPipe() { // Try to read MDA file try { cout << "Entered readMDAFile" << endl; // Check existence of the mda file first if ( !boost::filesystem::exists( fileName ) ) throw std::runtime_error( "ERROR: File " + fileName + " does not exist" ); // Create a pipe for mda-dump command, then turn it into a input stream for C++ string dumpCommand = string( "mda-dump" ) + " " + fileName; fileStream = new std::istream( &bufferPipe ); // create a stream from the pipe. // Throw an exception if the pipe cannot be open with a command line if ( bufferPipe.open( dumpCommand.c_str(), "r" ) == NULL ) { throw std::runtime_error( "ERROR: Cannot open pipe with command: " + dumpCommand ); } cout << "Done" << endl; } catch ( const runtime_error & e ) { string errMsg = e.what(); cerr << errMsg << endl; throw e; } return; } ScanFile::~ScanFile() { if ( fileStream != 0 ) delete fileStream; bufferPipe.close(); return; }