Commit c735d6df authored by David Cussans's avatar David Cussans

- MarocConfiguration.py  - passes configuration file name to MarocSC object and reads from configuration file.

- MarocHistograms.py - replaced print statements with logger.info / logger.debug

- MarocSC.py - debugged so can now read flags, parameters and register values from configuration file.

- takeMarocData.py - added command line switch to set configuration file name



git-svn-id: https://svn2.phy.bris.ac.uk/svn/uob-hep-pc049a/trunk@39 e1591323-3689-4d5a-aa31-d1a7cbdc5706
parent e6393c94
......@@ -17,16 +17,16 @@ class MarocConfiguration(object):
self.logger = logging.getLogger(__name__)
marocLogging(self.logger,debugLevel)
self.slowControlObject = MarocSC.MarocSC()
self.slowControlObject = MarocSC.MarocSC(debugLevel=debugLevel)
self.configurationFile = configurationFile
self.slowControlObject.readConfigFile(configurationFile )
def configure(self):
self.logger.info("Configuring board")
self.slowControlObject.setParameterValue("DAC",[650,450])
self.slowControlObject.setFlagValue("d1_d2",0)
self.slowControlObject.setFlagValue("cmd_fsb_fsu",1) # Select FSU
self.slowControlObject.setParameterValue("mask_OR",0x3,54) # Mask hot channel
SCData = self.slowControlObject.getWordArray() # Get data to write
self.logger.debug("Slow control data = %s"%( ' , '.join([format(i,'08x') for i in SCData ]) ))
......@@ -35,13 +35,14 @@ class MarocConfiguration(object):
self.board.blockWrite("scSrDataOut",SCData)
self.board.write("scSrCtrl" , 0x00000000)
# set up triggers
#triggerSource = 0x0000000D
triggerSource = 0x00000008
self.board.write("trigSourceSelect",triggerSource) # Set OR1,OR2 and internal triggers active
trigSourceReadback = self.board.read("trigSourceSelect")
self.logger.debug( "Trigger source select register = %s" % (hex(trigSourceReadback)))
# set up the registers.
for regName in self.slowControlObject.registers.keys():
regValue = self.slowControlObject.getRegisterValue(regName)
self.logger.info("Writing %i to register %s"%( int(regValue) , regName ))
self.board.write(regName,regValue)
regReadValue = self.board.read(regName)
self.logger.info("Read back %i from %s"%( int(regReadValue) , regName ))
self.logger.debug( "Resetting timestamp and trigger counters")
self.board.write("trigStatus",0x00000001)
......
......@@ -43,8 +43,8 @@ class MarocHistograms(object):
self.canvasNames = [ "c%s"%canvas for canvas in range(nCanvas) ]
self.canvasTitles = [ "ADC Value for Channels %s - %s"%(canvas*self.nPlotsPerCanvas , (canvas+1)*self.nPlotsPerCanvas -1) for canvas in range(nCanvas) ]
print self.canvasNames
print self.canvasTitles
#print self.canvasNames
#print self.canvasTitles
self.canvasList = [ TCanvas(self.canvasNames[chan],self.canvasTitles[chan],600,400) for chan in range(nCanvas) ]
......@@ -62,7 +62,7 @@ class MarocHistograms(object):
plot = canvasIndex*self.nPlotsPerCanvas + plotIndex # look the other way please....
print canvasIndex , plotIndex , plot
self.logger.debug("Booking histogram. Canvas , plot within canvas, plot = %i %i %i "%( canvasIndex , plotIndex , plot))
canvas.cd(plotIndex+1) # Change current pad. (plotIndex counts from 0. Root expects count from 1 (0 is the parent))
......
......@@ -166,7 +166,7 @@ class MarocSC(object):
def getFlagLocations(self):
"""Return the list of flags, positions and defaults"""
return self.flagLocation
def setParameterValue(self,paramName,newParamValue,index=-1):
"""Writes to the parameter array with name paramName at index the value n"""
[ paramLocation , paramWidth , paramDefault, description, comment ,oldParamValue] = self.parameterLocation[paramName]
......@@ -211,6 +211,9 @@ class MarocSC(object):
parameters , where the parameter entries are ( pName: p(1),p(2),....,p(N) . N.B. no bounds checking is done on the parameter indices, so don't add too many to the list
registers , values to write to FPGA registers
"""
self.logger.info("Reading Configuration from %s" %(fName))
config = ConfigParser.SafeConfigParser()
config.optionxform = str # stop parser from changing to lower case.
config.read(fName)
......@@ -226,7 +229,7 @@ class MarocSC(object):
# read the parameters
for ( parameter , valueList ) in parameters:
values = valueList.split(",")
self.setParameter( parameter , values )
self.setParameterValue( parameter , values , index=-1)
# read the register values...
for ( registerName , value ) in registers:
self.setRegisterValue( registerName , int(value) )
......@@ -254,8 +257,8 @@ class MarocSC(object):
config.set('parameters',paramName,paramString)
# Set register values
for registerName in self.flagLocation.keys():
registerValue = self.getRegisterValues(registerName)
for registerName in self.registers.keys():
registerValue = self.getRegisterValue(registerName)
self.logger.debug("Setting Register name %s in config file to %i " %(registerName,registerValue))
config.set('registers',registerName,str(registerValue))
......@@ -263,15 +266,6 @@ class MarocSC(object):
config.write(cfgFile)
cfgFile.close()
# def configure(self,board):
# """Writes contents of local data-structure to MAROC slow control.
# board - a PyChips object pointing to correct MAROC board"""
#
# SCData = self.getWordArray()
# # write data into buffer
# board.blockWrite("scSrDataOut",SCData)
# # trigger writing of buffer to slow control shift register
# board.write("scSrCtrl" , 0x00000001)
......
......@@ -34,6 +34,8 @@ parser.add_option("-o", dest = 'outputFile' , default = 'marocTimeStamps.root' )
parser.add_option("-n" , dest = 'numTriggers' , default = 1000 )
parser.add_option("-c" , dest = 'configFile' , default = 'testADC_marocSC.csv' )
(options, args) = parser.parse_args()
logger.info("IP address = %s"%( options.ipAddress))
......@@ -49,10 +51,10 @@ board = ChipsBusUdp(bAddrTab,options.ipAddress,50001)
firmwareID = board.read("FirmwareId")
print "Firmware ID = " , hex(firmwareID)
logger.info("Firmware ID = %s" % (hex(firmwareID)))
# Create object with configuration information - in the long run this should be done in a separate thread with a GUI
marocConfiguration = MarocConfiguration.MarocConfiguration(board,debugLevel=logging.DEBUG)
marocConfiguration = MarocConfiguration.MarocConfiguration(board,configurationFile = options.configFile , debugLevel=logging.DEBUG)
rawDataQueue = Queue.Queue()
......@@ -69,10 +71,16 @@ unpackerThread = MarocUnpackingThread.MarocUnpackingThread(2,"unpackingThread",r
histogramThread = MarocHistogrammingThread.MarocHistogrammingThread(3,"histogrammingThread",histogramDataQueue,debugLevel=logging.INFO)
recordingThread = MarocRecordingThread.MarocRecordingThread(3,"recordingThread",recordingDataQueue,fileName=options.outputFile, debugLevel=logging.DEBUG)
recordingThread = MarocRecordingThread.MarocRecordingThread(3,"recordingThread",recordingDataQueue,fileName=options.outputFile, debugLevel=logging.INFO)
# Send configuration to board.
#marocConfiguration.slowControlObject.setParameterValue("DAC",[650,450])
#marocConfiguration.slowControlObject.setFlagValue("d1_d2",0)
#marocConfiguration.slowControlObject.setFlagValue("cmd_fsb_fsu",1) # Select FSU
#marocConfiguration.slowControlObject.setParameterValue("mask_OR",0x3,54) # Mask hot channel
# Send configuration to board.
# Send configuration to the board ( read from configuration file)
marocConfiguration.configure()
# Having created the threads, now start them running
......
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