DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
afc.toolbox.IntRange Class Reference
Inheritance diagram for afc.toolbox.IntRange:
[legend]
Collaboration diagram for afc.toolbox.IntRange:
[legend]

Public Member Functions

 __init__ (self, min=None, max=None, clamp=False)
 
 convert (self, value, param, ctx)
 
 __repr__ (self)
 

Public Attributes

 min = min
 
 max = max
 
 clamp = clamp
 

Static Public Attributes

str name = 'integer range'
 

Detailed Description

A parameter that works similar to :data:`click.INT` but restricts
the value to fit into a range.  The default behavior is to fail if the
value falls outside the range, but it can also be silently clamped
between the two edges.

See :ref:`ranges` for an example.

Definition at line 8 of file toolbox.py.

Constructor & Destructor Documentation

◆ __init__()

afc.toolbox.IntRange.__init__ ( self,
min = None,
max = None,
clamp = False )

Definition at line 18 of file toolbox.py.

18 def __init__(self, min=None, max=None, clamp=False):
19 self.min = min
20 self.max = max
21 self.clamp = clamp
22

Member Function Documentation

◆ __repr__()

afc.toolbox.IntRange.__repr__ ( self)

Definition at line 55 of file toolbox.py.

55 def __repr__(self):
56 return 'IntRange(%r, %r)' % (self.min, self.max)
57# ------------------------------------------------------------------------------
58
59# ------------------------------------------------------------------------------

◆ convert()

afc.toolbox.IntRange.convert ( self,
value,
param,
ctx )

Definition at line 23 of file toolbox.py.

23 def convert(self, value, param, ctx):
24
25 if type(value) == str:
26 if value.startswith('0x'):
27 base = 16
28 elif value.startswith('0o'):
29 bae = 8
30 elif value.startswith('0b'):
31 base = 2
32 else:
33 base = 10
34 rv = int(value, base)
35 else:
36 rv = int(value)
37 if self.clamp:
38 if self.min is not None and rv < self.min:
39 return self.min
40 if self.max is not None and rv > self.max:
41 return self.max
42 if self.min is not None and rv < self.min or \
43 self.max is not None and rv > self.max:
44 if self.min is None:
45 self.fail('%s is bigger than the maximum valid value '
46 '%s.' % (rv, self.max), param, ctx)
47 elif self.max is None:
48 self.fail('%s is smaller than the minimum valid value '
49 '%s.' % (rv, self.min), param, ctx)
50 else:
51 self.fail('%s is not in the valid range of %s to %s.'
52 % (rv, self.min, self.max), param, ctx)
53 return rv
54

Member Data Documentation

◆ clamp

afc.toolbox.IntRange.clamp = clamp

Definition at line 21 of file toolbox.py.

◆ max

afc.toolbox.IntRange.max = max

Definition at line 20 of file toolbox.py.

◆ min

afc.toolbox.IntRange.min = min

Definition at line 19 of file toolbox.py.

◆ name

str afc.toolbox.IntRange.name = 'integer range'
static

Definition at line 16 of file toolbox.py.


The documentation for this class was generated from the following file: