Commit cd7bb016 authored by Paolo Baesso's avatar Paolo Baesso

ROOT write to file now working. Might still have some bugs to sort out

parent 194c133d
......@@ -4,7 +4,8 @@ import pprint;
import ConfigParser
from FmcTluI2c import *
import threading
from ROOT import TFile, TTree, gROOT
from ROOT import TFile, TTree, gROOT, AddressOf
from ROOT import *
from I2CuHal import I2CCore
......@@ -597,9 +598,7 @@ class TLU:
print "\tPacked =", hex(packed_bits)
return packed_bits
def parseFifoData(self, fifoData, nEvents, verbose):
def parseFifoData(self, fifoData, nEvents, mystruct, root_tree, verbose):
#for index in range(0, len(fifoData)-1, 6):
outList= []
for index in range(0, (nEvents)*6, 6):
......@@ -632,7 +631,22 @@ class TLU:
print fineTsList
fineTsList.insert(0, tStamp)
fineTsList.insert(0, evNum)
#print fineTsList
if (root_tree != None):
highWord= word0
lowWord= word1
extWord= word2
timeStamp= tStamp
bufPos= 0
evtNumber= evNum
evtType= evType
trigsFired= 0
mystruct.highWord= word0
mystruct.lowhWord= word1
mystruct.extWord= word2
mystruct.evtNumber= evNum
mystruct.tluTimeStamp= tStamp
root_tree.Fill()
outList.insert(len(outList), fineTsList)
#print "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
#print "EN#\tCOARSE_TS\tFINE_TS0...FINE_TS11"
......@@ -682,7 +696,6 @@ class TLU:
#Display plot
plt.show()
def saveFifoData(self, outList):
import csv
with open("output.csv", "wb") as f:
......@@ -691,7 +704,7 @@ class TLU:
##################################################################################################################################
##################################################################################################################################
def acquire(self):
def acquire(self, mystruct, root_tree= None):
print "STARTING ACQUIRE LOOP"
print "Run#" , self.runN, "\n"
self.isRunning= True
......@@ -701,8 +714,9 @@ class TLU:
nFifoWords= int(eventFifoFillLevel)
if (nFifoWords > 0):
fifoData= self.getFifoData(nFifoWords)
outList= self.parseFifoData(fifoData, nFifoWords/6, False)
time.sleep(0.5)
outList= self.parseFifoData(fifoData, nFifoWords/6, mystruct, root_tree, False)
time.sleep(0.1)
index= index + nFifoWords/6
print "STOPPING ACQUIRE LOOP:", index, "events collected"
return index
......@@ -823,7 +837,7 @@ class TLU:
##################################################################################################################################
##################################################################################################################################
def start(self, logtimestamps=False, runN=0, root_file= None):
def start(self, logtimestamps=False, runN=0, mystruct= None, root_tree= None):
print "TLU STARTING..."
self.runN= runN
......@@ -847,7 +861,7 @@ class TLU:
print "TLU STARTED"
nEvents= self.acquire()
nEvents= self.acquire(mystruct, root_tree)
return
......@@ -863,12 +877,10 @@ class TLU:
print " Turning on software trigger veto"
self.setTriggerVetoStatus( int("0x1",16) )
nFifoWords= int(eventFifoFillLevel)
fifoData= self.getFifoData(nFifoWords)
#nFifoWords= int(eventFifoFillLevel)
#fifoData= self.getFifoData(nFifoWords)
outList= self.parseFifoData(fifoData, nFifoWords/6, True)
#saveD= 0
#plotD= 0
#outList= self.parseFifoData(fifoData, nFifoWords/6, True)
if saveD:
self.saveFifoData(outList)
if plotD:
......
......@@ -20,7 +20,9 @@ import cmd
import ConfigParser
# Use root
from ROOT import TFile, TTree, gROOT
from ROOT import TFile, TTree, gROOT, AddressOf
from ROOT import *
import numpy as numpy
## Define class that creates the command user inteface
......@@ -58,6 +60,11 @@ class MyPrompt(cmd.Cmd):
print "\t Could not retrieve CONF data."
return
def do_id(self, args):
"""Interrogate the TLU and print it unique ID on screen"""
TLU.getSN()
return
def do_startRun(self, args):
"""Starts the TLU run"""
print "==== COMMAND RECEIVED: STARTING TLU RUN"
......@@ -74,6 +81,7 @@ class MyPrompt(cmd.Cmd):
#TLU.start(logdata)
if (TLU.isRunning): #Prevent double start
print " Run already in progress"
return
else:
now = datetime.now().strftime('%Y%m%d_%H%M%S')
default_filename = "./datafiles/"+ now + "_tluData_" + str(runN) + ".root"
......@@ -81,31 +89,43 @@ class MyPrompt(cmd.Cmd):
print "OPENING ROOT FILE:", rootFname
self.root_file = TFile( rootFname, 'RECREATE' )
# Create a root "tree"
tree = TTree( 'T', 'TLU Data' )
highWord =0
lowWord =0
evtNumber=0
timeStamp=0
evtType=0
trigsFired=0
bufPos = 0
root_tree = TTree( 'T', 'TLU Data' )
#highWord =0
#lowWord =0
#evtNumber=0
#timeStamp=0
#evtType=0
#trigsFired=0
#bufPos = 0
gROOT.ProcessLine(
"struct MyStruct {\
Int_t highWord;\
Int_t lowWord;\
Int_t extWord;\
Int_t evtNumber;\
Int_t tluTimeStamp;\
Int_t tluEvtType;\
};" );
mystruct= MyStruct()
# Create a branch for each piece of data
tree.Branch( 'tluHighWord' , highWord , "HighWord/l")
tree.Branch( 'tluLowWord' , lowWord , "LowWord/l")
tree.Branch( 'tluTimeStamp' , timeStamp , "TimeStamp/l")
tree.Branch( 'tluBufPos' , bufPos , "Bufpos/s")
tree.Branch( 'tluEvtNumber' , evtNumber , "EvtNumber/i")
tree.Branch( 'tluEvtType' , evtType , "EvtType/b")
tree.Branch( 'tluTrigFired' , trigsFired, "TrigsFired/b")
self.root_file.Write()
daq_thread= threading.Thread(target = TLU.start, args=(logdata, runN, self.root_file))
# Create a branch for each piece of data
root_tree.Branch('myints', mystruct, 'highWord/I:lowWord/I:extWord/I:evtNumber/I:tluTimeStamp/I:tluEvtType/I' )
# root_tree.Branch( 'tluHighWord' , highWord , "HighWord/l")
# root_tree.Branch( 'tluLowWord' , lowWord , "LowWord/l")
# root_tree.Branch( 'tluExtWord' , extWord , "ExtWord/l")
# root_tree.Branch( 'tluTimeStamp' , timeStamp , "TimeStamp/l")
# root_tree.Branch( 'tluBufPos' , bufPos , "Bufpos/s")
# root_tree.Branch( 'tluEvtNumber' , evtNumber , "EvtNumber/i")
# root_tree.Branch( 'tluEvtType' , evtType , "EvtType/b")
# root_tree.Branch( 'tluTrigFired' , trigsFired, "TrigsFired/b")
#self.root_file.Write()
daq_thread= threading.Thread(target = TLU.start, args=(logdata, runN, mystruct, root_tree))
daq_thread.start()
def do_endRun(self, args):
"""Stops the TLU run"""
print "==== COMMAND RECEIVED: STOP TLU RUN"
......@@ -113,7 +133,7 @@ class MyPrompt(cmd.Cmd):
TLU.isRunning= False
TLU.stop(False, False)
self.root_file.Write()
self.root_file.Write()
self.root_file.Close()
else:
print " No run to stop"
......@@ -121,7 +141,6 @@ class MyPrompt(cmd.Cmd):
def do_quit(self, args):
"""Quits the program."""
print "==== COMMAND RECEIVED: QUITTING TLU CONSOLE"
self.root_file.Close()
#raise SystemExit
return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment