inlib
1.2.0
|
Public Member Functions | |
key (ifile &a_file) | |
key (ifile &a_file, seek a_pos, uint32 a_nbytes) | |
virtual | ~key () |
key & | operator= (const key &a_from) |
ifile & | file () |
uint32 | nbytes () const |
seek | seek_key () const |
uint32 | object_size () const |
const std::string & | object_name () const |
std::string | object_name () |
const std::string & | object_title () const |
std::string | object_title () |
const std::string & | object_class () const |
std::string | object_class () |
bool | read_file () |
char * | buf () const |
char * | data_buffer () const |
const char * | eob () const |
uint32 | buf_size () const |
uint32 | key_length () const |
bool | from_buffer (const char *aEOB, char *&a_pos) |
char * | get_object_buffer (uint32 &a_size) |
void | dump (std::ostream &a_out) const |
Static Public Member Functions | |
static uint32 | std_string_record_size (const std::string &x) |
Protected Member Functions | |
key (const key &a_from) | |
uint32 | record_size (uint32 a_version) const |
bool | unzip (std::ostream &a_out, int a_srcsize, unsigned char *a_src, int a_tgtsize, unsigned char *a_tgt, int &a_irep) |
Static Protected Member Functions | |
static std::string | sout (const std::string &a_string) |
static const std::string & | s_class () |
Protected Attributes | |
ifile & | m_file |
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_parent_dir |
std::string | m_object_class |
std::string | m_object_name |
std::string | m_object_title |
Static Protected Attributes | |
static const uint32 | START_BIG_FILE = 2000000000 |
inlib::rroot::key::key | ( | ifile & | a_file | ) | [inline] |
Definition at line 42 of file key.
:m_file(a_file) ,m_buf_size(0) ,m_buffer(0) // Record : ,m_nbytes(0) ,m_version(class_version()) ,m_object_size(0) ,m_date(0) ,m_key_length(0) ,m_cycle(0) ,m_seek_key(0) ,m_seek_parent_dir(0) //,m_object_class //,m_object_name //,m_object_title { #ifdef INLIB_MEM mem::increment(s_class().c_str()); #endif m_key_length = record_size(m_version); //fDate.setDate(0); }
Definition at line 66 of file key.
:m_file(a_file) ,m_buf_size(0) ,m_buffer(0) // Record : ,m_nbytes(a_nbytes) //key len + compressed object size ,m_version(class_version()) ,m_object_size(0) ,m_date(0) ,m_key_length(0) ,m_cycle(0) ,m_seek_key(a_pos) ,m_seek_parent_dir(0) //,m_object_class //,m_object_name //,m_object_title { #ifdef INLIB_MEM mem::increment(s_class().c_str()); #endif if(a_pos>START_BIG_FILE) m_version += 1000; m_buffer = new char[a_nbytes]; if(!m_buffer) { m_file.out() << "inlib::rroot::key::key(cpcstor) :" << " can't alloc " << a_nbytes << "." << std::endl; } else { m_buf_size = a_nbytes; } }
virtual inlib::rroot::key::~key | ( | ) | [inline, virtual] |
inlib::rroot::key::key | ( | const key & | a_from | ) | [inline, protected] |
Definition at line 103 of file key.
:m_file(a_from.m_file) ,m_buf_size(0) ,m_buffer(0) ,m_nbytes(a_from.m_nbytes) ,m_version(a_from.m_version) ,m_object_size(a_from.m_object_size) ,m_date(a_from.m_date) ,m_key_length(a_from.m_key_length) ,m_cycle(a_from.m_cycle) ,m_seek_key(a_from.m_seek_key) ,m_seek_parent_dir(a_from.m_seek_parent_dir) ,m_object_class(a_from.m_object_class) ,m_object_name(a_from.m_object_name) ,m_object_title(a_from.m_object_title) { #ifdef INLIB_MEM mem::increment(s_class().c_str()); #endif if(a_from.m_buf_size && a_from.m_buffer) { m_buffer = new char[a_from.m_buf_size]; if(!m_buffer) { m_file.out() << "inlib::rroot::key::key(cpcstor) :" << " can't alloc " << a_from.m_buf_size << "." << std::endl; } else { m_buf_size = a_from.m_buf_size; ::memcpy(m_buffer,a_from.m_buffer,a_from.m_buf_size); } } }
char* inlib::rroot::key::buf | ( | ) | const [inline] |
uint32 inlib::rroot::key::buf_size | ( | ) | const [inline] |
Definition at line 200 of file key.
{return m_buf_size;}
char* inlib::rroot::key::data_buffer | ( | ) | const [inline] |
Definition at line 198 of file key.
{return m_buffer + m_key_length;}
void inlib::rroot::key::dump | ( | std::ostream & | a_out | ) | const [inline] |
Definition at line 410 of file key.
{ a_out << "class : " << sout(m_object_class) << ", name : " << sout(m_object_name) << ", title : " << sout(m_object_title) << ", size : " << m_object_size << "." << std::endl; }
const char* inlib::rroot::key::eob | ( | ) | const [inline] |
Definition at line 199 of file key.
{return m_buffer + m_buf_size;}
bool inlib::rroot::key::from_buffer | ( | const char * | aEOB, |
char *& | a_pos | ||
) | [inline] |
Definition at line 203 of file key.
{ rbuf rb(m_file.out(),m_file.byte_swap(),aEOB,a_pos); int nbytes; if(!rb.read(nbytes)) return false; /* if(m_nbytes) { if(nbytes!=int(m_nbytes)) { out << "inlib::rroot::key::from_buffer :" << " nbytes not consistent." << " read " << nbytes << ", expected " << m_nbytes << ". Continue with " << nbytes << std::endl; m_nbytes = nbytes; } } else { */ m_nbytes = nbytes; //} short version; if(!rb.read(version)) return false; m_version = version; {int v; if(!rb.read(v)) return false; m_object_size = v;} unsigned int date; if(!rb.read(date)) return false; //fDate.setDate(date); {short v; if(!rb.read(v)) return false; m_key_length = v;} {short v; if(!rb.read(v)) return false; m_cycle = v;} if(version>1000) { if(!rb.read(m_seek_key)) return false; if(!rb.read(m_seek_parent_dir)) return false; } else { {seek32 i; if(!rb.read(i)) return false; m_seek_key = i;} {seek32 i; if(!rb.read(i)) return false; m_seek_parent_dir = i;} } if(!rb.read(m_object_class)) return false; if(!rb.read(m_object_name)) return false; if(!rb.read(m_object_title)) return false; if(m_file.verbose()) { m_file.out() << "inlib::rroot::key::from_buffer :" << " nbytes : " << m_nbytes << ", object class : " << sout(m_object_class) << ", object name : " << sout(m_object_name) << ", object title : " << sout(m_object_title) << ", object size : " << m_object_size << "." << std::endl; } return true; }
char* inlib::rroot::key::get_object_buffer | ( | uint32 & | a_size | ) | [inline] |
Definition at line 264 of file key.
{ if(!m_key_length) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " WARNING : m_key_length is zero." << std::endl; //delete [] m_buffer; //m_buffer = 0; //m_buf_size = 0; //a_size = 0; //return 0; } if(!m_nbytes) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " m_nbytes is zero." << std::endl; delete [] m_buffer; m_buffer = 0; m_buf_size = 0; a_size = 0; return 0; } if(!m_object_size) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " WARNING : m_object_size is zero." << std::endl; } if(m_file.verbose()) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " m_nbytes : " << m_nbytes << " m_key_length : " << m_key_length << " m_object_size : " << m_object_size << "." << " m_seek_key : " << m_seek_key << "." << std::endl; } if(m_object_size <= (m_nbytes-m_key_length)) { delete [] m_buffer; m_buf_size = m_key_length+m_object_size; if(m_buf_size<m_nbytes) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " WARNING : m_buf_size<m_nbytes." << " m_buf_size " << m_buf_size << " m_nbytes " << m_nbytes << ". Raise m_buf_size to " << m_nbytes << "." << std::endl; m_buf_size = m_nbytes; //for read_file() } m_buffer = new char[m_buf_size]; if(!m_buffer) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " can't alloc " << m_buf_size << std::endl; m_buffer = 0; m_buf_size = 0; a_size = 0; return 0; } if(!read_file()) { delete [] m_buffer; m_buffer = 0; m_buf_size = 0; a_size = 0; return 0; } } else { // have to decompress. Need a second buffer. uint32 decsiz = m_key_length+m_object_size; char* decbuf = new char[decsiz]; if(!decbuf) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " can't alloc " << decsiz << std::endl; a_size = 0; return 0; } delete [] m_buffer; m_buffer = new char[m_nbytes]; m_buf_size = m_nbytes; if(!read_file()) { delete [] decbuf; decbuf = 0; delete [] m_buffer; m_buffer = 0; m_buf_size = 0; a_size = 0; return 0; } ::memcpy(decbuf,m_buffer,m_key_length); // decompress : unsigned char* objbuf = (unsigned char*)(decbuf+m_key_length); unsigned char* bufcur = (unsigned char*)(m_buffer+m_key_length); int nout = 0; uint32 noutot = 0; while(true) { int nin = 9 + ((int)bufcur[3] | ((int)bufcur[4] << 8) | ((int)bufcur[5] << 16)); int nbuf = (int)bufcur[6] | ((int)bufcur[7] << 8) | ((int)bufcur[8] << 16); if(!unzip(m_file.out(),nin,bufcur, nbuf,objbuf, nout)) break; if(!nout) break; noutot += nout; if(noutot >= m_object_size) break; bufcur += nin; objbuf += nout; } delete [] m_buffer; m_buffer = 0; m_buf_size = 0; if(!noutot) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " nothing from decompression." << std::endl; delete [] decbuf; decbuf = 0; a_size = 0; return 0; } if(noutot!=m_object_size) { m_file.out() << "inlib::rroot::key::get_object_buffer :" << " decompression mismatch." << " noutot " << noutot << " m_object_size " << m_object_size << std::endl; delete [] decbuf; decbuf = 0; a_size = 0; return 0; } m_buffer = decbuf; m_buf_size = decsiz; } a_size = m_object_size; return m_buffer+m_key_length; }
uint32 inlib::rroot::key::key_length | ( | ) | const [inline] |
Definition at line 201 of file key.
{return m_key_length;}
uint32 inlib::rroot::key::nbytes | ( | ) | const [inline] |
const std::string& inlib::rroot::key::object_class | ( | ) | const [inline] |
Definition at line 180 of file key.
{return m_object_class;}
std::string inlib::rroot::key::object_class | ( | ) | [inline] |
Definition at line 181 of file key.
{return m_object_class;}
const std::string& inlib::rroot::key::object_name | ( | ) | const [inline] |
Definition at line 174 of file key.
{return m_object_name;}
std::string inlib::rroot::key::object_name | ( | ) | [inline] |
Definition at line 175 of file key.
{return m_object_name;}
uint32 inlib::rroot::key::object_size | ( | ) | const [inline] |
Definition at line 172 of file key.
{return m_object_size;}
const std::string& inlib::rroot::key::object_title | ( | ) | const [inline] |
Definition at line 177 of file key.
{return m_object_title;}
std::string inlib::rroot::key::object_title | ( | ) | [inline] |
Definition at line 178 of file key.
{return m_object_title;}
Definition at line 135 of file key.
{ m_nbytes = a_from.m_nbytes; m_version = a_from.m_version; m_object_size = a_from.m_object_size; m_date = a_from.m_date; m_key_length = a_from.m_key_length; m_cycle = a_from.m_cycle; m_seek_key = a_from.m_seek_key; m_seek_parent_dir = a_from.m_seek_parent_dir; m_object_class = a_from.m_object_class; m_object_name = a_from.m_object_name; m_object_title = a_from.m_object_title; delete [] m_buffer; m_buffer = 0; m_buf_size = 0; if(a_from.m_buf_size && a_from.m_buffer) { m_buffer = new char[a_from.m_buf_size]; if(!m_buffer) { m_file.out() << "inlib::rroot::key::operator=() :" << " can't alloc " << a_from.m_buf_size << "." << std::endl; } else { m_buf_size = a_from.m_buf_size; ::memcpy(m_buffer,a_from.m_buffer,a_from.m_buf_size); } } return *this; }
bool inlib::rroot::key::read_file | ( | ) | [inline] |
Definition at line 183 of file key.
{ // Read the key structure from the file. if(!m_file.set_pos(m_seek_key)) return false; if(!m_file.read_buffer(m_buffer,m_nbytes)) return false; if(m_file.verbose()) { m_file.out() << "inlib::rroot::key::read_file :" << " reading " << m_nbytes << " bytes" << " at position " << m_seek_key << "." << std::endl; } return true; }
Definition at line 422 of file key.
{ // Return the size in bytes of the key header structure. uint32 nbytes = sizeof(m_nbytes); nbytes += sizeof(short); //2 nbytes += sizeof(m_object_size); nbytes += sizeof(date); nbytes += sizeof(m_key_length); nbytes += sizeof(m_cycle); //2+4*4=18 if(a_version>1000) { nbytes += sizeof(seek); nbytes += sizeof(seek); //18+2*8=34 } else { nbytes += sizeof(seek32); nbytes += sizeof(seek32); //18+2*4=26 } nbytes += std_string_record_size(m_object_class); nbytes += std_string_record_size(m_object_name); nbytes += std_string_record_size(m_object_title); //::printf("debug : record_size %d\n",nbytes); return nbytes; }
static const std::string& inlib::rroot::key::s_class | ( | ) | [inline, static, protected] |
Reimplemented in inlib::rroot::basket.
Definition at line 551 of file key.
{ static const std::string s_v("inlib::rroot::key"); return s_v; }
seek inlib::rroot::key::seek_key | ( | ) | const [inline] |
Definition at line 171 of file key.
{return m_seek_key;}
static std::string inlib::rroot::key::sout | ( | const std::string & | a_string | ) | [inline, static, protected] |
static uint32 inlib::rroot::key::std_string_record_size | ( | const std::string & | x | ) | [inline, static] |
bool inlib::rroot::key::unzip | ( | std::ostream & | a_out, |
int | a_srcsize, | ||
unsigned char * | a_src, | ||
int | a_tgtsize, | ||
unsigned char * | a_tgt, | ||
int & | a_irep | ||
) | [inline, protected] |
Definition at line 447 of file key.
{ // Author: E.Chernyaev (IHEP/Protvino) // Input: scrsize - size of input buffer // src - input buffer // tgtsize - size of target buffer // // Output: tgt - target buffer (decompressed) // irep - size of decompressed data // 0 - if error a_irep = 0; // C H E C K H E A D E R const int HDRSIZE = 9; if (a_srcsize < HDRSIZE) { a_out << "inlib::rroot::key::unzip : too small source" << std::endl; return false; } unsigned char DEFLATE = 8; if ((a_src[0] != 'C' && a_src[0] != 'Z') || (a_src[1] != 'S' && a_src[1] != 'L') || a_src[2] != DEFLATE) { a_out << "inlib::rroot::key::unzip : error in header" << std::endl; return false; } long _ibufcnt = (long)a_src[3] | ((long)a_src[4] << 8) | ((long)a_src[5] << 16); long isize = (long)a_src[6] | ((long)a_src[7] << 8) | ((long)a_src[8] << 16); if(a_tgtsize<isize) { a_out << "inlib::rroot::key::unzip : too small target." << std::endl; return false; } if(_ibufcnt + HDRSIZE != a_srcsize) { a_out << "inlib::rroot::key::unzip :" << " discrepancy in source length." << std::endl; return false; } // D E C O M P R E S S D A T A if (a_src[0] == 'Z' && a_src[1] == 'L') { //compressed with zlib. ifile::unzip_func func; if(!m_file.unziper('Z',func)) { a_out << "inlib::rroot::key::unzip : " << " zlib unziper not found." << std::endl; return false; } if(!func(a_out,a_srcsize,a_src + HDRSIZE,a_tgtsize,a_tgt,a_irep)) { a_out << "inlib::rroot::key::unzip : " << " unzip function failed." << std::endl; return false; } } else if (a_src[0] == 'C' && a_src[1] == 'S') { //compressed with Chernyaev & Smirnov csz__Init_Inflate(_ibufcnt,a_src + HDRSIZE,a_tgtsize,a_tgt); if (csz__Inflate()) { a_out << "inlib::rroot::key::unzip :" << " error during decompression." << std::endl; return false; } unsigned char* obufptr = csz__obufptr(); // if (obufptr - a_tgt != isize) { // There are some rare cases when a few more bytes are required if (obufptr - a_tgt > a_tgtsize) { a_out << "inlib::rroot::key::_unzip :" << " discrepancy " << (int)(obufptr - a_tgt) << " with initial size: " << (int)isize << ", tgtsize= " << a_tgtsize << std::endl; a_irep = obufptr - a_tgt; //return false; } a_irep = isize; //a_out << "inlib::rroot::key::unzip : CS : ok " // << a_irep << std::endl; } else { a_out << "inlib::rroot::key::_unzip : unknown a_src[0,1]." << " [0] = " << a_src[0] << ", [1] = " << a_src[1] << std::endl; a_irep = 0; return false; } return true; }
uint32 inlib::rroot::key::m_buf_size [protected] |
char* inlib::rroot::key::m_buffer [protected] |
uint16 inlib::rroot::key::m_cycle [protected] |
date inlib::rroot::key::m_date [protected] |
ifile& inlib::rroot::key::m_file [protected] |
uint16 inlib::rroot::key::m_key_length [protected] |
uint32 inlib::rroot::key::m_nbytes [protected] |
std::string inlib::rroot::key::m_object_class [protected] |
std::string inlib::rroot::key::m_object_name [protected] |
uint32 inlib::rroot::key::m_object_size [protected] |
std::string inlib::rroot::key::m_object_title [protected] |
seek inlib::rroot::key::m_seek_key [protected] |
seek inlib::rroot::key::m_seek_parent_dir [protected] |
uint32 inlib::rroot::key::m_version [protected] |
const uint32 inlib::rroot::key::START_BIG_FILE = 2000000000 [static, protected] |