BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
FileNameStrings Class Reference

#include <RawFileUtil.h>

Public Member Functions

 FileNameStrings ()
 
const file_name_stringsgetRecord () const
 
const std::string & gerAppName () const
 
const std::string & gerUsrTag () const
 
void dump (std::ostream &os=std::cout) const
 

Friends

raw_ifstreamoperator>> (raw_ifstream &is, FileNameStrings &record)
 
raw_ofstreamoperator<< (raw_ofstream &os, FileNameStrings &record)
 

Detailed Description

Definition at line 64 of file RawFileUtil.h.

Constructor & Destructor Documentation

◆ FileNameStrings()

FileNameStrings::FileNameStrings ( )

Definition at line 245 of file RawFileUtil.cxx.

246{
247 m_record.marker = 0x1234aabb;
248 m_record.length1 = 4;
249 m_record.length2 = 7;
250 m_appName = "BOSS";
251 m_usrTag = "offline";
252}
uint32_t length2
Definition: RawFileUtil.h:61
uint32_t length1
Definition: RawFileUtil.h:60

Member Function Documentation

◆ dump()

void FileNameStrings::dump ( std::ostream &  os = std::cout) const

Definition at line 304 of file RawFileUtil.cxx.

304 {
305 os << "[RawFile] FileNameStrings:" << std::endl << std::hex
306 << "[RawFile] \tmarker : 0x" << m_record.marker << std::endl
307 << "[RawFile] \tAppName length : 0x" << m_record.length1 << std::endl
308 << "[RawFile] \tAppName : " << m_appName << std::endl
309 << "[RawFile] \tUsrTag length : 0x" << m_record.length2 << std::endl
310 << "[RawFile] \tUsrTag : " << m_usrTag
311 << std::dec << std::endl;
312}

◆ gerAppName()

const std::string & FileNameStrings::gerAppName ( ) const
inline

Definition at line 73 of file RawFileUtil.h.

73{ return m_appName; }

◆ gerUsrTag()

const std::string & FileNameStrings::gerUsrTag ( ) const
inline

Definition at line 74 of file RawFileUtil.h.

74{ return m_usrTag; }

◆ getRecord()

const file_name_strings & FileNameStrings::getRecord ( ) const
inline

Definition at line 71 of file RawFileUtil.h.

71{ return m_record; }

Friends And Related Function Documentation

◆ operator<<

raw_ofstream & operator<< ( raw_ofstream os,
FileNameStrings record 
)
friend

Definition at line 185 of file RawFileUtil.cxx.

185 {
186 // write data block
187 os.write((char*)(&record.m_record), sizeof(uint32_t)*2);
188 uint32_t sizebyte = record.m_record.length1;
189 uint32_t sizeword = (sizebyte+3)/4;
190 os.write(record.m_appName.c_str(), sizeword*4);
191 os.write((char*)(&record.m_record.length2), sizeof(uint32_t));
192 sizebyte = record.m_record.length2;
193 sizeword = (sizebyte+3)/4;
194 os.write(record.m_usrTag.c_str(), sizeword*4);
195 if ( os.fail() ) {
196 std::cerr << "[RawFile] Error occurred while writing file" << std::endl;
197 throw FailedToWrite("FileNameStrings");
198 }
199 return os;
200}

◆ operator>>

raw_ifstream & operator>> ( raw_ifstream is,
FileNameStrings record 
)
friend

Definition at line 28 of file RawFileUtil.cxx.

28 {
29 // read marker
30 if (is.read((char*)(&record.m_record.marker), sizeof(uint32_t)).fail()) {
31 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl;
32 throw BadInputStream("FileNameStrings::marker");
33 }
34
35 // marker validation
36 if (record.m_record.marker != 0x1234aabb) {
37 //std::cerr << "[RawFile] Get an invalid record marker" << std::endl;
38 throw WrongMarker(0x1234aabb, record.m_record.marker);
39 }
40
41 // read length and strings
42 if (is.read((char*)(&record.m_record.length1), sizeof(uint32_t)).fail()) {
43 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl;
44 throw BadInputStream("FileNameStrings::length1");
45 }
46
47 uint32_t length1_word = (record.m_record.length1 + 3) / 4;
48 char* appName = new char[length1_word * 4 + 1];
49 if (is.read(appName, length1_word*4).fail()) {
50 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl;
51 throw BadInputStream("FileNameStrings::appName");
52 }
53 appName[record.m_record.length1] = '\0';
54 record.m_appName = appName;
55 delete[] appName;
56
57 if (is.read((char*)(&record.m_record.length2), sizeof(uint32_t)).fail()) {
58 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl;
59 throw BadInputStream("FileNameStrings::length2");
60 }
61
62 uint32_t length2_word = (record.m_record.length2 + 3) / 4;
63 char* usrTag = new char[length2_word * 4 + 1];
64 if (is.read(usrTag, length2_word*4).fail()) {
65 //std::cerr << "[RawFile] Error occurred while reading files" << std::endl;
66 throw BadInputStream("FileNameStrings::usrTag");
67 }
68 usrTag[record.m_record.length2] = '\0';
69 record.m_usrTag = usrTag;
70 delete[] usrTag;
71
72 return is;
73}

The documentation for this class was generated from the following files: