Functions | Variables
APDHVSetting_M150 Namespace Reference

Functions

def settings (apddict, filesuffix)
 

Variables

 pswdloc = os.environ['NOVADBPWDFILE']
 
 pswdfile = open(pswdloc, "r")
 
 pswd = pswdfile.read()
 
string SQL = "dbname=nova_hardware host=ifdbprod.fnal.gov user=nova_reader password={} port=5432"
 
 parser = argparse.ArgumentParser()
 
 help
 
 action
 
 default
 
 args = parser.parse_args()
 
 useSafeMode = args.safe
 
string dcm = "all"
 
 connFL = psycopg2.connect(SQL)
 
 connAR = psycopg2.connect(SQL)
 
 curFL = connFL.cursor()
 
 curAR = connAR.cursor()
 
string debugName = "debuginfo.txt"
 
 debugFile = open(debugName, "w")
 
string dummy = 'dummyhw'
 
 nonFDHW = dict(dummy = (dummy, dummy))
 
 rows = curFL.fetchall()
 
 hw_type = str(row[1])
 
 chars = len(row[0])
 
 sn = row[0][chars-7:]
 
 feb = str(row[0])
 
 febsn1 = feb.replace('_', '.')
 
 febinfo = dict(dummy = (-999., -999.))
 
 febsn = febsn1.replace('-', '.')
 
 apdStatsLowT = dict(dummy = (-999, -999, 999.) )
 
 apdStatsHighT = dict(dummy = (-999, 999, 999.) )
 
 apd = row[0][chars-7:]
 
 batch = row[1]
 
 temp = row[2]
 
 vr = row[3]
 
tuple stats = (batch, temp, vr)
 
 prevStats = apdStatsHighT.get(apd)
 
 prevBatch = prevStats[0]
 
 now = time.localtime()
 
 apdToFEBLowT = dict(dummy = ((-999, -999, 999., -999, now), ('stupidfeb', -999, now, -999., -999), -999))
 
 apdToFEBHighT = dict(dummy = ((-999, -999, 999., -999, now), ('stupidfeb', -999, now, -999., -999), -999))
 
 apdrows = curAR.fetchall()
 
 apdrowdict = dict()
 
 febrows = curAR.fetchall()
 
 febrowdict = dict()
 
 bcid = row[0]
 
 apdadded = row[2]
 
 apdcon = apdrowdict[bcid]
 
 mod = apdcon[0]
 
 modcon = apdcon[1]
 
 febcon = febrowdict[mod]
 
 added = febcon[3]
 
 febmb = febinfo.get(febsn)
 
tuple febdata = (febsn, febcon[1], added, febmb[0], febmb[1])
 
 apdstats = apdStatsLowT.get(apd)
 
tuple apdinfo = (apdstats[0], apdstats[1], apdstats[2], bcid, apdadded)
 

Function Documentation

def APDHVSetting_M150.settings (   apddict,
  filesuffix 
)

Definition at line 13 of file APDHVSetting_M150.py.

References novadaq::HexUtils.format(), if(), open(), and stan::math.round().

