#include <RawFileUtil.h>
Public Member Functions | |
FileNameStrings () | |
const file_name_strings & | getRecord () const |
const std::string & | gerAppName () const |
const std::string & | gerUsrTag () const |
void | dump (std::ostream &os=std::cout) const |
Private Attributes | |
file_name_strings | m_record |
std::string | m_appName |
std::string | m_usrTag |
Friends | |
raw_ifstream & | operator>> (raw_ifstream &is, FileNameStrings &record) |
raw_ofstream & | operator<< (raw_ofstream &os, FileNameStrings &record) |
Definition at line 64 of file RawFileUtil.h.
FileNameStrings::FileNameStrings | ( | ) |
Definition at line 245 of file RawFileUtil.cxx.
References file_name_strings::length1, file_name_strings::length2, m_appName, m_record, m_usrTag, and file_name_strings::marker.
00246 { 00247 m_record.marker = 0x1234aabb; 00248 m_record.length1 = 4; 00249 m_record.length2 = 7; 00250 m_appName = "BOSS"; 00251 m_usrTag = "offline"; 00252 }
void FileNameStrings::dump | ( | std::ostream & | os = std::cout |
) | const |
Definition at line 304 of file RawFileUtil.cxx.
References file_name_strings::length1, file_name_strings::length2, m_appName, m_record, m_usrTag, and file_name_strings::marker.
00304 { 00305 os << "[RawFile] FileNameStrings:" << std::endl << std::hex 00306 << "[RawFile] \tmarker : 0x" << m_record.marker << std::endl 00307 << "[RawFile] \tAppName length : 0x" << m_record.length1 << std::endl 00308 << "[RawFile] \tAppName : " << m_appName << std::endl 00309 << "[RawFile] \tUsrTag length : 0x" << m_record.length2 << std::endl 00310 << "[RawFile] \tUsrTag : " << m_usrTag 00311 << std::dec << std::endl; 00312 }
const std::string& FileNameStrings::gerAppName | ( | ) | const [inline] |
const std::string& FileNameStrings::gerUsrTag | ( | ) | const [inline] |
const file_name_strings& FileNameStrings::getRecord | ( | ) | const [inline] |
raw_ofstream& operator<< | ( | raw_ofstream & | os, | |
FileNameStrings & | record | |||
) | [friend] |
Definition at line 185 of file RawFileUtil.cxx.
00185 { 00186 // write data block 00187 os.write((char*)(&record.m_record), sizeof(uint32_t)*2); 00188 uint32_t sizebyte = record.m_record.length1; 00189 uint32_t sizeword = (sizebyte+3)/4; 00190 os.write(record.m_appName.c_str(), sizeword*4); 00191 os.write((char*)(&record.m_record.length2), sizeof(uint32_t)); 00192 sizebyte = record.m_record.length2; 00193 sizeword = (sizebyte+3)/4; 00194 os.write(record.m_usrTag.c_str(), sizeword*4); 00195 if ( os.fail() ) { 00196 std::cerr << "[RawFile] Error occurred while writing file" << std::endl; 00197 throw FailedToWrite("FileNameStrings"); 00198 } 00199 return os; 00200 }
raw_ifstream& operator>> | ( | raw_ifstream & | is, | |
FileNameStrings & | record | |||
) | [friend] |
Definition at line 28 of file RawFileUtil.cxx.
00028 { 00029 // read marker 00030 if (is.read((char*)(&record.m_record.marker), sizeof(uint32_t)).fail()) { 00031 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00032 throw BadInputStream("FileNameStrings::marker"); 00033 } 00034 00035 // marker validation 00036 if (record.m_record.marker != 0x1234aabb) { 00037 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00038 throw WrongMarker(0x1234aabb, record.m_record.marker); 00039 } 00040 00041 // read length and strings 00042 if (is.read((char*)(&record.m_record.length1), sizeof(uint32_t)).fail()) { 00043 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00044 throw BadInputStream("FileNameStrings::length1"); 00045 } 00046 00047 uint32_t length1_word = (record.m_record.length1 + 3) / 4; 00048 char* appName = new char[length1_word * 4 + 1]; 00049 if (is.read(appName, length1_word*4).fail()) { 00050 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00051 throw BadInputStream("FileNameStrings::appName"); 00052 } 00053 appName[record.m_record.length1] = '\0'; 00054 record.m_appName = appName; 00055 delete[] appName; 00056 00057 if (is.read((char*)(&record.m_record.length2), sizeof(uint32_t)).fail()) { 00058 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00059 throw BadInputStream("FileNameStrings::length2"); 00060 } 00061 00062 uint32_t length2_word = (record.m_record.length2 + 3) / 4; 00063 char* usrTag = new char[length2_word * 4 + 1]; 00064 if (is.read(usrTag, length2_word*4).fail()) { 00065 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00066 throw BadInputStream("FileNameStrings::usrTag"); 00067 } 00068 usrTag[record.m_record.length2] = '\0'; 00069 record.m_usrTag = usrTag; 00070 delete[] usrTag; 00071 00072 return is; 00073 }
std::string FileNameStrings::m_appName [private] |
Definition at line 80 of file RawFileUtil.h.
Referenced by dump(), FileNameStrings(), gerAppName(), operator<<(), and operator>>().
file_name_strings FileNameStrings::m_record [private] |
Definition at line 79 of file RawFileUtil.h.
Referenced by dump(), FileNameStrings(), getRecord(), operator<<(), and operator>>().
std::string FileNameStrings::m_usrTag [private] |
Definition at line 81 of file RawFileUtil.h.
Referenced by dump(), FileNameStrings(), gerUsrTag(), operator<<(), and operator>>().