Warning, /include/Geant4/tools/rroot/streamers 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_rroot_streamers
0005 #define tools_rroot_streamers
0006
0007 #include "dummy_fac"
0008
0009 #include "named"
0010 #include "date"
0011 #include "directory"
0012 //#include "graph"
0013 #include "clss"
0014 #include "dummy"
0015 #include "obj_list"
0016
0017 #include "../sout"
0018 #include "../vmanip"
0019
0020 //#include "../histo/histo_data"
0021 #include "../histo/profile_data"
0022
0023 #include "../histo/h1d"
0024 #include "../histo/h2d"
0025 #include "../histo/h3d"
0026 #include "../histo/p1d"
0027 #include "../histo/p2d"
0028
0029 #include <list>
0030 #include <cmath> //::log10, ::fabs.
0031 //#include "../rtausmed"
0032
0033 namespace tools {
0034 namespace rroot {
0035
0036 typedef histo::histo_data<double,unsigned int,unsigned int,double> hd_data;
0037 typedef histo::profile_data<double,unsigned int,unsigned int,double,double> pd_data;
0038
0039 inline bool AttAxis_stream(buffer& a_buffer){
0040 int fNdivisions = 510; //Number of divisions(10000*n3 + 100*n2 + n1)
0041 short fAxisColor = 1; //color of the line axis
0042 short fLabelColor = 1; //color of labels
0043 short fLabelFont = 62; //font for labels
0044 float fLabelOffset = 0.005F; //offset of labels
0045 float fLabelSize = 0.04F; //size of labels
0046 float fTickLength = 0.03F; //length of tick marks
0047 float fTitleOffset = 1; //offset of axis title
0048 float fTitleSize = 0.04F; //size of axis title
0049 short fTitleColor = 1; //color of axis title
0050 short fTitleFont = 62; //font for axis title
0051
0052 // Version 4 streaming (ROOT/v3-00-6).
0053 short v;
0054 unsigned int _s,_c;
0055 if(!a_buffer.read_version(v,_s,_c)) return false;
0056
0057 if(!a_buffer.read(fNdivisions)) return false;
0058 if(!a_buffer.read(fAxisColor)) return false;
0059 if(!a_buffer.read(fLabelColor)) return false;
0060 if(!a_buffer.read(fLabelFont)) return false;
0061 if(!a_buffer.read(fLabelOffset)) return false;
0062 if(!a_buffer.read(fLabelSize)) return false;
0063 if(!a_buffer.read(fTickLength)) return false;
0064 if(!a_buffer.read(fTitleOffset)) return false;
0065 if(!a_buffer.read(fTitleSize)) return false;
0066 if(!a_buffer.read(fTitleColor)) return false;
0067 if(!a_buffer.read(fTitleFont)) return false;
0068
0069 if(!a_buffer.check_byte_count(_s,_c,"TAttAxis")) return false;
0070 return true;
0071 }
0072
0073 inline bool Axis_stream(buffer& a_buffer,histo::axis<double,unsigned int>& a_fAxis){
0074 // Version 6 streaming (ROOT/v3-00-6).
0075 short v;
0076 unsigned int _s,_c;
0077 if(!a_buffer.read_version(v,_s,_c)) return false;
0078
0079 std::string name;
0080 std::string title;
0081 if(!Named_stream(a_buffer,name,title)) return false;
0082
0083 if(!AttAxis_stream(a_buffer)) return false;
0084
0085 int number;
0086 if(!a_buffer.read(number)) return false;
0087 double min;
0088 if(!a_buffer.read(min)) return false;
0089 double max;
0090 if(!a_buffer.read(max)) return false;
0091
0092 std::vector<double> edges;
0093 if(!Array_stream<double>(a_buffer,edges)) return false; //fXbins TArrayD
0094
0095 size_t edgen = edges.size();
0096 if(!edgen) {
0097 a_fAxis.configure(number,min,max);
0098 } else {
0099 std::vector<double> vedges;
0100 for(size_t index=0;index<edgen;index++) {
0101 vedges.push_back(edges[index]);
0102 }
0103 a_fAxis.configure(vedges);
0104 }
0105
0106 int First;
0107 if(!a_buffer.read(First)) return false;
0108 int Last;
0109 if(!a_buffer.read(Last)) return false;
0110
0111 if(v>=8) { //fBits2.
0112 unsigned short dummy;
0113 if(!a_buffer.read(dummy)) return false;
0114 }
0115
0116 //Bool_t
0117 unsigned char TimeDisplay;
0118 if(!a_buffer.read(TimeDisplay)) return false;
0119
0120 //TString
0121 std::string TimeFormat;
0122 if(!a_buffer.read(TimeFormat)) return false;
0123
0124 if(v>=7) {
0125 //THashList*
0126 dummy_fac fac(a_buffer.out());
0127 if(!dummy_TXxx_pointer_stream(a_buffer,fac)) return false;
0128 }
0129
0130 if(!a_buffer.check_byte_count(_s,_c,"TAxis")) return false;
0131 return true;
0132 }
0133
0134 inline bool null_epsil(double a_1,double a_2,double a_prec = -5) {
0135 return (::log10(::fabs(a_1-a_2))<a_prec?true:false);
0136 }
0137
0138 inline bool TH_read_1D(buffer& a_buffer,hd_data& a_data,
0139 double& a_entries,double& a_Sw,double& a_Sw2,double& a_Sxw,double& a_Sx2w){
0140 a_entries = 0;
0141 a_Sw = 0;
0142 a_Sw2 = 0;
0143 a_Sxw = 0;
0144 a_Sx2w = 0;
0145
0146 unsigned int _s,_c;
0147 short vers;
0148 if(!a_buffer.read_version(vers,_s,_c)) return false;
0149
0150 //::printf("debug : tools::rroot::TH_read_1D : version %d\n",vers);
0151
0152 // Version 3 streaming (ROOT/v3-00-6).
0153
0154 std::string name;
0155 std::string title;
0156 if(!Named_stream(a_buffer,name,title)) return false;
0157
0158 a_data.m_title = title;
0159
0160 {short color,style,width;
0161 if(!AttLine_stream(a_buffer,color,style,width)) return false;}
0162 {short color,style;
0163 if(!AttFill_stream(a_buffer,color,style)) return false;}
0164 if(!AttMarker_stream(a_buffer)) return false;
0165
0166 int Ncells;
0167 if(!a_buffer.read(Ncells)) return false;
0168
0169 //fXAxis
0170 if(!Axis_stream(a_buffer,a_data.m_axes[0])) return false;
0171 a_data.m_axes[0].m_offset = 1;
0172
0173 if(a_data.m_dimension==3) {
0174 if(!Axis_stream(a_buffer,a_data.m_axes[1])) return false; //fYAxis
0175 a_data.m_axes[1].m_offset = a_data.m_axes[0].m_offset * (a_data.m_axes[0].bins()+2);
0176
0177 if(!Axis_stream(a_buffer,a_data.m_axes[2])) return false; //fZAxis
0178 a_data.m_axes[2].m_offset = a_data.m_axes[1].m_offset * (a_data.m_axes[1].bins()+2);
0179
0180 } else if(a_data.m_dimension==2) {
0181 if(!Axis_stream(a_buffer,a_data.m_axes[1])) return false; //fYAxis
0182 a_data.m_axes[1].m_offset = a_data.m_axes[0].m_offset * (a_data.m_axes[0].bins()+2);
0183
0184 histo::axis<double,unsigned int> dummy;
0185 if(!Axis_stream(a_buffer,dummy)) return false; //fZAxis
0186 } else {
0187 histo::axis<double,unsigned int> dummy;
0188 if(!Axis_stream(a_buffer,dummy)) return false; //fYAxis
0189 if(!Axis_stream(a_buffer,dummy)) return false; //fZAxis
0190 }
0191
0192 short barOffset;
0193 if(!a_buffer.read(barOffset)) return false;
0194
0195 short barWidth;
0196 if(!a_buffer.read(barWidth)) return false;
0197
0198 if(!a_buffer.read(a_entries)) return false;
0199
0200 if(!a_buffer.read(a_Sw)) return false; //fTsumw
0201
0202 if(!a_buffer.read(a_Sw2)) return false;
0203
0204 if(!a_buffer.read(a_Sxw)) return false;
0205
0206 if(!a_buffer.read(a_Sx2w)) return false;
0207
0208 double max;
0209 if(!a_buffer.read(max)) return false;
0210
0211 double min;
0212 if(!a_buffer.read(min)) return false;
0213
0214 double NormFactor;
0215 if(!a_buffer.read(NormFactor)) return false;
0216
0217 {std::vector<double> v;
0218 if(!Array_stream<double>(a_buffer,v)) return false;} //fContour TArrayD
0219
0220 std::vector<double> sumw2; //fSumw2 TArrayD
0221 if(!Array_stream<double>(a_buffer,sumw2)) return false;
0222
0223 {std::string opt;
0224 if(!a_buffer.read(opt)) return false; //TString fOption
0225 //look if it is an "annotation trick" :
0226 //if(opt.size()&&(opt[0]==0)) {
0227 // fAnnotation = opt.substr(1,opt.size()-1);
0228 //}
0229 }
0230
0231 {dummy_fac fac(a_buffer.out());
0232 obj_list dummy(fac);
0233 if(!dummy.stream(a_buffer)) {
0234 a_buffer.out() << "tools::rroot::TH_read_1D :"
0235 << " obj_list stream failed."
0236 << std::endl;
0237 return false;
0238 }} //Functions
0239
0240 if(vers>=4) {
0241 int BufferSize;
0242 if(!a_buffer.read(BufferSize)) return false;
0243
0244 //Double_t* Buffer; //[fBufferSize]
0245 if(!dummy_array_stream<double>(a_buffer,BufferSize)) return false;
0246 }
0247
0248 if(vers>=7) {
0249 //EBinErrorOpt fBinStatErrOpt;
0250 int dummy;
0251 if(!a_buffer.read(dummy)) return false;
0252 }
0253
0254 // Add two for outflows.
0255 if(a_data.m_dimension==1) {
0256 a_data.m_bin_number = a_data.m_axes[0].m_number_of_bins + 2;
0257 } else if(a_data.m_dimension==2) {
0258 a_data.m_bin_number =
0259 (a_data.m_axes[0].m_number_of_bins + 2) *
0260 (a_data.m_axes[1].m_number_of_bins + 2);
0261 } else if(a_data.m_dimension==3) {
0262 a_data.m_bin_number =
0263 (a_data.m_axes[0].m_number_of_bins + 2) *
0264 (a_data.m_axes[1].m_number_of_bins + 2) *
0265 (a_data.m_axes[2].m_number_of_bins + 2);
0266 }
0267
0268 unsigned int binn = a_data.m_bin_number;
0269 a_data.m_bin_Sw2.resize(binn);
0270 if(binn==sumw2.size()) {
0271 for(unsigned int index=0;index<binn;index++){
0272 a_data.m_bin_Sw2[index] = sumw2[index];
0273 }
0274 } else {
0275 a_data.m_bin_Sw2.assign(binn,0);
0276 }
0277
0278 if(!a_buffer.check_byte_count(_s,_c,"TH")) return false;
0279
0280 return true;
0281 }
0282
0283
0284 inline bool TH_read_2D(buffer& a_buffer,hd_data& a_data,
0285 double& a_entries,double& a_Sw,double& a_Sw2,
0286 double& a_Sxw,double& a_Sx2w,double& a_Syw,double& a_Sy2w){
0287 unsigned int _s,_c;
0288 short v;
0289 if(!a_buffer.read_version(v,_s,_c)) return false;
0290
0291 // Version 3 streaming (ROOT/v3-00-6).
0292
0293 if(!TH_read_1D(a_buffer,a_data,a_entries,a_Sw,a_Sw2,a_Sxw,a_Sx2w)) return false;
0294 // the upper set :
0295 //data.m_title
0296 //data.m_bin_number
0297 //data.m_axes
0298 //data.m_bin_Sw2
0299
0300 double ScaleFactor;
0301 if(!a_buffer.read(ScaleFactor)) return false;
0302 if(!a_buffer.read(a_Syw)) return false;
0303 if(!a_buffer.read(a_Sy2w)) return false;
0304
0305 double Tsumwxy;
0306 if(!a_buffer.read(Tsumwxy)) return false;
0307 a_data.m_in_range_plane_Sxyw[0] = Tsumwxy;
0308
0309 if(!a_buffer.check_byte_count(_s,_c,"TH2")) return false;
0310
0311 return true;
0312 }
0313
0314 inline bool TH_read_3D(buffer& a_buffer,hd_data& a_data,
0315 double& a_entries,double& a_Sw,double& a_Sw2,
0316 double& a_Sxw,double& a_Sx2w,
0317 double& a_Syw,double& a_Sy2w,
0318 double& a_Szw,double& a_Sz2w){
0319 unsigned int _s,_c;
0320 short v;
0321 if(!a_buffer.read_version(v,_s,_c)) return false;
0322
0323 if(!TH_read_1D(a_buffer,a_data,a_entries,a_Sw,a_Sw2,a_Sxw,a_Sx2w)) return false;
0324 if(!Att3D_stream(a_buffer)) return false;
0325
0326 // the upper set :
0327 //data.m_title
0328 //data.m_bin_number
0329 //data.m_axes
0330 //data.m_bin_Sw2
0331
0332 if(!a_buffer.read(a_Syw)) return false;
0333 if(!a_buffer.read(a_Sy2w)) return false;
0334 double Tsumwxy;
0335 if(!a_buffer.read(Tsumwxy)) return false;
0336
0337 if(!a_buffer.read(a_Szw)) return false;
0338 if(!a_buffer.read(a_Sz2w)) return false;
0339 double Tsumwxz;
0340 if(!a_buffer.read(Tsumwxz)) return false;
0341 double Tsumwyz;
0342 if(!a_buffer.read(Tsumwyz)) return false;
0343
0344 a_data.m_in_range_plane_Sxyw[0] = Tsumwxy;
0345 a_data.m_in_range_plane_Sxyw[1] = Tsumwyz;
0346 a_data.m_in_range_plane_Sxyw[2] = Tsumwxz;
0347
0348 if(!a_buffer.check_byte_count(_s,_c,"TH3")) return false;
0349
0350 return true;
0351 }
0352
0353 inline histo::h1d* TH1F_stream(buffer& a_buffer){
0354 unsigned int _s,_c;
0355 short v;
0356 if(!a_buffer.read_version(v,_s,_c)) return 0;
0357
0358 // Version 1 streaming (ROOT/v3-00-6).
0359
0360 // Now we have to reconstruct a valid Histogram from a_buffer :
0361 hd_data data;
0362
0363 data.m_dimension = 1;
0364 //data.m_coords.resize(data.m_dimension,0);
0365 //data.m_ints.resize(data.m_dimension,0);
0366 data.m_axes.resize(1);
0367
0368 double fEntries; //in range + outflow.
0369 double fSw; //in range.
0370 double fSw2; //in range.
0371 double fSxw; //in range.
0372 double fSx2w; //in range.
0373 if(!TH_read_1D(a_buffer,data,fEntries,fSw,fSw2,fSxw,fSx2w)) return 0;
0374 // the upper set :
0375 //data.m_title
0376 //data.m_bin_number
0377 //data.m_axes
0378 //data.m_bin_Sw2
0379
0380 std::vector<float> bins; //fArray TArrayF
0381 if(!Array_stream<float>(a_buffer,bins)) return 0;
0382 if(!a_buffer.check_byte_count(_s,_c,"TH1F")) return 0;
0383
0384 unsigned int binn = data.m_bin_number;
0385 data.m_bin_Sw.resize(binn,0);
0386 {for(unsigned int index=0;index<binn;index++){
0387 data.m_bin_Sw[index] = double(bins[index]);
0388 }}
0389
0390 data.m_bin_entries.resize(binn,0);
0391 {std::vector<double> empty;
0392 empty.resize(1,0);
0393 data.m_bin_Sxw.resize(binn,empty);
0394 data.m_bin_Sx2w.resize(binn,empty);}
0395 data.m_all_entries = static_cast<unsigned int>(fEntries);
0396 data.m_in_range_entries = 0;
0397 data.m_in_range_Sw = fSw;
0398 data.m_in_range_Sw2 = fSw2;
0399 data.m_in_range_Sxw.resize(1,0);
0400 data.m_in_range_Sx2w.resize(1,0);
0401 data.m_in_range_Sxw[0] = fSxw;
0402 data.m_in_range_Sx2w[0] = fSx2w;
0403
0404 histo::h1d* h = new histo::h1d("",10,0,1);
0405 h->copy_from_data(data);
0406 return h; //give ownership to caller.
0407 }
0408
0409 inline histo::h1d* TH1D_stream(buffer& a_buffer){
0410 unsigned int _s,_c;
0411 short v;
0412 if(!a_buffer.read_version(v,_s,_c)) return 0;
0413
0414 // Version 1 streaming (ROOT/v3-00-6).
0415
0416 // Now we have to reconstruct a valid Histogram from a_buffer :
0417 hd_data data;
0418
0419 data.m_dimension = 1;
0420 data.m_axes.resize(1);
0421
0422 double fEntries; //in range + outflow.
0423 double fSw; //in range.
0424 double fSw2; //in range.
0425 double fSxw; //in range.
0426 double fSx2w; //in range.
0427 if(!TH_read_1D(a_buffer,data,fEntries,fSw,fSw2,fSxw,fSx2w)) return 0;
0428 // the upper set :
0429 //data.m_title
0430 //data.m_bin_number
0431 //data.m_axes
0432 //data.m_bin_Sw2
0433
0434 std::vector<double> bins; //fArray TArrayD
0435 if(!Array_stream<double>(a_buffer,bins)) return 0;
0436 if(!a_buffer.check_byte_count(_s,_c,"TH1D")) return 0;
0437
0438 unsigned int binn = data.m_bin_number;
0439 data.m_bin_Sw = bins;
0440
0441 data.m_bin_entries.resize(binn,0);
0442 {std::vector<double> empty;
0443 empty.resize(1,0);
0444 data.m_bin_Sxw.resize(binn,empty);
0445 data.m_bin_Sx2w.resize(binn,empty);}
0446
0447 data.m_all_entries = static_cast<unsigned int>(fEntries);
0448 data.m_in_range_entries = 0;
0449 data.m_in_range_Sw = fSw;
0450 data.m_in_range_Sw2 = fSw2;
0451 data.m_in_range_Sxw.resize(1,0);
0452 data.m_in_range_Sx2w.resize(1,0);
0453 data.m_in_range_Sxw[0] = fSxw;
0454 data.m_in_range_Sx2w[0] = fSx2w;
0455
0456 histo::h1d* h = new histo::h1d("",10,0,1);
0457 h->copy_from_data(data);
0458 return h;
0459 }
0460
0461 inline histo::h2d* TH2F_stream(buffer& a_buffer){
0462 unsigned int _s,_c;
0463 short v;
0464 if(!a_buffer.read_version(v,_s,_c)) return 0;
0465
0466 // Version 3 streaming (ROOT/v3-00-6).
0467
0468 // Now we have to reconstruct a valid Histogram from a_buffer :
0469 hd_data data;
0470
0471 data.m_dimension = 2;
0472 //data.m_coords.resize(data.m_dimension,0);
0473 //data.m_ints.resize(data.m_dimension,0);
0474 data.m_axes.resize(2);
0475 data.m_in_range_plane_Sxyw.resize(1,0);
0476
0477 double fEntries; //in range + outflow.
0478 double fSw; //in range.
0479 double fSw2; //in range.
0480 double fSxw; //in range.
0481 double fSx2w; //in range.
0482 double fSyw; //in range.
0483 double fSy2w; //in range.
0484 if(!TH_read_2D(a_buffer,data,fEntries,fSw,fSw2,fSxw,fSx2w,fSyw,fSy2w)) return 0;
0485 // the upper set :
0486 //data.m_title
0487 //data.m_bin_number
0488 //data.m_axes
0489 //data.m_bin_Sw2
0490
0491 std::vector<float> bins; //fArray TArrayF
0492 if(!Array_stream<float>(a_buffer,bins)) return 0;
0493 if(!a_buffer.check_byte_count(_s,_c,"TH2F")) return 0;
0494
0495 unsigned int binn = data.m_bin_number;
0496 data.m_bin_Sw.resize(binn,0);
0497 {for(unsigned int index=0;index<binn;index++){
0498 data.m_bin_Sw[index] = double(bins[index]);
0499 }}
0500
0501 data.m_bin_entries.resize(binn,0);
0502 {std::vector<double> empty;
0503 empty.resize(2,0);
0504 data.m_bin_Sxw.resize(binn,empty);
0505 data.m_bin_Sx2w.resize(binn,empty);}
0506
0507 data.m_all_entries = static_cast<unsigned int>(fEntries);
0508 data.m_in_range_entries = 0;
0509 data.m_in_range_Sw = fSw;
0510 data.m_in_range_Sw2 = fSw2;
0511 data.m_in_range_Sxw.resize(2,0);
0512 data.m_in_range_Sx2w.resize(2,0);
0513 data.m_in_range_Sxw[0] = fSxw;
0514 data.m_in_range_Sx2w[0] = fSx2w;
0515 data.m_in_range_Sxw[1] = fSyw;
0516 data.m_in_range_Sx2w[1] = fSy2w;
0517
0518 histo::h2d* h = new histo::h2d("",10,0,1,10,0,1);
0519 h->copy_from_data(data);
0520 return h;
0521 }
0522
0523 inline histo::h2d* TH2D_stream(buffer& a_buffer){
0524 unsigned int _s,_c;
0525 short v;
0526 if(!a_buffer.read_version(v,_s,_c)) return 0;
0527
0528 // Version 3 streaming (ROOT/v3-00-6).
0529
0530 // Now we have to reconstruct a valid Histogram from a_buffer :
0531 hd_data data;
0532
0533 data.m_dimension = 2;
0534 //data.m_coords.resize(data.m_dimension,0);
0535 //data.m_ints.resize(data.m_dimension,0);
0536 data.m_axes.resize(2);
0537 data.m_in_range_plane_Sxyw.resize(1,0);
0538
0539 double fEntries; //in range + outflow.
0540 double fSw; //in range.
0541 double fSw2; //in range.
0542 double fSxw; //in range.
0543 double fSx2w; //in range.
0544 double fSyw; //in range.
0545 double fSy2w; //in range.
0546 if(!TH_read_2D(a_buffer,data,fEntries,fSw,fSw2,fSxw,fSx2w,fSyw,fSy2w)) return 0;
0547 // the upper set :
0548 //data.m_title
0549 //data.m_bin_number
0550 //data.m_axes
0551 //data.m_bin_Sw2
0552
0553 std::vector<double> bins; //fArray TArrayD
0554 if(!Array_stream<double>(a_buffer,bins)) return 0;
0555 if(!a_buffer.check_byte_count(_s,_c,"TH2D")) return 0;
0556
0557 unsigned int binn = data.m_bin_number;
0558 data.m_bin_Sw = bins;
0559
0560 data.m_bin_entries.resize(binn,0);
0561 {std::vector<double> empty;
0562 empty.resize(2,0);
0563 data.m_bin_Sxw.resize(binn,empty);
0564 data.m_bin_Sx2w.resize(binn,empty);}
0565
0566 data.m_all_entries = static_cast<unsigned int>(fEntries);
0567 data.m_in_range_entries = 0;
0568 data.m_in_range_Sw = fSw;
0569 data.m_in_range_Sw2 = fSw2;
0570 data.m_in_range_Sxw.resize(2,0);
0571 data.m_in_range_Sx2w.resize(2,0);
0572 data.m_in_range_Sxw[0] = fSxw;
0573 data.m_in_range_Sx2w[0] = fSx2w;
0574 data.m_in_range_Sxw[1] = fSyw;
0575 data.m_in_range_Sx2w[1] = fSy2w;
0576
0577 histo::h2d* h = new histo::h2d("",10,0,1,10,0,1);
0578 h->copy_from_data(data);
0579 return h;
0580 }
0581
0582 inline histo::h3d* TH3D_stream(buffer& a_buffer){
0583 unsigned int _s,_c;
0584 short v;
0585 if(!a_buffer.read_version(v,_s,_c)) return 0;
0586
0587 // Now we have to reconstruct a valid Histogram from a_buffer :
0588 hd_data data;
0589
0590 data.m_dimension = 3;
0591 //data.m_coords.resize(data.m_dimension,0);
0592 //data.m_ints.resize(data.m_dimension,0);
0593 data.m_axes.resize(3);
0594 data.m_in_range_plane_Sxyw.resize(3,0);
0595
0596 double fEntries; //in range + outflow.
0597 double fSw; //in range.
0598 double fSw2; //in range.
0599 double fSxw; //in range.
0600 double fSx2w; //in range.
0601 double fSyw; //in range.
0602 double fSy2w; //in range.
0603 double fSzw; //in range.
0604 double fSz2w; //in range.
0605 if(!TH_read_3D(a_buffer,data,fEntries,fSw,fSw2,fSxw,fSx2w,fSyw,fSy2w,fSzw,fSz2w)) return 0;
0606 // the upper set :
0607 //data.m_title
0608 //data.m_bin_number
0609 //data.m_axes
0610 //data.m_bin_Sw2
0611
0612 std::vector<double> bins; //fArray TArrayD
0613 if(!Array_stream<double>(a_buffer,bins)) return 0;
0614 if(!a_buffer.check_byte_count(_s,_c,"TH3D")) return 0;
0615
0616 unsigned int binn = data.m_bin_number;
0617 data.m_bin_Sw = bins;
0618
0619 data.m_bin_entries.resize(binn,0);
0620 {std::vector<double> empty;
0621 empty.resize(3,0);
0622 data.m_bin_Sxw.resize(binn,empty);
0623 data.m_bin_Sx2w.resize(binn,empty);}
0624
0625 data.m_all_entries = static_cast<unsigned int>(fEntries);
0626 data.m_in_range_entries = 0;
0627 data.m_in_range_Sw = fSw;
0628 data.m_in_range_Sw2 = fSw2;
0629 data.m_in_range_Sxw.resize(3,0);
0630 data.m_in_range_Sx2w.resize(3,0);
0631 data.m_in_range_Sxw[0] = fSxw;
0632 data.m_in_range_Sx2w[0] = fSx2w;
0633 data.m_in_range_Sxw[1] = fSyw;
0634 data.m_in_range_Sx2w[1] = fSy2w;
0635 data.m_in_range_Sxw[2] = fSzw;
0636 data.m_in_range_Sx2w[2] = fSz2w;
0637
0638 histo::h3d* h = new histo::h3d("",10,0,1,10,0,1,10,0,1);
0639 h->copy_from_data(data);
0640 return h;
0641 }
0642
0643 inline histo::p1d* TProfile_stream(buffer& a_buffer){
0644 unsigned int _s,_c;
0645 short v;
0646 if(!a_buffer.read_version(v,_s,_c)) return 0;
0647
0648 // Version 3 streaming (ROOT/v3-00-6).
0649
0650 //WARNING : the mapping histo::p1d / TProfile is not obvious.
0651 //p1d::m_bin_Svw <---> TProfile::fArray
0652 //p1d::m_bin_Sv2w <---> TProfile::fSumw2
0653 //p1d::m_bin_Sw <---> TProfile::fBinEntries
0654
0655 histo::h1d* h = TH1D_stream(a_buffer);
0656 if(!h) return 0;
0657
0658 //NOTE : histo.m_bin_Sw <---> TH1D::TArrayD::fArray
0659
0660 pd_data data(h->dac());
0661 delete h;
0662
0663 std::vector<double> bins; //fBinEntries TArrayD
0664 if(!Array_stream<double>(a_buffer,bins)) return 0;
0665 int errorMode;
0666 if(!a_buffer.read(errorMode)) return 0;
0667 double ymin;
0668 if(!a_buffer.read(ymin)) return 0;
0669 double ymax;
0670 if(!a_buffer.read(ymax)) return 0;
0671
0672 if(v>=4) {
0673 double sumwy;
0674 if(!a_buffer.read(sumwy)) return 0;
0675 double sumwy2;
0676 if(!a_buffer.read(sumwy2)) return 0;
0677 }
0678 if(v>=5) {
0679 std::vector<double> bins_sumw2; //fBinSumw2 TArrayD
0680 if(!Array_stream<double>(a_buffer,bins_sumw2)) return 0;
0681 }
0682
0683 if(!a_buffer.check_byte_count(_s,_c,"TProfile")) return 0;
0684
0685 data.m_is_profile = true;
0686 data.m_cut_v = true;
0687 data.m_min_v = ymin;
0688 data.m_max_v = ymax;
0689
0690 unsigned int binn = data.m_bin_number;
0691 data.m_bin_Svw.resize(binn);
0692 data.m_bin_Sv2w.resize(binn);
0693
0694 for(unsigned int index=0;index<binn;index++){
0695 double svw = data.m_bin_Sw[index];
0696 double sv2w = data.m_bin_Sw2[index];
0697 double sw = bins[index];
0698 //data.m_bin_entries[index] = (int)sw; //FIXME : ok for w = 1 only !
0699 data.m_bin_Sw[index] = (double)sw;
0700 //FIXME : data.m_bin_Sxw
0701 //FIXME : data.m_bin_Sx2w
0702 data.m_bin_Svw[index] = svw;
0703 data.m_bin_Sv2w[index] = sv2w;
0704 }
0705
0706 histo::p1d* p = new histo::p1d("",10,0,1);
0707 p->copy_from_data(data);
0708 // We have now a valid histo::p1d.
0709 return p;
0710 }
0711
0712 inline histo::p2d* TProfile2D_stream(buffer& a_buffer){
0713 unsigned int _s,_c;
0714 short v;
0715 if(!a_buffer.read_version(v,_s,_c)) return 0;
0716
0717 // Version 3 streaming (ROOT/v3-00-6).
0718
0719 //WARNING : the mapping histo::p1d / TProfile is not obvious.
0720 //p1d::m_bin_Svw <---> TProfile::fArray
0721 //p1d::m_bin_Sv2w <---> TProfile::fSumw2
0722 //p1d::m_bin_Sw <---> TProfile::fBinEntries
0723
0724 histo::h2d* h = TH2D_stream(a_buffer);
0725 if(!h) return 0;
0726
0727 //NOTE : histo.m_bin_Sw <---> TH2D::TArrayD::fArray
0728
0729 pd_data data(h->dac());
0730 delete h;
0731
0732 std::vector<double> bins; //fBinEntries TArrayD
0733 if(!Array_stream<double>(a_buffer,bins)) return 0;
0734 int errorMode;
0735 if(!a_buffer.read(errorMode)) return 0;
0736 double zmin;
0737 if(!a_buffer.read(zmin)) return 0;
0738 double zmax;
0739 if(!a_buffer.read(zmax)) return 0;
0740 if(v>=5) {
0741 double sumwz;
0742 if(!a_buffer.read(sumwz)) return 0;
0743 double sumwz2;
0744 if(!a_buffer.read(sumwz2)) return 0;
0745 }
0746 if(v>=7) {
0747 std::vector<double> bins_sumw2; //fBinSumw2 TArrayD
0748 if(!Array_stream<double>(a_buffer,bins_sumw2)) return 0;
0749 }
0750 if(!a_buffer.check_byte_count(_s,_c,"TProfile2D")) return 0;
0751
0752 data.m_is_profile = true;
0753 data.m_cut_v = true;
0754 data.m_min_v = zmin;
0755 data.m_max_v = zmax;
0756
0757 unsigned int binn = data.m_bin_number;
0758 data.m_bin_Svw.resize(binn);
0759 data.m_bin_Sv2w.resize(binn);
0760
0761 for(unsigned int index=0;index<binn;index++){
0762 double svw = data.m_bin_Sw[index];
0763 double sv2w = data.m_bin_Sw2[index];
0764 double sw = bins[index];
0765 //data.m_bin_entries[index] = (int)sw; //FIXME : ok for w = 1 only !
0766 data.m_bin_Sw[index] = (double)sw;
0767 //FIXME : data.m_bin_Sxw
0768 //FIXME : data.m_bin_Sx2w
0769 data.m_bin_Svw[index] = svw;
0770 data.m_bin_Sv2w[index] = sv2w;
0771 }
0772
0773 histo::p2d* p = new histo::p2d("",10,0,1,10,0,1);
0774 p->copy_from_data(data);
0775 return p;
0776 }
0777
0778 class TDirectory : public directory {
0779 //public:
0780 // static const std::string& store_class() {return TDirectory_cls();}
0781 public:
0782 TDirectory(ifile& a_file):directory(a_file){}
0783 virtual ~TDirectory(){}
0784 protected:
0785 TDirectory(const TDirectory& a_from):directory(a_from){}
0786 TDirectory& operator=(const TDirectory&){return *this;}
0787 public:
0788 bool stream(buffer& a_buffer){
0789 initialize();
0790 short version;
0791 if(!a_buffer.read_version(version)) return false;
0792 unsigned int _date;
0793 if(!a_buffer.read(_date)) return false;
0794 //m_date_C.setDate(_date);
0795 if(!a_buffer.read(_date)) return false;
0796 //m_date_M.setDate(_date);
0797 if(!a_buffer.read(m_nbytes_keys)) return false;
0798 if(!a_buffer.read(m_nbytes_name)) return false;
0799 if((uint32)version>big_file_version_tag()) {
0800 if(!a_buffer.read(m_seek_directory)) return false;
0801 if(!a_buffer.read(m_seek_parent)) return false;
0802 if(!a_buffer.read(m_seek_keys)) return false;
0803 } else {
0804 {seek32 i;
0805 if(!a_buffer.read(i)) return false;
0806 m_seek_directory = i;}
0807
0808 {seek32 i;
0809 if(!a_buffer.read(i)) return false;
0810 m_seek_parent = i;}
0811
0812 {seek32 i;
0813 if(!a_buffer.read(i)) return false;
0814 m_seek_keys = i;}
0815 }
0816 //short v = version%big_file_version_tag();
0817
0818 if (m_seek_keys) {
0819 uint32 n;
0820 if(!read_keys(n)) {
0821 a_buffer.out() << "tools::rroot::TDirectory::stream :"
0822 << " cannot read keys."
0823 << std::endl;
0824 return false;
0825 }
0826 }
0827
0828 return true;
0829 }
0830 protected:
0831 void initialize(){
0832 // Initialise directory to defaults :
0833 // If directory is created via default ctor (when dir is read from file)
0834 // don't add it here to the directory since its name is not yet known.
0835 // It will be added to the directory in TKey::ReadObj().
0836 m_date_C = 0;//m_date_C.set();
0837 m_date_M = 0;//m_date_M.set();
0838 m_nbytes_keys = 0;
0839 m_seek_directory = 0;
0840 m_seek_parent = 0;
0841 m_seek_keys = 0;
0842 }
0843 };
0844
0845
0846 inline void dump(std::ostream& a_out,
0847 ifile& a_file,
0848 const std::vector<key*>& a_keys,
0849 bool a_recursive,
0850 unsigned int a_spaces = 0) {
0851
0852 // dump non directory objects :
0853 {std::vector<key*>::const_iterator it;
0854 for(it=a_keys.begin();it!=a_keys.end();++it) {
0855 key& k = *(*it);
0856 if(k.object_class()==TDirectory_cls()) continue;
0857 {for(unsigned int index=0;index<a_spaces;index++) a_out << " ";}
0858 k.dump(a_out);
0859 }}
0860
0861 // dump directories :
0862 {std::vector<key*>::const_iterator it;
0863 for(it=a_keys.begin();it!=a_keys.end();++it) {
0864 key& k = *(*it);
0865 if(k.object_class()!=TDirectory_cls()) continue;
0866
0867 std::string label = k.object_name();
0868 {for(unsigned int index=0;index<a_spaces;index++) a_out << " ";}
0869 a_out << "directory : " << label << std::endl;
0870
0871 if(!a_recursive) continue;
0872
0873 uint32 sz;
0874 char* buf = k.get_object_buffer(a_file,sz);
0875 //we don't have ownership of buf.
0876 if(!buf) {
0877 a_out << "tools::rroot::dump :"
0878 << " can't get directory data buffer."
0879 << std::endl;
0880 } else {
0881 buffer b(a_out,a_file.byte_swap(),sz,buf,k.key_length(),false);
0882 TDirectory tdir(a_file);
0883 if(!tdir.stream(b)) {
0884 a_out << "tools::rroot::dump :"
0885 << " can't stream TDirectory."
0886 << std::endl;
0887 } else {
0888 const std::vector<key*>& keys = tdir.keys();
0889 dump(a_out,a_file,keys,a_recursive,a_spaces+1);
0890 }
0891 }
0892 }}
0893 }
0894
0895 /*
0896 inline bool read_sinfos(ifile& a_file){
0897 key& k = a_file.sinfos_key();
0898 std::ostream& out = k.out();
0899 if(k.object_class()!=TList_cls()) {
0900 out << "tools::rroot::read_sinfos :"
0901 << " key not a TList."
0902 << std::endl;
0903 return false;
0904 }
0905 unsigned int sz;
0906 char* buf = k.get_object_buffer(a_file,sz); //we don't have ownership of buf.
0907 if(!buf) {
0908 out << "tools::rroot::read_sinfos :"
0909 << " can't get data buffer of " << k.object_name() << "."
0910 << std::endl;
0911 return false;
0912 }
0913 buffer b(out,a_file.byte_swap(),sz,buf,k.key_length(),false);
0914 dummy_fac fac(out);
0915 obj_list infos(fac);
0916 if(!infos.stream(b)) return false;
0917 tools_vforcit(iro*,infos,it) {
0918 streamer_info* info = safe_cast<iro,streamer_info>(*(*it));
0919 if(!info) return false;
0920 info->out(out);
0921 }
0922 return true;
0923 }
0924 */
0925
0926 }}
0927
0928 #endif