code: def get_suitable_slot_for_reference(self, reference):
          
          if not IReferenceSample.providedBy(reference):
              return -1
  
          occupied = self.get_slot_positions(type='all') or [0]
          wst = self.getWorksheetTemplate()
          if not wst:
              # No worksheet template assigned, add a new slot at the end of the
              # worksheet with the reference analyses there
              slot_to = max(occupied) + 1
              return slot_to
  
          # If there is a match with the layout defined in the Worksheet Template,
          # use that slot instead of adding a new one at the end of the worksheet
          slot_type = reference.getBlank() and 'b' or 'c'
          layout = wst.getLayout()
  
          for pos in layout:
              if pos['type'] != slot_type:
                  continue
              slot_to = int(pos['pos'])
              if slot_to in occupied:
                  # Not an empty slot
                  continue
  
              # This slot is empty, use it instead of adding a new slot at the end
              # of the worksheet
              return slot_to
  
          # Add a new slot at the end of the worksheet, but take into account
          # that a worksheet template is assigned, so we need to take care to
          # not override slots defined by its layout
          occupied.append(len(layout))
          slot_to = max(occupied) + 1
          return slot_to
docs: Returns the suitable position for reference analyses, taking into
          account if there is a WorksheetTemplate assigned to this worksheet.
  
          By default, returns a new slot at the end of the worksheet unless there
          is a slot defined for a reference of the same type (blank or control)
          in the worksheet template's layout that hasn't been used yet.
  
          :param reference: ReferenceSample the analyses will be created from
          :return: suitable slot position for reference analyses