g4tools  5.4.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::wroot::key Class Reference
Inheritance diagram for tools::wroot::key:
Inheritance graph
[legend]

Public Member Functions

 key (std::ostream &a_out, seek a_seek_directory, const std::string &a_object_name, const std::string &a_object_title, const std::string &a_object_class)
 
 key (std::ostream &a_out, ifile &a_file, seek a_seek_directory, const std::string &a_object_name, const std::string &a_object_title, const std::string &a_object_class, uint32 a_object_size)
 
virtual ~key ()
 
uint16 cycle () const
 
void set_cycle (uint16 a_cycle)
 
const std::string & object_name () const
 
const std::string & object_title () const
 
const std::string & object_class () const
 
bool write_self (ifile &a_file)
 
bool write_file (ifile &a_file, uint32 &a_nbytes)
 
void set_number_of_bytes (uint32 a_n)
 
uint32 number_of_bytes () const
 
uint32 object_size () const
 
seek seek_key () const
 
short key_length () const
 
char * data_buffer ()
 
const char * eob () const
 
bool to_buffer (wbuf &a_wb, bool a_verbose) const
 

Static Public Member Functions

static unsigned int std_string_record_size (const std::string &x)
 

Protected Member Functions

 key (const key &a_from)
 
keyoperator= (const key &)
 
uint32 record_size (uint32 a_version) const
 
bool initialize_zero ()
 
bool initialize (ifile &a_file, uint32 a_nbytes)
 

Protected Attributes

std::ostream & m_out
 
uint32 m_buf_size
 
char * m_buffer
 
uint32 m_nbytes
 
uint32 m_version
 
uint32 m_object_size
 
date m_date
 
uint16 m_key_length
 
uint16 m_cycle
 
seek m_seek_key
 
seek m_seek_directory
 
std::string m_object_class
 
std::string m_object_name
 
std::string m_object_title
 

Detailed Description

Definition at line 22 of file key.

Constructor & Destructor Documentation

◆ key() [1/3]

tools::wroot::key::key ( std::ostream &  a_out,
seek  a_seek_directory,
const std::string &  a_object_name,
const std::string &  a_object_title,
const std::string &  a_object_class 
)
inline

Definition at line 37 of file key.

42  :m_out(a_out)
43  ,m_buf_size(0)
44  ,m_buffer(0)
45  // Record :
46  ,m_nbytes(0)
47  ,m_version(class_version())
48  ,m_object_size(0)
49  ,m_date(0)
50  ,m_key_length(0)
51  ,m_cycle(0)
52  ,m_seek_key(0)
54  ,m_object_class(a_object_class)
55  ,m_object_name(a_object_name)
56  ,m_object_title(a_object_title)
57  {
58 #ifdef TOOLS_MEM
59  mem::increment(s_class().c_str());
60 #endif
61 
62  if(a_seek_directory>START_BIG_FILE()) m_version += big_file_version_tag();
63 
65 
67 
68  m_seek_directory = a_seek_directory;
69  }

◆ key() [2/3]

tools::wroot::key::key ( std::ostream &  a_out,
ifile a_file,
seek  a_seek_directory,
const std::string &  a_object_name,
const std::string &  a_object_title,
const std::string &  a_object_class,
uint32  a_object_size 
)
inline

Definition at line 71 of file key.

78  :m_out(a_out)
79  ,m_buf_size(0)
80  ,m_buffer(0)
81  // Record :
82  ,m_nbytes(0)
83  ,m_version(class_version())
84  ,m_object_size(a_object_size)
85  ,m_date(0)
86  ,m_key_length(0)
87  ,m_cycle(0)
88  ,m_seek_key(0)
90  ,m_object_class(a_object_class)
91  ,m_object_name(a_object_name)
92  ,m_object_title(a_object_title)
93  {
94 #ifdef TOOLS_MEM
95  mem::increment(s_class().c_str());
96 #endif
97 
98  if(a_object_size) {
99  if(a_file.END()>START_BIG_FILE()) m_version += big_file_version_tag();
100  }
102  } else {
103  if(a_seek_directory>START_BIG_FILE()) m_version += big_file_version_tag();
104  }
105 
107 
108  initialize(a_file,a_object_size);
109 
110  m_seek_directory = a_seek_directory;
111  }