13 def settings(apddict, filesuffix) :
14 
15  fileName = "hv_"+filesuffix+"_m150.csv"
16  if(useSafeMode) :
17  fileName = "hv_Safe"+filesuffix+".csv"
18  settingFile = open(fileName, "w")
19  fileName = "apd_installation.txt"
20  locFile = open(fileName, "w")
21 
22  default = '1,default,-1,cold,1000.0,0,1,2,3,4\n'
23  scaleFactor = 1.*1.02
24 
25  # according to Leon M, warm voltages should be 0.976 the value recorded because we
26  # operate at 15C, not the warm test value of 25C
27  if(filesuffix == "HighT") :
28  default = '1,default,-1,warm,2000.0,0,1,2,3,4\n'
29  scaleFactor = 0.976*1.02
30 
31  # put in the default line
32  settingFile.write(default)
33 
34  # make a dictionary of apd to location on the detector
35  # additional information is diblock, dcm, febport, then voltage
36  keyval = 'dcm-2-999-999-999'
37  locationToAPD = dict( keyval = ( 'stupidapd', (-999, -999, 999., -999, now), ('stupidfeb', -999, now, -999., -999), -999, (-999, -999, -999), -999.))
38 
39  #Query without a specific APD, only the module.barcoded_item_id to get blk,pln,pos in layer, and use feb_comm_cable table to join with diblk,dcmpos,port
40  print "Query without APD at ",time.localtime()
41  SQL = "select CAST(btrim(fcom.location1, 'DIBLK:') AS INT) diblk, CAST(btrim(fcom.position1, 'DCM:') AS INT) dcm , CAST(btrim(fcom.port1,'PRT:') AS INT) feb, CAST(btrim(fcom.location2,'BLK:') AS INT) blk, CAST(btrim(fcom.position2,'PLN:') AS INT) pln, CAST(btrim(fcom.port2,'POS:') AS INT) pos, mod.barcoded_item_id modid from fnalprod_public.feb_comm_cables fcom, module as mod where mod.block=CAST(btrim(fcom.location2,'BLK:') AS INT) and mod.layer= CAST(btrim(fcom.position2,'PLN:') AS INT) and mod.position_in_layer=CAST(btrim(fcom.port2,'POS:') AS INT)"
42  curAR.execute(SQL)
43  alllocs = curAR.fetchall()
44  #print " alllocs length = ",len(alllocs)
45  print "Done with query at ",time.localtime()
46  # make dictionary of locations
47  modlocations = dict() #(diblk,dcmpos,port,blk,pln,pos) use modid as index
48  for loc in alllocs:
49  modid = loc[6]
50  #print modid
51  modlocations[modid] = (loc[0],loc[1],loc[2],loc[3],loc[4],loc[5])
52  #print "made modlocations dictionary",time.localtime()
53 
54  # loop over the apds
55  for apd in apddict.iterkeys():
56  data = apddict.get(apd)
57  #print data
58  apdinfo = data[0] #(batch,Temp,V_r,barcode_ID,date)
59  febdata = data[1] #(feb_sn,barcode_id,date,intercept,slope)
60  mod = data[2] #(module barcode_ID)
61  #print mod,apdinfo[3] #Module barcode_ID,APD_barcode_ID
62  #print ("Matching {} and {} ".format(mod,apdinfo[3]))
63  if(apdinfo[0] == -999) : continue
64  loc = modlocations[mod] # get module placement from modlocations dictionary (diblk,dcmpos,port,blk,pln,pos) uses module id as index
65  #print loc
66  location = (loc[0], loc[1], loc[2])
67  keyval = "dcm-2-{}-{}-{}".format(loc[0], loc[1], loc[2])
68 
69  # have all the pieces we need now
70  # - apd voltage and location in apdinfo
71  # - feb to apd connection in febtoapd
72  # - feb voltage slope and intercept, remember abscisa is 4095 steps
73  # find nearest integer to (apdinfo[2] - febdata[3])/febdata[4]
74  # 1,<dcmName>,<febId>,<coolingState>,<voltage>,2,0,0,0,0
75  intercept = febdata[3]
76  slope = febdata[4]
77  if slope == 0. :
78  slope = 0.02586
79 
80  #voltage = (desiredV - intercept)/slope # yields the DAC setting
81  voltage = (scaleFactor*apdinfo[2] - intercept)/slope
82  if(useSafeMode) :
83  voltage = (apdinfo[2] - 30 - intercept)/slope
84 
85  # test the voltage setting
86  if apdinfo[1] > 0 and (voltage < 2500 or voltage > 4094) :
87  #print "Setting for loc: {} with APD: {} at temp {} is out of range {}".format(keyval, apd, apdinfo[1], voltage)
88  if voltage > 4094: voltage = 4094
89  elif voltage < 2500: voltage = 2500
90  elif apdinfo[1] < 0 and (voltage < 1000 or voltage > 4000) :
91  #print "Setting for loc: {} with APD: {} at temp {} is out of range {}".format(keyval, apd, apdinfo[1], voltage)
92  if voltage > 4094: voltage = 4094
93  elif voltage < 1000: voltage = 1000
94 
95  # check to see if the electronics location has already been used. If not, then
96  # insert it into the dictionary. If it has been used, then make sure the most
97  # recent entry is in the dictionary
98  if keyval not in locationToAPD :
99  locationToAPD[keyval] = (apd, apdinfo, febdata, mod, location, voltage)
100  else :
101  data = locationToAPD.get(keyval)
102  prevAPD = data[0]
103  prevAPDInfo = data[1]
104  prevFEB = data[2]
105  debugFile.write("dcm-2-{}-{} port {} assigned twice: \n".format(location[0], location[1], location[2]))
106  debugFile.write("\t Currently assigned APD: {} {} {}\n".format(prevAPD, prevAPDInfo, prevFEB))
107  debugFile.write("\t Alternate assigned APD: {} {} {}\n".format(apd, apdinfo, febdata))
108  if apdinfo[4] > prevAPDInfo[4] :
109  locationToAPD[keyval] = (apd, apdinfo, febdata, mod, location, voltage)
110  debugFile.write("\t\t Using APD: {} {} {}\n".format(apd, apdinfo, febdata))
111  else :
112  debugFile.write("\t\t Using APD: {} {} {}\n".format(prevAPD, prevAPDInfo, prevFEB))
113 
114  # loop over all electronics locations in the dictionary and
115  # and write them out to the file. Also write out the location used
116  # and the relevant information about the APD installed there
117  for keyval in locationToAPD :
118 
119  data = locationToAPD.get(keyval)
120  apd = data[0]
121  apdinfo = data[1]
122  febdata = data[2]
123  mod = data[3]
124  location = data[4]
125  voltage = data[5]
126 
127  if location[0] == -999 : continue
128 
129  diblock = '{}'.format(location[0])
130  if location[0] < 10 : diblock = '0{}'.format(location[0])
131  dcmposition = '{}'.format(location[1])
132  if location[1] < 10 : dcmposition = '0{}'.format(location[1])
133  temp = "warm"
134  if apdinfo[1] < 0 : temp = "cold"
135 
136  dcmloc = 'dcm-2-{}-{}'.format(diblock, dcmposition)
137 
138  #if dcm in dcmloc : # just write everything, you did all the work already.
139  settingInfo = '1,{},{},{},{},2,0,0,0,0\n'.format(dcmloc, location[2], temp, round(voltage) )
140  locInfo = '{},{},{},{}\n'.format(dcmloc, location[2], apd, apdinfo[4])
141  settingFile.write(settingInfo)
142  locFile.write(locInfo)
143 
144  # close the files.
145  settingFile.close()
146  locFile.close()
147 
148 
149 #read in the password for the db
fvar< T > round(const fvar< T > &x)
Definition: round.hpp:23
if(dump)
def settings(apddict, filesuffix)
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
procfile open("FD_BRL_v0.txt")

