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 inline bool to(directory& a_dir,const std::map<std::string,std::string>& a_annotations,const std::string& a_histo_name) {
0015 std::string sas;
0016 for(auto it = a_annotations.cbegin(); it != a_annotations.cend(); ++it) {
0017 if(it!=a_annotations.begin()) sas += "\n";
0018 sas += (*it).first;
0019 sas += "\n";
0020 sas += (*it).second;
0021 }
0022 std::string key_name = "annotations_"+a_histo_name;
0023 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,key_name,"annotations","TNamed");
0024 if(!Named_stream(*bo,a_histo_name,sas)) {
0025 a_dir.file().out() << "tools::wroot::to : Named_stream failed." << std::endl;
0026 delete bo;
0027 return false;
0028 }
0029 a_dir.append_object(bo); //a_dir takes ownership of bo.
0030 return true;
0031 }
0032
0033 inline bool to(directory& a_dir,const histo::h1d& a_histo,const std::string& a_name) {
0034 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH1D");
0035 if(!TH1D_stream(*bo,a_histo,a_name)) {
0036 a_dir.file().out() << "tools::wroot::to : TH1D_stream failed." << std::endl;
0037 delete bo;
0038 return false;
0039 }
0040 a_dir.append_object(bo); //a_dir takes ownership of bo.
0041 return true;
0042 }
0043
0044 inline bool to(directory& a_dir,const histo::h1df& a_histo,const std::string& a_name) {
0045 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH1F");
0046 if(!TH1F_stream(*bo,a_histo,a_name)) {
0047 a_dir.file().out() << "tools::wroot::to : TH1F_stream failed." << std::endl;
0048 delete bo;
0049 return false;
0050 }
0051 a_dir.append_object(bo); //a_dir takes ownership of bo.
0052 return true;
0053 }
0054
0055 inline bool to(directory& a_dir,const histo::h2d& a_histo,const std::string& a_name) {
0056 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH2D");
0057 if(!TH2D_stream(*bo,a_histo,a_name)) {
0058 a_dir.file().out() << "tools::wroot::to : TH2D_stream failed." << std::endl;
0059 delete bo;
0060 return false;
0061 }
0062 a_dir.append_object(bo); //a_dir takes ownership of bo.
0063 return true;
0064 }
0065
0066 inline bool to(directory& a_dir,const histo::h2df& a_histo,const std::string& a_name) {
0067 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH2F");
0068 if(!TH2F_stream(*bo,a_histo,a_name)) {
0069 a_dir.file().out() << "tools::wroot::to :"
0070 << " TH2F_stream failed."
0071 << std::endl;
0072 delete bo;
0073 return false;
0074 }
0075 a_dir.append_object(bo); //a_dir takes ownership of bo.
0076 return true;
0077 }
0078
0079 inline bool to(directory& a_dir,const histo::h3d& a_histo,const std::string& a_name) {
0080 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0081 a_name,a_histo.title(),"TH3D");
0082 if(!TH3D_stream(*bo,a_histo,a_name)) {
0083 a_dir.file().out() << "tools::wroot::to :"
0084 << " TH3D_stream failed."
0085 << std::endl;
0086 delete bo;
0087 return false;
0088 }
0089 a_dir.append_object(bo); //a_dir takes ownership of bo.
0090 return true;
0091 }
0092
0093 inline bool to(directory& a_dir,const histo::h3df& a_histo,const std::string& a_name) {
0094 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH3F");
0095 if(!TH3F_stream(*bo,a_histo,a_name)) {
0096 a_dir.file().out() << "tools::wroot::to :"
0097 << " TH3F_stream failed."
0098 << std::endl;
0099 delete bo;
0100 return false;
0101 }
0102 a_dir.append_object(bo); //a_dir takes ownership of bo.
0103 return true;
0104 }
0105
0106 inline bool to(directory& a_dir,const histo::p1d& a_histo,const std::string& a_name) {
0107 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0108 a_name,a_histo.title(),"TProfile");
0109 if(!TProfile_stream(*bo,a_histo,a_name)) {
0110 a_dir.file().out() << "tools::wroot::to :"
0111 << " TProfile_stream failed."
0112 << std::endl;
0113 delete bo;
0114 return false;
0115 }
0116 a_dir.append_object(bo); //a_dir takes ownership of bo.
0117 return true;
0118 }
0119
0120 inline bool to(directory& a_dir,const histo::p2d& a_histo,const std::string& a_name) {
0121 bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
0122 a_name,a_histo.title(),"TProfile2D");
0123 if(!TProfile2D_stream(*bo,a_histo,a_name)) {
0124 a_dir.file().out() << "tools::wroot::to :"
0125 << " TProfile2D_stream failed."
0126 << std::endl;
0127 delete bo;
0128 return false;
0129 }
0130 a_dir.append_object(bo); //a_dir takes ownership of bo.
0131 return true;
0132 }
0133
0134 inline bool write_histos(directory& a_dir,const std::vector< std::pair<std::string,void*> >& a_hists) {
0135
0136 for(auto it = a_hists.cbegin(); it != a_hists.cend(); ++it) {
0137 const std::string& scls = (*it).first;
0138 void* p = (*it).second;
0139 if(scls==histo::h1d::s_class()) {
0140 histo::h1d& h = *((histo::h1d*)p);
0141 if(!to(a_dir,h,h.title())) return false;
0142
0143 } else if(scls==histo::h2d::s_class()) {
0144 histo::h2d& h = *((histo::h2d*)p);
0145 if(!to(a_dir,h,h.title())) return false;
0146
0147 } else if(scls==histo::h3d::s_class()) {
0148 histo::h3d& h = *((histo::h3d*)p);
0149 if(!to(a_dir,h,h.title())) return false;
0150
0151 } else if(scls==histo::p1d::s_class()) {
0152 histo::p1d& h = *((histo::p1d*)p);
0153 if(!to(a_dir,h,h.title())) return false;
0154
0155 } else if(scls==histo::p2d::s_class()) {
0156 histo::p2d& h = *((histo::p2d*)p);
0157 if(!to(a_dir,h,h.title())) return false;
0158
0159 } else {
0160 a_dir.file().out() << "tools::wroot::write_histos :"
0161 << " WARNING : class " << scls << " not handled."
0162 << std::endl;
0163 }
0164
0165 }
0166 return true;
0167 }
0168
0169 }}
0170
0171 #endif