4 from __future__
import print_function
13 from importlib
import import_module
14 from argparse
import ArgumentParser, RawTextHelpFormatter
17 import pluginCondDBV2PyInterface
18 pluginCondDBV2PyInterface.CMSSWInit()
24 Temporarily disables stdout and stderr so that printouts from the plot 25 plugin does not compromise the purity of our ssh stream if 26 args.suppress_output is true 28 def decorated( *fargs, **fkwargs ):
30 suppress = args.suppress_output
37 saved_stdout = os.dup( 1 )
38 saved_stderr = os.dup( 2 )
41 devnull = os.open(
'/dev/null', os.O_WRONLY )
48 result =
f( *fargs, **fkwargs )
56 os.dup2( saved_stdout, 1 )
57 os.dup2( saved_stderr, 2 )
66 ''' Deserializes given iovs data and returns plot coordinates ''' 68 output(
'Starting to deserialize iovs: ',
'')
70 output(
'plugin name: ', plugin_name)
71 output(
'plot name: ', plot_name)
73 output(
'tag time type: ', time_type)
75 plugin_base = import_module(
'pluginModule_PayloadInspector')
76 output(
'PI plugin base: ', plugin_base)
78 plugin_obj = import_module(plugin_name)
79 output(
'PI plugin object: ', plugin_obj)
82 plot = getattr(plugin_obj, plot_name)()
83 output(
'plot object: ', plot)
86 db_name =
'frontier://FrontierProd/CMS_CONDITIONS' 88 db_name =
'frontier://FrontierPrep/CMS_CONDITIONS' 92 output(
'full DB name: ', db_name)
94 if input_params
is not None:
95 plot.setInputParamValues( input_params )
97 modv = getattr(plugin_base,
'ModuleVersion')
100 if modv.label ==
'1.0':
102 success = plot.process(db_name, tags[0][0], time_type,
int(tags[0][1]),
int(tags[0][2]) )
104 success = plot.processTwoTags(db_name, tags[0][0], tags[1][0],
int(tags[0][1]),
int(tags[1][1]) )
105 elif modv.label ==
'2.0':
106 success = plot.process(db_name, tags)
108 output(
'plot processed data successfully: ', success)
113 output(
'deserialized data: ', result)
117 ''' Returns a list of Payload Inspector plugin names 119 ['pluginBasicPayload_PayloadInspector', 'pluginBeamSpot_PayloadInspector', 'pluginSiStrip_PayloadInspector'] 121 architecture = os.environ.get(
'SCRAM_ARCH',
None)
122 output(
'architecture: ', architecture)
126 os.environ.get(
'CMSSW_BASE',
None),
127 os.environ.get(
'CMSSW_RELEASE_BASE',
None),
128 os.environ.get(
'CMSSW_FULL_RELEASE_BASE',
None)
135 path = os.path.join(r,
'lib', architecture)
136 output(
'* full release path: ', path)
138 plugins += glob.glob(path +
'/plugin*_PayloadInspector.so' )
139 output(
'found plugins: ', plugins)
144 output(
'# plugins found:',len(plugins))
153 result.append(p.split(
'/')[-1].
replace(
'.so',
''))
155 output(
'discovered plugins: ', result)
159 ''' Discovers object types and plots for a given cmssw release 163 {"plot": "plot_BeamSpot_x", "plot_type": "History", 164 "single_iov": false, "plugin_name": "pluginBeamSpot_PayloadInspector", 165 "title": "x vs run number"}, 171 plugin_base = import_module(
'pluginModule_PayloadInspector')
172 modv = getattr(plugin_base,
'ModuleVersion')
175 output(
' - plugin name: ', plugin_name)
176 plugin_obj = import_module(plugin_name)
177 output(
'*** PI plugin object: ', plugin_obj)
178 for plot
in dir(plugin_obj):
179 if 'plot_' not in plot:
continue 180 output(
' - plot name: ', plot)
181 plot_method= getattr(plugin_obj, plot)()
182 output(
' - plot object: ', plot_method)
183 payload_type = plot_method.payloadType()
184 output(
' - payload type: ', payload_type)
185 plot_title = plot_method.title()
186 output(
' - plot title: ', plot_title)
187 plot_type = plot_method.type()
188 output(
' - plot type: ', plot_type)
189 single_iov = plot_method.isSingleIov()
190 output(
' - is single iov: ', single_iov)
191 two_tags = plot_method.isTwoTags()
192 output(
' - is Two Tags: ', two_tags)
193 plot_dict = {
'plot': plot,
'plugin_name': plugin_name,
'title': plot_title,
'plot_type': plot_type,
'single_iov': single_iov,
'two_tags': two_tags }
194 if modv.label ==
'2.0':
195 input_params = plot_method.inputParams()
196 output(
' - input params: ', len(input_params))
197 plot_dict[
'input_params'] = input_params
198 result.setdefault(payload_type, []).
append( plot_dict )
199 output(
'currently discovered info: ', result)
200 output(
'*** final output:',
'')
201 return json.dumps(result)
206 print(description, param)
208 if __name__ ==
'__main__':
211 Payload Inspector - data visualisation tool which is integrated into the cmsDbBrowser. 212 It allows to display plots and monitor the calibration and alignment data. 214 You can access Payload Inspector with a link below: 215 https://cms-conddb.cern.ch/cmsDbBrowser/payload_inspector/Prod 217 This script is a part of the Payload Inspector service and is responsible for: 218 a) discovering PI objects that are available in a given cmssw release 219 b) deserializing payload data which is later used as plot coordinates 220 c) testing new PI objects which are under development 222 To test new PI objects please do the following: 223 a) run ./getPayloadData.py --discover 224 to check if your newly created object is found by the script. 225 Please note that we strongly rely on naming conventions so if you don't 226 see your object listed you probably misnamed it in objectType() method. 227 Also all plot methods should start with "plot_" prefix. 229 b) second step is to test if it returns data correctly: 230 run ./getPayloadData.py --plugin YourPIPluginName --plot YourObjectPlot --tag tagName --time_type Run --iovs '{"start_iov": "201", "end_iov": "801"}' --db Prod --test 232 Here is an example for BasicPayload object: 233 run ./getPayloadData.py --plugin pluginBasicPayload_PayloadInspector --plot plot_BasicPayload_data0 --tag BasicPayload_v2 --time_type Run --iovs '{"start_iov": "201", "end_iov": "801"}' --db Prod --test 235 c) if it works correctly please make a pull request and once it's accepted 236 go to cmsDbBrowser and wait for the next IB to test it. 239 parser = ArgumentParser(description=description, formatter_class=RawTextHelpFormatter)
240 parser.add_argument(
"-d",
"--discover", help=
"discovers object types and plots \nfor a given cmssw release", action=
"store_true")
241 parser.add_argument(
"-i",
"--iovs", help=
"deserializes given iovs data encoded in base64 and returns plot coordinates also encoded in base64")
242 parser.add_argument(
"-i2",
"--iovstwo", help=
"deserializes given iovs data encoded in base64 and returns plot coordinates also encoded in base64")
243 parser.add_argument(
"-o",
"--plugin", help=
"Payload Inspector plugin name needed for iovs deserialization")
244 parser.add_argument(
"-p",
"--plot", help=
"plot name needed for iovs deserialization")
245 parser.add_argument(
"-t",
"--tag", help=
"tag name needed for iovs deserialization")
246 parser.add_argument(
"-t2",
"--tagtwo", help=
"tag name needed for iovs deserialization")
247 parser.add_argument(
"-tt",
"--time_type", help=
"tag time type name needed for iovs deserialization")
248 parser.add_argument(
"-b",
"--db", help=
"db (Prod or Prep) needed for iovs deserialization")
249 parser.add_argument(
"-test",
"--test", help=
"add this flag if you want to test the deserialization function and want to see a readable output", action=
"store_true")
250 parser.add_argument(
"-v",
"--verbose", help=
"verbose mode. Shows more information", action=
"store_true")
251 parser.add_argument(
"-ip",
"--image_plot", help=
"Switch telling the script that this plot type is of type Image", action=
"store_true")
252 parser.add_argument(
"-s",
"--suppress-output", help=
"Supresses output from so that stdout and stderr can be kept pure for the ssh transmission", action=
"store_true")
253 parser.add_argument(
"-is",
"--input_params", help=
"Plot input parameters ( dictionary, JSON serialized into string )" )
256 if len(sys.argv) == 1:
260 args = parser.parse_args()
264 os.write( 1, str.encode(
discover()) )
267 if args.input_params
is not None:
268 input_params = yaml.safe_load(args.input_params)
272 iovDict = yaml.safe_load( args.iovs )
273 tags.append( (args.tag, iovDict[
'start_iov'], iovDict[
'end_iov'] ) )
275 iovDict = yaml.safe_load( args.iovstwo )
276 tags.append( (args.tagtwo, iovDict[
'start_iov'], iovDict[
'end_iov'] ) )
278 result =
deserialize_iovs(args.db, args.plugin, args.plot, tags, args.time_type, input_params)
282 os.write( 2, str.encode(json.dumps( json.loads( result ), indent=4 )))
285 elif args.image_plot:
290 filename = json.loads( result )[
'file']
292 except ValueError
as e:
293 os.write( 2,
'Value error when getting image name: %s\n' %
str( e ))
294 except KeyError
as e:
295 os.write( 2,
'Key error when getting image name: %s\n' %
str( e ))
297 if not filename
or not os.path.isfile( filename ):
298 os.write( 2, str.encode(
'Error: Generated image file (%s) not found\n' % filename ))
301 with open( filename,
'rb' )
as f:
302 shutil.copyfileobj( f, sys.stdout.buffer )
304 os.write( 2, str.encode(
'IO error when streaming image: %s' %
str( e )))
306 os.remove( filename )
312 os.write( 1, base64.b64encode(bytes(result,
'utf-8')))
def output(description, param)
def replace(string, replacements)
def deserialize_iovs(db, plugin_name, plot_name, tags, time_type, input_params)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
if(threadIdxLocalY==0 &&threadIdxLocalX==0)