Go to the documentation of this file.
4 #ifndef tools_rroot_buffer
5 #define tools_rroot_buffer
11 #include "../mapmanip"
22 #ifdef tools_stl_vector
23 #define TOOLS_RROOT_OBJ_MAP_HASH_TABLE
26 #define TOOLS_RROOT_OBJ_MAP_STD_MAP
29 #ifdef TOOLS_RROOT_OBJ_MAP_STD_MAP
32 #ifdef TOOLS_RROOT_OBJ_MAP_OMAP
35 #ifdef TOOLS_RROOT_OBJ_MAP_HASH_TABLE
36 #include "../hash_table"
46 static const std::string& s_class() {
47 static const std::string s_v(
"tools::rroot::buffer");
51 #ifdef TOOLS_RROOT_OBJ_MAP_STD_MAP
52 typedef std::map<uint32,iro*> obj_map;
54 #ifdef TOOLS_RROOT_OBJ_MAP_OMAP
55 typedef omap<uint32,iro*> obj_map;
57 #ifdef TOOLS_RROOT_OBJ_MAP_HASH_TABLE
58 class obj_map :
public hash_table<uint32,iro*> {
59 typedef hash_table<uint32,iro*>
parent;
61 virtual unsigned int hash(
const uint32& a_key) {
62 return hash(&a_key,
sizeof(
uint32));
65 return a_key1==a_key2?
true:
false;
71 obj_map(
const obj_map& a_from):
parent(a_from){}
72 obj_map&
operator=(
const obj_map& a_from){
80 buffer(std::ostream& a_out,
bool a_byte_swap,
uint32 a_size,
char* a_buffer,
uint32 a_klen,
bool a_verbose)
93 mem::increment(s_class().c_str());
99 mem::decrement(s_class().c_str());
109 mem::increment(s_class().c_str());
144 m_out <<
"tools::rroot::read_class_tag :"
145 <<
" read string." << std::endl;
162 unsigned int cl_offset = (tag & ~
kClassMask());
165 char* old_pos =
m_pos;
176 std::ios::fmtflags old_flags =
m_out.flags();
177 m_out <<
"tools::rroot::read_class_tag :"
178 <<
" tag unknown case ! "
179 << tag <<
" hex " << std::hex << tag
181 m_out.flags(old_flags);
200 std::ios::fmtflags old_flags =
m_out.flags();
201 m_out <<
"tools::rroot::read_class :"
202 <<
" first_int " << std::hex << first_int
204 m_out.flags(old_flags);
209 m_out <<
"tools::rroot::read_class :"
210 <<
" first_int is kNullTag."
228 m_out <<
"tools::rroot::read_class :"
229 <<
" first_int & kByteCountMask."
239 m_out <<
"tools::rroot::buffer::read_class :"
240 <<
" read_class_tag did not find a class name."
249 m_out <<
"tools::rroot::read_class :"
250 <<
" kNewClassTag : read class name " <<
sout(a_class)
251 <<
" a_bcnt " << a_bcnt
252 <<
" bef_tag " << bef_tag
260 std::ios::fmtflags old_flags =
m_out.flags();
261 m_out <<
"tools::rroot::read_class :"
262 <<
" first_int " << std::hex << first_int
263 <<
". first_int is position toward object."
265 m_out.flags(old_flags);
277 #ifdef TOOLS_RROOT_OBJ_MAP_HASH_TABLE
278 m_out <<
"tools::rroot::remove_in_map : dummy." << std::endl;
296 m_out <<
"tools::rroot::buffer::read_object :"
297 <<
" can't read class." << std::endl;
303 m_out <<
"tools::rroot::buffer::read_object :"
304 <<
" class " <<
sout(sclass) <<
", is_ref " << is_ref
312 unsigned int obj_offset = bcnt;
317 m_out <<
"tools::rroot::buffer::read_object : warning :"
318 <<
" class " <<
sout(sclass) <<
", is_ref but map objs is not enabled on this buffer."
323 #ifdef TOOLS_RROOT_OBJ_MAP_HASH_TABLE
324 if(
m_objs.find(obj_offset,a_obj)) {
329 obj_map::const_iterator it =
m_objs.find(obj_offset);
331 a_obj = (*it).second;
339 {
char* old_pos =
m_pos;
345 m_out <<
"tools::rroot::buffer::read_object : parent::read(first_int) failed." << std::endl;
351 m_out <<
"tools::rroot::buffer::read_object : read_class_tag() failed." << std::endl;
355 m_out <<
"tools::rroot::buffer::read_object :"
356 <<
" read_class_tag did not find a class name."
367 m_out <<
"tools::rroot::buffer::read_object : is_ref : creation of object"
368 <<
" of class " <<
sout(sclass) <<
" failed." << std::endl;
374 #ifdef TOOLS_RROOT_OBJ_MAP_HASH_TABLE
375 if(!
m_objs.insert(obj_offset,obj)) {
376 m_out <<
"tools::rroot::buffer::read_object :"
377 <<
" map insert failed."
386 m_out <<
"tools::rroot::buffer::read_object :"
387 <<
" is_ref : streamed failed for class " <<
sout(scls)
403 m_out <<
"tools::rroot::buffer::read_object :"
447 m_out <<
"tools::rroot::buffer::read_object : creation of object"
448 <<
" of class " <<
sout(sclass) <<
" failed." << std::endl;
455 #ifdef TOOLS_RROOT_OBJ_MAP_HASH_TABLE
456 if(!
m_objs.insert(startpos,obj)) {
457 m_out <<
"tools::rroot::buffer::read_object :"
458 <<
" map insert failed."
470 m_out <<
"tools::rroot::buffer::read_object : object.stream() failed"
471 <<
" for object of class " <<
sout(sclass) <<
"." << std::endl;
482 m_out <<
"tools::rroot::buffer::read_object :"
483 <<
" check_byte_count failed "
484 <<
"for object of class "
485 <<
sout(sclass) <<
"." << std::endl;
497 m_out <<
"tools::rroot::buffer::read_object : end." << std::endl;
555 m_pos -=
sizeof(
unsigned int);
562 a_start_pos = startpos;
569 if(!a_byte_count)
return true;
571 size_t len = a_start_pos + a_byte_count +
sizeof(
unsigned int);
575 if(
diff==len)
return true;
578 m_out <<
"tools::rroot::buffer::check_byte_count :"
579 <<
" object of class " <<
sout(a_store_cls)
580 <<
" read too few bytes ("
585 m_out <<
"tools::rroot::buffer::check_byte_count :"
586 <<
" object of class " <<
sout(a_store_cls)
587 <<
" read too many bytes ("
588 <<
long_out(
long(
diff-len)) <<
" in excess)." << std::endl;
591 m_out <<
"tools::rroot::buffer::check_byte_count :"
592 <<
" " <<
sout(a_store_cls)
593 <<
" streamer not in sync with data on file, fix streamer."
606 while (nr <
int(a_max-1)) {
648 const std::string& a_T_class,
649 T*& a_obj,
bool& a_created){
651 if(!a_buffer.
read_object(a_fac,a_args,obj,a_created)) {
652 a_buffer.
out() <<
"tools::rroot::pointer_stream : read_object failed." << std::endl;
661 a_obj = (T*)obj->
cast(a_T_class);
663 a_buffer.
out() <<
"tools::rroot::pointer_stream : "
664 <<
" inlib::cast to " << a_T_class <<
" failed."
665 <<
". Object is a " << obj->
s_cls() <<
"."
667 if(a_created)
delete obj;
679 T*& a_obj,
bool& a_created){
681 if(!a_buffer.
read_object(a_fac,a_args,obj,a_created)) {
682 a_buffer.
out() <<
"tools::rroot::pointer_stream : read_object failed." << std::endl;
691 a_obj = (T*)obj->
cast(a_T_class);
693 a_buffer.
out() <<
"tools::rroot::pointer_stream : "
694 <<
" inlib::cast to " << a_T_class <<
" failed."
695 <<
". Object is a " << obj->
s_cls() <<
"."
697 if(a_created)
delete obj;
708 return pointer_stream(a_buffer,a_fac,a_args,T::id_class(),a_obj,a_created);
716 if(!a_buffer.
read(is_array))
return false;
717 if(!is_array)
return true;
718 if(!a_n)
return true;