4 from __future__
import print_function
12 from importlib
import import_module
13 from argparse
import ArgumentParser, RawTextHelpFormatter
16 import pluginCondDBV2PyInterface
17 pluginCondDBV2PyInterface.CMSSWInit()
23 Temporarily disables stdout and stderr so that printouts from the plot 24 plugin does not compromise the purity of our ssh stream if 25 args.suppress_output is true 27 def decorated( *fargs, **fkwargs ):
29 suppress = args.suppress_output
36 saved_stdout = os.dup( 1 )
37 saved_stderr = os.dup( 2 )
40 devnull = os.open(
'/dev/null', os.O_WRONLY )
47 result =
f( *fargs, **fkwargs )
55 os.dup2( saved_stdout, 1 )
56 os.dup2( saved_stderr, 2 )
65 ''' Deserializes given iovs data and returns plot coordinates ''' 67 output(
'Starting to deserialize iovs: ',
'')
69 output(
'plugin name: ', plugin_name)
70 output(
'plot name: ', plot_name)
72 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' 91 output(
'full DB name: ', db_name)
94 success = plot.process(db_name, tag, time_type,
int(iovs[
'start_iov']),
int(iovs[
'end_iov']))
95 output(
'plot processed data successfully: ', success)
101 output(
'deserialized data: ', result)
105 ''' Returns a list of Payload Inspector plugin names 107 ['pluginBasicPayload_PayloadInspector', 'pluginBeamSpot_PayloadInspector', 'pluginSiStrip_PayloadInspector'] 109 architecture = os.environ.get(
'SCRAM_ARCH',
None)
110 output(
'architecture: ', architecture)
114 os.environ.get(
'CMSSW_BASE',
None),
115 os.environ.get(
'CMSSW_RELEASE_BASE',
None)
122 path = os.path.join(r,
'lib', architecture)
123 output(
'* full release path: ', path)
125 plugins += glob.glob(path +
'/plugin*_PayloadInspector.so' )
126 output(
'found plugins: ', plugins)
135 result.append(p.split(
'/')[-1].
replace(
'.so',
''))
137 output(
'discovered plugins: ', result)
141 ''' Discovers object types and plots for a given cmssw release 145 {"plot": "plot_BeamSpot_x", "plot_type": "History", 146 "single_iov": false, "plugin_name": "pluginBeamSpot_PayloadInspector", 147 "title": "x vs run number"}, 153 plugin_base = import_module(
'pluginModule_PayloadInspector')
156 output(
' - plugin name: ', plugin_name)
157 plugin_obj = import_module(plugin_name)
158 output(
'*** PI plugin object: ', plugin_obj)
159 for plot
in dir(plugin_obj):
160 if 'plot_' not in plot:
continue 161 output(
' - plot name: ', plot)
162 plot_method= getattr(plugin_obj, plot)()
163 output(
' - plot object: ', plot_method)
164 payload_type = plot_method.payloadType()
165 output(
' - payload type: ', payload_type)
166 plot_title = plot_method.title()
167 output(
' - plot title: ', plot_title)
168 plot_type = plot_method.type()
169 output(
' - plot type: ', plot_type)
170 single_iov = plot_method.isSingleIov()
171 output(
' - is single iov: ', single_iov)
172 result.setdefault(payload_type, []).
append({
'plot': plot,
'plugin_name': plugin_name,
'title': plot_title,
'plot_type': plot_type,
'single_iov': single_iov})
173 output(
'currently discovered info: ', result)
174 output(
'*** final output:',
'')
175 return json.dumps(result)
180 print(description, param)
182 if __name__ ==
'__main__':
185 Payload Inspector - data visualisation tool which is integrated into the cmsDbBrowser. 186 It allows to display plots and monitor the calibration and alignment data. 188 You can access Payload Inspector with a link below: 189 https://cms-conddb.cern.ch/cmsDbBrowser/payload_inspector/Prod 191 This script is a part of the Payload Inspector service and is responsible for: 192 a) discovering PI objects that are available in a given cmssw release 193 b) deserializing payload data which is later used as plot coordinates 194 c) testing new PI objects which are under development 196 To test new PI objects please do the following: 197 a) run ./getPayloadData.py --discover 198 to check if your newly created object is found by the script. 199 Please note that we strongly rely on naming conventions so if you don't 200 see your object listed you probably misnamed it in objectType() method. 201 Also all plot methods should start with "plot_" prefix. 203 b) second step is to test if it returns data correctly: 204 run ./getPayloadData.py --plugin YourPIPluginName --plot YourObjectPlot --tag tagName --time_type Run --iovs '{"start_iov": "201", "end_iov": "801"}' --db Prod --test 206 Here is an example for BasicPayload object: 207 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 209 c) if it works correctly please make a pull request and once it's accepted 210 go to cmsDbBrowser and wait for the next IB to test it. 213 parser = ArgumentParser(description=description, formatter_class=RawTextHelpFormatter)
214 parser.add_argument(
"-d",
"--discover", help=
"discovers object types and plots \nfor a given cmssw release", action=
"store_true")
215 parser.add_argument(
"-i",
"--iovs", help=
"deserializes given iovs data encoded in base64 and returns plot coordinates also encoded in base64")
216 parser.add_argument(
"-o",
"--plugin", help=
"Payload Inspector plugin name needed for iovs deserialization")
217 parser.add_argument(
"-p",
"--plot", help=
"plot name needed for iovs deserialization")
218 parser.add_argument(
"-t",
"--tag", help=
"tag name needed for iovs deserialization")
219 parser.add_argument(
"-tt",
"--time_type", help=
"tag time type name needed for iovs deserialization")
220 parser.add_argument(
"-b",
"--db", help=
"db (Prod or Prep) needed for iovs deserialization")
221 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")
222 parser.add_argument(
"-v",
"--verbose", help=
"verbose mode. Shows more information", action=
"store_true")
223 parser.add_argument(
"-ip",
"--image_plot", help=
"Switch telling the script that this plot type is of type Image", action=
"store_true")
224 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")
227 if len(sys.argv) == 1:
231 args = parser.parse_args()
241 result =
deserialize_iovs(args.db, args.plugin, args.plot, args.tag, args.time_type, json.loads(args.iovs))
245 os.write( 1, json.dumps( json.loads( result ), indent=4 ))
248 elif args.image_plot:
253 filename = json.loads( result )[
'file']
254 except ValueError
as e:
255 os.write( 2,
'Value error when getting image name: %s\n' %
str( e ))
256 except KeyError
as e:
257 os.write( 2,
'Key error when getting image name: %s\n' %
str( e ))
259 if not filename
or not os.path.isfile( filename ):
260 os.write( 2,
'Error: Generated image file (%s) not found\n' % filename )
263 with open( filename,
'r' ) as f: 264 shutil.copyfileobj( f, sys.stdout ) 266 os.write( 2,
'IO error when streaming image: %s' %
str( e ))
268 os.remove( filename )
273 os.write( 1, result.encode(
'base64' ))
def output(description, param)
def replace(string, replacements)
S & print(S &os, JobReport::InputFile const &f)
def deserialize_iovs(db, plugin_name, plot_name, tag, time_type, iovs)