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