inlib  1.2.0
Public Member Functions | Protected Member Functions | Protected Attributes
inlib::wroot::branch Class Reference
Inheritance diagram for inlib::wroot::branch:
Inheritance graph
[legend]
Collaboration diagram for inlib::wroot::branch:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual const std::string & store_cls () const
virtual bool stream (buffer &a_buffer) const
 branch (itree &a_tree, const std::string &a_name, const std::string &a_title)
virtual ~branch ()
void set_basket_size (uint32 a_size)
template<class T >
leaf< T > * create_leaf (const std::string &a_name, const std::string &a_title)
const std::vector< base_leaf * > & leaves () const
bool fill (uint32 &a_nbytes)

Protected Member Functions

 branch (const branch &a_from)
branchoperator= (const branch &)
bool fill_leaves (buffer &a_buffer)

Protected Attributes

itreem_tree
std::ostream & m_out
ObjArray< basketm_baskets
std::string m_name
std::string m_title
bool fAutoDelete
ObjArray< branchm_branches
ObjArray< base_leafm_leaves
uint32 m_basket_size
uint32 m_write_basket
uint64 m_entry_number
uint64 m_entries
uint64 m_tot_bytes
uint64 m_zip_bytes
uint32 m_max_baskets
uint32fBasketBytes
uint32fBasketEntry
seekfBasketSeek

Detailed Description

Definition at line 15 of file branch.


Constructor & Destructor Documentation

inlib::wroot::branch::branch ( itree a_tree,
const std::string &  a_name,
const std::string &  a_title 
) [inline]

Definition at line 103 of file branch.

  :m_tree(a_tree)
  ,m_out(a_tree.dir().file().out())
  ,m_name(a_name)
  ,m_title(a_title)
  ,fAutoDelete(false)

  //,m_branches(true)
  //,m_leaves(true)
  ,m_basket_size(32000)
  ,m_write_basket(0)
  ,m_entry_number(0)
  ,m_entries(0)
  ,m_tot_bytes(0)
  ,m_zip_bytes(0)
  ,m_max_baskets(10)
  ,fBasketBytes(0)
  ,fBasketEntry(0)
  ,fBasketSeek(0)
  {
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
    fBasketBytes = new uint32[m_max_baskets];
    fBasketEntry = new uint32[m_max_baskets];
    fBasketSeek = new seek[m_max_baskets];
   {for(uint32 i=0;i<m_max_baskets;i++) {
      fBasketBytes[i] = 0;
      fBasketEntry[i] = 0;
      fBasketSeek[i] = 0;
    }}
    m_baskets.push_back(new basket(m_tree.dir().file(),
                                   m_tree.dir().seek_directory(),
                                   m_name,m_title,"TBasket",
                                   m_basket_size));
  }
virtual inlib::wroot::branch::~branch ( ) [inline, virtual]

Definition at line 141 of file branch.

                   {
    delete [] fBasketBytes;
    delete [] fBasketEntry;
    delete [] fBasketSeek;
    fBasketBytes = 0;
    fBasketEntry = 0;
    fBasketSeek = 0;
#ifdef INLIB_MEM
    mem::decrement(s_class().c_str());
#endif
  }
inlib::wroot::branch::branch ( const branch a_from) [inline, protected]

Definition at line 153 of file branch.

  : ibo(a_from)
  ,m_tree(a_from.m_tree)
  ,m_out(a_from.m_out)
  {}

Member Function Documentation

template<class T >
leaf<T>* inlib::wroot::branch::create_leaf ( const std::string &  a_name,
const std::string &  a_title 
) [inline]

Definition at line 163 of file branch.

                                                       {
    leaf<T>* lf = new leaf<T>(m_out,*this,a_name,a_title);
    m_leaves.push_back(lf);
    return lf;
  }
bool inlib::wroot::branch::fill ( uint32 a_nbytes) [inline]

