ATLAS Offline Software
Loading...
Searching...
No Matches
TileDCSDataInfo.py
Go to the documentation of this file.
1# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2# Author: nils.gollub@cern.ch
3
4
5import os
6
8 """
9 Keeps a list of drawer, variable <---> folder, channel
10 associations and provides information about the available
11 variables and their datatypes.
12 """
13
14 LVPS_AI = ("/TILE/DCS/", "AI")
15 LVPS_STATES = ("/TILE/DCS/", "STATES")
16 VARS_HV = ("/TILE/DCS/", "HV")
17 VARS_HVSET = ("/TILE/DCS/", "HVSET")
18 VARS_DAQ = ("/DAQdummy/","/DAQdummy")
19 type_float = ('f','/F')
20 type_int = ('i','/I')
21
22 vars_LVPS_STATES = {"FORDAQ_MB" : [ LVPS_STATES, type_int],
23 "FORDAQ_HV" : [ LVPS_STATES, type_int],
24 "FORDAQ_MBHV" : [ LVPS_STATES, type_int]}
25
26 vars_LVPS_AI = {"15VMB_OUTPUT_I" : [ LVPS_AI, type_float],
27 "M5VMB_TEMP2" : [ LVPS_AI, type_float],
28 "M5VMB_SENSES" : [ LVPS_AI, type_float],
29 "M5VMB_OUTPUT_V" : [ LVPS_AI, type_float],
30 "M5VMB_OUTPUT_I" : [ LVPS_AI, type_float],
31 "M5VMB_INPUT_V" : [ LVPS_AI, type_float],
32 "15VHV_INPUT_V" : [ LVPS_AI, type_float],
33 "M15VHV_TEMP3" : [ LVPS_AI, type_float],
34 "M15VHV_TEMP2" : [ LVPS_AI, type_float],
35 "15VHV_OUTPUT_I" : [ LVPS_AI, type_float],
36 "M15VHV_OUTPUT_V" : [ LVPS_AI, type_float],
37 "M15VHV_OUTPUT_I" : [ LVPS_AI, type_float],
38 "M15VHV_INPUT_V" : [ LVPS_AI, type_float],
39 "15VHV_OUTPUT_V" : [ LVPS_AI, type_float],
40 "EXT_TEMP2" : [ LVPS_AI, type_float],
41 "15VMB_TEMP3" : [ LVPS_AI, type_float],
42 "3VDIG_INPUT_V" : [ LVPS_AI, type_float],
43 "3VDIG_OUTPUT_I" : [ LVPS_AI, type_float],
44 "3VDIG_OUTPUT_V" : [ LVPS_AI, type_float],
45 "3VDIG_SENSES" : [ LVPS_AI, type_float],
46 "15VMB_TEMP2" : [ LVPS_AI, type_float],
47 "3VDIG_TEMP2" : [ LVPS_AI, type_float],
48 "3VDIG_TEMP3" : [ LVPS_AI, type_float],
49 "15VMB_SENSES" : [ LVPS_AI, type_float],
50 "5VDIG_INPUT_V" : [ LVPS_AI, type_float],
51 "5VDIG_OUTPUT_I" : [ LVPS_AI, type_float],
52 "5VDIG_OUTPUT_V" : [ LVPS_AI, type_float],
53 "5VDIG_SENSES" : [ LVPS_AI, type_float],
54 "15VMB_OUTPUT_V" : [ LVPS_AI, type_float],
55 "5VDIG_TEMP2" : [ LVPS_AI, type_float],
56 "5VDIG_TEMP3" : [ LVPS_AI, type_float],
57 "M5VMB_TEMP3" : [ LVPS_AI, type_float],
58 "5VHV_INPUT_V" : [ LVPS_AI, type_float],
59 "5VHV_OUTPUT_I" : [ LVPS_AI, type_float],
60 "5VHV_OUTPUT_V" : [ LVPS_AI, type_float],
61 "15VMB_INPUT_V" : [ LVPS_AI, type_float],
62
63 "5VHV_TEMP2" : [ LVPS_AI, type_float],
64 "5VHV_TEMP3" : [ LVPS_AI, type_float],
65 "15VHV_TEMP3" : [ LVPS_AI, type_float],
66 "5VMB_INPUT_V" : [ LVPS_AI, type_float],
67 "5VMB_OUTPUT_I" : [ LVPS_AI, type_float],
68 "5VMB_OUTPUT_V" : [ LVPS_AI, type_float],
69 "5VMB_SENSES" : [ LVPS_AI, type_float],
70 "15VHV_TEMP2" : [ LVPS_AI, type_float],
71 "5VMB_TEMP2" : [ LVPS_AI, type_float],
72 "5VMB_TEMP3" : [ LVPS_AI, type_float],
73 "EXT_TEMP1" : [ LVPS_AI, type_float]}
74
75 vars_HV = {}
76 for i in range(48):
77 i = str(i+1)
78 vars_HV["hvOut"+i] = [ VARS_HV, type_float ]
79 for i in range(4):
80 i = str(i+1)
81 vars_HV["hvIn"+i] = [ VARS_HV, type_float ]
82 for i in range(7):
83 i = str(i+1)
84 vars_HV["volt"+i] = [ VARS_HV, type_float ]
85 vars_HV["temp"+i] = [ VARS_HV, type_float ]
86
87 vars_HVSET = {}
88 for i in range(48):
89 i = str(i+1)
90 vars_HVSET["Set.hvOut"+i] = [ VARS_HVSET, type_float ]
91 for i in range(4):
92 i = str(i+1)
93 vars_HVSET["Set.hvIn"+i] = [ VARS_HVSET, type_float ]
94 for i in range(7):
95 i = str(i+1)
96 vars_HVSET["Set.volt"+i] = [ VARS_HVSET, type_float ]
97 vars_HVSET["Set.temp"+i] = [ VARS_HVSET, type_float ]
98 #for i in range(2):
99 # i = str(i+1)
100 # vars_HVSET["Set.vFix1"+i] = [ VARS_HVSET, type_float ]
101
102 vars_DAQ = {}
103 vars_DAQ["STATE"] = [ VARS_DAQ, type_int]
104
105 systemID = { "LBA" : 88 ,
106 "LBC" : 87 ,
107 "EBA" : 86 ,
108 "EBC" : 89 ,
109 "SCS" : 80 }
110
111 partitionID = { 0 : "EBA",
112 1 : "LBA",
113 2 : "LBC",
114 3 : "EBC"}
115
116 def __init__( self, dbstring=None ):
117
118 self.vars = {}
119 for var, info in list(self.vars_LVPS_AI.items()):
120 self.vars[var] = info
121 for var, info in list(self.vars_LVPS_STATES.items()):
122 self.vars[var] = info
123 for var, info in list(self.vars_HV.items()):
124 self.vars[var] = info
125 for var, info in list(self.vars_HVSET.items()):
126 self.vars[var] = info
127 for var, info in list(self.vars_DAQ.items()):
128 self.vars[var] = info
129
133
134 filename=self.find_data_file("cool_channel_id.dat")
135 lines = open(filename,"r").readlines()
136 for line in lines:
137 line = line.strip()
138 folder, drawer, channel, oracleId = line.split()
139
140 keyFolderDrawer = ( folder , drawer)
141 if keyFolderDrawer in self.folderDrawer_to_channel:
142 raise Exception ("trying to generate key twice: ", keyFolderDrawer)
143 self.folderDrawer_to_channel[ keyFolderDrawer] = int(channel)
144 self.folderDrawer_to_oracleId[keyFolderDrawer] = oracleId
145
146 keyFolderChannel = ( folder , int(channel))
147 if keyFolderChannel in self.folderChannel_to_drawer:
148 raise Exception ("trying to generate key twice: ", keyFolderChannel)
149 self.folderChannel_to_drawer[keyFolderChannel] = drawer
150
151 self.dbstring = {"DEFAULT":[],"COOL":[],"ORACLE":[],"TESTBEAM":[]}
152 self.dbstring['DEFAULT'] += [dbstring]*3
153 dbstring = "oracle://ATLAS_COOLPROD;schema=ATLAS_COOLOFL_DCS;dbname=COMP200;"
154 dbstring+= "user=ATLAS_COOL_READER;password=COOLRED4PRO"
155 self.dbstring['COOL'] += [None]
156 self.dbstring['COOL'] += [dbstring]
157 self.dbstring['COOL'] += [dbstring.replace("COMP200","CONDBR2")]
158 self.dbstring['ORACLE'] += [["oracle://localhost/ATONR_PVSSPROD","ATLAS_PVSS_READER","PVSSRED4PRO"]]
159 self.dbstring['ORACLE'] += [["oracle://localhost/ATLAS_PVSSPROD","ATLAS_PVSS_READER","PVSSRED4PRO"]]
160 self.dbstring['ORACLE'] += [["oracle://localhost/ATONR_ADG","ATLAS_PVSS_READER","PVSSRED4PRO"]]
161 self.dbstring['TESTBEAM'] += [["oracle://localhost/INTR","ATLAS_PVSS_READER","PVSSRED4INT"]]*3
162
163
164 def get_dbstring(self, key, ind=2):
165 return self.dbstring[key][ind] if key in self.dbstring and len(self.dbstring[key])>ind else None
166
167 def get_channel(self, folder, drawer):
168
169 if not self.check_drawer_syntax(drawer):
170 raise Exception ("ERROR: drawer not valid: ", drawer)
171 key = (folder, drawer )
172 if key not in self.folderDrawer_to_channel:
173 print ("get_channel WARNING, can not resolve key: ", key)
174 return None
175 return self.folderDrawer_to_channel[key]
176
177 def get_drawer(self, folder, channel):
178
179 key = (folder, channel)
180 if key not in self.folderChannel_to_drawer:
181 print ("get_drawer WARNING, can not resolve key: ", key)
182 return None
183 return self.folderChannel_to_drawer[key]
184
185
186 def get_folder_and_channel(self, variable, drawer):
187 """
188 For a given DCS variable and drawer, return the complete COOL
189 folder name and the channel number associated to the drawer
190 """
191 if variable not in self.vars:
192 raise Exception ("Variable not known: ", variable)
193 partition = drawer[0:3]
194
195 folderDef = self.vars[variable][0]
196 #=== for STATE, we have only one "drawer" per partition
197 if variable=="STATE":
198 drawer = partition+"XX"
199 folder = folderDef[0]+partition+folderDef[1]
200 else:
201 folder = folderDef[0]+folderDef[1]
202 key = (folder, drawer)
203 if key not in self.folderDrawer_to_channel:
204 print ("WARNING, can not resolve key: ", key)
205 return None
206 channel = self.folderDrawer_to_channel[key]
207 return (folder, channel)
208
209 def get_variable_type(self, variable):
210 """
211 Returns the type of a variable
212 """
213 if variable not in self.vars:
214 raise Exception ("Variable not known: ", variable)
215 return self.vars[variable][1]
216
218 return list(self.vars.keys())
219
220 def check_drawer_syntax(self, drawer):
221 partition = drawer[0:3]
222 drawerNum = int(drawer[3:5])
223 valid = ("LBA" , "LBC", "EBA", "EBC")
224 if partition not in valid:
225 return False
226 if drawerNum<1 or drawerNum>64:
227 return False
228 return True
229
230 def get_variables_by_folder(self, variables, drawer):
231 """
232 Return a dictionary listing all folders that need to be
233 accessed as keys and all variables associated to the key folder
234 as values.
235 """
236 folderDict = {}
237 for var in variables:
238 if var not in self.vars:
239 print ("Unknown variable, IGNORING IT: ", var)
240 else:
241 folder, channel = self.get_folder_and_channel(var,drawer)
242 if folder not in folderDict:
243 folderDict[folder] = [var]
244 else:
245 folderDict[folder].extend([var])
246 return folderDict
247
248 def find_data_file(self, fname, pathlist=None, access=os.R_OK):
249 """the python equivalent to the C++ PathResolver for datafiles.
250 """
251
252 if pathlist is None:
253 pathlist = os.getenv('DATAPATH').split(os.pathsep)
254
255 for path in pathlist:
256 f = os.path.join( path, fname )
257 if os.access( f, access ):
258 return f
get_variables_by_folder(self, variables, drawer)
find_data_file(self, fname, pathlist=None, access=os.R_OK)
get_folder_and_channel(self, variable, drawer)
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177