__doc__ = "Testing the TPySelector for analysis"
'''

  #chain = TDSet('TTree','muons')
  #for file in fn:
  #chain.Add('/home/aidaph/mytree.root')
 
 ######## it does work but not chain.process()
  chain = ROOT.TChain("muons")
  chain.Add("mytree.root")
  print chain.GetEntries()
  chain.SetProof() 

  time.sleep(1) # needed for GUI to settle
  ######## Selec.py #######
  chain.Process("TPySelector","Selec")
  # MySelector.C 
  #chain.Process('MySelector.C+')
  #tsw.Print()
  #tsw.Stop()
'''
import argparse
import pickle
import time
from os.path import dirname, abspath
import sys

start = time.time()
tmpargv = sys.argv[:]    # [:] for a copy, not reference
sys.argv = []
from ROOT import *
from ROOT import TProof, TFileCollection, TChain
sys.argv = tmpargv

# giving some name to collection to shut up warning

#proof = TProof.Open("")

#chain = TChain("muons")
chain = TDSet("TTree", "muons")
chain.Add("mytree.root")
#print chain.GetEntries()
#Does not work >>> print chain.GetEntries(True, "mytree.root", "/home/aidaph/exercise/", "muons")
# add the current folder to the python path of root (or something)

#proof.Exec('TPython::Exec("%s");' %
 #       ("import sys; sys.path.insert(0,'"+dirname(abspath("Selec.py"))+"')"))
#chain.SetProof(True)

proof = TProof.Open("")
#chain.SetProof(True)
time.sleep(1)  # needed for GUI to settle

chain.Process('TPySelector', 'Selec')
#chain.Process("MySelector.C+")

print time.time() - start, "seconds"

