Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/wroot/to is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_wroot_to
0005 #define tools_wroot_to
0006 
0007 #include "directory"
0008 #include "streamers"
0009 #include "bufobj"
0010 
0011 namespace tools {
0012 namespace wroot {
0013 
0014 //typedef std::map<std::string,std::string> annotations_t;
0015 inline bool to(directory& a_dir,const std::map<std::string,std::string>& a_annotations,const std::string& a_histo_name) {
0016   //if(a_annotations.empty()) return true;
0017   std::string sas;
0018   tools_mforcit(std::string,std::string,a_annotations,it) {
0019     if(it!=a_annotations.begin()) sas += "\n";
0020     sas += (*it).first;
0021     sas += "\n";
0022     sas += (*it).second;
0023   }
0024   std::string key_name = "annotations_"+a_histo_name;
0025   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,key_name,"annotations","TNamed");
0026   if(!Named_stream(*bo,a_histo_name,sas)) {
0027     a_dir.file().out() << "tools::wroot::to : Named_stream failed." << std::endl;
0028     delete bo;
0029     return false;
0030   }
0031   a_dir.append_object(bo); //a_dir takes ownership of bo.
0032   return true;
0033 }
0034 
0035 inline bool to(directory& a_dir,const histo::h1d& a_histo,const std::string& a_name) {
0036   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH1D");
0037   if(!TH1D_stream(*bo,a_histo,a_name)) {
0038     a_dir.file().out() << "tools::wroot::to : TH1D_stream failed." << std::endl;
0039     delete bo;
0040     return false;
0041   }
0042   a_dir.append_object(bo); //a_dir takes ownership of bo.
0043   return true;
0044 }
0045 
0046 inline bool to(directory& a_dir,const histo::h1df& a_histo,const std::string& a_name) {
0047   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH1F");
0048   if(!TH1F_stream(*bo,a_histo,a_name)) {
0049     a_dir.file().out() << "tools::wroot::to : TH1F_stream failed." << std::endl;
0050     delete bo;
0051     return false;
0052   }
0053   a_dir.append_object(bo); //a_dir takes ownership of bo.
0054   return true;
0055 }
0056 
0057 inline bool to(directory& a_dir,const histo::h2d& a_histo,const std::string& a_name) {
0058   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH2D");
0059   if(!TH2D_stream(*bo,a_histo,a_name)) {
0060     a_dir.file().out() << "tools::wroot::to : TH2D_stream failed." << std::endl;
0061     delete bo;
0062     return false;
0063   }
0064   a_dir.append_object(bo); //a_dir takes ownership of bo.
0065   return true;
0066 }
0067 
0068 inline bool to(directory& a_dir,const histo::h2df& a_histo,const std::string& a_name) {
0069   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH2F");
0070   if(!TH2F_stream(*bo,a_histo,a_name)) {
0071     a_dir.file().out() << "tools::wroot::to :"
0072                        << " TH2F_stream failed."
0073                        << std::endl;
0074     delete bo;
0075     return false;
0076   }
0077   a_dir.append_object(bo); //a_dir takes ownership of bo.
0078   return true;
0079 }
0080 
0081 inline bool to(directory& a_dir,const histo::h3d& a_histo,const std::string& a_name) {
0082   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0083                           a_name,a_histo.title(),"TH3D");
0084   if(!TH3D_stream(*bo,a_histo,a_name)) {
0085     a_dir.file().out() << "tools::wroot::to :"
0086                        << " TH3D_stream failed."
0087                        << std::endl;
0088     delete bo;
0089     return false;
0090   }
0091   a_dir.append_object(bo); //a_dir takes ownership of bo.
0092   return true;
0093 }
0094 
0095 inline bool to(directory& a_dir,const histo::h3df& a_histo,const std::string& a_name) {
0096   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH3F");
0097   if(!TH3F_stream(*bo,a_histo,a_name)) {
0098     a_dir.file().out() << "tools::wroot::to :"
0099                        << " TH3F_stream failed."
0100                        << std::endl;
0101     delete bo;
0102     return false;
0103   }
0104   a_dir.append_object(bo); //a_dir takes ownership of bo.
0105   return true;
0106 }
0107 
0108 inline bool to(directory& a_dir,const histo::p1d& a_histo,const std::string& a_name) {
0109   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0110                           a_name,a_histo.title(),"TProfile");
0111   if(!TProfile_stream(*bo,a_histo,a_name)) {
0112     a_dir.file().out() << "tools::wroot::to :"
0113                        << " TProfile_stream failed."
0114                        << std::endl;
0115     delete bo;
0116     return false;
0117   }
0118   a_dir.append_object(bo); //a_dir takes ownership of bo.
0119   return true;
0120 }
0121 
0122 inline bool to(directory& a_dir,const histo::p2d& a_histo,const std::string& a_name) {
0123   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0124                           a_name,a_histo.title(),"TProfile2D");
0125   if(!TProfile2D_stream(*bo,a_histo,a_name)) {
0126     a_dir.file().out() << "tools::wroot::to :"
0127                        << " TProfile2D_stream failed."
0128                        << std::endl;
0129     delete bo;
0130     return false;
0131   }
0132   a_dir.append_object(bo); //a_dir takes ownership of bo.
0133   return true;
0134 }
0135 
0136 inline bool write_histos(directory& a_dir,const std::vector< std::pair<std::string,void*> >& a_hists) {
0137   typedef std::pair<std::string,void*> class_pointer;
0138 
0139   tools_vforcit(class_pointer,a_hists,it) {
0140     const std::string& scls = (*it).first;
0141     void* p = (*it).second;
0142     if(scls==histo::h1d::s_class()) {
0143       histo::h1d& h = *((histo::h1d*)p);
0144       if(!to(a_dir,h,h.title())) return false;
0145 
0146     } else if(scls==histo::h2d::s_class()) {
0147       histo::h2d& h = *((histo::h2d*)p);
0148       if(!to(a_dir,h,h.title())) return false;
0149 
0150     } else if(scls==histo::h3d::s_class()) {
0151       histo::h3d& h = *((histo::h3d*)p);
0152       if(!to(a_dir,h,h.title())) return false;
0153 
0154     } else if(scls==histo::p1d::s_class()) {
0155       histo::p1d& h = *((histo::p1d*)p);
0156       if(!to(a_dir,h,h.title())) return false;
0157 
0158     } else if(scls==histo::p2d::s_class()) {
0159       histo::p2d& h = *((histo::p2d*)p);
0160       if(!to(a_dir,h,h.title())) return false;
0161 
0162     } else {
0163       a_dir.file().out() << "tools::wroot::write_histos :"
0164                          << " WARNING : class " << scls << " not handled."
0165                          << std::endl;
0166     }
0167 
0168   }
0169   return true;
0170 }
0171 
0172 }}
0173 
0174 #include "member_writer"
0175 #include "../store/osc_streamers"
0176 
0177 namespace tools {
0178 namespace wroot {
0179 
0180 inline bool to_osc(directory& a_dir,const histo::h1d& a_histo,const std::string& a_name) {
0181   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0182                           a_name,a_histo.title(),osc::s_h1d());
0183 
0184   //Stream as in a BatchLab/Rio/Data.h :
0185   if(!bo->write_version(1)) return false;
0186   if(!Named_stream(*bo,a_name,a_histo.title())) return false;
0187 
0188   member_writer mw(*bo);
0189   if(!osc::visit(mw,a_histo)) {
0190     a_dir.file().out() << "tools::wroot::to_osc :"
0191                        << " Histogram1D_stream failed."
0192                        << std::endl;
0193     delete bo;
0194     return false;
0195   }
0196   a_dir.append_object(bo); //a_dir takes ownership of bo.
0197   return true;
0198 }
0199 
0200 inline bool to_osc(directory& a_dir,const histo::h2d& a_histo,const std::string& a_name) {
0201   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0202                           a_name,a_histo.title(),osc::s_h2d());
0203 
0204   //Stream as in a BatchLab/Rio/Data.h :
0205   if(!bo->write_version(1)) return false;
0206   if(!Named_stream(*bo,a_name,a_histo.title())) return false;
0207 
0208   member_writer mw(*bo);
0209   if(!osc::visit(mw,a_histo)) {
0210     a_dir.file().out() << "tools::wroot::to_osc :"
0211                        << " Histogram2D_stream failed."
0212                        << std::endl;
0213     delete bo;
0214     return false;
0215   }
0216   a_dir.append_object(bo); //a_dir takes ownership of bo.
0217   return true;
0218 }
0219 
0220 inline bool to_osc(directory& a_dir,const histo::h3d& a_histo,const std::string& a_name) {
0221   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0222                           a_name,a_histo.title(),osc::s_h3d());
0223 
0224   //Stream as in a BatchLab/Rio/Data.h :
0225   if(!bo->write_version(1)) return false;
0226   if(!Named_stream(*bo,a_name,a_histo.title())) return false;
0227 
0228   member_writer mw(*bo);
0229   if(!osc::visit(mw,a_histo)) {
0230     a_dir.file().out() << "tools::wroot::to_osc :"
0231                        << " Histogram3D_stream failed."
0232                        << std::endl;
0233     delete bo;
0234     return false;
0235   }
0236   a_dir.append_object(bo); //a_dir takes ownership of bo.
0237   return true;
0238 }
0239 
0240 inline bool to_osc(directory& a_dir,const histo::p1d& a_histo,const std::string& a_name) {
0241   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0242                           a_name,a_histo.title(),osc::s_p1d());
0243 
0244   //Stream as in a BatchLab/Rio/Data.h :
0245   if(!bo->write_version(1)) return false;
0246   if(!Named_stream(*bo,a_name,a_histo.title())) return false;
0247 
0248   member_writer mw(*bo);
0249   if(!osc::visit(mw,a_histo)) {
0250     a_dir.file().out() << "tools::wroot::to_osc :"
0251                        << " Profile1D_stream failed."
0252                        << std::endl;
0253     delete bo;
0254     return false;
0255   }
0256   a_dir.append_object(bo); //a_dir takes ownership of bo.
0257   return true;
0258 }
0259 
0260 inline bool to_osc(directory& a_dir,const histo::p2d& a_histo,const std::string& a_name) {
0261   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0262                           a_name,a_histo.title(),osc::s_p2d());
0263 
0264   //Stream as in a BatchLab/Rio/Data.h :
0265   if(!bo->write_version(1)) return false;
0266   if(!Named_stream(*bo,a_name,a_histo.title())) return false;
0267 
0268   member_writer mw(*bo);
0269   if(!osc::visit(mw,a_histo)) {
0270     a_dir.file().out() << "tools::wroot::to_osc :"
0271                        << " Profile2D_stream failed."
0272                        << std::endl;
0273     delete bo;
0274     return false;
0275   }
0276   a_dir.append_object(bo); //a_dir takes ownership of bo.
0277   return true;
0278 }
0279 
0280 }}
0281 
0282 #endif