#include "ErrorPropTest.h"
#include "TFile.h"
#include <iostream>
#include "TClonesArray.h"
#include <math.h>

using namespace std;

void errproptest(void)
{
  Double_t a = 1;
  DoubleErr ae = a;
  cout << " Assigning double to DoubleErr: " << a << " = " << ae << endl;
  
  DoubleErr be = 2;
  Double_t b = be;
  cout << "Assigning DoulbeErr to double: " << be << " = " << b << endl;

  DoubleErr x(3,0.5);
  DoubleErr y(2,1.0);
  Double_t  k(2);
  cout << "x:     " << x << endl;
  cout << "y:     " << y << endl;
  cout << "k:     " << k << endl;
  cout << "x + k: " << x+k << endl;
  cout << "k + x: " << k+x << endl;
  cout << "x + y: " << x+y << endl;
  cout << endl;
  cout << "x - k: " << x-k << endl;
  cout << "k - x: " << k-x << endl;
  cout << "x - y: " << x-y << endl;
  cout << endl;
  cout << "x * k: " << x*k << endl;
  cout << "k * x: " << k*x << endl;
  cout << "x * y: " << x*y << endl;
  cout << "x * 3: " << x*3 << endl;
  cout << endl;
  cout << "x / k: " << x/k << endl;
  cout << "k / x: " << k/x << endl;
  cout << "x / y: " << x/y << endl;
  cout << endl;
  cout << "x+= k: " << (x+=k) << endl;
  cout << "x+= 3: " << (x+=3) << endl;
  cout << endl;
  cout << "fmod(y,0.5): " << fmod(y,0.3) << endl;
  y.Print();


  cout << "Testing read/write of objects with ValueErr data members." << endl;
  
  cout << "Writing: " << endl; 
  TFile fsave("errorprop0.root","RECREATE");
  ErrorData2 ed2;
  ed2.Print();
  ed2.Write("ed2");
  fsave.Close();


  cout << "Reading: " << endl;
  TFile fread("errorprop0.root");
  fread.Get("ed2")->Print();
  fread.Close();



  return; // Skip the rest...................................

  // Bulk test of write:
  const int n = 100;

  TClonesArray a1("ErrorData1",n);
  for(int i = 0; i<n; i++) {
    new(a1[i]) ErrorData1();
  }
  TFile f1("errorprop1.root","RECREATE");
  a1.Write("array");
  f1.Close();


  TClonesArray a2("ErrorData2",n);
  for(int i = 0; i<n; i++) {
    new(a2[i]) ErrorData2();
  }
  TFile f2("errorprop2.root","RECREATE");
  a2.Write("array");
  f2.Close();


}
