From 3923fdc6cffce8fe40edea4689a5acfe7c1668b6 Mon Sep 17 00:00:00 2001 From: Giacomo Govi Date: Thu, 14 Feb 2019 10:25:16 +0100 Subject: [PATCH] getPayloadData.py script adapted for the two tags support --- CondCore/Utilities/scripts/getPayloadData.py | 104 ++++++++++++++++--- 1 file changed, 89 insertions(+), 15 deletions(-) diff --git a/CondCore/Utilities/scripts/getPayloadData.py b/CondCore/Utilities/scripts/getPayloadData.py index c0d7f48f95669..c8f420e6b9054 100755 --- a/CondCore/Utilities/scripts/getPayloadData.py +++ b/CondCore/Utilities/scripts/getPayloadData.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -from __future__ import print_function import shutil import glob import json @@ -82,14 +81,9 @@ def deserialize_iovs(db, plugin_name, plot_name, tag, time_type, iovs): plot = getattr(plugin_obj, plot_name)() output('plot object: ', plot) - if db == "Prod": - db_name = 'frontier://FrontierProd/CMS_CONDITIONS' - elif db == 'Prep' : - db_name = 'frontier://FrontierPrep/CMS_CONDITIONS' - else: - db_name = db + db_name = 'oracle://cms_orcon_adg/CMS_CONDITIONS' if db == 'Prod' else 'oracle://cms_orcoff_prep/CMS_CONDITIONS' output('full DB name: ', db_name) - + success = plot.process(db_name, tag, time_type, int(iovs['start_iov']), int(iovs['end_iov'])) output('plot processed data successfully: ', success) @@ -97,6 +91,46 @@ def deserialize_iovs(db, plugin_name, plot_name, tag, time_type, iovs): return False + result = plot.data() + output('deserialized data: ', result) + return result +@supress_output +def deserialize_twoiovs(db, plugin_name, plot_name, tag,tagtwo,iovs,iovstwo): + ''' Deserializes given iovs data and returns plot coordinates ''' + #print "Starting to deserialize iovs:" + #print 'First Iovs',iovs + #print 'Two Iovs', iovstwo + output('Starting to deserialize iovs: ', '') + output('db: ', db) + output('plugin name: ', plugin_name) + output('plot name: ', plot_name) + output('tag name: ', tag) + output('tagtwo name: ', tagtwo) + #output('tag time type: ', time_type) + output('iovs: ', iovs) + output('iovstwo: ', iovstwo) + + plugin_base = import_module('pluginModule_PayloadInspector') + output('PI plugin base: ', plugin_base) + + plugin_obj = import_module(plugin_name) + output('PI plugin object: ', plugin_obj) + + # get plot method and execute it with given iovs + plot = getattr(plugin_obj, plot_name)() + output('plot object: ', plot) + + db_name = 'oracle://cms_orcon_adg/CMS_CONDITIONS' if db == 'Prod' else 'oracle://cms_orcoff_prep/CMS_CONDITIONS' + output('full DB name: ', db_name) + + + success = plot.processTwoTags(db_name, tag,tagtwo,int(iovs['start_iov']), int(iovstwo['end_iov'])) + #print "All good",success + output('plot processed data successfully: ', success) + if not success: + return False + + result = plot.data() output('deserialized data: ', result) return result @@ -169,15 +203,17 @@ def discover(): output(' - plot type: ', plot_type) single_iov = plot_method.isSingleIov() output(' - is single iov: ', single_iov) - result.setdefault(payload_type, []).append({'plot': plot, 'plugin_name': plugin_name, 'title': plot_title, 'plot_type': plot_type, 'single_iov': single_iov}) + two_tags = plot_method.isTwoTags() + output(' - is Two Tags: ', two_tags) + result.setdefault(payload_type, []).append({'plot': plot, 'plugin_name': plugin_name, 'title': plot_title, 'plot_type': plot_type, 'single_iov': single_iov, 'two_tags': two_tags}) output('currently discovered info: ', result) output('*** final output:', '') return json.dumps(result) def output(description, param): if args.verbose: - print('') - print(description, param) + print '' + print description, param if __name__ == '__main__': @@ -213,9 +249,11 @@ def output(description, param): parser = ArgumentParser(description=description, formatter_class=RawTextHelpFormatter) parser.add_argument("-d", "--discover", help="discovers object types and plots \nfor a given cmssw release", action="store_true") parser.add_argument("-i", "--iovs", help="deserializes given iovs data encoded in base64 and returns plot coordinates also encoded in base64") + parser.add_argument("-i2", "--iovstwo", help="deserializes given iovs data encoded in base64 and returns plot coordinates also encoded in base64") parser.add_argument("-o", "--plugin", help="Payload Inspector plugin name needed for iovs deserialization") parser.add_argument("-p", "--plot", help="plot name needed for iovs deserialization") parser.add_argument("-t", "--tag", help="tag name needed for iovs deserialization") + parser.add_argument("-t2", "--tagtwo", help="tag name needed for iovs deserialization") parser.add_argument("-tt", "--time_type", help="tag time type name needed for iovs deserialization") parser.add_argument("-b", "--db", help="db (Prod or Prep) needed for iovs deserialization") 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") @@ -235,9 +273,44 @@ def output(description, param): os.write( 1, discover() ) # Return a plot if iovs are provided - if args.iovs: + #print '* getiovs: ',args.iovs + #print '* getiovstwo: ',args.iovstwo + if args.iovstwo: # Run plugin with arguments + #print 'We are here' + a=json.loads(args.iovs) + #print 'A',a + b=json.loads(args.iovstwo) + #print 'B',b + result = deserialize_twoiovs(args.db, args.plugin, args.plot, args.tag,args.tagtwo,a,b) + # If test -> output the result as formatted json + if args.test: + os.write( 1, json.dumps( json.loads( result ), indent=4 )) + #print 'Result:',result + if args.image_plot: + try: + filename = json.loads( result )['file'] + #print 'File name',filename + except ValueError, e: + os.write( 2, 'Value error when getting image name: %s\n' % str( e )) + except KeyError, e: + os.write( 2, 'Key error when getting image name: %s\n' % str( e )) + + if not filename or not os.path.isfile( filename ): + os.write( 2, 'Error: Generated image file (%s) not found\n' % filename ) + + try: + with open( filename, 'r' ) as f: + shutil.copyfileobj( f, sys.stdout ) + except IOError, e: + os.write( 2, 'IO error when streaming image: %s' % str( e )) + finally: + os.remove( filename ) + + + # Else -> output result json string with base 64 encoding + elif args.iovs: result = deserialize_iovs(args.db, args.plugin, args.plot, args.tag, args.time_type, json.loads(args.iovs)) # If test -> output the result as formatted json @@ -251,9 +324,10 @@ def output(description, param): try: filename = json.loads( result )['file'] - except ValueError as e: + #print 'File name',filename + except ValueError, e: os.write( 2, 'Value error when getting image name: %s\n' % str( e )) - except KeyError as e: + except KeyError, e: os.write( 2, 'Key error when getting image name: %s\n' % str( e )) if not filename or not os.path.isfile( filename ): @@ -262,7 +336,7 @@ def output(description, param): try: with open( filename, 'r' ) as f: shutil.copyfileobj( f, sys.stdout ) - except IOError as e: + except IOError, e: os.write( 2, 'IO error when streaming image: %s' % str( e )) finally: os.remove( filename )