Definition at line 172 of file branch.

                              {
    a_nbytes = 0;

    //FIXME if (TestBit(kDoNotProcess)) return 0;

    basket* bk = m_baskets[m_write_basket];
    if(!bk) {
      m_out << "inlib::wroot::branch::fill :"
            << " get_basket failed."
            << std::endl;
      return false;
    }

    buffer& buf = bk->datbuf();
    
    uint32 lold = buf.length();
  
    bk->update(bk->key_length()+lold);
    m_entries++;
    m_entry_number++;
  
    if(!fill_leaves(buf)) return false;
  
    uint32 lnew   = buf.length();
    uint32 nbytes = lnew - lold;
    uint32 nsize  = 0;

    // Should we create a new basket?
    // Compare expected next size with m_basket_size.
    if((lnew+2*nsize+nbytes)>=m_basket_size) { 
      uint32 nout;
      if(!bk->write_on_file(m_write_basket,nout)) {
        m_out << "inlib::wroot::branch::fill :"
              << " basket.write_buffer() failed."
              << std::endl;
        return false;
      }
      fBasketBytes[m_write_basket]  = bk->number_of_bytes();
    //fBasketEntry[m_write_basket] //can't be set here.
      fBasketSeek[m_write_basket]   = bk->seek_key();
      uint32 add_bytes = bk->object_size() + bk->key_length();

      delete bk;
      m_baskets[m_write_basket] = 0;

      m_tot_bytes += add_bytes;
      m_zip_bytes += nout;

      m_tree.add_tot_bytes(add_bytes);
      m_tree.add_zip_bytes(nout);

      bk = new basket(m_tree.dir().file(),m_tree.dir().seek_directory(),
                      m_name,m_title,"TBasket",m_basket_size);

      m_write_basket++;

      if(m_write_basket>=m_baskets.size())  {
        m_baskets.resize(2*m_write_basket,0);
      }
      m_baskets[m_write_basket] = bk;
  
      if(m_write_basket>=m_max_baskets) {
        //Increase BasketEntry buffer of a minimum of 10 locations
        // and a maximum of 50 per cent of current size
        uint32 newsize = mx<uint32>(10,uint32(1.5*m_max_baskets));
        if(newsize>=START_BIG_FILE()) {
          //we are going to have pb with uint32[] indexing.
          m_out << "inlib::wroot::branch::fill :"
                << " new size for fBasket[Bytes,Entry,Seek] arrays"
                << " is too close of 32 bits limit."
                << std::endl;
          m_out << "inlib::wroot::branch::fill :"
                << " you have to work with larger basket size."
                << std::endl;
          return false;
        }

        if(!realloc<uint32>(fBasketBytes,newsize,m_max_baskets,true)) {
          m_out << "inlib::wroot::branch::fill : realloc failed." << std::endl;
          return false;
        }
        if(!realloc<uint32>(fBasketEntry,newsize,m_max_baskets,true)){
          m_out << "inlib::wroot::branch::fill : realloc failed." << std::endl;
          return false;
        }
        if(!realloc<seek>(fBasketSeek,newsize,m_max_baskets,true)){
          m_out << "inlib::wroot::branch::fill : realloc failed." << std::endl;
          return false;
        }
        m_max_baskets = newsize;
      }
      fBasketBytes[m_write_basket] = 0;
      fBasketEntry[m_write_basket] = (uint32)m_entry_number;
      fBasketSeek[m_write_basket]  = 0;
    }
    a_nbytes = nbytes;
    return true;
  }
bool inlib::wroot::branch::fill_leaves ( buffer a_buffer) [inline, protected]

Definition at line 271 of file branch.

                                     {
    std::vector<base_leaf*>::iterator it;
    for(it=m_leaves.begin();it!=m_leaves.end();++it) {
      if(!(*it)->fill_basket(a_buffer)) return false;
    }
    return true;
  }
const std::vector<base_leaf*>& inlib::wroot::branch::leaves ( ) const [inline]

Definition at line 170 of file branch.

{return m_leaves;}
branch& inlib::wroot::branch::operator= ( const branch ) [inline, protected]

Definition at line 158 of file branch.

{return *this;}
void inlib::wroot::branch::set_basket_size ( uint32  a_size) [inline]

Definition at line 160 of file branch.

{m_basket_size = a_size;}
virtual const std::string& inlib::wroot::branch::store_cls ( ) const [inline, virtual]

