Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:18

0001 #!/usr/bin/env python
0002 # Licensed under the Apache License, Version 2.0 (the "License");
0003 # you may not use this file except in compliance with the License.
0004 # You may obtain a copy of the License at
0005 # http://www.apache.org/licenses/LICENSE-2.0
0006 #
0007 # Authors:
0008 # - Paul Nilsson, paul.nilsson@cern.ch, 2017-2019
0009 
0010 # This module contains functions that are used with the get_parameters() function defined in the information module.
0011 
0012 # WARNING: IN GENERAL, NEEDS TO USE PLUG-IN MANAGER
0013 
0014 from pilot.info import infosys
0015 
0016 import logging
0017 logger = logging.getLogger(__name__)
0018 
0019 
0020 def get_maximum_input_sizes():
0021     """
0022     This function returns the maximum allowed size for all input files. The sum of all input file sizes should not
0023     exceed this value.
0024 
0025     :return: maxinputsizes (integer value in MB).
0026     """
0027 
0028     try:
0029         _maxinputsizes = infosys.queuedata.maxwdir  # normally 14336+2000 MB
0030     except TypeError as e:
0031         from pilot.util.config import config
0032         _maxinputsizes = config.Pilot.maximum_input_file_sizes  # MB
0033         logger.warning('could not convert schedconfig value for maxwdir: %s (will use default value instead - %s)' %
0034                        (e, _maxinputsizes))
0035 
0036         if type(_maxinputsizes) == str and ' MB' in _maxinputsizes:
0037             _maxinputsizes = _maxinputsizes.replace(' MB', '')
0038 
0039     try:
0040         _maxinputsizes = int(_maxinputsizes)
0041     except Exception as e:
0042         _maxinputsizes = 14336 + 2000
0043         logger.warning('failed to convert maxinputsizes to int: %s (using value: %d MB)' % (e, _maxinputsizes))
0044 
0045     return _maxinputsizes
0046 
0047 
0048 def convert_to_int(parameter, default=None):
0049     """
0050     Try to convert a given parameter to an integer value.
0051     The default parameter can be used to force the function to always return a given value in case the integer
0052     conversion, int(parameter), fails.
0053 
0054     :param parameter: parameter (any type).
0055     :param default: None by default (if set, always return an integer; the given value will be returned if
0056     conversion to integer fails).
0057     :return: converted integer.
0058     """
0059 
0060     try:
0061         value = int(parameter)
0062     except Exception:  # can be ValueError or TypeValue (for None)
0063         value = default
0064 
0065     return value