00001 /* 00002 * DaqFromFStream.cc 00003 * FileReadoutFormat 00004 * 00005 * Created by Simon Patton on 7/18/10. 00006 * Copyright 2010 DayaBay Collaboration. All rights reserved. 00007 * 00008 */ 00009 #include "FileReadoutFormat/DaqFromFStream.h" 00010 00011 #include <iostream> 00012 #include <string> 00013 00014 using DybDaq::DaqFromFStream; 00015 using DybDaq::DaqFromIStream; 00016 using std::ifstream; 00017 using std::istream; 00018 using std::string; 00019 00020 DaqFromFStream::DaqFromFStream() : 00021 m_fileName(0), 00022 m_ifstream(0) { 00023 } 00024 00025 DaqFromFStream::~DaqFromFStream() { 00026 if (0 != m_fileName) { 00027 delete m_fileName; 00028 } 00029 if (hasIStream()) { 00030 if (m_ifstream->is_open()) { 00031 m_ifstream->close(); 00032 } 00033 } 00034 } 00035 00036 std::istream* DaqFromFStream::openStream() { 00037 m_ifstream = new ifstream(m_fileName->c_str(), 00038 istream::in | istream::binary); 00039 return m_ifstream; 00040 } 00041 00042 void DaqFromFStream::closeStream(std::istream& stream) { 00043 ifstream& fileStream = dynamic_cast<ifstream&> (stream); 00044 fileStream.close(); 00045 m_ifstream = 0; 00046 } 00047 00048 const bool DaqFromFStream::openFile(const char* const fileName) { 00049 if (0 != m_fileName) { 00050 delete m_fileName; 00051 } 00052 m_fileName = new string(fileName); 00053 return open(); 00054 }