DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
timing.cli.toolbox Namespace Reference

Classes

class  InterruptHandler
 
class  IntRange
 

Functions

 get_default_clock_source (lDesign, lBoard)
 
 hookDebugger (debugger='gdb')
 
 sanitizeConnectionPaths (aConnectionPaths)
 
 completeDevices (ctx, args, incomplete)
 
 readSubNodes (aNode, dispatch=True)
 
 resetSubNodes (aNode, aValue=0x0, dispatch=True)
 
 validate_device (ctx, param, value)
 
 complete_device (ctx, args, incomplete)
 
 split (ctx, param, value)
 
 __str2int__ (value)
 
 split_ints (ctx, param, value)
 
 printRegTable (aRegs, aHeader=True, sort=True)
 
 printDictTable (aDict, aHdr=True, aSort=True, aFmtr=None)
 
 collateTables (t1, t2)
 
 escape_ansi (line)
 
 formatTStamp (aRawTStamp, clock_frequency_hz)
 
 tstamp2int (aRawTStamp)
 
 fmtEpState (aState)
 
 twos_complement (value, n_bits)
 

Variables

 kReEscapeAnsi = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
 

Function Documentation

◆ __str2int__()

timing.cli.toolbox.__str2int__ ( value)

Definition at line 191 of file toolbox.py.

191def __str2int__( value ):
192 if value.startswith('0x'):
193 base = 16
194 elif value.startswith('0o'):
195 bae = 8
196 elif value.startswith('0b'):
197 base = 2
198 else:
199 base = 10
200 return int(value, base)
201

◆ collateTables()

timing.cli.toolbox.collateTables ( t1,
t2 )

Definition at line 241 of file toolbox.py.

241def collateTables(t1, t2):
242 l1 = t1.split('\n')
243 l2 = t2.split('\n')
244
245 col1 = max([len(escape_ansi(l)) for l in l1])
246 col2 = max([len(escape_ansi(l)) for l in l2])
247
248 nrows = max(len(l1), len(l2));
249
250 l1 += [''] * (nrows - len(l1))
251 l2 += [''] * (nrows - len(l2))
252 fmt = '\'{:<%d}\' \'{:<%d}\'' % (col1, col2)
253 for c1,c2 in zip(l1, l2):
254 print (c1 + ' '*(col1-len(escape_ansi(c1))), ' ' ,c2 + ' '*(col2-len(escape_ansi(c2))))
255# ------------------------------------------------------------------------------
256
257# ------------------------------------------------------------------------------

◆ complete_device()

timing.cli.toolbox.complete_device ( ctx,
args,
incomplete )

Definition at line 176 of file toolbox.py.

176def complete_device(ctx, args, incomplete):
177 lDevices = ctx.obj.mConnectionManager.getDevices()
178
179 return [k for k in lDevices if incomplete in k]
180# -----------------
181
182# ------------------------------------------------------------------------------

◆ completeDevices()

timing.cli.toolbox.completeDevices ( ctx,
args,
incomplete )

Definition at line 113 of file toolbox.py.

113def completeDevices(ctx, args, incomplete):
114 import uhal
115 root_ctx = ctx.find_root()
116 devs = uhal.ConnectionManager(sanitizeConnectionPaths(str(root_ctx.params['connections']))).getDevices()
117 return [k for k in devs if incomplete in k]
118 # return []
119# ------------------------------------------------------------------------------
120
121
122# ------------------------------------------------------------------------------

◆ escape_ansi()

timing.cli.toolbox.escape_ansi ( line)

Definition at line 260 of file toolbox.py.

260def escape_ansi(line):
261 return kReEscapeAnsi.sub('', line)
262# ------------------------------------------------------------------------------
263
264# ------------------------------------------------------------------------------

◆ fmtEpState()

timing.cli.toolbox.fmtEpState ( aState)

Definition at line 282 of file toolbox.py.

