#-------------------------------------------------------------------------------- # Utility: GetCardCoord.py # # To be used with L1CAL_IIb_Gui command files. # Get Master/Slave/Slot Coordinates, Card ID, and Full Scale Range of ADF-2 Card # # Created : 23-Mar-2005 Create unique output directory name # Rev : 08-Apr-2005 Changed test stand Stefano slot from 8 to 10 JDB # Rev : 30-Jun-2005 Changed Sidewalk SCLD slot from 8 to 11, and add MasterNum_Sidewalk #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- # # This utility file is meant for command files to manage getting ADF card coordinates # # Constants to import in command files : # # SlotNum_Stefano_TestStand # Slot number at the MSU test stand which receives the Stefano generator inputs # SlotNum_Maestro_TestStand # Slot number at the MSU test stand for the ADF-2 Maestro card # # SlotNum_Maestro_Sidewalk # Slot Number at the FNAL sidewalk for the ADF-2 Maestro card # # SpeciesFullScaleVolt # Full scale range per card species as a floating point value # This variable can be imported elsewhere, but the intention # is for the command file to use the FullScaleVolt utility below # e.g. use SpeciesFullScaleVolt['A'][TT_EM] = 4.0 # to the EM channel full scale range for species A # # Retrieving coordinates : # # General idea # # The goal is to share the card coordinates retrieved from the operator # in the main command file with lower level command files subsequently # called within the main command file. This allows using the lower # level command files directly or using multiple lower level command file # from a single main command file without needing to request user input # every time. The main command file may also set some variables to # constant values that the lower level command file then doesn't need # to ask for interactively. # # These utilities will look in the dictionnary passed as argument for # the previous definition of a variable before asking the user. # They also accept an optional argument to override previous values # and replace asking a question. # # In all the functions below the argument ArgDict is a dictionnary # that is automatically available in command files and passed from # a calling file to a called file. # # GetCardCoord.MasterNum ( ArgDict, _MasterNum = '' ) # # If _MasterNum is not provided, this command file returns 0 (for now) # or will return the value acquired and remembered by a previous call # to this same function. # # e.g. GetCardCoord.MasterNum ( ArgDict ) returns 0 # GetCardCoord.MasterNum ( ArgDict, 1 ) returns 1 # # GetCardCoord.SlaveNum ( ArgDict, _SlaveNum = '' ) # # If _SlaveNum is not provided, this command file returns 0 (for now) # or will return the value acquired and remembered by a previous call # to this same function. # # e.g. GetCardCoord.SlaveNum ( ArgDict ) returns 0 # GetCardCoord.SlaveNum ( ArgDict, 1 ) returns 1 # # GetCardCoord.SlotNum ( ArgDict, _SlotNum = '' ) # # If _SlotNum is not provided, this command file will interactively # ask the user for the slot number of the targeted card # or will return the value acquired and remembered by a previous call # to this same function. # # e.g. GetCardCoord.SlotNum ( ArgDict ) asks for a slot number # (if not already defined in the ArgDict) # GetCardCoord.SlotNum ( ArgDict, 1 ) returns 1 # # GetCardCoord.CardID ( ArgDict, _CardID = '' ) # # If _CardID is not provided, this command file will interactively # ask the user for the Card ID of the targeted card # or will return the value acquired and remembered by a previous call # to this same function. # # The Card ID must start with a letter A,B,C or D which represents # the card Species. All other values are rejected. Lower case inputs # are forced to upper case. # # e.g. GetCardCoord.CardID ( ArgDict ) asks for a Card ID # (if not already defined in the ArgDict) # GetCardCoord.CardID ( ArgDict, 'A1' ) returns 'A1' # # GetCardCoord.Species ( ArgDict, _Species = '' ) # # If _Species is not provided, this command file will call the CardID # function to derive a species from the card ID # or will return the value acquired and remembered by a previous call # to this same function. # # e.g. GetCardCoord.Species ( ArgDict ) may ask for a Card ID # (if not already defined in the ArgDict) # returns the first character of Card ID # # GetCardCoord.FullScaleVolt ( ArgDict, _FullScaleVolt = '' ) # # If _FullScaleVolt is not provided, this command file will call the Species # function to look up the Full Scale values using the card Species # or will return the value acquired and remembered by a previous call # to this same function. # # e.g. GetCardCoord.FullScaleVolt ( ArgDict ) may ask for a Card ID # (if not already defined in the ArgDict) # and returns a pair of EM and HD # full scale range values in Volts # # GetCardCoord.LinkNum ( ArgDict, _LinkNum = '' ) # # If _LinkNum is not provided, this command file will interactively # ask the user for a Channel Link number on the targeted card # or will return the value acquired and remembered by a previous call # to this same function. # # e.g. GetCardCoord.LinkNum ( ArgDict ) asks for a link number # (if not already defined in the ArgDict) # GetCardCoord.LinkNum ( ArgDict, 1 ) returns 1 # #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- import string from Print_Utils import printLine #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- # some special card locations... # ... at the MSU Test Stand MasterNum_TestStand = '0' SlaveNum_TestStand = '0' SlotNum_Stefano_TestStand = '10' # has the wave form generator plugged in the back SlotNum_Maestro_TestStand = '20' # has the SCLD cable plugged in the back # ... at dzero, on the sidewalk MasterNum_Sidewalk = '0' # the 4 ADF crates use this Master number SlotNum_Maestro_Sidewalk = '11' # has the SCLD cable plugged in the back #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- # # ADF-2 Number EM HD R705, R706, R725, R726, # Species to Make F.S. F.S. R755, R756 R775, R776 # ------- ------- ---- ---- ----------- ----------- # A 21 4.0 2.0 1.02 K 511 # B 21 5.5 3.5 1.37 K 866 # C 11 4.0 4.0 1.02 K 1.02 K # D 37 5.5 5.5 1.37 K 1.37 K # SpeciesFullScaleVolt = { 'A' : [ 4.00, 2.08 ], 'B' : [ 5.32, 3.42 ], 'C' : [ 4.00, 4.00 ], 'D' : [ 5.32, 5.32 ] } #-------------------------------------------------------------------------------- #-------------------------------------------------------------------------------- ################################## # Master and Slave are typically fixed for now ################################## def MasterNum ( ArgDict, _MasterNum = '' ) : if ( _MasterNum == '' ) : if ( ArgDict.has_key ( 'MasterNum' ) ) : _MasterNum = ArgDict['MasterNum'] else: _MasterNum = raw_input( '\n\n MASTER NUMBER of this ADF-2 Card ( to abort): ' ) if ( _MasterNum == '' ) : raise TypeError ArgDict['MasterNum'] = int(_MasterNum) if ( ( int(_MasterNum) < 0 ) \ or ( int(_MasterNum) > 0 ) ) : # that was not a valid entry, remove it and try again del ArgDict['MasterNum'] _MasterNum = MasterNum ( ArgDict ) return int(_MasterNum) def SlaveNum ( ArgDict, _SlaveNum = '' ) : if ( _SlaveNum == '' ) : if ( ArgDict.has_key ( 'SlaveNum' ) ) : _SlaveNum = ArgDict['SlaveNum'] else: _SlaveNum = raw_input( '\n\n SLAVE NUMBER of this ADF-2 Card ( to abort): ' ) if ( _SlaveNum == '' ) : raise TypeError ArgDict['SlaveNum'] = int(_SlaveNum) if ( ( int(_SlaveNum) < 0 ) \ or ( int(_SlaveNum) > 3 ) ) : # that was not a valid entry, remove it and try again del ArgDict['SlaveNum'] _SlaveNum = SlaveNum ( ArgDict ) return int(_SlaveNum) ################################## # get the Slot Number interactively, unless this is a recursive call # where the Slot Number may have been defined in the Argument Dictionary ################################## def SlotNum ( ArgDict, _SlotNum = '' ) : if ( _SlotNum == '' ) : if ( ArgDict.has_key ( 'SlotNum' ) ) : _SlotNum = ArgDict['SlotNum'] else: _SlotNum = raw_input( '\n\n SLOT NUMBER of this ADF-2 Card ( to abort): ' ) if ( _SlotNum == '' ) : raise TypeError ArgDict['SlotNum'] = int(_SlotNum) if ( ( int(_SlotNum) < 2 ) \ or ( int(_SlotNum) > 21 ) ) : # that was not a valid entry, remove it and try again del ArgDict['SlotNum'] _SlotNum = SlotNum ( ArgDict ) return int(_SlotNum) ################################## # ditto for the Card ID ################################## def CardID ( ArgDict, _CardID = '' ) : if ( _CardID == '' ) : if ( ArgDict.has_key ( 'CardID' ) ) : _CardID = ArgDict['CardID'] else: _CardID = raw_input( '\n SERIAL NUMBER of the ADF-2 Card in slot #%s ( to abort): ' % SlotNum ( ArgDict ) ) if ( _CardID == '' ) : raise TypeError _CardID = string.upper ( string.strip ( _CardID ) ) ArgDict['CardID'] = str(_CardID) # We verify right away this is a legal SN by deriving a Species from it try : Species ( ArgDict ) except TypeError : # that was not a valid entry, remove it and try again del ArgDict['CardID'] _CardID = CardID ( ArgDict ) return str(_CardID) ################################## # extract Card Species from CardID ################################## def Species ( ArgDict, _Species = '' ) : global SpeciesFullScaleVolt if ( _Species == '' ) : if ( not ArgDict.has_key ( 'CardID' ) ) : CardID ( ArgDict ) _CardID = ArgDict['CardID'] _Species = _CardID[0] if ( _Species == '' ) : raise TypeError if ( _Species not in SpeciesFullScaleVolt.keys() ) : printLine ( '**Error**' ) printLine ( '**Error**', 'CardID must start with a letter of %s' % str ( SpeciesFullScaleVolt.keys() ) ) printLine ( '**Error**' ) raise TypeError ArgDict['Species'] = _Species ArgDict['FullScaleVolt'] = SpeciesFullScaleVolt[_Species] return _Species ################################## # extract full scale range from CardID ################################## def FullScaleVolt ( ArgDict, _FullScaleVolt = '' ) : if ( _FullScaleVolt == '' ) : if ( not ArgDict.has_key ( 'FullScaleVolt' ) ) : CardID ( ArgDict ) _FullScaleVolt = ArgDict['FullScaleVolt'] ArgDict['FullScaleVolt'] = _FullScaleVolt return _FullScaleVolt ################################## # Get everything above # which can then be retrieved # by the calling program via the ArgDict ################################## def All ( ArgDict ) : MasterNum ( ArgDict ) SlaveNum ( ArgDict ) SlotNum ( ArgDict ) CardID ( ArgDict ) ################################## # extract full scale range from CardID ################################## def LinkNum ( ArgDict, _LinkNum = '' ) : if ( _LinkNum == '' ) : if ( ArgDict.has_key ( 'LinkNum' ) ) : _LinkNum = ArgDict['LinkNum'] else: _LinkNum = raw_input( '\n\n CHANNEL LINK NUMBER [0..2] ( to abort): ' ) if ( _LinkNum == '' ) : raise TypeError ArgDict['LinkNum'] = int(_LinkNum) if ( ( int(_LinkNum) < 0 ) \ or ( int(_LinkNum) > 2 ) ) : # that was not a valid entry, remove it and try again del ArgDict['LinkNum'] _LinkNum = LinkNum ( ArgDict ) return int(_LinkNum)