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.0.p4)


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