282def fmtEpState(aState):
283 aState = aState.value()
284 return '{} ({})'.format(defs.kEpStates[aState], hex(aState)) if aState in defs.kEpStates else hex(aState)
285# ------------------------------------------------------------------------------
286
287
288# ------------------------------------------------------------------------------

◆ formatTStamp()

timing.cli.toolbox.formatTStamp ( aRawTStamp,
clock_frequency_hz )

Definition at line 265 of file toolbox.py.

265def formatTStamp( aRawTStamp, clock_frequency_hz ):
266 ts = int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
267
268 lSubSec = ts % clock_frequency_hz
269 lSecFromEpoch = ts / clock_frequency_hz
270
271 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(lSecFromEpoch))
272# ------------------------------------------------------------------------------
273
274
275# ------------------------------------------------------------------------------

◆ get_default_clock_source()

timing.cli.toolbox.get_default_clock_source ( lDesign,
lBoard )

Definition at line 13 of file toolbox.py.

13def get_default_clock_source(lDesign, lBoard):
14 lClockSource = None
15 if lDesign in [defs.kDesignMaster, defs.kDesignBoreas,
16 defs.kDesignOuroboros, defs.kDesignOuroborosSim]:
17 lClockSource = defs.kFreeRun
18 elif lDesign in [defs.kDesignEndpoint, defs.kDesignChronos,
19 defs.kDesignHades, defs.kDesignCharon]:
20 lClockSource = defs.kInput1
21 elif lDesign == defs.kDesignFanout:
22 if lBoard == defs.kBoardFIB: #technically only fib v2
23 lClockSource = defs.kInput0
24 elif lBoard == defs.kBoardPC059:
25 lClockSource = defs.kInput1
26 elif lDesign in [defs.kDesignGaia, defs.kDesignKerberos]:
27 lClockSource = defs.kInput0
28 return lClockSource
29# ------------------------------------------------------------------------------
30
31# ------------------------------------------------------------------------------

◆ hookDebugger()

timing.cli.toolbox.hookDebugger ( debugger = 'gdb')
debugging helper, hooks debugger to running interpreter process
debugging helper, hooks debugger to running interpreter process

Definition at line 32 of file toolbox.py.

32def hookDebugger(debugger='gdb'):
33 '''debugging helper, hooks debugger to running interpreter process'''
34
35 import os
36 pid = os.spawnvp(os.P_NOWAIT,
37 debugger, [debugger, '-q', 'python', str(os.getpid())])
38
39 # give debugger some time to attach to the python process
40 import time
41 time.sleep( 1 )
42
43 # verify the process' existence (will raise OSError if failed)
44 os.waitpid( pid, os.WNOHANG )
45 os.kill( pid, 0 )
46 return
47# ------------------------------------------------------------------------------
48
49# ------------------------------------------------------------------------------

◆ printDictTable()

timing.cli.toolbox.printDictTable ( aDict,
aHdr = True,
aSort = True,
aFmtr = None )

Definition at line 235 of file toolbox.py.

235def printDictTable(aDict, aHdr=True, aSort=True, aFmtr=None):
236 echo ( formatDictTable(aDict, aHdr, aSort, aFmtr) )
237# ------------------------------------------------------------------------------
238
239
240# ------------------------------------------------------------------------------

◆ printRegTable()

timing.cli.toolbox.printRegTable ( aRegs,
aHeader = True,
sort = True )

Definition at line 230 of file toolbox.py.

230def printRegTable(aRegs, aHeader=True, sort=True):
231 echo ( format_reg_table(aRegs, aHeader, sort) )
232# ------------------------------------------------------------------------------
233
234# ------------------------------------------------------------------------------

◆ readSubNodes()

timing.cli.toolbox.readSubNodes ( aNode,
dispatch = True )

Definition at line 123 of file toolbox.py.

123def readSubNodes(aNode, dispatch=True):
124 lValues = { n:aNode.getNode(n).read() for n in aNode.getNodes() }
125
126 if dispatch:
127 aNode.getClient().dispatch()
128 return lValues
129# ------------------------------------------------------------------------------
130
131
132# ------------------------------------------------------------------------------

