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 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 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  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> annotations_t;
 15 inline bool to(directory& a_dir,const std::map<std::string,std::string>& a_annotations,const std::string& a_histo_name) {
 16   //if(a_annotations.empty()) return true;
 17   std::string sas;
 18   tools_mforcit(std::string,std::string,a_annotations,it) {
 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_histo_name;
 25   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,key_name,"annotations","TNamed");
 26   if(!Named_stream(*bo,a_histo_name,sas)) {
 27     a_dir.file().out() << "tools::wroot::to : Named_stream failed." << std::endl;
 28     delete bo;
 29     return false;
 30   }
 31   a_dir.append_object(bo); //a_dir takes ownership of bo.
 32   return true;
 33 }
 34 
 35 inline bool to(directory& a_dir,const histo::h1d& a_histo,const std::string& a_name) {
 36   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH1D");
 37   if(!TH1D_stream(*bo,a_histo,a_name)) {
 38     a_dir.file().out() << "tools::wroot::to : TH1D_stream failed." << std::endl;
 39     delete bo;
 40     return false;
 41   }
 42   a_dir.append_object(bo); //a_dir takes ownership of bo.
 43   return true;
 44 }
 45 
 46 inline bool to(directory& a_dir,const histo::h1df& a_histo,const std::string& a_name) {
 47   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH1F");
 48   if(!TH1F_stream(*bo,a_histo,a_name)) {
 49     a_dir.file().out() << "tools::wroot::to : TH1F_stream failed." << std::endl;
 50     delete bo;
 51     return false;
 52   }
 53   a_dir.append_object(bo); //a_dir takes ownership of bo.
 54   return true;
 55 }
 56 
 57 inline bool to(directory& a_dir,const histo::h2d& a_histo,const std::string& a_name) {
 58   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH2D");
 59   if(!TH2D_stream(*bo,a_histo,a_name)) {
 60     a_dir.file().out() << "tools::wroot::to : TH2D_stream failed." << std::endl;
 61     delete bo;
 62     return false;
 63   }
 64   a_dir.append_object(bo); //a_dir takes ownership of bo.
 65   return true;
 66 }
 67 
 68 inline bool to(directory& a_dir,const histo::h2df& a_histo,const std::string& a_name) {
 69   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH2F");
 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 ownership of bo.
 78   return true;
 79 }
 80 
 81 inline bool to(directory& a_dir,const histo::h3d& a_histo,const std::string& a_name) {
 82   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
 83                           a_name,a_histo.title(),"TH3D");
 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 ownership of bo.
 92   return true;
 93 }
 94 
 95 inline bool to(directory& a_dir,const histo::h3df& a_histo,const std::string& a_name) {
 96   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,a_name,a_histo.title(),"TH3F");
 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 ownership of bo.
105   return true;
106 }
107 
108 inline bool to(directory& a_dir,const histo::p1d& a_histo,const std::string& a_name) {
109   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
110                           a_name,a_histo.title(),"TProfile");
111   if(!TProfile_stream(*bo,a_histo,a_name)) {
112     a_dir.file().out() << "tools::wroot::to :"
113                        << " TProfile_stream failed."
114                        << std::endl;
115     delete bo;
116     return false;
117   }
118   a_dir.append_object(bo); //a_dir takes ownership of bo.
119   return true;
120 }
121 
122 inline bool to(directory& a_dir,const histo::p2d& a_histo,const std::string& a_name) {
123   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
124                           a_name,a_histo.title(),"TProfile2D");
125   if(!TProfile2D_stream(*bo,a_histo,a_name)) {
126     a_dir.file().out() << "tools::wroot::to :"
127                        << " TProfile2D_stream failed."
128                        << std::endl;
129     delete bo;
130     return false;
131   }
132   a_dir.append_object(bo); //a_dir takes ownership of bo.
133   return true;
134 }
135 
136 inline bool write_histos(directory& a_dir,const std::vector< std::pair<std::string,void*> >& a_hists) {
137   typedef std::pair<std::string,void*> class_pointer;
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::write_histos :"
164                          << " WARNING : class " << scls << " not handled."
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 histo::h1d& a_histo,const std::string& a_name) {
181   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
182                           a_name,a_histo.title(),osc::s_h1d());
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())) return false;
187 
188   member_writer mw(*bo);
189   if(!osc::visit(mw,a_histo)) {
190     a_dir.file().out() << "tools::wroot::to_osc :"
191                        << " Histogram1D_stream failed."
192                        << std::endl;
193     delete bo;
194     return false;
195   }
196   a_dir.append_object(bo); //a_dir takes ownership of bo.
197   return true;
198 }
199 
200 inline bool to_osc(directory& a_dir,const histo::h2d& a_histo,const std::string& a_name) {
201   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
202                           a_name,a_histo.title(),osc::s_h2d());
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())) return false;
207 
208   member_writer mw(*bo);
209   if(!osc::visit(mw,a_histo)) {
210     a_dir.file().out() << "tools::wroot::to_osc :"
211                        << " Histogram2D_stream failed."
212                        << std::endl;
213     delete bo;
214     return false;
215   }
216   a_dir.append_object(bo); //a_dir takes ownership of bo.
217   return true;
218 }
219 
220 inline bool to_osc(directory& a_dir,const histo::h3d& a_histo,const std::string& a_name) {
221   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
222                           a_name,a_histo.title(),osc::s_h3d());
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())) return false;
227 
228   member_writer mw(*bo);
229   if(!osc::visit(mw,a_histo)) {
230     a_dir.file().out() << "tools::wroot::to_osc :"
231                        << " Histogram3D_stream failed."
232                        << std::endl;
233     delete bo;
234     return false;
235   }
236   a_dir.append_object(bo); //a_dir takes ownership of bo.
237   return true;
238 }
239 
240 inline bool to_osc(directory& a_dir,const histo::p1d& a_histo,const std::string& a_name) {
241   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
242                           a_name,a_histo.title(),osc::s_p1d());
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())) return false;
247 
248   member_writer mw(*bo);
249   if(!osc::visit(mw,a_histo)) {
250     a_dir.file().out() << "tools::wroot::to_osc :"
251                        << " Profile1D_stream failed."
252                        << std::endl;
253     delete bo;
254     return false;
255   }
256   a_dir.append_object(bo); //a_dir takes ownership of bo.
257   return true;
258 }
259 
260 inline bool to_osc(directory& a_dir,const histo::p2d& a_histo,const std::string& a_name) {
261   bufobj* bo = new bufobj(a_dir.file().out(),a_dir.file().byte_swap(),256,
262                           a_name,a_histo.title(),osc::s_p2d());
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())) return false;
267 
268   member_writer mw(*bo);
269   if(!osc::visit(mw,a_histo)) {
270     a_dir.file().out() << "tools::wroot::to_osc :"
271                        << " Profile2D_stream failed."
272                        << std::endl;
273     delete bo;
274     return false;
275   }
276   a_dir.append_object(bo); //a_dir takes ownership of bo.
277   return true;
278 }
279 
280 }}
281 
282 #endif