#include <IORawData/CSCTFCommissioning/src/FileReaderSPNewFormat.h>
Public Member Functions | |
virtual void | Configure () |
virtual int | disableBlock () |
virtual int | enableBlock () |
virtual int | endBlockRead () |
FileReaderSPNewFormat () | |
virtual int | readSP (unsigned short **buf, const bool debug=false) |
assumes fd_schar has been set | |
virtual int | reset () |
virtual | ~FileReaderSPNewFormat () |
Protected Member Functions | |
virtual int | chunkSize () |
How many bytes to read at a time. | |
unsigned | findTrailer1 (const unsigned short *, unsigned length) |
unsigned | findTrailer2 (const unsigned short *, unsigned length) |
bool | hasTrailer (const unsigned short *, unsigned length) |
bool | isTrailer1 (const unsigned short *) |
bool | isTrailer2 (const unsigned short *) |
Protected Attributes | |
unsigned short | header [8] |
unsigned | pointer |
unsigned short | trailer [8] |
Definition at line 8 of file FileReaderSPNewFormat.h.
FileReaderSPNewFormat::FileReaderSPNewFormat | ( | ) |
Definition at line 10 of file FileReaderSPNewFormat.cc.
References header, pointer, and trailer.
00011 { 00012 pointer = 0; 00013 trailer[0] = 0xf000; 00014 trailer[1] = 0xf07f; 00015 trailer[2] = 0xf000; 00016 trailer[3] = 0xf000; 00017 trailer[4] = 0xe000; 00018 trailer[5] = 0xe000; 00019 trailer[6] = 0xe000; 00020 trailer[7] = 0xe000; 00021 00022 header[0] = 0x9000; 00023 header[1] = 0x9000; 00024 header[2] = 0x9000; 00025 header[3] = 0x9000; 00026 header[4] = 0xa000; 00027 header[5] = 0xa000; 00028 header[6] = 0xa000; 00029 header[7] = 0xa000; 00030 }
virtual FileReaderSPNewFormat::~FileReaderSPNewFormat | ( | ) | [inline, virtual] |
int FileReaderSPNewFormat::chunkSize | ( | ) | [protected, virtual] |
How many bytes to read at a time.
Implements SPReader.
Definition at line 36 of file FileReaderSPNewFormat.cc.
Referenced by readSP().
00036 { 00037 // The smallest piece of the data format 00038 // is 64 bits so read in that amount. 00039 return sizeof(long long); 00040 }
void FileReaderSPNewFormat::Configure | ( | ) | [virtual] |
virtual int FileReaderSPNewFormat::disableBlock | ( | ) | [inline, virtual] |
virtual int FileReaderSPNewFormat::enableBlock | ( | ) | [inline, virtual] |
virtual int FileReaderSPNewFormat::endBlockRead | ( | ) | [inline, virtual] |
unsigned FileReaderSPNewFormat::findTrailer1 | ( | const unsigned short * | buf, | |
unsigned | length | |||
) | [protected] |
Definition at line 100 of file FileReaderSPNewFormat.cc.
References isTrailer1().
Referenced by readSP().
00101 { 00102 unsigned short* itr = const_cast<unsigned short*>(buf); 00103 00104 unsigned pos = 0; 00105 00106 while( itr + 3 <= buf + length ) 00107 { 00108 if(isTrailer1(itr)) pos = (unsigned)itr; 00109 ++itr; 00110 } 00111 00112 return pos; 00113 }
unsigned FileReaderSPNewFormat::findTrailer2 | ( | const unsigned short * | buf, | |
unsigned | length | |||
) | [protected] |
Definition at line 115 of file FileReaderSPNewFormat.cc.
References isTrailer2().
Referenced by readSP().
00116 { 00117 unsigned short* itr = const_cast<unsigned short*>(buf); 00118 00119 unsigned pos = 0; 00120 00121 while( itr + 3 <= buf + length ) 00122 { 00123 if(isTrailer2(itr)) pos = (unsigned)itr; // I hate to brute force this but I had to :-( 00124 ++itr; 00125 } 00126 00127 return pos; 00128 }
bool FileReaderSPNewFormat::hasTrailer | ( | const unsigned short * | buf, | |
unsigned | length | |||
) | [protected] |
Definition at line 151 of file FileReaderSPNewFormat.cc.
References isTrailer1(), and isTrailer2().
Referenced by readSP().
00152 { 00153 return (isTrailer1(buf + length - 8) && isTrailer2(buf + length - 4)); 00154 }
bool FileReaderSPNewFormat::isTrailer1 | ( | const unsigned short * | buf | ) | [protected] |
Definition at line 130 of file FileReaderSPNewFormat.cc.
References HLT_VtxMuL3::result, and trailer.
Referenced by findTrailer1(), and hasTrailer().
00131 { 00132 bool result = false; 00133 result = (trailer[0] & buf[0]) == trailer[0]; 00134 result = (trailer[1] & buf[1]) == trailer[1]; 00135 result = (trailer[2] & buf[2]) == trailer[2]; 00136 result = (trailer[3] & buf[3]) == trailer[3]; 00137 00138 return result; 00139 }
bool FileReaderSPNewFormat::isTrailer2 | ( | const unsigned short * | buf | ) | [protected] |
Definition at line 141 of file FileReaderSPNewFormat.cc.
References HLT_VtxMuL3::result, and trailer.
Referenced by findTrailer2(), and hasTrailer().
00142 { 00143 bool result = false; 00144 result = (trailer[4] & buf[0]) == trailer[4]; 00145 result = (trailer[5] & buf[1]) == trailer[5]; 00146 result = (trailer[6] & buf[2]) == trailer[6]; 00147 result = (trailer[7] & buf[3]) == trailer[7]; 00148 return result; 00149 }
assumes fd_schar has been set
Implements SPReader.
Definition at line 43 of file FileReaderSPNewFormat.cc.
References a, chunkSize(), counter(), event(), SPReader::fd_schar, findTrailer1(), findTrailer2(), hasTrailer(), pointer, SiStripLorentzAngle_cfi::read, and trailer.
00044 { 00045 unsigned short a[50000]; 00046 int bytes_read=0; 00047 unsigned trailer_pos; 00048 unsigned counter = 0; 00049 00050 do 00051 { 00052 if(pointer == 0) 00053 { 00054 bytes_read = read(fd_schar, a, chunkSize()); //read 1 chunk 00055 counter += bytes_read; 00056 pointer += counter; 00057 if(bytes_read != chunkSize()) 00058 { 00059 edm::LogInfo("FileReaderSPNewFormat") << "Reached end of file."; 00060 return 0; // we can safely return zero since an event size less than one chunk is useless. 00061 } 00062 } 00063 else 00064 { 00065 bytes_read = read(fd_schar, a + counter/sizeof(short), chunkSize()); 00066 counter += bytes_read; 00067 pointer += counter; 00068 if(bytes_read != chunkSize()) 00069 { 00070 edm::LogInfo("FileReaderSPNewFormat") << "Reached end of file, recovering last data."; 00071 if( !findTrailer2(a, counter/sizeof(short)) ) 00072 { 00073 if( (trailer_pos = findTrailer1(a, counter)) ) // if the first trailer is there 00074 { 00075 memcpy(a + trailer_pos + 4, trailer + 4, 4*sizeof(short)); 00076 counter += 4; 00077 } 00078 else 00079 { 00080 memcpy(a + counter/sizeof(short), trailer, 8*sizeof(short)); 00081 counter += 8; 00082 } 00083 } 00084 } 00085 } 00086 00087 }while( !hasTrailer(a, counter/sizeof(short)) ); 00088 00089 void * event = malloc(counter); 00090 memset(event,0,counter); 00091 memcpy(event,a,counter); 00092 *buf=reinterpret_cast<unsigned short*>(event); 00093 00094 //printf("\n\n\n returning %d: \n\n\n",(count*8)); 00095 00096 return counter; //Total number of bytes read 00097 00098 } //readSP
unsigned short FileReaderSPNewFormat::header[8] [protected] |
unsigned FileReaderSPNewFormat::pointer [protected] |
Definition at line 31 of file FileReaderSPNewFormat.h.
Referenced by FileReaderSPNewFormat(), and readSP().
unsigned short FileReaderSPNewFormat::trailer[8] [protected] |
Definition at line 33 of file FileReaderSPNewFormat.h.
Referenced by FileReaderSPNewFormat(), isTrailer1(), isTrailer2(), and readSP().