Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/rroot/rall

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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/rall (Version 11.3.0) and /externals/g4tools/include/tools/rroot/rall (Version 11.2.1)


  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_rall                            4 #ifndef tools_rroot_rall
  5 #define tools_rroot_rall                            5 #define tools_rroot_rall
  6                                                     6 
  7 #include "streamers"                                7 #include "streamers"
  8 #include "fac"                                      8 #include "fac"
  9 #include "tree"                                     9 #include "tree"
 10 #include "../words" //for annotations.             10 #include "../words" //for annotations.
 11                                                    11 
 12 #define TOOLS_RROOT_NOT_OSC                        12 #define TOOLS_RROOT_NOT_OSC
 13                                                    13 
 14 #ifndef TOOLS_RROOT_NOT_OSC                        14 #ifndef TOOLS_RROOT_NOT_OSC
 15 #include "osc"                                     15 #include "osc"
 16 #endif                                             16 #endif
 17                                                    17 
 18 #include "THistogram"                              18 #include "THistogram"
 19                                                    19 
 20 namespace tools {                                  20 namespace tools {
 21 namespace rroot {                                  21 namespace rroot {
 22                                                    22 
 23 inline TDirectory* find_dir(directory& a_dir,c     23 inline TDirectory* find_dir(directory& a_dir,const std::string& a_name) {
 24   std::ostream& out = a_dir.file().out();          24   std::ostream& out = a_dir.file().out();
 25   key* k = a_dir.find_key(a_name);                 25   key* k = a_dir.find_key(a_name);
 26   if(!k) {                                         26   if(!k) {
 27     //out << "tools::rroot::find_dir :"            27     //out << "tools::rroot::find_dir :"
 28     //    << " " << a_name << " not a key."        28     //    << " " << a_name << " not a key."
 29     //    << std::endl;                            29     //    << std::endl;
 30     return 0;                                      30     return 0;
 31   }                                                31   }
 32                                                    32 
 33   if(k->object_class()!=TDirectory_cls()) {        33   if(k->object_class()!=TDirectory_cls()) {
 34     out << "tools::rroot::find_dir :"              34     out << "tools::rroot::find_dir :"
 35         << " key " << a_name << " not a TDirec     35         << " key " << a_name << " not a TDirectory."
 36         << std::endl;                              36         << std::endl;
 37     return 0;                                      37     return 0;
 38   }                                                38   }
 39   uint32 sz;                                       39   uint32 sz;
 40   char* buf = k->get_object_buffer(a_dir.file(     40   char* buf = k->get_object_buffer(a_dir.file(),sz); //we don't have ownership of buf.
 41   if(!buf) {                                       41   if(!buf) {
 42     out  << "tools::rroot::find_dir :"             42     out  << "tools::rroot::find_dir :"
 43          << " can't get directory data buffer.     43          << " can't get directory data buffer."
 44          << std::endl;                             44          << std::endl;
 45     return 0;                                      45     return 0;
 46   }                                                46   }
 47   buffer b(out,a_dir.file().byte_swap(),sz,buf     47   buffer b(out,a_dir.file().byte_swap(),sz,buf,k->key_length(),false);
 48   TDirectory* tdir = new TDirectory(a_dir.file     48   TDirectory* tdir = new TDirectory(a_dir.file());
 49   if(!tdir) return 0;                              49   if(!tdir) return 0;
 50   if(!tdir->stream(b)) {                           50   if(!tdir->stream(b)) {
 51     out << "tools::rroot::find_dir :"              51     out << "tools::rroot::find_dir :"
 52         << " can't stream TDirectory."             52         << " can't stream TDirectory."
 53         << std::endl;                              53         << std::endl;
 54     delete tdir;                                   54     delete tdir;
 55     return 0;                                      55     return 0;
 56   }                                                56   }
 57   return tdir;                                     57   return tdir;
 58 }                                                  58 }
 59                                                    59 
 60 inline directory* find_path_dir(directory& a_f     60 inline directory* find_path_dir(directory& a_from,const std::string& a_path) {
 61   if(a_path.empty()) return 0;                     61   if(a_path.empty()) return 0;
 62   std::vector<std::string> ws;                     62   std::vector<std::string> ws;
 63   words(a_path,"/",false,ws);                      63   words(a_path,"/",false,ws);
 64   directory* cur_dir = &a_from;                    64   directory* cur_dir = &a_from;
 65   for(unsigned int index=0;index<ws.size();ind     65   for(unsigned int index=0;index<ws.size();index++) {
 66     TDirectory* _dir = find_dir(*cur_dir,ws[in     66     TDirectory* _dir = find_dir(*cur_dir,ws[index]);
 67     if(!_dir) return 0;                            67     if(!_dir) return 0;
 68     if(index==(ws.size()-1)) return _dir;          68     if(index==(ws.size()-1)) return _dir;
 69     if(index) delete cur_dir;                      69     if(index) delete cur_dir;
 70     cur_dir = _dir;                                70     cur_dir = _dir;
 71   }                                                71   }
 72   return 0;                                        72   return 0;
 73 }                                                  73 }
 74                                                    74 
 75 inline bool read_key(std::ostream& a_out,ifile     75 inline bool read_key(std::ostream& a_out,ifile& a_file,key& a_key,bool a_dump){
 76   unsigned int sz;                                 76   unsigned int sz;
 77   char* buf = a_key.get_object_buffer(a_file,s     77   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
 78   if(!buf) {                                       78   if(!buf) {
 79     a_out << "tools::rroot::read_key : can't g     79     a_out << "tools::rroot::read_key : can't get data buffer of " << a_key.object_name() << "." << std::endl;
 80     return false;                                  80     return false;
 81   }                                                81   }
 82                                                    82 
 83   //a_out << "tools::rroot::read_key :"            83   //a_out << "tools::rroot::read_key :"
 84   //      << " get data buffer size " << sz <<     84   //      << " get data buffer size " << sz << "."
 85   //      << std::endl;                            85   //      << std::endl;
 86                                                    86 
 87   buffer b(a_out,a_file.byte_swap(),sz,buf,a_k     87   buffer b(a_out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
 88                                                    88 
 89   if(a_key.object_class()==TNamed_cls()) {         89   if(a_key.object_class()==TNamed_cls()) {
 90     std::string name,title;                        90     std::string name,title;
 91     if(!Named_stream(b,name,title)) {              91     if(!Named_stream(b,name,title)) {
 92       a_out << "tools::rroot::read_key : TName     92       a_out << "tools::rroot::read_key : TNamed streaming failed" << std::endl;
 93     } else {                                       93     } else {
 94       if(a_dump) {                                 94       if(a_dump) {
 95         a_out << "Named : name = " << sout(nam     95         a_out << "Named : name = " << sout(name) << ", title = " << sout(title) << std::endl;
 96       }                                            96       }
 97     }                                              97     }
 98                                                    98 
 99   } else if(a_key.object_class()==TH1F_cls())      99   } else if(a_key.object_class()==TH1F_cls()) {
100     histo::h1d* h = TH1F_stream(b);               100     histo::h1d* h = TH1F_stream(b);
101     if(!h) {                                      101     if(!h) {
102       a_out << "tools::rroot::read_key : TH1F     102       a_out << "tools::rroot::read_key : TH1F streaming failed" << std::endl;
103     } else {                                      103     } else {
104       if(a_dump) h->hprint(a_out);                104       if(a_dump) h->hprint(a_out);
105     }                                             105     }
106     delete h;                                     106     delete h;
107                                                   107 
108   } else if(a_key.object_class()==TH1D_cls())     108   } else if(a_key.object_class()==TH1D_cls()) {
109     histo::h1d* h = TH1D_stream(b);               109     histo::h1d* h = TH1D_stream(b);
110     if(!h) {                                      110     if(!h) {
111       a_out << "tools::rroot::read_key :"         111       a_out << "tools::rroot::read_key :"
112             << " TH1D streaming failed"           112             << " TH1D streaming failed"
113             << std::endl;                         113             << std::endl;
114     } else {                                      114     } else {
115       if(a_dump) h->hprint(a_out);                115       if(a_dump) h->hprint(a_out);
116     }                                             116     }
117     delete h;                                     117     delete h;
118                                                   118 
119   } else if(a_key.object_class()==TH2F_cls())     119   } else if(a_key.object_class()==TH2F_cls()) {
120     histo::h2d* h = TH2F_stream(b);               120     histo::h2d* h = TH2F_stream(b);
121     if(!h) {                                      121     if(!h) {
122       a_out << "tools::rroot::read_key :"         122       a_out << "tools::rroot::read_key :"
123             << " TH2F streaming failed"           123             << " TH2F streaming failed"
124             << std::endl;                         124             << std::endl;
125     } else {                                      125     } else {
126       if(a_dump) h->hprint(a_out);                126       if(a_dump) h->hprint(a_out);
127     }                                             127     }
128     delete h;                                     128     delete h;
129                                                   129 
130   } else if(a_key.object_class()==TH2D_cls())     130   } else if(a_key.object_class()==TH2D_cls()) {
131     histo::h2d* h = TH2D_stream(b); //we get o    131     histo::h2d* h = TH2D_stream(b); //we get ownership of h.
132     if(!h) {                                      132     if(!h) {
133       a_out << "tools::rroot::read_key :"         133       a_out << "tools::rroot::read_key :"
134             << " TH2D streaming failed"           134             << " TH2D streaming failed"
135             << std::endl;                         135             << std::endl;
136     } else {                                      136     } else {
137       if(a_dump) h->hprint(a_out);                137       if(a_dump) h->hprint(a_out);
138     }                                             138     }
139     delete h;                                     139     delete h;
140                                                   140 
141   } else if(a_key.object_class()==TH3D_cls())     141   } else if(a_key.object_class()==TH3D_cls()) {
142     histo::h3d* h = TH3D_stream(b); //we get o    142     histo::h3d* h = TH3D_stream(b); //we get ownership of h.
143     if(!h) {                                      143     if(!h) {
144       a_out << "tools::rroot::read_key :"         144       a_out << "tools::rroot::read_key :"
145             << " TH3D streaming failed"           145             << " TH3D streaming failed"
146             << std::endl;                         146             << std::endl;
147     } else {                                      147     } else {
148       if(a_dump) h->hprint(a_out);                148       if(a_dump) h->hprint(a_out);
149     }                                             149     }
150     delete h;                                     150     delete h;
151                                                   151 
152   } else if(a_key.object_class()==TProfile_cls    152   } else if(a_key.object_class()==TProfile_cls()) {
153     histo::p1d* p = TProfile_stream(b);           153     histo::p1d* p = TProfile_stream(b);
154     if(!p) {                                      154     if(!p) {
155       a_out << "tools::rroot::read_key :"         155       a_out << "tools::rroot::read_key :"
156             << " TProfile streaming failed"       156             << " TProfile streaming failed"
157             << std::endl;                         157             << std::endl;
158     } else {                                      158     } else {
159       if(a_dump) p->hprint(a_out);                159       if(a_dump) p->hprint(a_out);
160     }                                             160     }
161     delete p;                                     161     delete p;
162                                                   162 
163   } else if(a_key.object_class()==TProfile2D_c    163   } else if(a_key.object_class()==TProfile2D_cls()) {
164     histo::p2d* p = TProfile2D_stream(b);         164     histo::p2d* p = TProfile2D_stream(b);
165     if(!p) {                                      165     if(!p) {
166       a_out << "tools::rroot::read_key :"         166       a_out << "tools::rroot::read_key :"
167             << " TProfile2D streaming failed"     167             << " TProfile2D streaming failed"
168             << std::endl;                         168             << std::endl;
169     } else {                                      169     } else {
170       if(a_dump) p->hprint(a_out);                170       if(a_dump) p->hprint(a_out);
171     }                                             171     }
172     delete p;                                     172     delete p;
173                                                   173 
174   } else if(a_key.object_class()==TTree_cls())    174   } else if(a_key.object_class()==TTree_cls()) {
175     b.set_map_objs(true); //for "root_ls -ls"     175     b.set_map_objs(true); //for "root_ls -ls" on esb evetest.root files.
176     fac _fac(a_out);                              176     fac _fac(a_out);
177     tree tree(a_file,_fac);                       177     tree tree(a_file,_fac);
178     if(!tree.stream(b)) {                         178     if(!tree.stream(b)) {
179       a_out << "tools::rroot::read_key :"         179       a_out << "tools::rroot::read_key :"
180             << " TTree streaming failed"          180             << " TTree streaming failed"
181             << std::endl;                         181             << std::endl;
182     } else {                                      182     } else {
183       //tree->dump(a_out);                        183       //tree->dump(a_out);
184       if(a_dump) {                                184       if(a_dump) {
185         tree.dump(a_out,"","  ");                 185         tree.dump(a_out,"","  ");
186                                                   186 
187         uint64 entries = tree.entries();          187         uint64 entries = tree.entries();
188                                                   188 
189        /*                                         189        /*
190        {for(uint32 j=0;j<10;j++){ //to test me    190        {for(uint32 j=0;j<10;j++){ //to test memory.
191         for(uint32 i=0;i<entries;i++){            191         for(uint32 i=0;i<entries;i++){
192           uint32 n;                               192           uint32 n;
193           if(!tree.find_entry(i,n)) {             193           if(!tree.find_entry(i,n)) {
194             a_out << " can't find entry " << i    194             a_out << " can't find entry " << i
195                   << std::endl;                   195                   << std::endl;
196           }                                       196           }
197         }                                         197         }
198         }}                                        198         }}
199         */                                        199         */
200                                                   200 
201        {for(uint32 i=0;i<5;i++){                  201        {for(uint32 i=0;i<5;i++){
202           if(!tree.show(a_out,i)) {               202           if(!tree.show(a_out,i)) {
203             a_out << " show failed for entry "    203             a_out << " show failed for entry " << i
204                   << std::endl;                   204                   << std::endl;
205           }                                       205           }
206         }}                                        206         }}
207        {for(uint64 i=mx<int64>(5,entries-5);i<    207        {for(uint64 i=mx<int64>(5,entries-5);i<entries;i++){
208           if(!tree.show(a_out,(uint32)i)) {       208           if(!tree.show(a_out,(uint32)i)) {
209             a_out << " show failed for entry "    209             a_out << " show failed for entry " << i
210                   << std::endl;                   210                   << std::endl;
211           }                                       211           }
212         }}                                        212         }}
213                                                   213 
214       }                                           214       }
215     }                                             215     }
216                                                   216 
217 #ifndef TOOLS_RROOT_NOT_OSC                       217 #ifndef TOOLS_RROOT_NOT_OSC
218   } else if(a_key.object_class()==osc::s_h1d()    218   } else if(a_key.object_class()==osc::s_h1d()) {
219                                                   219 
220     histo::h1d h("",10,0,1);                      220     histo::h1d h("",10,0,1);
221     if(!from_osc(b,osc::s_h1d(),h)) {             221     if(!from_osc(b,osc::s_h1d(),h)) {
222       a_out << "tools::rroot::read_key :"         222       a_out << "tools::rroot::read_key :"
223             << " " << osc::s_h1d() << " stream    223             << " " << osc::s_h1d() << " streaming failed"
224             << std::endl;                         224             << std::endl;
225     } else {                                      225     } else {
226       if(a_dump) h.hprint(a_out);                 226       if(a_dump) h.hprint(a_out);
227     }                                             227     }
228                                                   228 
229   } else if(a_key.object_class()==osc::s_h2d()    229   } else if(a_key.object_class()==osc::s_h2d()) {
230                                                   230 
231     histo::h2d h("",10,0,1,10,0,1);               231     histo::h2d h("",10,0,1,10,0,1);
232     if(!from_osc(b,osc::s_h2d(),h)) {             232     if(!from_osc(b,osc::s_h2d(),h)) {
233       a_out << "tools::rroot::read_key :"         233       a_out << "tools::rroot::read_key :"
234             << " " << osc::s_h2d() << " stream    234             << " " << osc::s_h2d() << " streaming failed"
235             << std::endl;                         235             << std::endl;
236     } else {                                      236     } else {
237       if(a_dump) h.hprint(a_out);                 237       if(a_dump) h.hprint(a_out);
238     }                                             238     }
239                                                   239 
240   } else if(a_key.object_class()==osc::s_h3d()    240   } else if(a_key.object_class()==osc::s_h3d()) {
241                                                   241 
242     histo::h3d h("",10,0,1,10,0,1,10,0,1);        242     histo::h3d h("",10,0,1,10,0,1,10,0,1);
243     if(!from_osc(b,osc::s_h3d(),h)) {             243     if(!from_osc(b,osc::s_h3d(),h)) {
244       a_out << "tools::rroot::read_key :"         244       a_out << "tools::rroot::read_key :"
245             << " " << osc::s_h3d() << " stream    245             << " " << osc::s_h3d() << " streaming failed"
246             << std::endl;                         246             << std::endl;
247     } else {                                      247     } else {
248       if(a_dump) h.hprint(a_out);                 248       if(a_dump) h.hprint(a_out);
249     }                                             249     }
250                                                   250 
251   } else if(a_key.object_class()==osc::s_p1d()    251   } else if(a_key.object_class()==osc::s_p1d()) {
252                                                   252 
253     histo::p1d h("",10,0,1);                      253     histo::p1d h("",10,0,1);
254     if(!from_osc(b,osc::s_p1d(),h)) {             254     if(!from_osc(b,osc::s_p1d(),h)) {
255       a_out << "tools::rroot::read_key :"         255       a_out << "tools::rroot::read_key :"
256             << " " << osc::s_p1d() << " stream    256             << " " << osc::s_p1d() << " streaming failed"
257             << std::endl;                         257             << std::endl;
258     } else {                                      258     } else {
259       if(a_dump) h.hprint(a_out);                 259       if(a_dump) h.hprint(a_out);
260     }                                             260     }
261                                                   261 
262   } else if(a_key.object_class()==osc::s_p2d()    262   } else if(a_key.object_class()==osc::s_p2d()) {
263                                                   263 
264     histo::p2d h("",10,0,1,10,0,1);               264     histo::p2d h("",10,0,1,10,0,1);
265     if(!from_osc(b,osc::s_p2d(),h)) {             265     if(!from_osc(b,osc::s_p2d(),h)) {
266       a_out << "tools::rroot::read_key :"         266       a_out << "tools::rroot::read_key :"
267             << " " << osc::s_p2d() << " stream    267             << " " << osc::s_p2d() << " streaming failed"
268             << std::endl;                         268             << std::endl;
269     } else {                                      269     } else {
270       if(a_dump) h.hprint(a_out);                 270       if(a_dump) h.hprint(a_out);
271     }                                             271     }
272 #endif                                            272 #endif
273                                                   273 
274   } else if(a_key.object_class()==THistogram_c    274   } else if(a_key.object_class()==THistogram_cls()) { //produced with osc/AIDA through BatchLab/Rio/THistogram.
275                                                   275 
276     pd_data_t data;                               276     pd_data_t data;
277     annotations_t annotations;                    277     annotations_t annotations;
278     if(!read_THistogram(b,data,annotations)) {    278     if(!read_THistogram(b,data,annotations)) {
279       a_out << "tools::rroot::read_key : read_    279       a_out << "tools::rroot::read_key : read_THistogram() failed." << std::endl;
280     } else {                                      280     } else {
281       if(histo::h1d* _h1d = THistogram_to_h1d(    281       if(histo::h1d* _h1d = THistogram_to_h1d(data)) {
282         if(a_dump) _h1d->hprint(a_out);           282         if(a_dump) _h1d->hprint(a_out);
283         delete _h1d;                              283         delete _h1d;
284       } else if(histo::h2d* _h2d = THistogram_    284       } else if(histo::h2d* _h2d = THistogram_to_h2d(data)) {
285         if(a_dump) _h2d->hprint(a_out);           285         if(a_dump) _h2d->hprint(a_out);
286         delete _h2d;                              286         delete _h2d;
287       } else if(histo::p1d* _p1d = THistogram_    287       } else if(histo::p1d* _p1d = THistogram_to_p1d(data)) {
288         if(a_dump) _p1d->hprint(a_out);           288         if(a_dump) _p1d->hprint(a_out);
289         delete _p1d;                              289         delete _p1d;
290       } else if(histo::p2d* _p2d = THistogram_    290       } else if(histo::p2d* _p2d = THistogram_to_p2d(data)) {
291         if(a_dump) _p2d->hprint(a_out);           291         if(a_dump) _p2d->hprint(a_out);
292         delete _p2d;                              292         delete _p2d;
293       } else {                                    293       } else {
294         a_out << "tools::rroot::read_key : can    294         a_out << "tools::rroot::read_key : can't convert THistogram dat to h1d,h2d,p1d or p2d." << std::endl;
295       }                                           295       }
296     }                                             296     }
297                                                   297 
298   } else if(a_key.object_class()==TDirectory_c    298   } else if(a_key.object_class()==TDirectory_cls()) {
299                                                   299 
300     //we should not pass here.                    300     //we should not pass here.
301                                                   301 
302   } else {                                        302   } else {
303     a_out << "tools::rroot::read_key :"           303     a_out << "tools::rroot::read_key :"
304           << " dont't know how to read key wit    304           << " dont't know how to read key with object class "
305           << sout(a_key.object_class())           305           << sout(a_key.object_class())
306           << std::endl;                           306           << std::endl;
307   }                                               307   }
308   return true;                                    308   return true;
309 }                                                 309 }
310                                                   310 
311 //typedef std::map<std::string,std::string> an    311 //typedef std::map<std::string,std::string> annotations_t;
312 inline bool key_to_annotations(ifile& a_file,k    312 inline bool key_to_annotations(ifile& a_file,key& a_key,std::map<std::string,std::string>& a_annotations,bool a_warn = true) {
313   a_annotations.clear();                          313   a_annotations.clear();
314   std::ostream& out = a_key.out();                314   std::ostream& out = a_key.out();
315   if(a_key.object_class()!=TNamed_cls()) {        315   if(a_key.object_class()!=TNamed_cls()) {
316     if(a_warn) out << "tools::rroot::key_to_an    316     if(a_warn) out << "tools::rroot::key_to_annotations : key not a TNamed." << std::endl;
317     return false;                                 317     return false;
318   }                                               318   }
319   unsigned int sz;                                319   unsigned int sz;
320   char* buf = a_key.get_object_buffer(a_file,s    320   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
321   if(!buf) {                                      321   if(!buf) {
322     out << "tools::rroot::key_to_annotations :    322     out << "tools::rroot::key_to_annotations : can't get data buffer of " << a_key.object_name() << "." << std::endl;
323     return false;                                 323     return false;
324   }                                               324   }
325   buffer b(out,a_file.byte_swap(),sz,buf,a_key    325   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
326   std::string histo_name;                         326   std::string histo_name;
327   std::string sas;                                327   std::string sas;
328   if(!Named_stream(b,histo_name,sas)) return f    328   if(!Named_stream(b,histo_name,sas)) return false;
329   std::vector<std::string> ws;                    329   std::vector<std::string> ws;
330   words(sas,"\n",true,ws);                        330   words(sas,"\n",true,ws);
331   size_t wordn = ws.size();                       331   size_t wordn = ws.size();
332   if(2*(wordn/2)!=wordn) {                        332   if(2*(wordn/2)!=wordn) {
333     out << "tools::rroot::key_to_annotations :    333     out << "tools::rroot::key_to_annotations : wordn should be even in " << sout(sas) << "." << std::endl;
334     return false;                                 334     return false;
335   }                                               335   }
336   std::vector<std::string>::const_iterator it;    336   std::vector<std::string>::const_iterator it;
337   for(it=ws.begin();it!=ws.end();) {              337   for(it=ws.begin();it!=ws.end();) {
338     const std::string& key = *it;it++;            338     const std::string& key = *it;it++;
339     const std::string& value = *it;it++;          339     const std::string& value = *it;it++;
340     a_annotations[key] = value;                   340     a_annotations[key] = value;
341   }                                               341   }
342   return true;                                    342   return true;
343 }                                                 343 }
344                                                   344 
345 inline histo::h1d* key_to_h1d(ifile& a_file,ke    345 inline histo::h1d* key_to_h1d(ifile& a_file,key& a_key,bool a_warn = true) {
346   std::ostream& out = a_key.out();                346   std::ostream& out = a_key.out();
347   if( (a_key.object_class()!=TH1D_cls()) && (a    347   if( (a_key.object_class()!=TH1D_cls()) && (a_key.object_class()!=TH1F_cls()) ) {
348     if(a_warn) out << "tools::rroot::key_to_h1    348     if(a_warn) out << "tools::rroot::key_to_h1d : key not a TH1D and not a TH1F." << std::endl;
349     return 0;                                     349     return 0;
350   }                                               350   }
351   unsigned int sz;                                351   unsigned int sz;
352   char* buf = a_key.get_object_buffer(a_file,s    352   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
353   if(!buf) {                                      353   if(!buf) {
354     out << "tools::rroot::key_to_h1d : can't g    354     out << "tools::rroot::key_to_h1d : can't get data buffer of " << a_key.object_name() << "." << std::endl;
355     return 0;                                     355     return 0;
356   }                                               356   }
357   buffer b(out,a_file.byte_swap(),sz,buf,a_key    357   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
358   if(a_key.object_class()==TH1D_cls()) {          358   if(a_key.object_class()==TH1D_cls()) {
359     return TH1D_stream(b);                        359     return TH1D_stream(b);
360   } else {                                        360   } else {
361     return TH1F_stream(b);                        361     return TH1F_stream(b);
362   }                                               362   }
363 }                                                 363 }
364                                                   364 
365 inline histo::h2d* key_to_h2d(ifile& a_file,ke    365 inline histo::h2d* key_to_h2d(ifile& a_file,key& a_key,bool a_warn = true){
366   std::ostream& out = a_key.out();                366   std::ostream& out = a_key.out();
367   if( (a_key.object_class()!=TH2D_cls()) && (a    367   if( (a_key.object_class()!=TH2D_cls()) && (a_key.object_class()!=TH2F_cls()) ) {
368     if(a_warn) out << "tools::rroot::key_to_h2    368     if(a_warn) out << "tools::rroot::key_to_h2d : key not a TH2D and not a TH2F." << std::endl;
369     return 0;                                     369     return 0;
370   }                                               370   }
371   unsigned int sz;                                371   unsigned int sz;
372   char* buf = a_key.get_object_buffer(a_file,s    372   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
373   if(!buf) {                                      373   if(!buf) {
374     out << "tools::rroot::key_to_h2d : can't g    374     out << "tools::rroot::key_to_h2d : can't get data buffer of " << a_key.object_name() << "." << std::endl;
375     return 0;                                     375     return 0;
376   }                                               376   }
377   buffer b(out,a_file.byte_swap(),sz,buf,a_key    377   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
378   if(a_key.object_class()==TH2D_cls()) {          378   if(a_key.object_class()==TH2D_cls()) {
379     return TH2D_stream(b);                        379     return TH2D_stream(b);
380   } else {                                        380   } else {
381     return TH2F_stream(b);                        381     return TH2F_stream(b);
382   }                                               382   }
383 }                                                 383 }
384                                                   384 
385 inline histo::h3d* key_to_h3d(ifile& a_file,ke    385 inline histo::h3d* key_to_h3d(ifile& a_file,key& a_key){
386   std::ostream& out = a_key.out();                386   std::ostream& out = a_key.out();
387   if(a_key.object_class()!=TH3D_cls()) {          387   if(a_key.object_class()!=TH3D_cls()) {
388     out << "tools::rroot::key_to_h3d :"           388     out << "tools::rroot::key_to_h3d :"
389         << " key not a TH3D."                     389         << " key not a TH3D."
390         << std::endl;                             390         << std::endl;
391     return 0;                                     391     return 0;
392   }                                               392   }
393   unsigned int sz;                                393   unsigned int sz;
394   char* buf = a_key.get_object_buffer(a_file,s    394   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
395   if(!buf) {                                      395   if(!buf) {
396     out << "tools::rroot::key_to_h3d :"           396     out << "tools::rroot::key_to_h3d :"
397         << " can't get data buffer of " << a_k    397         << " can't get data buffer of " << a_key.object_name() << "."
398         << std::endl;                             398         << std::endl;
399     return 0;                                     399     return 0;
400   }                                               400   }
401   buffer b(out,a_file.byte_swap(),sz,buf,a_key    401   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
402   return TH3D_stream(b);                          402   return TH3D_stream(b);
403 }                                                 403 }
404                                                   404 
405 inline histo::p1d* key_to_p1d(ifile& a_file,ke    405 inline histo::p1d* key_to_p1d(ifile& a_file,key& a_key){
406   std::ostream& out = a_key.out();                406   std::ostream& out = a_key.out();
407   if(a_key.object_class()!=TProfile_cls()) {      407   if(a_key.object_class()!=TProfile_cls()) {
408     out << "tools::rroot::key_to_p1d :"           408     out << "tools::rroot::key_to_p1d :"
409         << " key not a TProfile."                 409         << " key not a TProfile."
410         << std::endl;                             410         << std::endl;
411     return 0;                                     411     return 0;
412   }                                               412   }
413   unsigned int sz;                                413   unsigned int sz;
414   char* buf = a_key.get_object_buffer(a_file,s    414   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
415   if(!buf) {                                      415   if(!buf) {
416     out << "tools::rroot::key_to_p1d :"           416     out << "tools::rroot::key_to_p1d :"
417         << " can't get data buffer of " << a_k    417         << " can't get data buffer of " << a_key.object_name() << "."
418         << std::endl;                             418         << std::endl;
419     return 0;                                     419     return 0;
420   }                                               420   }
421   buffer b(out,a_file.byte_swap(),sz,buf,a_key    421   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
422   return TProfile_stream(b);                      422   return TProfile_stream(b);
423 }                                                 423 }
424                                                   424 
425 inline histo::p2d* key_to_p2d(ifile& a_file,ke    425 inline histo::p2d* key_to_p2d(ifile& a_file,key& a_key){
426   std::ostream& out = a_key.out();                426   std::ostream& out = a_key.out();
427   if(a_key.object_class()!=TProfile2D_cls()) {    427   if(a_key.object_class()!=TProfile2D_cls()) {
428     out << "tools::rroot::key_to_p2d :"           428     out << "tools::rroot::key_to_p2d :"
429         << " key not a TProfile2D."               429         << " key not a TProfile2D."
430         << std::endl;                             430         << std::endl;
431     return 0;                                     431     return 0;
432   }                                               432   }
433   unsigned int sz;                                433   unsigned int sz;
434   char* buf = a_key.get_object_buffer(a_file,s    434   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
435   if(!buf) {                                      435   if(!buf) {
436     out << "tools::rroot::key_to_p2d :"           436     out << "tools::rroot::key_to_p2d :"
437         << " can't get data buffer of " << a_k    437         << " can't get data buffer of " << a_key.object_name() << "."
438         << std::endl;                             438         << std::endl;
439     return 0;                                     439     return 0;
440   }                                               440   }
441   buffer b(out,a_file.byte_swap(),sz,buf,a_key    441   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
442   return TProfile2D_stream(b);                    442   return TProfile2D_stream(b);
443 }                                                 443 }
444                                                   444 
445 inline tree* key_to_tree(ifile& a_file,ifac& a    445 inline tree* key_to_tree(ifile& a_file,ifac& a_fac,key& a_key,bool a_warn = true) {
446   std::ostream& out = a_key.out();                446   std::ostream& out = a_key.out();
447   if(a_key.object_class()!=TTree_cls()) {         447   if(a_key.object_class()!=TTree_cls()) {
448     if(a_warn) out << "tools::rroot::key_to_tr    448     if(a_warn) out << "tools::rroot::key_to_tree : key not a TTree." << std::endl;
449     return 0;                                     449     return 0;
450   }                                               450   }
451   unsigned int sz;                                451   unsigned int sz;
452   char* buf = a_key.get_object_buffer(a_file,s    452   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
453   if(!buf) {                                      453   if(!buf) {
454     out << "tools::rroot::key_to_tree : can't     454     out << "tools::rroot::key_to_tree : can't get data buffer of " << a_key.object_name() << "." << std::endl;
455     return 0;                                     455     return 0;
456   }                                               456   }
457   buffer b(out,a_file.byte_swap(),sz,buf,a_key    457   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
458   b.set_map_objs(true); //for ioda/comres/tree    458   b.set_map_objs(true); //for ioda/comres/tree.py, tree.lua.
459   tree* _tree = new tree(a_file,a_fac);           459   tree* _tree = new tree(a_file,a_fac);
460   if(!_tree->stream(b)) {                         460   if(!_tree->stream(b)) {
461     out << "tools::rroot::key_to_tree : TTree     461     out << "tools::rroot::key_to_tree : TTree streaming failed" << std::endl;
462     delete _tree;                                 462     delete _tree;
463     return 0;                                     463     return 0;
464   }                                               464   }
465   return _tree;                                   465   return _tree;
466 }                                                 466 }
467                                                   467 
468 inline void read(std::ostream& a_out,             468 inline void read(std::ostream& a_out,
469                  ifile& a_file,                   469                  ifile& a_file,
470                  const std::vector<key*>& a_ke    470                  const std::vector<key*>& a_keys,
471                  bool a_recursive,                471                  bool a_recursive,
472                  bool a_ls,                       472                  bool a_ls,
473                  bool a_dump,                     473                  bool a_dump,
474                  unsigned int a_spaces) {         474                  unsigned int a_spaces) {
475                                                   475 
476  {std::vector<key*>::const_iterator it;           476  {std::vector<key*>::const_iterator it;
477   for(it=a_keys.begin();it!=a_keys.end();++it)    477   for(it=a_keys.begin();it!=a_keys.end();++it) {
478     key& k = *(*it);                              478     key& k = *(*it);
479     if(k.object_class()!=TDirectory_cls()) {      479     if(k.object_class()!=TDirectory_cls()) {
480       if(a_ls||a_dump) {                          480       if(a_ls||a_dump) {
481         {for(unsigned int index=0;index<a_spac    481         {for(unsigned int index=0;index<a_spaces;index++) a_out << " ";}
482         std::string label = k.object_name();      482         std::string label = k.object_name();
483         a_out << "object : " << sout(label)       483         a_out << "object : " << sout(label)
484               << ", class : " << k.object_clas    484               << ", class : " << k.object_class()
485               << std::endl;                       485               << std::endl;
486         //k.dump(a_out);                          486         //k.dump(a_out);
487       }                                           487       }
488       if(!read_key(a_out,a_file,k,a_dump)) ret    488       if(!read_key(a_out,a_file,k,a_dump)) return;
489     }                                             489     }
490   }}                                              490   }}
491                                                   491 
492  {std::vector<key*>::const_iterator it;           492  {std::vector<key*>::const_iterator it;
493   for(it=a_keys.begin();it!=a_keys.end();++it)    493   for(it=a_keys.begin();it!=a_keys.end();++it) {
494     key& k = *(*it);                              494     key& k = *(*it);
495     if(k.object_class()==TDirectory_cls()) {      495     if(k.object_class()==TDirectory_cls()) {
496                                                   496 
497       if(a_ls||a_dump) {                          497       if(a_ls||a_dump) {
498         {for(unsigned int index=0;index<a_spac    498         {for(unsigned int index=0;index<a_spaces;index++) a_out << " ";}
499         std::string label = k.object_name();      499         std::string label = k.object_name();
500         a_out << "directory : " << label << st    500         a_out << "directory : " << label << std::endl;
501       }                                           501       }
502                                                   502 
503       if(!a_recursive) continue;                  503       if(!a_recursive) continue;
504                                                   504 
505       uint32 sz;                                  505       uint32 sz;
506       char* buf = k.get_object_buffer(a_file,s    506       char* buf = k.get_object_buffer(a_file,sz);
507       if(!buf) {                                  507       if(!buf) {
508         a_out  << "read :"                        508         a_out  << "read :"
509                << " can't get directory data b    509                << " can't get directory data buffer."
510                << std::endl;                      510                << std::endl;
511       } else {                                    511       } else {
512         buffer b(a_out,a_file.byte_swap(),sz,b    512         buffer b(a_out,a_file.byte_swap(),sz,buf,k.key_length(),false);
513         TDirectory dir(a_file);                   513         TDirectory dir(a_file);
514         if(!dir.stream(b)) {                      514         if(!dir.stream(b)) {
515           a_out << "read :"                       515           a_out << "read :"
516                 << " can't stream TDirectory."    516                 << " can't stream TDirectory."
517                 << std::endl;                     517                 << std::endl;
518         } else {                                  518         } else {
519           const std::vector<key*>& keys = dir.    519           const std::vector<key*>& keys = dir.keys();
520           read(a_out,a_file,keys,a_recursive,a    520           read(a_out,a_file,keys,a_recursive,a_ls,a_dump,a_spaces+1);
521         }                                         521         }
522       }                                           522       }
523     }                                             523     }
524   }}                                              524   }}
525 }                                                 525 }
526                                                   526 
527 }}                                                527 }}
528                                                   528 
529 #endif                                            529 #endif