Skip to content
Snippets Groups Projects
Commit 194c133d authored by Paolo Baesso's avatar Paolo Baesso
Browse files

Added ROOT functionality, almost done with the reading/writing to file

parent 0ba0bf2a
Branches
Tags
No related merge requests found
......@@ -3,6 +3,10 @@ import uhal;
import pprint;
import ConfigParser
from FmcTluI2c import *
import threading
from ROOT import TFile, TTree, gROOT
from I2CuHal import I2CCore
from si5345 import si5345 # Library for clock chip
from AD5665R import AD5665R # Library for DAC
......@@ -11,6 +15,9 @@ from PCA9539PW import PCA9539PW # Library for serial line expander
class TLU:
"""docstring for TLU"""
def __init__(self, dev_name, man_file, parsed_cfg):
self.isRunning= False
section_name= "Producer.fmctlu"
self.dev_name = dev_name
......@@ -291,10 +298,11 @@ class TLU:
#print "\tFIFO Data:", hex(fifoData)
return fifoData
def getFifoLevel(self):
def getFifoLevel(self, verbose= 0):
FifoFill= self.hw.getNode("eventBuffer.EventFifoFillLevel").read()
self.hw.dispatch()
print "\tFIFO level read back as:", hex(FifoFill)
if (verbose > 0):
print "\tFIFO level read back as:", hex(FifoFill)
return FifoFill
def getFifoCSR(self):
......@@ -683,6 +691,21 @@ class TLU:
##################################################################################################################################
##################################################################################################################################
def acquire(self):
print "STARTING ACQUIRE LOOP"
print "Run#" , self.runN, "\n"
self.isRunning= True
index=0
while (self.isRunning == True):
eventFifoFillLevel= self.getFifoLevel(0)
nFifoWords= int(eventFifoFillLevel)
if (nFifoWords > 0):
fifoData= self.getFifoData(nFifoWords)
outList= self.parseFifoData(fifoData, nFifoWords/6, False)
time.sleep(0.5)
index= index + nFifoWords/6
print "STOPPING ACQUIRE LOOP:", index, "events collected"
return index
def configure(self, parsed_cfg):
print "\nTLU INITIALIZING..."
......@@ -800,8 +823,9 @@ class TLU:
##################################################################################################################################
##################################################################################################################################
def start(self, logtimestamps=False):
def start(self, logtimestamps=False, runN=0, root_file= None):
print "TLU STARTING..."
self.runN= runN
print " FIFO RESET:"
FIFOcmd= 0x2
......@@ -819,11 +843,14 @@ class TLU:
self.pulseT0()
print " Turning off software trigger veto"
cmd = int("0x0",16)
self.setTriggerVetoStatus(cmd)
self.setTriggerVetoStatus( int("0x0",16) )
print "TLU STARTED"
nEvents= self.acquire()
return
##################################################################################################################################
##################################################################################################################################
def stop(self, saveD= False, plotD= False):
......@@ -834,8 +861,7 @@ class TLU:
self.getFifoFlags()
self.getFifoCSR()
print " Turning on software trigger veto"
cmd = int("0x1",16)
self.setTriggerVetoStatus(cmd)
self.setTriggerVetoStatus( int("0x1",16) )
nFifoWords= int(eventFifoFillLevel)
fifoData= self.getFifoData(nFifoWords)
......@@ -852,3 +878,4 @@ class TLU:
# outFile.write("%s\n" % fifoData[iData])
# print hex(fifoData[iData])
print "TLU STOPPED"
return
......@@ -48,7 +48,7 @@ DACThreshold5 = -0.2
DutMask = 1
# Define mode of DUT (00 EUDET, 11 AIDA)
DUTMaskMode= 0xFFFFFFFC
DUTMaskMode= 0xFFFFFFFF
# Allow asynchronous veto
DUTMaskModeModifier= 0x0
......@@ -60,7 +60,7 @@ DUTIgnoreBusy = 0x0
DUTIgnoreShutterVeto = 0x0
# Generate internal triggers (in Hz, 0= no triggers)
InternalTriggerFreq = 160
InternalTriggerFreq = 10
......
......@@ -6,6 +6,8 @@ from FmcTluI2c import *
import uhal
import sys
import time
from datetime import datetime
import threading
# from ROOT import TFile, TTree
# from ROOT import gROOT
from datetime import datetime
......@@ -17,6 +19,9 @@ import cmd
# Use to have config file parser
import ConfigParser
# Use root
from ROOT import TFile, TTree, gROOT
## Define class that creates the command user inteface
class MyPrompt(cmd.Cmd):
......@@ -42,7 +47,7 @@ class MyPrompt(cmd.Cmd):
"""Processes the CONF file and writes its values to the TLU. To use a specific file type:\n
parseIni path/to/filename.conf\n
(without quotation marks)"""
print "COMMAND RECEIVED: PARSE CONFIG"
print "==== COMMAND RECEIVED: PARSE CONFIG"
#self.testme()
parsed_cfg= self.open_cfg_file(args, "/users/phpgb/workspace/myFirmware/AIDA/TLU_v1e/scripts/localConf.conf")
try:
......@@ -55,21 +60,68 @@ class MyPrompt(cmd.Cmd):
def do_startRun(self, args):
"""Starts the TLU run"""
print "COMMAND RECEIVED: STARTING TLU RUN"
print "==== COMMAND RECEIVED: STARTING TLU RUN"
#startTLU( uhalDevice = self.hw, pychipsBoard = self.board, writeTimestamps = ( options.writeTimestamps == "True" ) )
arglist = args.split()
if len(arglist) == 0:
print "\tno run# specified, using 1"
runN= 1
else:
runN= arglist[0]
logdata= True
TLU.start(logdata)
#print self.hw
def do_stopRun(self, args):
#TLU.start(logdata)
if (TLU.isRunning): #Prevent double start
print " Run already in progress"
else:
now = datetime.now().strftime('%Y%m%d_%H%M%S')
default_filename = "./datafiles/"+ now + "_tluData_" + str(runN) + ".root"
rootFname= default_filename
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
# 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))
daq_thread.start()
def do_endRun(self, args):
"""Stops the TLU run"""
print "COMMAND RECEIVED: STOP TLU RUN"
TLU.stop(False, False)
#stopTLU( uhalDevice = hw, pychipsBoard = board )
print "==== COMMAND RECEIVED: STOP TLU RUN"
if TLU.isRunning:
TLU.isRunning= False
TLU.stop(False, False)
self.root_file.Write()
self.root_file.Write()
else:
print " No run to stop"
def do_quit(self, args):
"""Quits the program."""
print "COMMAND RECEIVED: QUITTING SCRIPT."
print "==== COMMAND RECEIVED: QUITTING TLU CONSOLE"
self.root_file.Close()
#raise SystemExit
return True
......
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