Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_wroot_to 5 #define tools_wroot_to 6 7 #include "directory" 8 #include "streamers" 9 #include "bufobj" 10 11 namespace tools { 12 namespace wroot { 13 14 //typedef std::map<std::string,std::string> an 15 inline bool to(directory& a_dir,const std::map 16 //if(a_annotations.empty()) return true; 17 std::string sas; 18 tools_mforcit(std::string,std::string,a_anno 19 if(it!=a_annotations.begin()) sas += "\n"; 20 sas += (*it).first; 21 sas += "\n"; 22 sas += (*it).second; 23 } 24 std::string key_name = "annotations_"+a_hist 25 bufobj* bo = new bufobj(a_dir.file().out(),a 26 if(!Named_stream(*bo,a_histo_name,sas)) { 27 a_dir.file().out() << "tools::wroot::to : 28 delete bo; 29 return false; 30 } 31 a_dir.append_object(bo); //a_dir takes owner 32 return true; 33 } 34 35 inline bool to(directory& a_dir,const histo::h 36 bufobj* bo = new bufobj(a_dir.file().out(),a 37 if(!TH1D_stream(*bo,a_histo,a_name)) { 38 a_dir.file().out() << "tools::wroot::to : 39 delete bo; 40 return false; 41 } 42 a_dir.append_object(bo); //a_dir takes owner 43 return true; 44 } 45 46 inline bool to(directory& a_dir,const histo::h 47 bufobj* bo = new bufobj(a_dir.file().out(),a 48 if(!TH1F_stream(*bo,a_histo,a_name)) { 49 a_dir.file().out() << "tools::wroot::to : 50 delete bo; 51 return false; 52 } 53 a_dir.append_object(bo); //a_dir takes owner 54 return true; 55 } 56 57 inline bool to(directory& a_dir,const histo::h 58 bufobj* bo = new bufobj(a_dir.file().out(),a 59 if(!TH2D_stream(*bo,a_histo,a_name)) { 60 a_dir.file().out() << "tools::wroot::to : 61 delete bo; 62 return false; 63 } 64 a_dir.append_object(bo); //a_dir takes owner 65 return true; 66 } 67 68 inline bool to(directory& a_dir,const histo::h 69 bufobj* bo = new bufobj(a_dir.file().out(),a 70 if(!TH2F_stream(*bo,a_histo,a_name)) { 71 a_dir.file().out() << "tools::wroot::to :" 72 << " TH2F_stream failed 73 << std::endl; 74 delete bo; 75 return false; 76 } 77 a_dir.append_object(bo); //a_dir takes owner 78 return true; 79 } 80 81 inline bool to(directory& a_dir,const histo::h 82 bufobj* bo = new bufobj(a_dir.file().out(),a 83 a_name,a_histo.title 84 if(!TH3D_stream(*bo,a_histo,a_name)) { 85 a_dir.file().out() << "tools::wroot::to :" 86 << " TH3D_stream failed 87 << std::endl; 88 delete bo; 89 return false; 90 } 91 a_dir.append_object(bo); //a_dir takes owner 92 return true; 93 } 94 95 inline bool to(directory& a_dir,const histo::h 96 bufobj* bo = new bufobj(a_dir.file().out(),a 97 if(!TH3F_stream(*bo,a_histo,a_name)) { 98 a_dir.file().out() << "tools::wroot::to :" 99 << " TH3F_stream failed 100 << std::endl; 101 delete bo; 102 return false; 103 } 104 a_dir.append_object(bo); //a_dir takes owner 105 return true; 106 } 107 108 inline bool to(directory& a_dir,const histo::p 109 bufobj* bo = new bufobj(a_dir.file().out(),a 110 a_name,a_histo.title 111 if(!TProfile_stream(*bo,a_histo,a_name)) { 112 a_dir.file().out() << "tools::wroot::to :" 113 << " TProfile_stream fa 114 << std::endl; 115 delete bo; 116 return false; 117 } 118 a_dir.append_object(bo); //a_dir takes owner 119 return true; 120 } 121 122 inline bool to(directory& a_dir,const histo::p 123 bufobj* bo = new bufobj(a_dir.file().out(),a 124 a_name,a_histo.title 125 if(!TProfile2D_stream(*bo,a_histo,a_name)) { 126 a_dir.file().out() << "tools::wroot::to :" 127 << " TProfile2D_stream 128 << std::endl; 129 delete bo; 130 return false; 131 } 132 a_dir.append_object(bo); //a_dir takes owner 133 return true; 134 } 135 136 inline bool write_histos(directory& a_dir,cons 137 typedef std::pair<std::string,void*> class_p 138 139 tools_vforcit(class_pointer,a_hists,it) { 140 const std::string& scls = (*it).first; 141 void* p = (*it).second; 142 if(scls==histo::h1d::s_class()) { 143 histo::h1d& h = *((histo::h1d*)p); 144 if(!to(a_dir,h,h.title())) return false; 145 146 } else if(scls==histo::h2d::s_class()) { 147 histo::h2d& h = *((histo::h2d*)p); 148 if(!to(a_dir,h,h.title())) return false; 149 150 } else if(scls==histo::h3d::s_class()) { 151 histo::h3d& h = *((histo::h3d*)p); 152 if(!to(a_dir,h,h.title())) return false; 153 154 } else if(scls==histo::p1d::s_class()) { 155 histo::p1d& h = *((histo::p1d*)p); 156 if(!to(a_dir,h,h.title())) return false; 157 158 } else if(scls==histo::p2d::s_class()) { 159 histo::p2d& h = *((histo::p2d*)p); 160 if(!to(a_dir,h,h.title())) return false; 161 162 } else { 163 a_dir.file().out() << "tools::wroot::wri 164 << " WARNING : class 165 << std::endl; 166 } 167 168 } 169 return true; 170 } 171 172 }} 173 174 #include "member_writer" 175 #include "../store/osc_streamers" 176 177 namespace tools { 178 namespace wroot { 179 180 inline bool to_osc(directory& a_dir,const hist 181 bufobj* bo = new bufobj(a_dir.file().out(),a 182 a_name,a_histo.title 183 184 //Stream as in a BatchLab/Rio/Data.h : 185 if(!bo->write_version(1)) return false; 186 if(!Named_stream(*bo,a_name,a_histo.title()) 187 188 member_writer mw(*bo); 189 if(!osc::visit(mw,a_histo)) { 190 a_dir.file().out() << "tools::wroot::to_os 191 << " Histogram1D_stream 192 << std::endl; 193 delete bo; 194 return false; 195 } 196 a_dir.append_object(bo); //a_dir takes owner 197 return true; 198 } 199 200 inline bool to_osc(directory& a_dir,const hist 201 bufobj* bo = new bufobj(a_dir.file().out(),a 202 a_name,a_histo.title 203 204 //Stream as in a BatchLab/Rio/Data.h : 205 if(!bo->write_version(1)) return false; 206 if(!Named_stream(*bo,a_name,a_histo.title()) 207 208 member_writer mw(*bo); 209 if(!osc::visit(mw,a_histo)) { 210 a_dir.file().out() << "tools::wroot::to_os 211 << " Histogram2D_stream 212 << std::endl; 213 delete bo; 214 return false; 215 } 216 a_dir.append_object(bo); //a_dir takes owner 217 return true; 218 } 219 220 inline bool to_osc(directory& a_dir,const hist 221 bufobj* bo = new bufobj(a_dir.file().out(),a 222 a_name,a_histo.title 223 224 //Stream as in a BatchLab/Rio/Data.h : 225 if(!bo->write_version(1)) return false; 226 if(!Named_stream(*bo,a_name,a_histo.title()) 227 228 member_writer mw(*bo); 229 if(!osc::visit(mw,a_histo)) { 230 a_dir.file().out() << "tools::wroot::to_os 231 << " Histogram3D_stream 232 << std::endl; 233 delete bo; 234 return false; 235 } 236 a_dir.append_object(bo); //a_dir takes owner 237 return true; 238 } 239 240 inline bool to_osc(directory& a_dir,const hist 241 bufobj* bo = new bufobj(a_dir.file().out(),a 242 a_name,a_histo.title 243 244 //Stream as in a BatchLab/Rio/Data.h : 245 if(!bo->write_version(1)) return false; 246 if(!Named_stream(*bo,a_name,a_histo.title()) 247 248 member_writer mw(*bo); 249 if(!osc::visit(mw,a_histo)) { 250 a_dir.file().out() << "tools::wroot::to_os 251 << " Profile1D_stream f 252 << std::endl; 253 delete bo; 254 return false; 255 } 256 a_dir.append_object(bo); //a_dir takes owner 257 return true; 258 } 259 260 inline bool to_osc(directory& a_dir,const hist 261 bufobj* bo = new bufobj(a_dir.file().out(),a 262 a_name,a_histo.title 263 264 //Stream as in a BatchLab/Rio/Data.h : 265 if(!bo->write_version(1)) return false; 266 if(!Named_stream(*bo,a_name,a_histo.title()) 267 268 member_writer mw(*bo); 269 if(!osc::visit(mw,a_histo)) { 270 a_dir.file().out() << "tools::wroot::to_os 271 << " Profile2D_stream f 272 << std::endl; 273 delete bo; 274 return false; 275 } 276 a_dir.append_object(bo); //a_dir takes owner 277 return true; 278 } 279 280 }} 281 282 #endif