◆ ~key()

virtual tools::wroot::key::~key ( )
inlinevirtual

Definition at line 112 of file key.

112  {
113  delete [] m_buffer;
114 #ifdef TOOLS_MEM
115  mem::decrement(s_class().c_str());
116 #endif
117  }

◆ key() [3/3]

tools::wroot::key::key ( const key a_from)
inlineprotected

Definition at line 119 of file key.

119  :m_out(a_from.m_out){
120 #ifdef TOOLS_MEM
121  mem::increment(s_class().c_str());
122 #endif
123  }

Member Function Documentation

◆ cycle()

uint16 tools::wroot::key::cycle ( ) const
inline

Definition at line 126 of file key.

126 {return m_cycle;}

◆ data_buffer()

char* tools::wroot::key::data_buffer ( )
inline

Definition at line 174 of file key.

174 {return m_buffer + m_key_length;}

◆ eob()

const char* tools::wroot::key::eob ( ) const
inline

Definition at line 175 of file key.

175 {return m_buffer + m_buf_size;}

◆ initialize()

bool tools::wroot::key::initialize ( ifile a_file,
uint32  a_nbytes 
)
inlineprotected

Definition at line 255 of file key.

255  {
256  uint32 nsize = m_key_length+a_nbytes;
257 
258  m_date = get_date();
259 
260  if(a_nbytes) {//GB
261  m_seek_key = a_file.END();
262  a_file.set_END(m_seek_key+nsize);
263 
264  //NOTE : the free segment logic found in CERN-ROOT/TKey
265  // is not yet needed right now for us, since
266  // we always write at end of file. The update
267  // of the eof free_seg is done in set_END.
268  } else { //basket
269  m_seek_key = 0;
270  }
271 
272  delete [] m_buffer;
273  m_buffer = new char[nsize];
274  m_buf_size = nsize;
275  m_nbytes = nsize;
276 
277  return true;
278  }

◆ initialize_zero()

bool tools::wroot::key::initialize_zero ( )
inlineprotected

Definition at line 245 of file key.

245  {
246  uint32 nsize = m_key_length;
247  m_date = get_date();
248  m_seek_key = 0;
249  delete [] m_buffer;
250  m_buffer = new char[nsize];
251  m_buf_size = nsize;
252  m_nbytes = nsize;
253  return true;
254  }

◆ key_length()

short tools::wroot::key::key_length ( ) const
inline

Definition at line 172 of file key.

172 {return m_key_length;}

◆ number_of_bytes()

uint32 tools::wroot::key::number_of_bytes ( ) const
inline

Definition at line 167 of file key.

167 {return m_nbytes;}

◆ object_class()

const std::string& tools::wroot::key::object_class ( ) const
inline

Definition at line 131 of file key.

131 {return m_object_class;}

◆ object_name()

const std::string& tools::wroot::key::object_name ( ) const
inline

Definition at line 129 of file key.

129 {return m_object_name;}

◆ object_size()

uint32 tools::wroot::key::object_size ( ) const
inline

Definition at line 169 of file key.

169 {return m_object_size;}

◆ object_title()

const std::string& tools::wroot::key::object_title ( ) const
inline

Definition at line 130 of file key.

130 {return m_object_title;}

◆ operator=()

key& tools::wroot::key::operator= ( const key )
inlineprotected

Definition at line 124 of file key.

124 {return *this;}

◆ record_size()

uint32 tools::wroot::key::record_size ( uint32  a_version) const
inlineprotected

Definition at line 224 of file key.

224  {
225  // Return the size in bytes of the key header structure.
226  uint32 nbytes = sizeof(m_nbytes);
227  nbytes += sizeof(short);
228  nbytes += sizeof(m_object_size);
229  nbytes += sizeof(date);
230  nbytes += sizeof(m_key_length);
231  nbytes += sizeof(m_cycle);
232  if(a_version>big_file_version_tag()) {
233  nbytes += sizeof(seek);
234  nbytes += sizeof(seek);
235  } else {
236  nbytes += sizeof(seek32);
237  nbytes += sizeof(seek32);
238  }
242  return nbytes;
243  }

