## \file
## \ingroup tutorial_dataframe
## \notebook
##
## Extract the statistics relative to RDataFrame columns and store them
##  in TStatistic instances.
##
## \macro_code
## \macro_output
##
## \date April 2019
## \author Danilo Piparo

import ROOT
import time
import sys

threads=int(sys.argv[1] if len(sys.argv)==2 else 0)

ROOT.ROOT.EnableImplicitMT(threads);


# Create a data frame and add two columns: one for the values and one for the weight.
r = ROOT.ROOT.RDataFrame(100000000);
rr = r.Define("v", "rdfentry_")\
      .Define("w", "return 1./(v+1)")\
      .Define("x", "v*w")\
      .Filter("v%100==0")
    
# Now extract the statistics, weighted, unweighted
stats_iw = rr.Stats("x", "w")


# Now print them: they are all identical of course!
t1=time.time()
stats_iw.Print()
t2=time.time()
print("%d\t%f"%(threads,t2-t1))
