#------------------------------------------------------------------------ # ThisCommandFile = 'DAQ96_Collect_OneAdf.cmd' # # called by DAQ96_Collect_Main.cmd to retrieve all 32 channels from # one ADF Card, and append to the Event File already opened by the calling file # # Created 18-Dec-2006 # #------------------------------------------------------------------------ #------------------------------------------------------------------------ from Site_Dependent import LogTcsDir from Site_Dependent import AdfChannelTot from Site_Dependent import AdfSlotVsCardNum from Site_Dependent import AdfFpgaVsChNum from Site_Dependent import AdfBufferBaseVsChNum from Site_Dependent import ChannelBeginStr from Site_Dependent import SamplesPerChannel #------------------------------------------------------------------------ # Retrieve the implicit arguments from the argument dictionary # these arguments must have been filled in by DAQ96_Collect_Main.cmd AdfNum = ArgDict['AdfNum'] # Index 0..2 of ADF to be read out RunNumStr = ArgDict['RunNumStr'] # String for Run Number EvtCaptNumStr = ArgDict['EvtCaptNumStr'] # String for Event Number EventFile = ArgDict['EventFile'] # File Object to write data to #------------------------------------------------------------------------ # Register Address for Address Generator stopping addresses RegAddr_AddrGenStop = 514 #------------------------------------------------------------------------ #------------------------------------------------------------------------ # Start by reading the Stop Address of the Raw ADC Address Generator # from both Data Path FPGAs (instead of reading it again for each channel) StopAddrVsFpga = [ 0, 0 ] for FpgaNum in range(2) : StopAddrVsFpga[FpgaNum], \ Reply_Status \ = Rio_Read ( SlotNum = AdfSlotVsCardNum[AdfNum], ChipNum = FpgaNum, RegAddr = RegAddr_AddrGenStop ) # now retrieve the monitoring data for each system channel, one at a time, # by channel number (i.e. alternating between FPGAs) for ChannelNum in range(AdfChannelTot) : # write channel number identification e.g. "# System Channel #064" EventFile.write ( "%s%#03d\n" % ( ChannelBeginStr, ( AdfNum * AdfChannelTot + ChannelNum ) ) ) # Read the raw ADC circular buffer data from ADF2_Card_Number, # Ch_Num_On_ADF2_Card into a temporary_working_file. Average_str, \ Deviation_str, \ FileName_str, \ Reply_Status \ = Hst_Histogram( SlotNum = AdfSlotVsCardNum[AdfNum], ChipNum = AdfFpgaVsChNum[ChannelNum], RegAddr = AdfBufferBaseVsChNum[ChannelNum], Samples = SamplesPerChannel, AddrIncr = 1, DumpToFile = 1, Comment = "Run#%s Evt#%s ADF#%d Ch#%d" % ( RunNumStr, EvtCaptNumStr, AdfNum, ChannelNum ) ) # Open data file collected by histogram routine # and read the whole thing into a list try : RawDataFile = open ( LogTcsDir + FileName_str, 'r' ) RawDataLines = RawDataFile.readlines () # if everything went well, delete the temporary file RawDataFile.close () os.remove( LogTcsDir + FileName_str ) except : printLine ( "**Error**", "error while Reading temporary Dump File" ) # Re-align and copy data to event file try : UseFakeData = 0 # set to 1 to use fake data for code devolopment (will be removed later) if ( UseFakeData ) : from FakeData import FakeData from random import randint StopAddrThisChannel = 400 for LineNum in range ( StopAddrThisChannel+1, SamplesPerChannel ) + range ( StopAddrThisChannel+1 ) : EventFile.write ( "%d\n" % ( FakeData [(LineNum + 20 * ChannelNum) % SamplesPerChannel] + randint(0,2) - 1 ) ) else : # We already have the stop address StopAddrThisChannel = StopAddrVsFpga[ AdfFpgaVsChNum[ChannelNum] ] # Start with the part after the stop address (older data) # End with the part before the stop address (newer data) for LineNum in range ( StopAddrThisChannel+1, SamplesPerChannel ) \ + range ( StopAddrThisChannel+1 ) : SampleValStr = "%s%d\n" % ( (5-len(RawDataLines[LineNum])) * ' ', int(RawDataLines[LineNum]) ) EventFile.write ( SampleValStr ) except : printLine ( "**Error**", "Error while Writing Channel #%#03d to Event File\n" % ( AdfNum * AdfChannelTot + ChannelNum ) ) # last try closing the temp data file in case there was a problem if ( globals().has_key( 'RawDataFile' ) ) : RawDataFile.close()