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 pathdacScanV3.py
executable file
·181 lines (139 loc) · 6.68 KB
/
dacScanV3.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
#!/bin/env python
r"""
Dac Scan
========
Performs a VFAT3 DAC scan on all unmasked optohybrids. Measures the correspondence between DAC units
and physical values (in fC, uA, or V depending on the register of interest).
``dacScanV3.py``
================
Synopsis
--------
**run_scans.py** **dacScanV3** [-**h**] [--**dacSelect** *DACSELECT*] [-**e**] shelf slot ohMask
Mandatory arguments
-------------------
.. program:: run_Scans.py dacScanV3
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:: --dacSelect <DACSELECT>
DAC Selection, see `The VFAT3 Manual <https://espace.cern.ch/cms-project-GEMElectronics/VFAT3/Forms/AllItems.aspx>`_
.. option:: -e, --extRefADC
Use the externally referenced ADC on the VFAT3
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`
"""
from gempython.tools.hw_constants import maxVfat3DACSize
import os
if __name__ == '__main__':
"""
Script to perform DAC scans with VFAT3
By: Brian Dorney ([email protected])
"""
# create the parser
import argparse
parser = argparse.ArgumentParser(description="Scans a given DAC on a VFAT3 against the chip's ADC. Either the internally or externally referenced ADC can be used. Scans all VFATs on a given link 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", metavar="ohMask")
# Optional arguments
from gempython.tools.hw_constants import gemVariants
parser.add_argument("-d","--debug", action="store_true", dest="debug",
help = "Print additional debugging information")
parser.add_argument("--dacSelect", type=int, dest="dacSelect",
help = "DAC Selection", default=None)
parser.add_argument("-e","--extRefADC", action="store_true", dest="extRefADC",
help = "Use the externally referenced ADC on the VFAT3.")
parser.add_argument("-f","--filename",type=str,dest="filename",default="dacScanV3.root",
help = "Specify output filename to store data in.")
parser.add_argument("--series", action="store_true", dest="series",
help = "Scan nonzero links in ohMask in series (successive RPC calls) instead of in parallel (one RPC call)")
parser.add_argument("--stepSize", type=int, dest="stepSize",default=1,
help="Supply a step size for the scan")
parser.add_argument("-v","--vfatmask",type=parseInt,dest="vfatmask",default=None,
help="VFATs to be masked in scan & analysis applications (e.g. 0xFFFFF masks all VFATs)")
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=None)
args = parser.parse_args()
from gempython.utils.gemlogger import printRed
if ((args.dacSelect not in maxVfat3DACSize.keys()) and (args.dacSelect is not None)):
printRed("Input DAC selection {0} not understood".format(args.dacSelect))
printRed("possible options include:")
from gempython.vfatqc.utils.qcutilities import printDACOptions
printDACOptions()
exit(os.EX_USAGE)
# 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) # Assign link 0; we will update later
print 'opened connection'
amcBoard = vfatBoard.parentOH.parentAMC
if amcBoard.fwVersion < 3:
printRed("DAC 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.scanUtils import dacScanAllLinks, dacScanSingleLink
from gempython.vfatqc.utils.treeStructure import gemDacCalTreeStructure
calTree = gemDacCalTreeStructure(
name="dacScanTree",
nameX="dummy", # temporary name, will be over-ridden
nameY=("ADC1" if args.extRefADC else "ADC0"),
dacSelect=-1, #temporary value, will be over-ridden
description="GEM DAC Calibration of VFAT3 DAC"
)
if args.dacSelect is None: # No DAC selected; scan them all
for dacSelect in maxVfat3DACSize.keys():
args.dacSelect = dacSelect
if args.series:
for ohN in range(0, amcBoard.nOHs):
if( not ((args.ohMask >> ohN) & 0x1)):
continue
# update the OH in question
vfatBoard.parentOH.link = ohN
dacScanSingleLink(args, calTree, vfatBoard)
pass
pass
else:
dacScanAllLinks(args, calTree, vfatBoard)
else: # Specific DAC Requested; scan only this DAC
if args.series:
for ohN in range(0, amcBoard.nOHs):
if( not ((args.ohMask >> ohN) & 0x1)):
continue
# update the OH in question
vfatBoard.parentOH.link = ohN
dacScanSingleLink(args, calTree, vfatBoard)
pass
pass
else:
dacScanAllLinks(args, calTree, vfatBoard)
outF.cd()
calTree.autoSave("SaveSelf")
calTree.write()
outF.Close()
print("All DAC Scans Completed. Goodbye")