This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsbitThreshScan.py
executable file
·186 lines (139 loc) · 6.7 KB
/
sbitThreshScan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/env python
r"""
SBit Threshold
==============
FIXME Add detailed description
``sbitTHreshScanParallel.py``
=============================
Synopsis
--------
**run_scans.py** **sbitThresh** [-**h**] [--**scanmin** *SCANMIN*] [--**scanmax** *SCANMAX*] [--**stepSize** *STEPSIZE*] shelf slot ohMask
Mandatory arguments
-------------------
.. program:: run_Scans.py sbitThresh
Positional arguments
--------------------
.. option:: shelf
uTCA crate shelf number
.. option:: slot
AMC slot number in the uTCA crate
.. option:: ohMask
optohybrid mask to apply, a 1 in the n^{th} bit indicates the n^{th} OH should be considered
Optional arguments
------------------
.. option:: -h, --help
show the help message and exit
.. option:: --scanmin <SCANMIN>
Minimum ``CFG_THR_ARM_DAC``
.. option:: --scanmax <SCANMAX>
Maximum ``CFG_THR_ARM_DAC``
.. option:: --stepSize <STEPSIZE>
Step size to use when scanning ``CFG_THR_ARM_DAC``
Environment
-----------
The following `$SHELL` variables should be defined beforehand:
.. glossary::
:envvar: `BUILD_HOME`
the location of your ``vfatqc-python-scripts`` directory
:envvar: `DATA_PATH`
the location of input data
Then execute:
`source $BUILD_HOME/vfatqc-python-scripts/setup/paths.sh`
"""
if __name__ == '__main__':
"""
Script to measure sbit rate as a function of CFG_THR_ARM_DAC
By: Brian Dorney ([email protected])
Evaldas Juska ([email protected])
"""
import sys, os
from array import array
from ctypes import *
from gempython.tools.vfat_user_functions_xhal import *
# create the parser
import argparse
parser = argparse.ArgumentParser(description="For each unmasked optohybrid this script will scan the CFG_THR_ARM_DAC register for each VFAT on the optohybrid. At each DAC point it will measure the rate of SBITs being sent to the optohybrid. All links will be measured simultaneously.")
# Positional arguments
from reg_utils.reg_interface.common.reg_xml_parser import parseInt
parser.add_argument("shelf", type=int, help="uTCA shelf to access")
parser.add_argument("slot", type=int,help="slot in the uTCA of the AMC you are connceting too")
parser.add_argument("ohMask", type=parseInt, help="ohMask to apply, a 1 in the n^th bit indicates the n^th OH should be considered")
# Optional arguments
parser.add_argument("--chMin", type=int, help="Specify minimum channel number to scan", default=0)
parser.add_argument("--chMax", type=int, help="Specify maximum channel number to scan", default=127)
parser.add_argument("-d", "--debug", action="store_true", help="print extra debugging information")
parser.add_argument("-f", "--filename", type=str, help="Specify Output Filename", default="SBitRateData.root")
parser.add_argument("--perchannel", action="store_true", help="Run a per-channel sbit rate scan")
parser.add_argument("--scanmin", type=int, help="Minimum value of scan parameter", default=0)
parser.add_argument("--scanmax", type=int, help="Maximum value of scan parameter", default=255)
parser.add_argument("--stepSize", type=int, help="Supply a step size to the scan from scanmin to scanmax", default=1)
parser.add_argument("--waitTime", type=int, help="Length of the time window within which the rate is measured, in seconds",default=1)
parser.add_argument("--gemType",type=str,help="String that defines the GEM variant, available from the list: {0}".format(gemVariants.keys()),default="ge11")
parser.add_argument("--detType",type=str,
help="Detector type within gemType. If gemType is 'ge11' then this should be from list {0}; if gemType is 'ge21' then this should be from list {1}; and if type is 'me0' then this should be from the list {2}".format(gemVariants['ge11'],gemVariants['ge21'],gemVariants['me0']),default="short")
args = parser.parse_args()
from gempython.utils.gemlogger import printRed, printYellow
remainder = (args.scanmax-args.scanmin+1) % args.stepSize
if remainder != 0:
args.scanmax = args.scanmax - remainder
printYellow("Reducing scanmax to: {0}".format(args.scanmax))
if args.scanmax > 255:
printYellow("CFG_THR_ARM_DAC and CFG_THR_ZCC_DAC only go up to 0xff (255)")
printYellow("Current value %i will roll over to 0"%(args.scanmax))
printYellow("Seting scanmax to 255")
args.scanmax=255
#determine total time in hours
if args.perchannel:
totalTime=(args.scanmax-args.scanmin)*(args.chMax-args.chMin)*(1./3600.)
print("I see you've asked for a perchannel scan")
print("Right now this is done in series, are you sure you want to continue?")
print("I expect this will take: %f hours"%totalTime)
bInputUnderstood=False
performTest=raw_input("Do you want to continue? (yes/no)")
while(not bInputUnderstood):
performTest=performTest.upper()
if performTest == "NO":
print("Okay, exiting!")
print("Please run again and change the '--chMin', '--chMax', '--scanmin', and/or '--scanmax' parameters")
sys.exit(os.EX_USAGE)
elif performTest == "YES":
bInputUnderstood = True
break;
else:
performTest=raw_input("input not understood, please enter 'yes' or 'no'")
# Open rpc connection to hw
from gempython.vfatqc.utils.qcutilities import getCardName, inputOptionsValid
cardName = getCardName(args.shelf,args.slot)
from gempython.tools.vfat_user_functions_xhal import *
vfatBoard = HwVFAT(cardName, 0, args.debug, args.gemType, args.detType)
print 'opened connection'
amcBoard = vfatBoard.parentOH.parentAMC
if amcBoard.fwVersion < 3:
print("SBIT Threshold Scan of v2b electronics is not supported, exiting!!!")
exit(os.EX_USAGE)
# Check options
if not inputOptionsValid(args, amcBoard.fwVersion):
exit(os.EX_USAGE)
pass
# Make output files
import ROOT as r
outF = r.TFile(args.filename,'recreate')
from gempython.vfatqc.utils.treeStructure import gemSbitRateTreeStructure
rateTree = gemSbitRateTreeStructure(nameX="CFG_THR_ARM_DAC")
import time
rateTree.utime[0] = int(time.time())
# Scan over all channels or just a channel OR???
from gempython.vfatqc.utils.scanUtils import sbitRateScanAllLinks
if args.perchannel:
for chan in range(args.chMin,args.chMax+1):
sbitRateScanAllLinks(args,rateTree,vfatBoard,chan=chan)
pass
pass
else:
sbitRateScanAllLinks(args,rateTree,vfatBoard)
pass
outF.cd()
rateTree.autoSave("SaveSelf")
rateTree.write()
outF.Close()
print("Scan Completed. Goodbye!")