Hello, I have a short python script that I would like to call from a regular ROOT macro. Here is the original script:
[code]import Get_Info
import time, numpy, sys
runnum = int(sys.argv[1])
info = Get_Info.Get_Info(runnum)
st,sd = info[‘Start time’],info[‘Start date’]
et,ed = info[‘end time’],info[‘end date’]
sdt = time.mktime(time.strptime(st+sd,"%H:%M:%S%m/%d/%Y"))
edt = time.mktime(time.strptime(et+ed,"%H:%M:%S%m/%d/%Y"))
delta = (edt-sdt)
nevents = int(info[‘No. Events’])
evt_times = numpy.arange(sdt,edt,delta/nevents)
[/code]
Now, I would like to call this script inside a ROOT macro such that I can get the array evt_times for a given integer as a command-line argument. I looked at the TPython documentation but couldn’t get anything to work. I tried creating a class with a member function that returns a TVectorD:
class Evt_Times():
def __init__(self):
print 'Creating Evt_Times object...'
def evt_times(self,runnum):
info = Get_Info.Get_Info(runnum)
...
nevents = int(info['No. Events'])
evt_times = numpy.arange(sdt,edt,delta/nevents)
return ROOT.TVectorD(len(evt_times),evt_times)
But then in the ROOT interpreter none of the commands that I tried seemed to work:
root [0] TPython::LoadMacro("dateinterpolate.py")
root [1] et = Evt_Times()
Creating Evt_Times object...
(class Evt_Times::Evt_Times)4355969680
root [2] et.evt_times(387)
Error: Can't call Evt_Times::evt_times(387) in current scope (tmpfile):1:
Possible candidates are...
(in Evt_Times)
public: TPyReturnEvt_Timesevt_times Evt_Times::evt_times();
*** Interpreter error recovered ***
root [4] et->evt_times(387)
Error: Can't call Evt_Times::evt_times(387) in current scope (tmpfile):1:
Possible candidates are...
(in Evt_Times)
public: TPyReturnEvt_Timesevt_times Evt_Times::evt_times();
*** Interpreter error recovered ***
root [5] et::evt_times(387)
Error: Function evt_times(387) is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
root [6] Evt_Times::evt_times(387)
Error: cannot call member function without object (tmpfile):1:
(compiled) 0 TPyReturnEvt_Timesevt_times Evt_Times::evt_times();
Calling : Evt_Times::evt_times(int);
Match rank: file line signature
*** Interpreter error recovered ***
root [7] TVectorD tvd = (TVectorD*)et.evt_times(387)
Error: Can't call Evt_Times::evt_times(387) in current scope (tmpfile):1:
Possible candidates are...
(in Evt_Times)
public: TPyReturnEvt_Timesevt_times Evt_Times::evt_times();
*** Interpreter error recovered ***
Any ideas on where to go would be appreciated. I would like to have access to the array evt_times inside ROOT, ideally as a TVector or as a more basic type.
Thank you,
Jean-François