Variable Documentation

APDHVSetting_M150.action

Definition at line 158 of file APDHVSetting_M150.py.

APDHVSetting_M150.added = febcon[3]

Definition at line 368 of file APDHVSetting_M150.py.

APDHVSetting_M150.apd = row[0][chars-7:]

Definition at line 251 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdadded = row[2]

Definition at line 313 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdcon = apdrowdict[bcid]

Definition at line 336 of file APDHVSetting_M150.py.

tuple APDHVSetting_M150.apdinfo = (apdstats[0], apdstats[1], apdstats[2], bcid, apdadded)

Definition at line 400 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdrowdict = dict()

Definition at line 294 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdrows = curAR.fetchall()

Definition at line 293 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdstats = apdStatsLowT.get(apd)

Definition at line 399 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdStatsHighT = dict(dummy = (-999, 999, 999.) )

Definition at line 245 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdStatsLowT = dict(dummy = (-999, -999, 999.) )

Definition at line 244 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdToFEBHighT = dict(dummy = ((-999, -999, 999., -999, now), ('stupidfeb', -999, now, -999., -999), -999))

Definition at line 286 of file APDHVSetting_M150.py.

APDHVSetting_M150.apdToFEBLowT = dict(dummy = ((-999, -999, 999., -999, now), ('stupidfeb', -999, now, -999., -999), -999))

Definition at line 285 of file APDHVSetting_M150.py.

APDHVSetting_M150.args = parser.parse_args()

Definition at line 160 of file APDHVSetting_M150.py.

APDHVSetting_M150.batch = row[1]

Definition at line 252 of file APDHVSetting_M150.py.

APDHVSetting_M150.bcid = row[0]

Definition at line 312 of file APDHVSetting_M150.py.

APDHVSetting_M150.chars = len(row[0])

Definition at line 207 of file APDHVSetting_M150.py.

APDHVSetting_M150.connAR = psycopg2.connect(SQL)

Definition at line 177 of file APDHVSetting_M150.py.

APDHVSetting_M150.connFL = psycopg2.connect(SQL)

Definition at line 171 of file APDHVSetting_M150.py.

