Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/rroot/directory is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_rroot_directory
0005 #define tools_rroot_directory
0006 
0007 #include "seek"
0008 #include "date"
0009 #include "key"
0010 #include "ifile"
0011 #include "../forit"
0012 #include "../vmanip"
0013 
0014 namespace tools {
0015 namespace rroot {
0016 
0017 class directory {
0018 public:
0019   static const std::string& s_class() {
0020     static const std::string s_v("tools::rroot::directory");
0021     return s_v;
0022   }
0023 public:
0024   directory(ifile& a_file)
0025   :m_file(a_file)
0026   {
0027 #ifdef TOOLS_MEM
0028     mem::increment(s_class().c_str());
0029 #endif
0030     m_date_C = 0; //.set();
0031     m_date_M = 0; //.set();
0032     m_nbytes_keys = 0;
0033     m_nbytes_name = 0;
0034     m_seek_directory = 0;
0035     m_seek_parent = 0;
0036     m_seek_keys = 0;
0037   }
0038   virtual ~directory(){
0039     clear_keys();
0040 #ifdef TOOLS_MEM
0041     mem::decrement(s_class().c_str());
0042 #endif
0043   }
0044 protected:
0045   directory(const directory& a_from):m_file(a_from.m_file){
0046 #ifdef TOOLS_MEM
0047     mem::increment(s_class().c_str());
0048 #endif
0049   }
0050   directory& operator=(const directory &){return *this;}
0051 public:
0052   ifile& file() {return m_file;}
0053 
0054   const std::vector<key*>& keys() const {return m_keys;}
0055   std::vector<key*>& keys() {return m_keys;}
0056 
0057   key* find_key(const std::string& a_name) {
0058     if(m_file.verbose()) {
0059       m_file.out() << "tools::rroot::directory::find_key :"
0060                    << " " << sout(a_name) << " ..."
0061                    << std::endl;
0062     }
0063     tools_vforcit(key*,m_keys,it) {
0064       if((*it)->object_name()==a_name) return *it;
0065     }
0066 
0067     return 0;
0068   }
0069 
0070   key* find_key_from_class(const std::string& a_class) {
0071     if(m_file.verbose()) {
0072       m_file.out() << "tools::rroot::directory::find_key_from_class :"
0073                    << " " << sout(a_class) << " ..."
0074                    << std::endl;
0075     }
0076     tools_vforcit(key*,m_keys,it) {
0077       if((*it)->object_class()==a_class) return *it;
0078     }
0079 
0080     return 0;
0081   }
0082 
0083   uint32 nbytes_name() const {return m_nbytes_name;}
0084   seek seek_keys() const {return m_seek_keys;}
0085   uint32 record_size(uint32 a_version) const {
0086     uint32 nbytes = sizeof(short);
0087     nbytes += sizeof(date); //m_date_C.record_size();
0088     nbytes += sizeof(date); //m_date_M.record_size();
0089     nbytes += sizeof(m_nbytes_keys);
0090     nbytes += sizeof(m_nbytes_name);
0091     if(a_version>=40000) {
0092       nbytes += sizeof(seek);
0093       nbytes += sizeof(seek);
0094       nbytes += sizeof(seek);
0095     } else {
0096       nbytes += sizeof(seek32);
0097       nbytes += sizeof(seek32);
0098       nbytes += sizeof(seek32);
0099     }
0100     return nbytes;
0101   }
0102   bool from_buffer(const char* aEOB,char*& a_buffer){
0103     // Decode input buffer.
0104     // (Name, title) are stored in the (name, title) of the associated key.
0105     rbuf rb(m_file.out(),m_file.byte_swap(),aEOB,a_buffer);
0106     short versiondir;
0107     if(!rb.read(versiondir)) return false;
0108     unsigned int _date;
0109     if(!rb.read(_date)) return false;
0110     //fDateC.setDate(_date);
0111     if(!rb.read(_date)) return false;
0112     //fDateM.setDate(_date);
0113    {int v;
0114     if(!rb.read(v)) return false;
0115     m_nbytes_keys = v;}
0116    {int v;
0117     if(!rb.read(v)) return false;
0118     m_nbytes_name = v;}
0119     if(versiondir>(short)big_file_version_tag()) {
0120       if(!rb.read(m_seek_directory)) return false;
0121       if(!rb.read(m_seek_parent)) return false;
0122       if(!rb.read(m_seek_keys)) return false;
0123     } else {
0124      {seek32 i;
0125       if(!rb.read(i)) return false;
0126       m_seek_directory = i;}
0127 
0128      {seek32 i;
0129       if(!rb.read(i)) return false;
0130       m_seek_parent = i;}
0131 
0132      {seek32 i;
0133       if(!rb.read(i)) return false;
0134       m_seek_keys = i;}
0135     }
0136     if(m_file.verbose()) {
0137       m_file.out() << "tools::rroot::key::from_buffer :"
0138                    << " nbytes keys : " << m_nbytes_keys
0139                    << ", pos keys : " << m_seek_keys
0140                    << std::endl;
0141     }
0142     return true;
0143   }
0144   bool read_keys(uint32& a_number) {
0145     // Read the KEYS :
0146     //  Every directory has a list (fKeys). This list has been
0147     //  written on the file via CERN-ROOT::TDirectory::writeKeys
0148     //  as a single data record.
0149     a_number = 0;
0150 
0151     clear_keys();
0152 
0153     key headerkey(m_file.out(),m_seek_keys,m_nbytes_keys);
0154     if(!headerkey.read_file(m_file)) return false;
0155     char* buffer = headerkey.data_buffer();
0156     if(!headerkey.from_buffer(m_file.byte_swap(),headerkey.eob(),buffer,m_file.verbose())) return false;
0157     int nkeys = 0;
0158     rbuf rb(m_file.out(),m_file.byte_swap(),headerkey.eob(),buffer);
0159     if(!rb.read(nkeys)) return false;
0160     if(m_file.verbose()) {
0161       m_file.out() << "tools::rroot::directory::read_keys :"
0162                    << " nkeys " << nkeys
0163                    << "."
0164                    << std::endl;
0165     }
0166     for(int i=0;i<nkeys;i++) {
0167       key* k = new key(m_file.out());
0168       if(!k->from_buffer(m_file.byte_swap(),headerkey.eob(),buffer,m_file.verbose())) {
0169         delete k;
0170         return false;
0171       }
0172       m_keys.push_back(k);
0173     }
0174     a_number = nkeys;
0175     return true;
0176   }
0177   void clear_keys() {
0178     safe_clear<key>(m_keys);
0179   }
0180 protected:
0181   ifile& m_file;
0182   std::vector<key*> m_keys;
0183   // Record (stored in file):
0184   date m_date_C;           //Date and time when directory is created
0185   date m_date_M;           //Date and time of last modification
0186   uint32 m_nbytes_keys;    //Number of bytes for the keys
0187   uint32 m_nbytes_name;    //Number of bytes in TNamed at creation time
0188   seek m_seek_directory;   //Location of directory on file
0189   seek m_seek_parent;      //Location of parent directory on file
0190   seek m_seek_keys;        //Location of Keys record on file
0191 };
0192 
0193 }}
0194 
0195 #endif