Implements inlib::wroot::ibo.

Definition at line 25 of file branch.

                                             {
    static const std::string s_v("TBranch");
    return s_v;
  }
virtual bool inlib::wroot::branch::stream ( buffer a_buffer) const [inline, virtual]

Implements inlib::wroot::ibo.

Definition at line 29 of file branch.

                                              {
    unsigned int c;
    if(!a_buffer.write_version(8,c)) return false;
    if(!Named_stream(a_buffer,m_name,m_title)) return false;

    if(!AttFill_stream(a_buffer)) return false;

    int fCompress = m_tree.dir().file().compression();
    int fEntryOffsetLen = 1000;
    int fOffset = 0;
    int fSplitLevel = 0;

    if(!a_buffer.write(fCompress)) return false;
    if(!a_buffer.write(m_basket_size)) return false;
    if(!a_buffer.write(fEntryOffsetLen)) return false;
    if(!a_buffer.write(m_write_basket)) return false;
    int fEntryNumber = (int)m_entry_number;
    if(!a_buffer.write(fEntryNumber)) return false;
    if(!a_buffer.write(fOffset)) return false;
    if(!a_buffer.write(m_max_baskets)) return false;
    if(!a_buffer.write(fSplitLevel)) return false;
    double fEntries = (double)m_entries;
    if(!a_buffer.write(fEntries)) return false;
    double fTotBytes = (double)m_tot_bytes;
    double fZipBytes = (double)m_zip_bytes;
    if(!a_buffer.write(fTotBytes)) return false;
    if(!a_buffer.write(fZipBytes)) return false;

    if(!m_branches.stream(a_buffer)) return false;
    if(!m_leaves.stream(a_buffer)) return false;
    if(!m_baskets.stream(a_buffer)) return false;

    // See TStreamerInfo::ReadBuffer::WriteBasicPointer
    if(!a_buffer.write((char)1)) return false;
    if(!a_buffer.write_fast_array(fBasketBytes,m_max_baskets)) return false;
    if(!a_buffer.write((char)1)) return false;
    if(!a_buffer.write_fast_array(fBasketEntry,m_max_baskets)) return false;

    char isBigFile = 1;
    //GB : begin
    //if(fTree.directory().file().end()>RIO_START_BIG_FILE()) isBigFile = 2;
   {for(uint32 i=0;i<m_max_baskets;i++) {
      if(fBasketSeek[i]>START_BIG_FILE()) {
        isBigFile = 2;
        break;
      }
    }}
    //GB : end
   
    if(!a_buffer.write(isBigFile)) return false;
    if(isBigFile==2) {
      if(!a_buffer.write_fast_array(fBasketSeek,m_max_baskets)) return false;
    } else {
      for(uint32 i=0;i<m_max_baskets;i++) {
        if(fBasketSeek[i]>START_BIG_FILE()) { //G.Barrand : add this test.
          m_out << "inlib::wroot::branch::stream :"
                << " attempt to write big Seek "
                << fBasketSeek[i] << " on 32 bits."
                << std::endl;
          return false;
        }

        if(!a_buffer.write((seek32)fBasketSeek[i])) return false;
      }
    }

    // fFileName
    if(!a_buffer.write(std::string(""))) return false;

    if(!a_buffer.set_byte_count(c)) return false;
    return true;
  }

Member Data Documentation

Definition at line 289 of file branch.

Definition at line 299 of file branch.

Definition at line 300 of file branch.

Definition at line 301 of file branch.

Definition at line 292 of file branch.

Definition at line 281 of file branch.

Definition at line 290 of file branch.

Definition at line 295 of file branch.

Definition at line 294 of file branch.

Definition at line 291 of file branch.

Definition at line 298 of file branch.

std::string inlib::wroot::branch::m_name [protected]

Definition at line 286 of file branch.

std::ostream& inlib::wroot::branch::m_out [protected]

Definition at line 280 of file branch.

std::string inlib::wroot::branch::m_title [protected]

Definition at line 287 of file branch.

Definition at line 296 of file branch.

Definition at line 279 of file branch.

Definition at line 293 of file branch.

Definition at line 297 of file branch.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines