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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/rroot/directory (Version 11.3.0) and /externals/g4tools/include/tools/rroot/directory (Version 11.0)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_rroot_directory                       4 #ifndef tools_rroot_directory
  5 #define tools_rroot_directory                       5 #define tools_rroot_directory
  6                                                     6 
  7 #include "seek"                                     7 #include "seek"
  8 #include "date"                                     8 #include "date"
  9 #include "key"                                      9 #include "key"
 10 #include "ifile"                                   10 #include "ifile"
 11 #include "../forit"                                11 #include "../forit"
 12 #include "../vmanip"                               12 #include "../vmanip"
 13                                                    13 
 14 namespace tools {                                  14 namespace tools {
 15 namespace rroot {                                  15 namespace rroot {
 16                                                    16 
 17 class directory {                                  17 class directory {
 18 public:                                            18 public:
 19   static const std::string& s_class() {            19   static const std::string& s_class() {
 20     static const std::string s_v("tools::rroot     20     static const std::string s_v("tools::rroot::directory");
 21     return s_v;                                    21     return s_v;
 22   }                                                22   }
 23 public:                                            23 public:
 24   directory(ifile& a_file)                         24   directory(ifile& a_file)
 25   :m_file(a_file)                                  25   :m_file(a_file)
 26   {                                                26   {
 27 #ifdef TOOLS_MEM                                   27 #ifdef TOOLS_MEM
 28     mem::increment(s_class().c_str());             28     mem::increment(s_class().c_str());
 29 #endif                                             29 #endif
 30     m_date_C = 0; //.set();                        30     m_date_C = 0; //.set();
 31     m_date_M = 0; //.set();                        31     m_date_M = 0; //.set();
 32     m_nbytes_keys = 0;                             32     m_nbytes_keys = 0;
 33     m_nbytes_name = 0;                             33     m_nbytes_name = 0;
 34     m_seek_directory = 0;                          34     m_seek_directory = 0;
 35     m_seek_parent = 0;                             35     m_seek_parent = 0;
 36     m_seek_keys = 0;                               36     m_seek_keys = 0;
 37   }                                                37   }
 38   virtual ~directory(){                            38   virtual ~directory(){
 39     clear_keys();                                  39     clear_keys();
 40 #ifdef TOOLS_MEM                                   40 #ifdef TOOLS_MEM
 41     mem::decrement(s_class().c_str());             41     mem::decrement(s_class().c_str());
 42 #endif                                             42 #endif
 43   }                                                43   }
 44 protected:                                         44 protected:
 45   directory(const directory& a_from):m_file(a_     45   directory(const directory& a_from):m_file(a_from.m_file){
 46 #ifdef TOOLS_MEM                                   46 #ifdef TOOLS_MEM
 47     mem::increment(s_class().c_str());             47     mem::increment(s_class().c_str());
 48 #endif                                             48 #endif
 49   }                                                49   }
 50   directory& operator=(const directory &){retu     50   directory& operator=(const directory &){return *this;}
 51 public:                                            51 public:
 52   ifile& file() {return m_file;}                   52   ifile& file() {return m_file;}
 53                                                    53 
 54   const std::vector<key*>& keys() const {retur     54   const std::vector<key*>& keys() const {return m_keys;}
 55   std::vector<key*>& keys() {return m_keys;}       55   std::vector<key*>& keys() {return m_keys;}
 56                                                    56 
 57   key* find_key(const std::string& a_name) {       57   key* find_key(const std::string& a_name) {
 58     if(m_file.verbose()) {                         58     if(m_file.verbose()) {
 59       m_file.out() << "tools::rroot::directory     59       m_file.out() << "tools::rroot::directory::find_key :"
 60                    << " " << sout(a_name) << "     60                    << " " << sout(a_name) << " ..."
 61                    << std::endl;                   61                    << std::endl;
 62     }                                              62     }
 63     tools_vforcit(key*,m_keys,it) {                63     tools_vforcit(key*,m_keys,it) {
 64       if((*it)->object_name()==a_name) return      64       if((*it)->object_name()==a_name) return *it;
 65     }                                              65     }
 66                                                    66 
 67     return 0;                                      67     return 0;
 68   }                                                68   }
 69                                                    69 
 70   key* find_key_from_class(const std::string&      70   key* find_key_from_class(const std::string& a_class) {
 71     if(m_file.verbose()) {                         71     if(m_file.verbose()) {
 72       m_file.out() << "tools::rroot::directory     72       m_file.out() << "tools::rroot::directory::find_key_from_class :"
 73                    << " " << sout(a_class) <<      73                    << " " << sout(a_class) << " ..."
 74                    << std::endl;                   74                    << std::endl;
 75     }                                              75     }
 76     tools_vforcit(key*,m_keys,it) {                76     tools_vforcit(key*,m_keys,it) {
 77       if((*it)->object_class()==a_class) retur     77       if((*it)->object_class()==a_class) return *it;
 78     }                                              78     }
 79                                                    79 
 80     return 0;                                      80     return 0;
 81   }                                                81   }
 82                                                    82 
 83   uint32 nbytes_name() const {return m_nbytes_     83   uint32 nbytes_name() const {return m_nbytes_name;}
 84   seek seek_keys() const {return m_seek_keys;}     84   seek seek_keys() const {return m_seek_keys;}
 85   uint32 record_size(uint32 a_version) const {     85   uint32 record_size(uint32 a_version) const {
 86     uint32 nbytes = sizeof(short);                 86     uint32 nbytes = sizeof(short);
 87     nbytes += sizeof(date); //m_date_C.record_     87     nbytes += sizeof(date); //m_date_C.record_size();
 88     nbytes += sizeof(date); //m_date_M.record_     88     nbytes += sizeof(date); //m_date_M.record_size();
 89     nbytes += sizeof(m_nbytes_keys);               89     nbytes += sizeof(m_nbytes_keys);
 90     nbytes += sizeof(m_nbytes_name);               90     nbytes += sizeof(m_nbytes_name);
 91     if(a_version>=40000) {                         91     if(a_version>=40000) {
 92       nbytes += sizeof(seek);                      92       nbytes += sizeof(seek);
 93       nbytes += sizeof(seek);                      93       nbytes += sizeof(seek);
 94       nbytes += sizeof(seek);                      94       nbytes += sizeof(seek);
 95     } else {                                       95     } else {
 96       nbytes += sizeof(seek32);                    96       nbytes += sizeof(seek32);
 97       nbytes += sizeof(seek32);                    97       nbytes += sizeof(seek32);
 98       nbytes += sizeof(seek32);                    98       nbytes += sizeof(seek32);
 99     }                                              99     }
100     return nbytes;                                100     return nbytes;
101   }                                               101   }
102   bool from_buffer(const char* aEOB,char*& a_b    102   bool from_buffer(const char* aEOB,char*& a_buffer){
103     // Decode input buffer.                       103     // Decode input buffer.
104     // (Name, title) are stored in the (name,     104     // (Name, title) are stored in the (name, title) of the associated key.
105     rbuf rb(m_file.out(),m_file.byte_swap(),aE    105     rbuf rb(m_file.out(),m_file.byte_swap(),aEOB,a_buffer);
106     short versiondir;                             106     short versiondir;
107     if(!rb.read(versiondir)) return false;        107     if(!rb.read(versiondir)) return false;
108     unsigned int _date;                           108     unsigned int _date;
109     if(!rb.read(_date)) return false;             109     if(!rb.read(_date)) return false;
110     //fDateC.setDate(_date);                      110     //fDateC.setDate(_date);
111     if(!rb.read(_date)) return false;             111     if(!rb.read(_date)) return false;
112     //fDateM.setDate(_date);                      112     //fDateM.setDate(_date);
113    {int v;                                        113    {int v;
114     if(!rb.read(v)) return false;                 114     if(!rb.read(v)) return false;
115     m_nbytes_keys = v;}                           115     m_nbytes_keys = v;}
116    {int v;                                        116    {int v;
117     if(!rb.read(v)) return false;                 117     if(!rb.read(v)) return false;
118     m_nbytes_name = v;}                           118     m_nbytes_name = v;}
119     if(versiondir>(short)big_file_version_tag(    119     if(versiondir>(short)big_file_version_tag()) {
120       if(!rb.read(m_seek_directory)) return fa    120       if(!rb.read(m_seek_directory)) return false;
121       if(!rb.read(m_seek_parent)) return false    121       if(!rb.read(m_seek_parent)) return false;
122       if(!rb.read(m_seek_keys)) return false;     122       if(!rb.read(m_seek_keys)) return false;
123     } else {                                      123     } else {
124      {seek32 i;                                   124      {seek32 i;
125       if(!rb.read(i)) return false;               125       if(!rb.read(i)) return false;
126       m_seek_directory = i;}                      126       m_seek_directory = i;}
127                                                   127 
128      {seek32 i;                                   128      {seek32 i;
129       if(!rb.read(i)) return false;               129       if(!rb.read(i)) return false;
130       m_seek_parent = i;}                         130       m_seek_parent = i;}
131                                                   131 
132      {seek32 i;                                   132      {seek32 i;
133       if(!rb.read(i)) return false;               133       if(!rb.read(i)) return false;
134       m_seek_keys = i;}                           134       m_seek_keys = i;}
135     }                                             135     }
136     if(m_file.verbose()) {                        136     if(m_file.verbose()) {
137       m_file.out() << "tools::rroot::key::from    137       m_file.out() << "tools::rroot::key::from_buffer :"
138                    << " nbytes keys : " << m_n    138                    << " nbytes keys : " << m_nbytes_keys
139                    << ", pos keys : " << m_see    139                    << ", pos keys : " << m_seek_keys
140                    << std::endl;                  140                    << std::endl;
141     }                                             141     }
142     return true;                                  142     return true;
143   }                                               143   }
144   bool read_keys(uint32& a_number) {              144   bool read_keys(uint32& a_number) {
145     // Read the KEYS :                            145     // Read the KEYS :
146     //  Every directory has a list (fKeys). Th    146     //  Every directory has a list (fKeys). This list has been
147     //  written on the file via CERN-ROOT::TDi    147     //  written on the file via CERN-ROOT::TDirectory::writeKeys
148     //  as a single data record.                  148     //  as a single data record.
149     a_number = 0;                                 149     a_number = 0;
150                                                   150 
151     clear_keys();                                 151     clear_keys();
152                                                   152 
153     key headerkey(m_file.out(),m_seek_keys,m_n    153     key headerkey(m_file.out(),m_seek_keys,m_nbytes_keys);
154     if(!headerkey.read_file(m_file)) return fa    154     if(!headerkey.read_file(m_file)) return false;
155     char* buffer = headerkey.data_buffer();       155     char* buffer = headerkey.data_buffer();
156     if(!headerkey.from_buffer(m_file.byte_swap    156     if(!headerkey.from_buffer(m_file.byte_swap(),headerkey.eob(),buffer,m_file.verbose())) return false;
157     int nkeys = 0;                                157     int nkeys = 0;
158     rbuf rb(m_file.out(),m_file.byte_swap(),he    158     rbuf rb(m_file.out(),m_file.byte_swap(),headerkey.eob(),buffer);
159     if(!rb.read(nkeys)) return false;             159     if(!rb.read(nkeys)) return false;
160     if(m_file.verbose()) {                        160     if(m_file.verbose()) {
161       m_file.out() << "tools::rroot::directory    161       m_file.out() << "tools::rroot::directory::read_keys :"
162                    << " nkeys " << nkeys          162                    << " nkeys " << nkeys
163                    << "."                         163                    << "."
164                    << std::endl;                  164                    << std::endl;
165     }                                             165     }
166     for(int i=0;i<nkeys;i++) {                    166     for(int i=0;i<nkeys;i++) {
167       key* k = new key(m_file.out());             167       key* k = new key(m_file.out());
168       if(!k->from_buffer(m_file.byte_swap(),he    168       if(!k->from_buffer(m_file.byte_swap(),headerkey.eob(),buffer,m_file.verbose())) {
169         delete k;                                 169         delete k;
170         return false;                             170         return false;
171       }                                           171       }
172       m_keys.push_back(k);                        172       m_keys.push_back(k);
173     }                                             173     }
174     a_number = nkeys;                             174     a_number = nkeys;
175     return true;                                  175     return true;
176   }                                               176   }
177   void clear_keys() {                             177   void clear_keys() {
178     safe_clear<key>(m_keys);                      178     safe_clear<key>(m_keys);
179   }                                               179   }
180 protected:                                        180 protected:
181   ifile& m_file;                                  181   ifile& m_file;
182   std::vector<key*> m_keys;                       182   std::vector<key*> m_keys;
183   // Record (stored in file):                     183   // Record (stored in file):
184   date m_date_C;           //Date and time whe    184   date m_date_C;           //Date and time when directory is created
185   date m_date_M;           //Date and time of     185   date m_date_M;           //Date and time of last modification
186   uint32 m_nbytes_keys;    //Number of bytes f    186   uint32 m_nbytes_keys;    //Number of bytes for the keys
187   uint32 m_nbytes_name;    //Number of bytes i    187   uint32 m_nbytes_name;    //Number of bytes in TNamed at creation time
188   seek m_seek_directory;   //Location of direc    188   seek m_seek_directory;   //Location of directory on file
189   seek m_seek_parent;      //Location of paren    189   seek m_seek_parent;      //Location of parent directory on file
190   seek m_seek_keys;        //Location of Keys     190   seek m_seek_keys;        //Location of Keys record on file
191 };                                                191 };
192                                                   192 
193 }}                                                193 }}
194                                                   194 
195 #endif                                            195 #endif