LArTPC DAQ 96 Routine Details ------------------------------------ Original Rev. 13-DEC-2006 Current Rev. 29-DEC-2006 The purpose of this file is to describe the details of the various routines that make up the "DAQ 96" system. The sections of this document are: Constants that we declare and assign values to ahead of time Variables to Declare Recall some relationships Start a New Run Event Loop Readout an Event Read_ADFs_into_Event_Data_File Loop_Over_ADF2_Cards Loop_Over_Channels_on_a_ADF2_Card Read_a_Channel End the Current Run Status Window Update Constants that we declare and assign values to ahead of time: ============================================================= MasterNum = 0 SlaveNum = 0 Note: There is no Vertical Interconnect in the DAQ 96 system but I think that we still call this master 0 slave 0. Slot_Num_of_ADF2_Card_Num_Zero = 10 List_of_DAQ_96_ADF_2_Cards ADF-2 cards are numbered starting from card "0". ADF-2 card number 0 is in the slot number given by the variable Slot_Num_of_ADF2_Card_Num_Zero. Higher number ADF-2 cards are in monotonically increasing slot numbers. ADF-2 card number 0 is of the Maestro type and must always be in the system. List_of_DAQ_96_ADF_2_Cards and Slot_Num_of_ADF2_Card_Num_Zero provide a description of the current hardware configuration of the system. Directory_for_Run_Sub_Directories This is the full absolute path name of the directory that holds all of the sub-directories for each run. Chip_Num_On_ADF2_Card = The Data Path FPGA Chip Number is defined as a function of the 0:31 Ch_Num_On_ADF2_Card variable. See the table below. This layout comes from the table near the bottom of the document daq_96_definition.txt Buf_Start_Adrs = The Raw ADC Data Circular Buffer Starting Address is defined as a function of the 0:31 Ch_Num_On_ADF2_Card variable. See the table below. This layout comes from the table near the bottom of the document daq_96_definition.txt Table showing the Chip_Num_On_ADF_Card and the Circular Buffer Starting Address as a function of the ADF-2 Card Channel Number ADF-2 LArTPC Data Circular ADF-2 Path FPGA Buffer Ch Num Chip Numb Start Adrs ------ --------- ---------- 0 0 0x1000 1 0 0x1800 2 0 0x9000 3 0 0x9800 4 1 0x1000 5 1 0x1800 6 1 0x9000 7 1 0x9800 8 0 0x3000 9 0 0x3800 10 0 0xB000 11 0 0xB800 12 1 0x3000 13 1 0x3800 14 1 0xB000 15 1 0xB800 16 0 0x5000 17 0 0x5800 18 0 0xD000 19 0 0xD800 20 1 0x5000 21 1 0x5800 22 1 0xD000 23 1 0xD800 24 0 0x7000 25 0 0x7800 26 0 0xF000 27 0 0xF800 28 1 0x7000 29 1 0x7800 30 1 0xF000 31 1 0xF800 The variable Ch_Num_On_ADF2_Card in the DAQ 96 application always refers to the 0:31 form of the LArTPC ADF-2 Card Channel Number shown in the table above. Variables to Declare: ===================== Directory_for_this_Run This is the full absolute path name of the sub-directory that holds all of the Event Data Files for the current run. Event_Data_File_Name This is the full absolute path name to the Event Data File for the current event that is being (or just was) written. Run_Number Integer Event_Number This variable has the values 0 : 64k The system should wake up with this variable set to 0. This variable is set to 0 by the: Start_A_Run routine. It is incremented in the Run_Event_Loop routine. Mask_of_Cards_to_be_Read This is a list of ADF2_Card_Numbers. For an ADF2_Card_Number to be in this list it must be in the list List_of_DAQ_96_ADF_2_Cards. ADF2_Card_Number Integer starting from 0 Ch_Num_On_ADF2_Card Integer 0:31 Note that the ADF-2 channel numbering for the D-Zero application is 0:15 EM & HD. For the LArTPC application it makes more sense to number the ADF-2 channels 0:31. Both of these schemes are shown in the tables at the bottom of the daq_96_definition.txt document. For all LArTPC DAQ 96 system work Ch_Num_On_ADF2_Card refers to the 0:31 ADF-2 card channel number. Auto_Pause This variable has the values 0 and 1. 0 means that that this run does not use Auto_Pause. 1 means that in this run a "Pause" will automatically be issued after each event is recorded. PreScale_Value This is an integer value between 0 and 1000. It indicates the number of seconds that the DAQ 96 system should sleep after it has recorded each event. 0 means that the system will not do any "prescaling". Run_Is_Underway This variable has the values 0 and 1. 0 means that a run is not underway and 1 means that a run is underway. The system should wakeup with this set to 0. This variable is set by the: Start_A_Run and End_A_Run routines. It is read by the Update_Status_Window routine. Paused_State This variable has the values 0 and 1. 1 means that that the DAQ 96 System is currently Paused. Recall some relationships: ========================== System_Ch_Num = (ADF2_Card_Num * 32) + (Ch_Num_On_ADF2_Card) Ch_Num_On_ADF2_Card = System_Ch_Num MOD 32 SlotNum = Slot_Num_of_ADF2_Card_Num_Zero + ADF2_Card_Number SlotNum = Slot_Num_of_ADF2_Card_Num_Zero + integer_part_of (System_Ch_Num / 32) Start a New Run =============== I believe that all of the Start_a_Run routine is code in the "main gui code section". The Start_A_Run routine has the following steps: 1. Verify that a run is not currently under way. Test to see if the variable Run_Is_Underway is set to 0 or 1. If it is set to 1 then warn the operator that a run is already underway and exit. 2. Establish the Run Number of this new run. Look in the directory Directory_for_Run_Sub_Directories and find in there the run sub-directory with the highest run number. Set variable Run_Number equal to the run number in that run sub-directory + 1. 3. Make the run sub-directory to hold the Event Data Files for this new current run. Generate the name of the run sub-directory that will hold the events from this new run. Its name is: Evts_from_Run_"Run_Num"_Time_"get_system_time".dir Some how express the time without any special characters like ":" I don't want any file system to have trouble with these directory names. Make a new sub-directory with this name in the. Make it under the directory Directory_for_Run_Sub_Directories. Set the variable Directory_for_this_Run equal to the full absolute path to this newly created sub-directory. 4. Ask the operator which DAQ 96 System Channels should be included (i.e. readout) in this run. This is specified at the ADF-2 card level, i.e. at the 32 channel level. The operator may either click on the "ALL Channels" button in which case the system will readout all of the ADF-2 cards listed in List_of_DAQ_96_ADF_2_Cards i.e. it will copy List_of_DAQ_96_ADF_2_Cards to Mask_of_Cards_to_be_Read. or The operator may enter a comma separated list of ADF-2 card numbers. This list must be entered in monotonically increasing ADF-2 card number. Each entry in this list is checked to verify that it is in the List_of_DAQ_96_ADF_2_Cards and if it is then it is added to the Mask_of_Cards_to_be_Read for this run. The operator must enter at least ADF-2 Card Number 0. 5. Ask the operator whether or not they want this to be and auto-pause run. If they want an auto-pause run then set the variable Auto_Pause = 1 else set Auto_Pause = 0. 6. If this is not an auto-pause run then ask the operator if they want a prescale, that is to sleep for N seconds after taking each event before being sensitive to a new trigger. Input an integer value between 0 and 1000. 0 means no prescale sleep. Check that the value read in is in the range 0:1000. If it is then set the variable PreScale_Value equal to the read value. 7. Update a number of the system variables: Set the variable Run_Is_Underway = 1. Set the variable Event_Number = 0. Set the variable Paused_State = 0. 8. Update the status window to show that a Run is underway: Call the routine to update the status window. It will re-paint all of the following information: Run_Is_Underway, Run_Num, Event_Num, and Paused_State. 9. Call the Run_Event_Loop routine. Note: When we eventually leave the Run Event Loop we do not return to this Start_A_Run routine. We are finished with Start_A_Run and never return to it (except when called again from the main gui code). Event Loop ========== The details of the event loop are in the daq_96_definition.txt document. I believe that the Event Loop is all gui command file code. Readout an Event ================ The followings is the set of routines which do the actual work to readout and event and put its data into and Event Data File. I believe that all of this is gui command file code. Read_ADFs_into_Event_Data_File Loop_Over_ADF2_Cards Loop_Over_Channels_on_a_ADF2_Card Read_a_Channel Read_ADFs_into_Event_Data_File ------------------------------ Once it has been determined that an event is ready to be readout then this routine takes care of all of the steps to read out that event. Before calling this routine you must have determined that there is an event to readout by seeing that the ADF-2 card Address Generators have stopped. This routine needs read only access to the following variables: Directory_for_this_Run, Event_Number, Run_Number This routine needs write access to the following variable: Event_Data_File_Name This routine takes care of: generating the filename for this event's Event Data File, opening that file, and after reading out all of the ADF-2 cards used in this run then this routine closes the Event Data file. This routine needs to know the Event Number and Run Number to generate the filename for this event's Event Data File. 1. Generate the filename for the Event_Data_File for this event. This filename is based on: the Run Number, the Event Number, and the current time. Event_Data_File_Name = Run_"Run_Number"_Evt_"Event_Number"_Time_"get_system_time".txt Some how express the time without any special characters like ":" I don't want any file system to have trouble with these filenames. 2. In "Directory_for_this_Run" open the file "Event_Data_File_Name". 3. Call the routine Loop_Over_ADF2_Cards to loop over all of the ADF-2 cards that are currently in the DAQ System. 4. Close the Event_Data_File. 5. Return Loop_Over_ADF2_Cards -------------------- This routine loops over all of the ADF-2 cards in the DAQ 96 System. It selects the ADF-2 cards that are in the Mask_of_Cards_to_be_Read. For each of the ADF-2 card that is in this mask it calls the routine which reads out a given ADF-2 card. This routine needs read only access to the following variable: Mask_of_Cards_to_be_Read This routine needs write access to the following variable: ADF2_Card_Number The steps in this routine are: 1. Loop over all of the ADF-2 cards in the DAQ 96 System. For each ADF-2 card that has its ADF-2 Card Number in the Mask_of_Cards_to_be_Read call the routine Loop_Over_Channels_on_a_ADF2_Card which loops over the 32 channels on a given ADF-2 card. Skip over the ADF-2 cards that are not in the Mask_of_Cards_to_be_Read. 2. Return Loop_Over_Channels_on_a_ADF2_Card --------------------------------- This is the routine to loop over all 32 channels on a given ADF-2 card and for each channel to call the routine that reads out the event data from a given channel. This routine is called without knowledge of which ADF-2 card is being readout at this time. This routine needs write access to the following variable: Ch_Num_On_ADF2_Card The steps in this routine are: 1. Loop from Ch_Num_On_ADF2_Card = 0 through 31 For each of these Channel Numbers call the routine Read_a_Channel to readout a channel's worth of event data. 2. Return Note that this process will readout the various channels in their natural DAQ System Channel Number order. Read_a_Channel -------------- This is the routine to read out a single channel's worth of event data. This routine needs read only access to the following variables: ADF2_Card_Number, Ch_Num_On_ADF2_Card, Event_Data_File_Name This routine needs write access to the file given by the Event_Data_File_Name variable. The steps in this routine are: 1. Read the raw ADC circular buffer data from ADF2_Card_Number, Ch_Num_On_ADF2_Card into a temporary_working_file. Hst_Histogram( MasterNum = 0, SlaveNum = 0, SlotNum = SlotNum, ChipNum = Chip_Num_On_ADF2_Card, RegAddr = Buf_Start_Adrs, Samples = 2048, AddrIncr = 1, DumpToFile = 1 ) Where: SlotNum = Slot_Num_of_ADF2_Card_Num_Zero + ADF2_Card_Number Chip_Num_On_ADF2_Card = The Data Path FPGA Chip Number is defined as a function of the 0:31 Ch_Num_On_ADF2_Card variable in the constants data section at the beginning of this document. Buf_Start_Adrs = The Raw ADC Data Circular Buffer Starting Address is defined as a function of the 0:31 Ch_Num_On_ADF2_Card variable in the constants data section at the beginning of this document. 2. Write into the Event_Data_File "# Data from Channel "System_Ch_Num"" Where: System_Ch_Num = (ADF2_Card_Num * 32) + (Ch_Num_On_ADF2_Card) 3. Get the Stop_Adrs_for_this_Ch by reading the Address Generator stop address from the Data Path FPGA Chip Number for this channel. Rio_Read( MasterNum = 0, SlaveNum = 0, SlotNum = SlotNum, ChipNum = Chip_Num_On_ADF2_Card, RegAddr = 514 ) Where: SlotNum = Slot_Num_of_ADF2_Card_Num_Zero + ADF2_Card_Number Chip_Num_On_ADF2_Card = The Data Path FPGA Chip Number is defined as a function of the 0:31 Ch_Num_On_ADF2_Card variable in the constant data section at the beginning of this document. 4. From the temporary_working_file to the Event_Data_File Copy from Line_Num = Stop_Adrs_for_this_Ch + 2 through Line_Num 2048 then Copy from Line_Num = 1 through Line_Num = Stop_Adrs_for_this_Ch + 1 Notes: The line numbers in the temporary_working_file are assumed to run 1:2048 The additions above to get the line numbers, e.g. Stop_Adrs_for_this_Ch + 2 must be done MOD 2048 e.g. if the stop address is 2047 then stop_adrs + 2 equals 1. The copy into the Event_Data_File is always 4 characters with the data right justified. For example of the ADC data value is 401 then what is written on this line of the Event_Data_File is "blank space"401 5. Clean up after ourselves by Deleting the temporary_working_file from the directory where the c++ engine writes the Hst_Histogram files. 6. Return End the Current Run =================== The End_a_Run routine is called either by the operator pressing the gui button to end the run or it is called automatically when the event loop detects that 64k events have been taken. I believe that this is all gui command file code. The End_A_Run routine has the following steps: 1. Are there any work files that we need to clean up ? 2. Update some of the system variables: Set the variable Run_Is_Underway = 0. Set the variable Paused_State = 0. 3. Update the status window to show that we are no longer in a Run: Call the routine to update the status window. It will re-paint all of the following information: Run_Is_Underway, Run_Num, Event_Num, and Paused_State. This will leave the displayed Run_Num and Event_Num showing the state of the system at the end of the run that is just now ending. 4. Return Status Window Update ==================== The Status_Window_Update routine "re-paints" the Status Window based on the values of 4 system variables. Note that the Status Window Update routine must be called from other routines any time when they have made a change that the operator should know about. That is, there is no automatic or periodic update of the Status Window. This routine needs read only access to the following variables: Run_Is_Underway, Run_Number, Event_Number, Paused_State The steps in this routine are: 1. If Run_Is_Underway = 0 then write, "No Run Is Currently Underway" in the Status Window. If Run_Is_Underway = 1 then write, "Currently Run Number "Run_Number" Is Underway". 2. Use the value of Run_Number to write, "The current or just completed Run is "Run_Number"". 3. Use the value of Event_Number to write, "The number of events recorded in this run is "Event_Number"". 4. If Paused_State = 1 then write, "The DAQ 96 System Is Currently Paused". If Paused_State = 0 then write, "The DAQ 96 System Is Currently Running".