APDHVSetting_M150.curAR = connAR.cursor()

Definition at line 183 of file APDHVSetting_M150.py.

APDHVSetting_M150.curFL = connFL.cursor()

Definition at line 182 of file APDHVSetting_M150.py.

string APDHVSetting_M150.dcm = "all"

Definition at line 162 of file APDHVSetting_M150.py.

APDHVSetting_M150.debugFile = open(debugName, "w")

Definition at line 194 of file APDHVSetting_M150.py.

string APDHVSetting_M150.debugName = "debuginfo.txt"

Definition at line 193 of file APDHVSetting_M150.py.

APDHVSetting_M150.default

Definition at line 159 of file APDHVSetting_M150.py.

string APDHVSetting_M150.dummy = 'dummyhw'

Definition at line 198 of file APDHVSetting_M150.py.

APDHVSetting_M150.feb = str(row[0])

Definition at line 210 of file APDHVSetting_M150.py.

APDHVSetting_M150.febcon = febrowdict[mod]

Definition at line 365 of file APDHVSetting_M150.py.

tuple APDHVSetting_M150.febdata = (febsn, febcon[1], added, febmb[0], febmb[1])

Definition at line 387 of file APDHVSetting_M150.py.

APDHVSetting_M150.febinfo = dict(dummy = (-999., -999.))

Definition at line 219 of file APDHVSetting_M150.py.

APDHVSetting_M150.febmb = febinfo.get(febsn)

Definition at line 386 of file APDHVSetting_M150.py.

APDHVSetting_M150.febrowdict = dict()

Definition at line 303 of file APDHVSetting_M150.py.

APDHVSetting_M150.febrows = curAR.fetchall()

Definition at line 302 of file APDHVSetting_M150.py.

APDHVSetting_M150.febsn = febsn1.replace('-', '.')

Definition at line 230 of file APDHVSetting_M150.py.

APDHVSetting_M150.febsn1 = feb.replace('_', '.')

Definition at line 211 of file APDHVSetting_M150.py.

APDHVSetting_M150.help

Definition at line 158 of file APDHVSetting_M150.py.

APDHVSetting_M150.hw_type = str(row[1])

Definition at line 205 of file APDHVSetting_M150.py.

APDHVSetting_M150.mod = apdcon[0]

Definition at line 337 of file APDHVSetting_M150.py.

APDHVSetting_M150.modcon = apdcon[1]

Definition at line 338 of file APDHVSetting_M150.py.

APDHVSetting_M150.nonFDHW = dict(dummy = (dummy, dummy))

Definition at line 199 of file APDHVSetting_M150.py.

APDHVSetting_M150.now = time.localtime()

Definition at line 283 of file APDHVSetting_M150.py.

APDHVSetting_M150.parser = argparse.ArgumentParser()

Definition at line 157 of file APDHVSetting_M150.py.

APDHVSetting_M150.prevBatch = prevStats[0]

Definition at line 265 of file APDHVSetting_M150.py.

APDHVSetting_M150.prevStats = apdStatsHighT.get(apd)

Definition at line 264 of file APDHVSetting_M150.py.

APDHVSetting_M150.pswd = pswdfile.read()

Definition at line 152 of file APDHVSetting_M150.py.

APDHVSetting_M150.pswdfile = open(pswdloc, "r")

Definition at line 151 of file APDHVSetting_M150.py.

APDHVSetting_M150.pswdloc = os.environ['NOVADBPWDFILE']

Definition at line 150 of file APDHVSetting_M150.py.

APDHVSetting_M150.rows = curFL.fetchall()

Definition at line 203 of file APDHVSetting_M150.py.

APDHVSetting_M150.sn = row[0][chars-7:]

Definition at line 208 of file APDHVSetting_M150.py.

string APDHVSetting_M150.SQL = "dbname=nova_hardware host=ifdbprod.fnal.gov user=nova_reader password={} port=5432"

Definition at line 154 of file APDHVSetting_M150.py.

tuple APDHVSetting_M150.stats = (batch, temp, vr)

Definition at line 255 of file APDHVSetting_M150.py.

APDHVSetting_M150.temp = row[2]

Definition at line 253 of file APDHVSetting_M150.py.

APDHVSetting_M150.useSafeMode = args.safe

Definition at line 161 of file APDHVSetting_M150.py.

APDHVSetting_M150.vr = row[3]

Definition at line 254 of file APDHVSetting_M150.py.