◆ seek_key()

seek tools::wroot::key::seek_key ( ) const
inline

Definition at line 171 of file key.

171 {return m_seek_key;}

◆ set_cycle()

void tools::wroot::key::set_cycle ( uint16  a_cycle)
inline

Definition at line 127 of file key.

127 {m_cycle = a_cycle;}

◆ set_number_of_bytes()

void tools::wroot::key::set_number_of_bytes ( uint32  a_n)
inline

Definition at line 166 of file key.

166 {m_nbytes = a_n;}

◆ std_string_record_size()

static unsigned int tools::wroot::key::std_string_record_size ( const std::string &  x)
inlinestatic

Definition at line 29 of file key.

29  {
30  // Returns size string will occupy on I/O buffer.
31  if (x.size() > 254)
32  return uint32(x.size()+sizeof(unsigned char)+sizeof(int));
33  else
34  return uint32(x.size()+sizeof(unsigned char));
35  }

◆ to_buffer()

bool tools::wroot::key::to_buffer ( wbuf a_wb,
bool  a_verbose 
) const
inline

Definition at line 177 of file key.

177  {
178  if(!a_wb.write(m_nbytes)) return false;
179  short version = m_version;
180  if(!a_wb.write(version)) return false;
181  if(!a_wb.write(m_object_size)) return false;
182  unsigned int _date = 0; //FIXME
183  if(!a_wb.write(_date)) return false;
184  if(!a_wb.write(m_key_length)) return false;
185  if(!a_wb.write(m_cycle)) return false;
186  if(version>(short)big_file_version_tag()) {
187  if(!a_wb.write(m_seek_key)) return false;
188  if(!a_wb.write(m_seek_directory)) return false;
189  } else {
190  if(m_seek_key>START_BIG_FILE()) {
191  m_out << "tools::wroot::key::to_buffer :"
192  << " attempt to write big seek "
193  << m_seek_key << " on 32 bits."
194  << std::endl;
195  return false;
196  }
197  if(!a_wb.write((seek32)m_seek_key)) return false;
199  m_out << "tools::wroot::key::to_buffer :"
200  << " (2) attempt to write big seek "
201  << m_seek_directory << " on 32 bits."
202  << std::endl;
203  return false;
204  }
205  if(!a_wb.write((seek32)m_seek_directory)) return false;
206  }
207  if(!a_wb.write(m_object_class)) return false;
208  if(!a_wb.write(m_object_name)) return false;
209  if(!a_wb.write(m_object_title)) return false;
210  if(a_verbose) {
211  m_out << "tools::wroot::key::to_buffer :"
212  << " nbytes : " << m_nbytes
213  << ", object class : " << sout(m_object_class)
214  << ", object name : " << sout(m_object_name)
215  << ", object title : " << sout(m_object_title)
216  << ", object size : " << m_object_size
217  << "."
218  << std::endl;
219  }
220  return true;
221  }

◆ write_file()

bool tools::wroot::key::write_file ( ifile a_file,
uint32 a_nbytes 
)
inline

Definition at line 139 of file key.

139  {
140  if(!a_file.set_pos(m_seek_key)) {
141  a_nbytes = 0;
142  return false;
143  }
144  if(!a_file.write_buffer(m_buffer,m_nbytes)) {
145  a_nbytes = 0;
146  return false;
147  }
148 
149  if(a_file.verbose()) {
150  m_out << "tools::wroot::key::write_file :"
151  << " writing " << m_nbytes << " bytes"
152  << " at address " << m_seek_key
153  << " for ID=" << sout(m_object_name)
154  << " Title=" << sout(m_object_title) << "."
155  << std::endl;
156  }
157 
158  delete [] m_buffer; //???
159  m_buffer = 0;
160  m_buf_size = 0;
161 
162  a_nbytes = m_nbytes;
163  return true;
164  }

◆ write_self()

bool tools::wroot::key::write_self ( ifile a_file)
inline

Definition at line 133 of file key.