◆ resetSubNodes()

timing.cli.toolbox.resetSubNodes ( aNode,
aValue = 0x0,
dispatch = True )
Reset subnodes of aNode to aValue

Definition at line 133 of file toolbox.py.

133def resetSubNodes(aNode, aValue=0x0, dispatch=True):
134 """
135 Reset subnodes of aNode to aValue
136 """
137 lValues = { n:aNode.getNode(n).write(aValue) for n in aNode.getNodes() }
138 if dispatch:
139 aNode.getClient().dispatch()
140# ------------------------------------------------------------------------------
141
142# ------------------------------------------------------------------------------

◆ sanitizeConnectionPaths()

timing.cli.toolbox.sanitizeConnectionPaths ( aConnectionPaths)

Definition at line 103 of file toolbox.py.

103def sanitizeConnectionPaths(aConnectionPaths):
104
105 lConnectionList = aConnectionPaths.split(';')
106 for i,c in enumerate(lConnectionList):
107 if re.match('^\w+://.*', c) is None:
108 lConnectionList[i] = 'file://'+c
109 return ';'.join(lConnectionList)
110# ------------------------------------------------------------------------------
111
112# ------------------------------------------------------------------------------

◆ split()

timing.cli.toolbox.split ( ctx,
param,
value )

Definition at line 183 of file toolbox.py.

183def split(ctx, param, value):
184 if value is None:
185 return []
186
187 return value.split(',')
188# ------------------------------------------------------------------------------
189
190# ------------------------------------------------------------------------------

◆ split_ints()

timing.cli.toolbox.split_ints ( ctx,
param,
value )

Definition at line 202 of file toolbox.py.

202def split_ints(ctx, param, value):
203
204 sep = ','
205 dash = '-'
206
207 if value is None:
208 return []
209
210 numbers = []
211 for item in value.split(sep):
212 nums = item.split(dash)
213 if len(nums) == 1:
214 # single entry
215 numbers.append(__str2int__(item))
216 elif len(nums) == 2:
217 # range
218 i, j = __str2int__(nums[0]), __str2int__(nums[1])
219 if i > j:
220 click.ClickException('Invalid interval '+item)
221 numbers.extend(list(range(i,j+1)))
222 else:
223 click.ClickException('Malformed option (comma separated list expected): {}'.format(value))
224
225 return numbers
226# ------------------------------------------------------------------------------
227
228
229# ------------------------------------------------------------------------------

◆ tstamp2int()

timing.cli.toolbox.tstamp2int ( aRawTStamp)

Definition at line 276 of file toolbox.py.

276def tstamp2int( aRawTStamp ):
277 return int(aRawTStamp[0]) + int((aRawTStamp[1]) << 32)
278# ------------------------------------------------------------------------------
279
280
281# ------------------------------------------------------------------------------

◆ twos_complement()

timing.cli.toolbox.twos_complement ( value,
n_bits )

Definition at line 325 of file toolbox.py.

325def twos_complement(value, n_bits):
326 if (value & (1 << (n_bits - 1))) != 0:
327 value = value - (1 << n_bits)
328 return value
329# ------------------------------------------------------------------------------

◆ validate_device()

timing.cli.toolbox.validate_device ( ctx,
param,
value )

Definition at line 163 of file toolbox.py.

163def validate_device(ctx, param, value):
164
165 lDevices = ctx.obj.mConnectionManager.getDevices()
166 if value not in lDevices:
167 raise click.BadParameter(
168 'Device must be one of '+
169 ', '.join(["'"+lId+"'" for lId in lDevices])
170 )
171 return value
172# -----------------
173
174
175# -----------------

Variable Documentation

◆ kReEscapeAnsi

timing.cli.toolbox.kReEscapeAnsi = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')

Definition at line 258 of file toolbox.py.