#include "RawFile/RawFileUtil.h"
#include "RawFile/raw_ifstream.h"
#include "RawFile/raw_ofstream.h"
#include "IRawFile/RawFileExceptions.h"
#include <cstring>
Go to the source code of this file.
Functions | |
raw_ifstream & | operator>> (raw_ifstream &is, FileStartRecord &record) |
raw_ifstream & | operator>> (raw_ifstream &is, FileNameStrings &record) |
raw_ifstream & | operator>> (raw_ifstream &is, RunParametersRecord &record) |
raw_ifstream & | operator>> (raw_ifstream &is, DataSeparatorRecord &record) |
raw_ifstream & | operator>> (raw_ifstream &is, FileEndRecord &record) |
raw_ifstream & | makeEndRecord (DataSeparatorRecord &sep, raw_ifstream &is, FileEndRecord &record) |
raw_ofstream & | operator<< (raw_ofstream &os, FileStartRecord &record) |
raw_ofstream & | operator<< (raw_ofstream &os, FileNameStrings &record) |
raw_ofstream & | operator<< (raw_ofstream &os, RunParametersRecord &record) |
raw_ofstream & | operator<< (raw_ofstream &os, DataSeparatorRecord &record) |
raw_ofstream & | operator<< (raw_ofstream &os, FileEndRecord &record) |
raw_ifstream& makeEndRecord | ( | DataSeparatorRecord & | sep, | |
raw_ifstream & | is, | |||
FileEndRecord & | record | |||
) |
Definition at line 146 of file RawFileUtil.cxx.
References file_end_record::end_marker, file_end_record::events_in_file, DataSeparatorRecord::getRecord(), is, FileEndRecord::m_record, file_end_record::marker, and file_end_record::record_size.
00146 { 00147 // copy file_end_record data that already read by data_separator_record 00148 memcpy((void*)&record.m_record, (const void*)&(sep.getRecord()), sizeof(data_separator_record)); 00149 // read data block 00150 if (is.read((char*)(&record.m_record.events_in_file), ( 00151 sizeof(file_end_record) - sizeof(data_separator_record) 00152 )).fail()) { 00153 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00154 throw BadInputStream("FileEndRecord"); 00155 } 00156 00157 // data validation checks 00158 if (record.m_record.marker != 0x1234dddd) { 00159 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00160 throw WrongMarker(0x1234dddd, record.m_record.marker); 00161 } 00162 if (record.m_record.end_marker != 0x1234eeee) { 00163 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00164 throw WrongMarker(0x1234eeee, record.m_record.end_marker); 00165 } 00166 00167 if (record.m_record.record_size != 10) { 00168 //std::cerr << "[RawFile] Get an unexpected record size" << std::endl; 00169 throw UnexpectedRecordSize("FileEndRecord", 10, record.m_record.record_size); 00170 } 00171 00172 return is; 00173 }
raw_ofstream& operator<< | ( | raw_ofstream & | os, | |
FileEndRecord & | record | |||
) |
Definition at line 222 of file RawFileUtil.cxx.
References FileEndRecord::m_record.
00222 { 00223 // write data block 00224 if (os.write((char*)(&record.m_record), sizeof(file_end_record)).fail()) { 00225 std::cerr << "[RawFile] Error occurred while writing file" << std::endl; 00226 throw FailedToWrite("FileEndRecord"); 00227 } 00228 00229 return os; 00230 }
raw_ofstream& operator<< | ( | raw_ofstream & | os, | |
DataSeparatorRecord & | record | |||
) |
Definition at line 212 of file RawFileUtil.cxx.
References DataSeparatorRecord::m_record.
00212 { 00213 // write data block 00214 if (os.write((char*)(&record.m_record), sizeof(data_separator_record)).fail()) { 00215 std::cerr << "[RawFile] Error occurred while writing file" << std::endl; 00216 throw FailedToWrite("DataSeparatorRecord"); 00217 } 00218 00219 return os; 00220 }
raw_ofstream& operator<< | ( | raw_ofstream & | os, | |
RunParametersRecord & | record | |||
) |
Definition at line 202 of file RawFileUtil.cxx.
References RunParametersRecord::m_record.
00202 { 00203 // write data block 00204 if (os.write((char*)(&record.m_record), sizeof(run_parameters_record)).fail()) { 00205 std::cerr << "[RawFile] Error occurred while writing file" << std::endl; 00206 throw FailedToWrite("RunParametersRecord"); 00207 } 00208 00209 return os; 00210 }
raw_ofstream& operator<< | ( | raw_ofstream & | os, | |
FileNameStrings & | record | |||
) |
Definition at line 185 of file RawFileUtil.cxx.
References file_name_strings::length1, file_name_strings::length2, FileNameStrings::m_appName, FileNameStrings::m_record, and FileNameStrings::m_usrTag.
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_ofstream& operator<< | ( | raw_ofstream & | os, | |
FileStartRecord & | record | |||
) |
Definition at line 175 of file RawFileUtil.cxx.
References FileStartRecord::m_record.
00175 { 00176 // write data block 00177 if (os.write((char*)(&record.m_record), sizeof(file_start_record)).fail()) { 00178 std::cerr << "[RawFile] Error occurred while writing file" << std::endl; 00179 throw FailedToWrite("FileStartRecord"); 00180 } 00181 00182 return os; 00183 }
raw_ifstream& operator>> | ( | raw_ifstream & | is, | |
FileEndRecord & | record | |||
) |
Definition at line 121 of file RawFileUtil.cxx.
References file_end_record::end_marker, is, FileEndRecord::m_record, file_end_record::marker, and file_end_record::record_size.
00121 { 00122 // read data block 00123 if (is.read((char*)(&record.m_record), sizeof(file_end_record)).fail()) { 00124 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00125 throw BadInputStream("FileEndRecord"); 00126 } 00127 00128 // data validation checks 00129 if (record.m_record.marker != 0x1234dddd) { 00130 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00131 throw WrongMarker(0x1234dddd, record.m_record.marker); 00132 } 00133 if (record.m_record.end_marker != 0x1234eeee) { 00134 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00135 throw WrongMarker(0x1234eeee, record.m_record.end_marker); 00136 } 00137 00138 if (record.m_record.record_size != 10) { 00139 //std::cerr << "[RawFile] Get an unexpected record size" << std::endl; 00140 throw UnexpectedRecordSize("FileEndRecord", 10, record.m_record.record_size); 00141 } 00142 00143 return is; 00144 }
raw_ifstream& operator>> | ( | raw_ifstream & | is, | |
DataSeparatorRecord & | record | |||
) |
Definition at line 96 of file RawFileUtil.cxx.
References is, DataSeparatorRecord::m_record, data_separator_record::marker, and data_separator_record::record_size.
00096 { 00097 // read data block 00098 if (is.read((char*)(&record.m_record), sizeof(data_separator_record)).fail()) { 00099 //std::cerr << "[RawFile] Error occurred while reading file" << std::endl; 00100 throw BadInputStream("DataSeparatorRecord"); 00101 //throw ReachEndOfFile(); 00102 } 00103 00104 // data validation checks 00105 if (record.m_record.marker != 0x1234cccc) { 00106 if (record.m_record.marker == 0x1234dddd) { 00107 throw ReachEndOfFile(is.currentFile().c_str()); 00108 } 00109 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00110 throw WrongMarker(0x1234cccc, record.m_record.marker); 00111 } 00112 00113 if (record.m_record.record_size != 4) { 00114 //std::cerr << "[RawFile] Get an unexpected record size" << std::endl; 00115 throw UnexpectedRecordSize("DataSeparatorRecord", 4, record.m_record.record_size); 00116 } 00117 00118 return is; 00119 }
raw_ifstream& operator>> | ( | raw_ifstream & | is, | |
RunParametersRecord & | record | |||
) |
Definition at line 75 of file RawFileUtil.cxx.
References is, RunParametersRecord::m_record, run_parameters_record::marker, and run_parameters_record::record_size.
00075 { 00076 // read data block 00077 if (is.read((char*)(&record.m_record), sizeof(run_parameters_record)).fail()) { 00078 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00079 throw BadInputStream("RunParametersRecord"); 00080 } 00081 00082 // data validation checks 00083 if (record.m_record.marker != 0x1234bbbb) { 00084 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00085 throw WrongMarker(0x1234bbbb, record.m_record.marker); 00086 } 00087 00088 if (record.m_record.record_size != 9) { 00089 //std::cerr << "[RawFile] Get an unexpected record size" << std::endl; 00090 throw UnexpectedRecordSize("RunParametersRecord", 9, record.m_record.record_size); 00091 } 00092 00093 return is; 00094 }
raw_ifstream& operator>> | ( | raw_ifstream & | is, | |
FileNameStrings & | record | |||
) |
Definition at line 28 of file RawFileUtil.cxx.
References is, file_name_strings::length1, file_name_strings::length2, FileNameStrings::m_appName, FileNameStrings::m_record, FileNameStrings::m_usrTag, and file_name_strings::marker.
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 }
raw_ifstream& operator>> | ( | raw_ifstream & | is, | |
FileStartRecord & | record | |||
) |
Definition at line 7 of file RawFileUtil.cxx.
References is, FileStartRecord::m_record, file_start_record::marker, and file_start_record::record_size.
00007 { 00008 // read data block 00009 if (is.read((char*)(&record.m_record), sizeof(file_start_record)).fail()) { 00010 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl; 00011 throw BadInputStream("FileStartRecord"); 00012 } 00013 00014 // data validation checks 00015 if (record.m_record.marker != 0x1234aaaa) { 00016 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl; 00017 throw WrongMarker(0x1234aaaa, record.m_record.marker); 00018 } 00019 00020 if (record.m_record.record_size != 8) { 00021 //std::cerr << "[RawFile] Get an unexpected record size" << std::endl; 00022 throw UnexpectedRecordSize("FileStartRecord", 8, record.m_record.record_size); 00023 } 00024 00025 return is; 00026 }