133  {
134  char* buffer = m_buffer;
135  wbuf wb(m_out,a_file.byte_swap(),eob(),buffer);
136  return to_buffer(wb,a_file.verbose());
137  }

Member Data Documentation

◆ m_buf_size

uint32 tools::wroot::key::m_buf_size
protected

Definition at line 281 of file key.

◆ m_buffer

char* tools::wroot::key::m_buffer
protected

Definition at line 282 of file key.

◆ m_cycle

uint16 tools::wroot::key::m_cycle
protected

Definition at line 289 of file key.

◆ m_date

date tools::wroot::key::m_date
protected

Definition at line 287 of file key.

◆ m_key_length

uint16 tools::wroot::key::m_key_length
protected

Definition at line 288 of file key.

◆ m_nbytes

uint32 tools::wroot::key::m_nbytes
protected

Definition at line 284 of file key.

◆ m_object_class

std::string tools::wroot::key::m_object_class
protected

Definition at line 292 of file key.

◆ m_object_name

std::string tools::wroot::key::m_object_name
protected

Definition at line 293 of file key.

◆ m_object_size

uint32 tools::wroot::key::m_object_size
protected

Definition at line 286 of file key.

◆ m_object_title

std::string tools::wroot::key::m_object_title
protected

Definition at line 294 of file key.

◆ m_out

std::ostream& tools::wroot::key::m_out
protected

Definition at line 280 of file key.

◆ m_seek_directory

seek tools::wroot::key::m_seek_directory
protected

Definition at line 291 of file key.

◆ m_seek_key

seek tools::wroot::key::m_seek_key
protected

Definition at line 290 of file key.

◆ m_version

uint32 tools::wroot::key::m_version
protected

Definition at line 285 of file key.


The documentation for this class was generated from the following file:
tools::wroot::seek
int64 seek
Definition: seek:16
tools::wroot::key::m_date
date m_date
Definition: key:287
tools::wroot::key::m_key_length
uint16 m_key_length
Definition: key:288
tools::wroot::seek32
int seek32
Definition: seek:17
tools::wroot::get_date
date get_date()
Definition: date:19
tools::wroot::big_file_version_tag
uint32 big_file_version_tag()
Definition: seek:21
tools::wroot::key::m_cycle
uint16 m_cycle
Definition: key:289
tools::wroot::key::m_seek_key
seek m_seek_key
Definition: key:290
tools::wroot::key::m_buffer
char * m_buffer
Definition: key:282
tools::wroot::key::initialize_zero
bool initialize_zero()
Definition: key:245
tools::version
unsigned int version()
Definition: version:14
tools::wroot::key::m_version
uint32 m_version
Definition: key:285
tools::wroot::key::m_object_title
std::string m_object_title
Definition: key:294
tools::wroot::date
unsigned int date
Definition: date:17
tools::wroot::key::std_string_record_size
static unsigned int std_string_record_size(const std::string &x)
Definition: key:29
tools::wroot::key::m_out
std::ostream & m_out
Definition: key:280
tools::wroot::key::m_seek_directory
seek m_seek_directory
Definition: key:291
tools::wroot::key::eob
const char * eob() const
Definition: key:175
tools::wroot::key::record_size
uint32 record_size(uint32 a_version) const
Definition: key:224
tools::wroot::key::m_nbytes
uint32 m_nbytes
Definition: key:284
tools::wroot::key::m_object_class
std::string m_object_class
Definition: key:292
tools::wroot::key::m_buf_size
uint32 m_buf_size
Definition: key:281
tools::wroot::key::m_object_size
uint32 m_object_size
Definition: key:286
tools::wroot::key::initialize
bool initialize(ifile &a_file, uint32 a_nbytes)
Definition: key:255
tools::uint32
unsigned int uint32
Definition: typedefs:71
tools::wroot::key::m_object_name
std::string m_object_name
Definition: key:293
tools::wroot::key::to_buffer
bool to_buffer(wbuf &a_wb, bool a_verbose) const
Definition: key:177
tools::wroot::START_BIG_FILE
uint32 START_BIG_FILE()
Definition: seek:19