#include "TPCCommandCoderFile.h" #define CoCoVersion "TPCCommandCoderFile" //=========================================================================== TPCCommandCoderFile::TPCCommandCoderFile() { frcu = new RCUCommandCoder(); faltro = new AltroCommandCoder(); fbc = new BoardControllerCommandCoder(); frcuce = new RCUControlEngine(); version = CoCoVersion; } //=========================================================================== TPCCommandCoderFile::~TPCCommandCoderFile() { delete frcu; delete faltro; delete fbc; delete frcuce; free(iMem); } //=========================================================================== uint32_t* TPCCommandCoderFile::getDataBlock() { return iMem; } //=========================================================================== int32_t TPCCommandCoderFile::createDataBlock(char* target,int32_t tag){ ifstream *inFile = new ifstream(); int32_t retval = 0; string filename; if ( tag >= 0 ) { char buffer [256]; sprintf(buffer,"%s.%d.binary", target, tag); filename = buffer; } else { filename = target; } cout << "TPCCommandCoderFile: Opening File " << filename.c_str() << endl; inFile->open(filename.c_str(), ios::binary); if ( inFile->is_open() == false){ cout << "TPCCommandCoderFile: Could not open File " << filename.c_str() << endl; ferror.push_back("Could not open file"); return (uint32_t) 0; } // Get length of file inFile->seekg (0, ios::end); int32_t filesize = inFile->tellg(); cout << "Filesize is " << filesize << endl; // Allocate Memory iMem = (uint32_t*) malloc(filesize); //iMem = new long int(filesize); // Read inFile->seekg (0, ios::beg); inFile->read((char*)iMem, filesize); inFile->close(); //cout.setf(ios::hex, ios::basefield); //cout << iMem[0] << endl; retval = filesize; delete inFile; return retval; } //=========================================================================== std::string& TPCCommandCoderFile::getCoCoInfo(){ return version; } //=========================================================================== vector &TPCCommandCoderFile::getError(){ return ferror; } //=========================================================================== CommandCoderBase* getCoCoInst(void){ static TPCCommandCoderFile instance; return &instance; }