00001 #include <iostream> 00002 #include <fcntl.h> 00003 #include <sys/ioctl.h> 00004 #include <cstdio> 00005 #include <unistd.h> 00006 #include <stdlib.h> 00007 #include <errno.h> 00008 #include <string> 00009 00010 #include <IORawData/CSCTFCommissioning/src/SPReader.h> 00011 00012 using namespace std; 00013 00014 int SPReader::openFile(string filename) { 00015 00016 fd_schar = open(filename.c_str(), O_RDONLY); 00017 // Abort in case of any failure 00018 if (fd_schar == -1) { 00019 cerr << "SPReader: FATAL in openFile - " << strerror(errno) << endl; 00020 cerr << "SPReader will abort!!!" << endl; 00021 abort(); 00022 } 00023 return 0; 00024 } 00025 00026 bool SPReader::readNextEvent() { 00027 bool debug = false; 00028 if(theBuffer) 00029 { 00030 delete theBuffer; 00031 theBuffer = NULL; 00032 } 00033 unsigned short ** buf2 = new unsigned short*; 00034 theDataLength = readSP(buf2, debug); 00035 if (debug) cout << " theDataLength " << theDataLength << endl; 00036 if(theDataLength<=4) return false; 00037 unsigned short * buf=(unsigned short *)*buf2; 00038 theBuffer = buf; 00039 delete buf2; 00040 return true; 00041 } 00042 00043 void SPReader::printStats() 00044 { 00045 cout << " npackets " << dec << npack_schar 00046 << " nbytes " << nbytes_schar << endl; 00047 } 00048 00049 void SPReader::closeFile() { 00050 if(fd_schar != -1000) 00051 close(fd_schar); 00052 }