ROOT  6.06/09
Reference Guide
testIO.cxx
Go to the documentation of this file.
1 //
2 // Cint macro to test I/O of SMatrix classes and compare with a TMatrix
3 // A ROOT tree is written and read in both using either a SMatrix or
4 /// a TMatrixD.
5 //
6 // To execute the macro type in:
7 //
8 // root[0]: .x smatrixIO.C
9 
10 #include "Math/SMatrix.h"
11 #include "TMatrixD.h"
12 #include "TMatrixDSym.h"
13 #include "TRandom3.h"
14 #include "TFile.h"
15 #include "TTree.h"
16 #include "TStopwatch.h"
17 #include "TSystem.h"
18 
19 #include <iostream>
20 
21 #ifdef USE_REFLEX
22 #include "Cintex/Cintex.h"
23 #include "Reflex/Reflex.h"
24 #endif
25 
26 #include "Track.h"
27 
30 
31 
32 //#define DEBUG
33 
34 // if I use double32 or not depends on the dictionary
35 ////#define USE_DOUBLE32
36 #ifdef USE_DOUBLE32
39 const std::string sname = "ROOT::Math::SMatrix<Double32_t,5,5,ROOT::Math::MatRepStd<Double32_t,5,5> >";
40 const std::string sname_sym = "ROOT::Math::SMatrix<Double32_t,5,5,ROOT::Math::MatRepSym<Double32_t,5> >";
41 double tol = 1.E-6;
42 #else
45 const std::string sname = "ROOT::Math::SMatrix<double,5,5,ROOT::Math::MatRepStd<double,5,5> >";
46 const std::string sname_sym = "ROOT::Math::SMatrix<double,5,5,ROOT::Math::MatRepSym<double,5> >";
47 double tol = 1.E-16;
48 #endif
49 double tol32 = 1.E-6;
50 
51 #ifdef USE_REFLEX
52  std::string sfile1 = "smatrix_rflx.root";
53  std::string sfile2 = "smatrix.root";
54 
55  std::string symfile1 = "smatrixsym_rflx.root";
56  std::string symfile2 = "smatrixsym.root";
57 #else
58  std::string sfile1 = "smatrix.root";
59  std::string sfile2 = "smatrix_rflx.root";
60 
61  std::string symfile1 = "smatrixsym.root";
62  std::string symfile2 = "smatrixsym_rflx.root";
63 #endif
64 
65 
66 
67 //using namespace ROOT::Math;
68 
69 
70 template<class Matrix>
71 void FillMatrix(Matrix & m) {
72  for (int i = 0; i < 5; ++i) {
73  for (int j = 0; j < 5; ++j) {
74  m(i,j) = R.Rndm() + 1;
75  }
76  }
77 }
78 
79 void FillCArray(double * m) {
80  for (int i = 0; i < 5; ++i) {
81  for (int j = 0; j < 5; ++j) {
82  m[i*5+j] = R.Rndm() + 1;
83  }
84  }
85 }
86 
87 template<class Matrix>
88 void FillMatrixSym(Matrix & m) {
89  for (int i = 0; i < 5; ++i) {
90  for (int j = 0; j < 5; ++j) {
91  if (j>=i) m(i,j) = R.Rndm() + 1;
92  else m(i,j) = m(j,i);
93  }
94  }
95 }
96 
97 template<class R>
99  double sum = 0;
100  for (int i = 0; i < 5*5; ++i) {
101  sum += m.apply(i);
102  }
103  return sum;
104 }
105 
106 double SumCArray(double * m) {
107  double sum = 0;
108  for (int i = 0; i < 5*5; ++i) {
109  sum += m[i];
110  }
111  return sum;
112 }
113 
114 template<class TM>
115 double SumTMatrix(TM & m) {
116  double sum = 0;
117  const double * d = m.GetMatrixArray();
118  for (int i = 0; i < 5*5; ++i) {
119  sum += d[i];
120  }
121  return sum;
122 }
123 
124 
125 
126 void initMatrix(int n) {
127 
128  // using namespace ROOT::Math;
129 
130  timer.Start();
131  SMatrix5 s;
132  R.SetSeed(1); // use same seed
133  for (int i = 0; i < n; ++i) {
134  FillMatrix(s);
135  }
136  timer.Stop();
137  std::cout << " Time to fill SMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
138 
139  timer.Start();
140  SMatrixSym5 ss;
141  R.SetSeed(1); // use same seed
142  for (int i = 0; i < n; ++i) {
143  FillMatrixSym(ss);
144  }
145  timer.Stop();
146  std::cout << " Time to fill SMatrix Sym " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
147 
148  timer.Start();
149  TMatrixD t(5,5);
150  R.SetSeed(1); // use same seed
151  for (int i = 0; i < n; ++i) {
152  FillMatrix(t);
153  }
154  timer.Stop();
155  std::cout << " Time to fill TMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
156 
157  timer.Start();
158  TMatrixDSym ts(5);
159  R.SetSeed(1); // use same seed
160  for (int i = 0; i < n; ++i) {
161  FillMatrixSym(ts);
162  }
163  timer.Stop();
164  std::cout << " Time to fill TMatrix Sym " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
165 
166 }
167 
168 
169 
170 double writeCArray(int n) {
171 
172  std::cout << "\n";
173  std::cout << "**************************************************\n";
174  std::cout << " Test writing a C Array ........\n";
175  std::cout << "**************************************************\n";
176 
177  TFile f1("cmatrix.root","RECREATE");
178 
179 
180  // create tree
181  TTree t1("t1","Tree with C Array");
182 
183  double m1[25];
184  t1.Branch("C Array branch",m1,"m1[25]/D");
185 
186  timer.Start();
187  double etot = 0;
188  R.SetSeed(1); // use same seed
189  for (int i = 0; i < n; ++i) {
190  FillCArray(m1);
191  etot += SumCArray(m1);
192  t1.Fill();
193  }
194 
195  f1.Write();
196  timer.Stop();
197 
198  std::cout << " Time to Write CArray " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
199 
200 #ifdef DEBUG
201  t1.Print();
202  int pr = std::cout.precision(18);
203  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
204  std::cout.precision(pr);
205 #endif
206 
207  return etot/double(n);
208 }
209 
210 double writeSMatrix(int n, const std::string & file) {
211 
212  std::cout << "\n";
213  std::cout << "**************************************************\n";
214  std::cout << " Test writing SMatrix ........\n";
215  std::cout << "**************************************************\n";
216 
217  TFile f1(file.c_str(),"RECREATE");
218 
219  // create tree
220  TTree t1("t1","Tree with SMatrix");
221 
222  SMatrix5 * m1 = new SMatrix5;
223  //t1.Branch("SMatrix branch",&m1,16000,0);
224  // need to pass type name explicitly to distinguish double/double32
225  t1.Branch("SMatrix branch",sname.c_str(),&m1,16000,0);
226 
227  timer.Start();
228  double etot = 0;
229  R.SetSeed(1); // use same seed
230  for (int i = 0; i < n; ++i) {
231  FillMatrix(*m1);
232  etot += SumSMatrix(*m1);
233  t1.Fill();
234  }
235 
236  f1.Write();
237  timer.Stop();
238 
239  std::cout << " Time to Write SMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
240 #ifdef DEBUG
241  t1.Print();
242  int pr = std::cout.precision(18);
243  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
244  std::cout.precision(pr);
245 #endif
246 
247  return etot/double(n);
248 }
249 
250 
251 
252 double writeSMatrixSym(int n, const std::string & file) {
253 
254  std::cout << "\n";
255  std::cout << "**************************************************\n";
256  std::cout << " Test writing SMatrix Sym.....\n";
257  std::cout << "**************************************************\n";
258 
259  TFile f1(file.c_str(),"RECREATE");
260 
261  // create tree
262  TTree t1("t1","Tree with SMatrix");
263 
264  SMatrixSym5 * m1 = new SMatrixSym5;
265  //t1.Branch("SMatrixSym branch",&m1,16000,0);
266  t1.Branch("SMatrixSym branch",sname_sym.c_str(),&m1,16000,0);
267 
268  timer.Start();
269  double etot = 0;
270  R.SetSeed(1); // use same seed
271  for (int i = 0; i < n; ++i) {
272  FillMatrixSym(*m1);
273  etot += SumSMatrix(*m1);
274  t1.Fill();
275  }
276 
277  f1.Write();
278  timer.Stop();
279 
280 
281  std::cout << " Time to Write SMatrix Sym " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
282 #ifdef DEBUG
283  t1.Print();
284  int pr = std::cout.precision(18);
285  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
286  std::cout.precision(pr);
287 #endif
288 
289  return etot/double(n);
290 }
291 
292 
293 
294 
295 
296 double writeTMatrix(int n) {
297 
298  // create tree with TMatrix
299  std::cout << "\n";
300  std::cout << "**************************************************\n";
301  std::cout << " Test writing TMatrix........\n";
302  std::cout << "**************************************************\n";
303 
304 
305  TFile f2("tmatrix.root","RECREATE");
306  TTree t2("t2","Tree with TMatrix");
307 
308  TMatrixD * m2 = new TMatrixD(5,5);
309  TMatrixD::Class()->IgnoreTObjectStreamer();
310 
311  //t2.Branch("TMatrix branch","TMatrixD",&m2,16000,2);
312  t2.Branch("TMatrix branch",&m2,16000,2);
313 
314  double etot = 0;
315  timer.Start();
316  R.SetSeed(1); // use same seed
317  for (int i = 0; i < n; ++i) {
318  FillMatrix(*m2);
319  etot += SumTMatrix(*m2);
320  t2.Fill();
321  }
322 
323  f2.Write();
324  timer.Stop();
325 
326  std::cout << " Time to Write TMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
327 #ifdef DEBUG
328  t2.Print();
329  int pr = std::cout.precision(18);
330  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
331  std::cout.precision(pr);
332  std::cout << "\n\n\n";
333 #endif
334 
335  return etot/double(n);
336 
337 }
338 
339 double writeTMatrixSym(int n) {
340 
341  // create tree with TMatrix
342  std::cout << "\n";
343  std::cout << "**************************************************\n";
344  std::cout << " Test writing TMatrix.Sym....\n";
345  std::cout << "**************************************************\n";
346 
347 
348  TFile f2("tmatrixsym.root","RECREATE");
349  TTree t2("t2","Tree with TMatrix");
350 
351  TMatrixDSym * m2 = new TMatrixDSym(5);
352  TMatrixDSym::Class()->IgnoreTObjectStreamer();
353 
354  //t2.Branch("TMatrix branch","TMatrixDSym",&m2,16000,0);
355  t2.Branch("TMatrixSym branch",&m2,16000,0);
356 
357  double etot = 0;
358  timer.Start();
359  R.SetSeed(1); // use same seed
360  for (int i = 0; i < n; ++i) {
361  FillMatrixSym(*m2);
362  etot += SumTMatrix(*m2);
363  t2.Fill();
364  }
365 
366  f2.Write();
367  timer.Stop();
368 
369  std::cout << " Time to Write TMatrix Sym " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
370 #ifdef DEBUG
371  t2.Print();
372  int pr = std::cout.precision(18);
373  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
374  std::cout.precision(pr);
375  std::cout << "\n\n\n";
376 #endif
377 
378  return etot/double(n);
379 
380 }
381 
382 
383 
384 
385 double readTMatrix() {
386 
387 
388  // read tree with old TMatrix
389 
390  std::cout << "\n\n";
391  std::cout << "**************************************************\n";
392  std::cout << " Test reading TMatrix........\n";
393  std::cout << "**************************************************\n";
394 
395 
396  TFile f2("tmatrix.root");
397  if (f2.IsZombie() ) {
398  std::cerr << "Error opening the ROOT file" << std::endl;
399  return -1;
400  }
401  TTree *t2 = (TTree*)f2.Get("t2");
402 
403 
404  TMatrixD * v2 = 0;
405  t2->SetBranchAddress("TMatrix branch",&v2);
406 
407  timer.Start();
408  int n = (int) t2->GetEntries();
409  double etot = 0;
410  for (int i = 0; i < n; ++i) {
411  t2->GetEntry(i);
412  etot += SumTMatrix(*v2);
413  }
414 
415  timer.Stop();
416  std::cout << " Time for TMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
417  double val = etot/double(n);
418 #ifdef DEBUG
419  std::cout << " Tree Entries " << n << std::endl;
420  int pr = std::cout.precision(18);
421  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
422  std::cout.precision(pr);
423 #endif
424  return val;
425 }
426 
427 
428 double readTMatrixSym() {
429 
430 
431  // read tree with old TMatrix
432 
433  std::cout << "\n\n";
434  std::cout << "**************************************************\n";
435  std::cout << " Test reading TMatrix.Sym....\n";
436  std::cout << "**************************************************\n";
437 
438 
439  TFile f2("tmatrixsym.root");
440  if (f2.IsZombie() ) {
441  std::cerr << "Error opening the ROOT file" << std::endl;
442  return -1;
443  }
444 
445 
446  TTree *t2 = (TTree*)f2.Get("t2");
447 
448 
449  TMatrixDSym * v2 = 0;
450  t2->SetBranchAddress("TMatrixSym branch",&v2);
451 
452  timer.Start();
453  int n = (int) t2->GetEntries();
454  double etot = 0;
455  for (int i = 0; i < n; ++i) {
456  t2->GetEntry(i);
457  etot += SumTMatrix(*v2);
458  }
459 
460  timer.Stop();
461  std::cout << " Time for TMatrix Sym" << timer.RealTime() << " " << timer.CpuTime() << std::endl;
462  double val = etot/double(n);
463 #ifdef DEBUG
464  std::cout << " Tree Entries " << n << std::endl;
465  int pr = std::cout.precision(18);
466  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
467  std::cout.precision(pr);
468 #endif
469 
470  return val;
471 }
472 
473 
474 double readSMatrix(const std::string & file) {
475 
476 
477  std::cout << "\n";
478  std::cout << "**************************************************\n";
479  std::cout << " Test reading SMatrix........\n";
480  std::cout << "**************************************************\n";
481 
482 
483  TFile f1(file.c_str());
484  if (f1.IsZombie() ) {
485  std::cerr << "Error opening the ROOT file" << file << std::endl;
486  return -1;
487  }
488 
489  // create tree
490  TTree *t1 = (TTree*)f1.Get("t1");
491 
492  SMatrix5 *v1 = 0;
493  t1->SetBranchAddress("SMatrix branch",&v1);
494 
495  timer.Start();
496  int n = (int) t1->GetEntries();
497  double etot=0;
498  for (int i = 0; i < n; ++i) {
499  t1->GetEntry(i);
500  etot += SumSMatrix(*v1);
501  }
502 
503 
504  timer.Stop();
505  std::cout << " Time for SMatrix : " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
506 
507 #ifdef DEBUG
508  std::cout << " Tree Entries " << n << std::endl;
509  int pr = std::cout.precision(18);
510  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
511  std::cout.precision(pr);
512 #endif
513  std::cout << "\n";
514 
515 
516  return etot/double(n);
517 }
518 
519 
520 double readSMatrixSym(const std::string & file) {
521 
522 
523  std::cout << "\n";
524  std::cout << "**************************************************\n";
525  std::cout << " Test reading SMatrix.Sym....\n";
526  std::cout << "**************************************************\n";
527 
528 
529  TFile f1(file.c_str());
530  if (f1.IsZombie() ) {
531  std::cerr << "Error opening the ROOT file" << file << std::endl;
532  return -1;
533  }
534 
535 
536  // create tree
537  TTree *t1 = (TTree*)f1.Get("t1");
538 
539  SMatrixSym5 *v1 = 0;
540  t1->SetBranchAddress("SMatrixSym branch",&v1);
541 
542  timer.Start();
543  int n = (int) t1->GetEntries();
544  double etot=0;
545  for (int i = 0; i < n; ++i) {
546  t1->GetEntry(i);
547  etot += SumSMatrix(*v1);
548  }
549 
550 
551  timer.Stop();
552  std::cout << " Time for SMatrix Sym : " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
553 
554 #ifdef DEBUG
555  std::cout << " Tree Entries " << n << std::endl;
556  int pr = std::cout.precision(18);
557  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
558  std::cout.precision(pr);
559 #endif
560  std::cout << "\n";
561 
562  return etot/double(n);
563 }
564 
565 
566 double writeTrackD(int n) {
567 
568  std::cout << "\n";
569  std::cout << "**************************************************\n";
570  std::cout << " Test writing Track class........\n";
571  std::cout << "**************************************************\n";
572 
573  TFile f1("track.root","RECREATE");
574 
575  // create tree
576  TTree t1("t1","Tree with Track based on SMatrix");
577 
578  TrackD * m1 = new TrackD();
579 
580  t1.Branch("Track branch",&m1,16000,0);
581 
582  timer.Start();
583  double etot = 0;
584  R.SetSeed(1); // use same seed
585  for (int i = 0; i < n; ++i) {
586  FillMatrix(m1->CovMatrix());
587  etot += SumSMatrix(m1->CovMatrix() );
588  t1.Fill();
589  }
590 
591  f1.Write();
592  timer.Stop();
593 
594  std::cout << " Time to Write TrackD of SMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
595 
596 #ifdef DEBUG
597  t1.Print();
598  int pr = std::cout.precision(18);
599  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
600  std::cout.precision(pr);
601 #endif
602 
603  return etot/double(n);
604 }
605 
606 
607 double writeTrackD32(int n) {
608 
609  std::cout << "\n";
610  std::cout << "**************************************************\n";
611  std::cout << " Test writing TrackD32 class........\n";
612  std::cout << "**************************************************\n";
613 
614  TFile f1("track32.root","RECREATE");
615 
616  // create tree
617  TTree t1("t1","Tree with Track based on SMatrix");
618 
619  TrackD32 * m1 = new TrackD32();
620  t1.Branch("Track32 branch",&m1,16000,0);
621 
622  timer.Start();
623  double etot = 0;
624  R.SetSeed(1); // use same seed
625  for (int i = 0; i < n; ++i) {
626  FillMatrix(m1->CovMatrix());
627  etot += SumSMatrix(m1->CovMatrix() );
628  t1.Fill();
629  }
630 
631  f1.Write();
632  timer.Stop();
633 
634  std::cout << " Time to Write TrackD32 of SMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
635 
636 #ifdef DEBUG
637  t1.Print();
638  int pr = std::cout.precision(18);
639  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
640  std::cout.precision(pr);
641 #endif
642 
643  return etot/double(n);
644 }
645 
646 
647 double readTrackD() {
648 
649  std::cout << "\n";
650  std::cout << "**************************************************\n";
651  std::cout << " Test reading Track class........\n";
652  std::cout << "**************************************************\n";
653 
654  TFile f1("track.root");
655  if (f1.IsZombie() ) {
656  std::cerr << "Error opening the ROOT file" << std::endl;
657  return -1;
658  }
659 
660  // create tree
661  TTree *t1 = (TTree*)f1.Get("t1");
662 
663  TrackD *trk = 0;
664  t1->SetBranchAddress("Track branch",&trk);
665 
666  timer.Start();
667  int n = (int) t1->GetEntries();
668  double etot=0;
669  for (int i = 0; i < n; ++i) {
670  t1->GetEntry(i);
671  etot += SumSMatrix(trk->CovMatrix());
672  }
673 
674  timer.Stop();
675 
676  std::cout << " Time to Read TrackD of SMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
677 
678 #ifdef DEBUG
679  std::cout << " Tree Entries " << n << std::endl;
680  int pr = std::cout.precision(18);
681  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
682  std::cout.precision(pr);
683 #endif
684 
685  return etot/double(n);
686 }
687 
688 double readTrackD32() {
689 
690  std::cout << "\n";
691  std::cout << "**************************************************\n";
692  std::cout << " Test reading Track32 class........\n";
693  std::cout << "**************************************************\n";
694 
695  TFile f1("track32.root");
696  if (f1.IsZombie() ) {
697  std::cerr << "Error opening the ROOT file" << std::endl;
698  return -1;
699  }
700 
701  // create tree
702  TTree *t1 = (TTree*)f1.Get("t1");
703 
704  TrackD32 *trk = 0;
705  t1->SetBranchAddress("Track32 branch",&trk);
706 
707  timer.Start();
708  int n = (int) t1->GetEntries();
709  double etot=0;
710  for (int i = 0; i < n; ++i) {
711  t1->GetEntry(i);
712  etot += SumSMatrix(trk->CovMatrix());
713  }
714 
715  timer.Stop();
716 
717  std::cout << " Time to Read TrackD32 of SMatrix " << timer.RealTime() << " " << timer.CpuTime() << std::endl;
718 
719 #ifdef DEBUG
720  std::cout << " Tree Entries " << n << std::endl;
721  int pr = std::cout.precision(18);
722  std::cout << " sum " << n<< " " << etot << " " << etot/double(n) << std::endl;
723  std::cout.precision(pr);
724 #endif
725 
726  return etot/double(n);
727 }
728 
729 
730 //-----------------------------------------------------------------
731 
732 
733 int testWrite(int nEvents, double & w1, double & w2) {
734 
735  int iret = 0;
736  double w0 = writeCArray(nEvents);
737 
738  w1 = writeTMatrix(nEvents);
739  w2 = writeSMatrix(nEvents,sfile1);
740  if ( fabs(w1-w2) > tol) {
741  std::cout << "\nERROR: Differeces SMatrix-TMatrix found when writing" << std::endl;
742  int pr = std::cout.precision(18); std::cout << w1 << " != " << w2 << std::endl; std::cout.precision(pr);
743  iret = 1;
744  }
745  if ( fabs(w1-w0) > tol) {
746  std::cout << "\nERROR: Differeces TMatrix-C Array found when writing" << std::endl;
747  int pr = std::cout.precision(18); std::cout << w1 << " != " << w0 << std::endl; std::cout.precision(pr);
748  iret = 1;
749  }
750 
751  std::cout << "\n\n*************************************************************\n";
752  if (iret == 0 )
753  std::cout << " Writing Test:\t" << "OK";
754  else {
755  std::cout << " Writing Test:\t" << "FAILED";
756  }
757  std::cout << "\n*************************************************************\n\n";
758 
759 
760  return iret;
761 }
762 
763 int testRead(double & r1, double & r2, double & r3) {
764 
765  int iret = 0;
766 
767 
768 
769  r1 = readTMatrix();
770  r2 = readSMatrix(sfile1);
771  if ( fabs(r1-r2) > tol) {
772  std::cout << "\nERROR: Differeces SMatrix-TMatrix found when reading " << std::endl;
773  int pr = std::cout.precision(18); std::cout << r1 << " != " << r2 << std::endl; std::cout.precision(pr);
774  iret = 2;
775  }
776 
777 #ifdef USE_REFLEX
778  std::cout << "try to read file written with CINT using Reflex Dictionaries " << std::endl;
779 #else
780  std::cout << "try to read file written with Reflex using CINT Dictionaries " << std::endl;
781 #endif
782  r3 = readSMatrix(sfile2);
783  if ( r3 != -1. && fabs(r2-r3) > tol) {
784  std::cout << "\nERROR: Differeces Reflex-CINT found when reading SMatrices" << std::endl;
785  int pr = std::cout.precision(18); std::cout << r2 << " != " << r3 << std::endl; std::cout.precision(pr);
786  iret = 3;
787  }
788 
789 
790  return iret;
791 }
792 
793 
794 int testWriteSym(int nEvents, double & w1, double & w2) {
795 
796  int iret = 0;
797 
798 
799 
800  w1 = writeTMatrixSym(nEvents);
801  w2 = writeSMatrixSym(nEvents,symfile1);
802  if ( fabs(w1-w2) > tol) {
803  std::cout << "\nERROR: Differeces found when writing" << std::endl;
804  int pr = std::cout.precision(18); std::cout << w1 << " != " << w2 << std::endl; std::cout.precision(pr);
805  iret = 11;
806  }
807 
808  std::cout << "\n\n*************************************************************\n";
809  if (iret == 0 )
810  std::cout << " Writing Test:\t" << "OK";
811  else {
812  std::cout << " Writing Test:\t" << "FAILED";
813  }
814  std::cout << "\n*************************************************************\n\n";
815 
816  return iret;
817 }
818 
819 int testReadSym(double & r1, double & r2, double & r3) {
820 
821  int iret = 0;
822 
823 
824  r1 = readTMatrixSym();
825  r2 = readSMatrixSym(symfile1);
826  if ( fabs(r1-r2) > tol) {
827  std::cout << "\nERROR: Differeces SMatrixSym-TMAtrixSym found when reading " << std::endl;
828  int pr = std::cout.precision(18); std::cout << r1 << " != " << r2 << std::endl; std::cout.precision(pr);
829  iret = 12;
830  }
831 
832 #ifdef USE_REFLEX
833  std::cout << "try to read file written with CINT using Reflex Dictionaries " << std::endl;
834 #else
835  std::cout << "try to read file written with Reflex using CINT Dictionaries " << std::endl;
836 #endif
837 
838  r3 = readSMatrixSym(symfile2);
839  if ( r3 != -1. && fabs(r2-r3) > tol) {
840  std::cout << "\nERROR: Differeces Reflex-CINT found when reading SMatricesSym" << std::endl;
841  int pr = std::cout.precision(18); std::cout << r2 << " != " << r3 << std::endl; std::cout.precision(pr);
842  iret = 13;
843  }
844 
845 
846  return iret;
847 }
848 int testResult(double w1, double r1, double w2, double r2, double r3) {
849 
850  int iret = 0;
851 
852  if ( fabs(w1-r1) > tol) {
853  std::cout << "\nERROR: Differeces found when reading TMatrices" << std::endl;
854  int pr = std::cout.precision(18); std::cout << w1 << " != " << r1 << std::endl; std::cout.precision(pr);
855  iret = -1;
856  }
857  if ( fabs(w2-r2) > tol) {
858  std::cout << "\nERROR: Differeces found when reading SMatrices" << std::endl;
859  int pr = std::cout.precision(18); std::cout << w2 << " != " << r2 << std::endl; std::cout.precision(pr);
860  iret = -2;
861  }
862  if ( r3 != -1. && fabs(w2-r3) > tol) {
863  std::cout << "\nERROR: Differeces found when reading SMatrices with different Dictionary" << std::endl;
864  int pr = std::cout.precision(18); std::cout << w2 << " != " << r2 << std::endl; std::cout.precision(pr);
865  iret = -3;
866  }
867  return iret;
868 }
869 
870 int testTrack(int nEvents) {
871 
872  int iret = 0;
873 
874  double wt1 = writeTrackD(nEvents);
875 
876 #ifdef USE_REFLEX
877  // for the double32 need ROOT Cint
878  gSystem->Load("libSmatrix");
879 #endif
880 
881  double wt2 = writeTrackD32(nEvents);
882 
883  if ( fabs(wt2-wt1) > tol) {
884  std::cout << "\nERROR: Differeces found when writing Track" << std::endl;
885  int pr = std::cout.precision(18); std::cout << wt2 << " != " << wt1 << std::endl; std::cout.precision(pr);
886  iret = 13;
887  }
888 
889  double rt1 = readTrackD();
890  if ( fabs(rt1-wt1) > tol) {
891  std::cout << "\nERROR: Differeces found when reading Track" << std::endl;
892  int pr = std::cout.precision(18); std::cout << rt1 << " != " << wt1 << std::endl; std::cout.precision(pr);
893  iret = 13;
894  }
895 
896  double rt2 = readTrackD32();
897  if ( fabs(rt2-wt2) > tol32) {
898  std::cout << "\nERROR: Differeces found when reading Track 32" << std::endl;
899  int pr = std::cout.precision(18); std::cout << rt2 << " != " << wt2 << std::endl; std::cout.precision(pr);
900  iret = 13;
901  }
902 
903  return iret;
904 }
905 
906 
907 int testIO() {
908 
909 
910  int iret = 0;
911 
912 
913 #ifdef USE_REFLEX
914 
915 
916  gSystem->Load("libReflex");
917  gSystem->Load("libCintex");
918  ROOT::Cintex::Cintex::SetDebug(1);
919  ROOT::Cintex::Cintex::Enable();
920 
921  std::cout << "Use Reflex dictionary " << std::endl;
922 
923 #ifdef USE_REFLEX_SMATRIX
924  iret |= gSystem->Load("libSmatrixRflx");
925 #endif
926  iret |= gSystem->Load("libSmatrix");
927 
928 
929 #else
930 
931  iret |= gSystem->Load("libSmatrix");
932 
933 #endif
934 
935  iret |= gSystem->Load("libMatrix");
936 
937 
938  int nEvents = 10000;
939 
940  initMatrix(nEvents);
941 
942  double w1, w2 = 0;
943  iret |= testWrite(nEvents,w1,w2);
944 
945 
946 
947  double r1, r2, r3 = 0;
948  int iret2 = 0;
949  iret2 |= testRead(r1,r2,r3);
950  iret2 |= testResult(w1,r1,w2,r2,r3);
951  std::cout << "\n\n*************************************************************\n";
952  if (iret2 == 0 )
953  std::cout << " Reading Test:\t" << "OK";
954  else {
955  std::cout << " Reading Test:\t" << "FAILED";
956  }
957  std::cout << "\n*************************************************************\n\n";
958 
959  iret |= iret2;
960 
961 
962  std::cout << "\n*****************************************************\n";
963  std::cout << " Test Symmetric matrices";
964  std::cout << "\n*****************************************************\n\n";
965 
966  iret = testWriteSym(nEvents,w1,w2);
967  iret2 = testReadSym(r1,r2,r3);
968  iret2 = testResult(w1,r1,w2,r2,r3);
969 
970  std::cout << "\n\n*************************************************************\n";
971  if (iret2 == 0 )
972  std::cout << " Reading Test:\t" << "OK";
973  else {
974  std::cout << " Reading Test:\t" << "FAILED";
975  }
976  std::cout << "\n*************************************************************\n\n";
977 
978  iret |= iret2;
979 
980 
981  std::cout << "\n*****************************************************\n";
982  std::cout << " Test Track class";
983  std::cout << "\n*****************************************************\n\n";
984 
985  // load track dictionary
986  iret |= gSystem->Load("libTrackDict");
987  if (iret != 0 ) return iret;
988 
989  iret |= testTrack(nEvents);
990  std::cout << "\n\n*************************************************************\n";
991  if (iret2 == 0 )
992  std::cout << " Track Test:\t" << "OK";
993  else {
994  std::cout << " Track Test:\t" << "FAILED";
995  }
996  std::cout << "\n*************************************************************\n\n";
997 
998 
999  return iret;
1000 
1001 }
1002 
1003 
1004 
1005 int main() {
1006  int iret = testIO();
1007  std::cout << "\n\n*************************************************************\n";
1008  if (iret != 0) {
1009  std::cerr << "\nERROR !!!!! " << iret << std::endl;
1010  std::cerr << "TESTIO \t FAILED " << std::endl;
1011  }
1012  else
1013  std::cerr << "TESTIO \t OK " << std::endl;
1014  return iret;
1015  std::cout << "*************************************************************\n\n";
1016 }
double SumTMatrix(TM &m)
Definition: testIO.cxx:115
void FillMatrix(Matrix &m)
Definition: testIO.cxx:71
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TObject.cxx:823
double tol32
Definition: testIO.cxx:49
Random number generator class based on M.
Definition: TRandom3.h:29
void FillMatrixSym(Matrix &m)
Definition: testIO.cxx:88
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:108
double writeTrackD32(int n)
Definition: testIO.cxx:607
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:56
const Double_t * v1
Definition: TArcBall.cxx:33
double writeTMatrix(int n)
Definition: testIO.cxx:296
int testTrack(int nEvents)
Definition: testIO.cxx:870
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4328
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
int testRead(double &r1, double &r2, double &r3)
Definition: testIO.cxx:763
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition: TTree.cxx:5163
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1818
Bool_t IsZombie() const
Definition: TObject.h:141
double readTMatrix()
Definition: testIO.cxx:385
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition: TStopwatch.cxx:123
int testReadSym(double &r1, double &r2, double &r3)
Definition: testIO.cxx:819
SMatrix5D & CovMatrix()
Definition: Track.h:19
void FillCArray(double *m)
Definition: testIO.cxx:79
ROOT::Math::SMatrix< double, 5, 5 > SMatrix5
Definition: testIO.cxx:44
int testWriteSym(int nEvents, double &w1, double &w2)
Definition: testIO.cxx:794
int testIO()
Definition: testIO.cxx:907
TLatex * t1
Definition: textangle.C:20
double SumCArray(double *m)
Definition: testIO.cxx:106
double readSMatrix(const std::string &file)
Definition: testIO.cxx:474
std::string sfile1
Definition: testIO.cxx:58
virtual void Print(Option_t *option="") const
Print a summary of the tree contents.
Definition: TTree.cxx:6514
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:75
SMatrix: a generic fixed size D1 x D2 Matrix class.
void Class()
Definition: Class.C:29
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition: TTree.cxx:7529
double tol
Definition: testIO.cxx:47
unsigned int r3[N_CITIES]
Definition: simanTSP.cxx:323
T apply(unsigned int i) const
access the parse tree with the index starting from zero and following the C convention for the order ...
Definition: SMatrix.icc:626
double writeSMatrix(int n, const std::string &file)
Definition: testIO.cxx:210
std::string symfile2
Definition: testIO.cxx:62
std::string symfile1
Definition: testIO.cxx:61
void initMatrix(int n)
Definition: testIO.cxx:126
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom3.cxx:93
Definition: Track.h:24
std::string sfile2
Definition: testIO.cxx:59
double readTMatrixSym()
Definition: testIO.cxx:428
TMatrixT< Double_t > TMatrixD
Definition: TMatrixDfwd.h:24
const int nEvents
Definition: testRooFit.cxx:42
double writeSMatrixSym(int n, const std::string &file)
Definition: testIO.cxx:252
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
double readTrackD32()
Definition: testIO.cxx:688
virtual void SetSeed(UInt_t seed=0)
Set the random generator sequence if seed is 0 (default value) a TUUID is generated and used to fill ...
Definition: TRandom3.cxx:200
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file.
Definition: TFile.cxx:2248
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
TMarker * m
Definition: textangle.C:8
double readTrackD()
Definition: testIO.cxx:647
const std::string sname
Definition: testIO.cxx:45
double SumSMatrix(ROOT::Math::SMatrix< double, 5, 5, R > &m)
Definition: testIO.cxx:98
const std::string sname_sym
Definition: testIO.cxx:46
TStopwatch timer
Definition: testIO.cxx:29
int main()
Definition: testIO.cxx:1005
double writeCArray(int n)
Definition: testIO.cxx:170
TMatrixTSym< Double_t > TMatrixDSym
double readSMatrixSym(const std::string &file)
Definition: testIO.cxx:520
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
Definition: TTree.cxx:1624
double f2(const double *x)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > SMatrixSym5
Definition: testIO.cxx:43
TF1 * f1
Definition: legend1.C:11
int testWrite(int nEvents, double &w1, double &w2)
Definition: testIO.cxx:733
virtual Long64_t GetEntries() const
Definition: TTree.h:382
A TTree object has a header with a name and a title.
Definition: TTree.h:94
Definition: Track.h:56
double writeTMatrixSym(int n)
Definition: testIO.cxx:339
const Int_t n
Definition: legend1.C:16
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
double writeTrackD(int n)
Definition: testIO.cxx:566
SMatrix5D & CovMatrix()
Definition: Track.h:36
int testResult(double w1, double r1, double w2, double r2, double r3)
Definition: testIO.cxx:848
Stopwatch class.
Definition: TStopwatch.h:30