Get information about a T0 tag from AMI.
416def getTrfConfigFromAMI(tag, suppressNonJobOptions = True):
417 msg.debug('Using AMI to get info about tag %s', tag)
418
419 try:
420
421 import pyAMI.exception
422 except ImportError as e:
423 raise TransformAMIException(AMIerrorCode, 'Import of pyAMI modules failed ({0})'.format(e))
424
425 try:
426 amiclient=getAMIClient()
427
428 result = get_ami_tag(amiclient, tag, suppressNonJobOptions)
429 except pyAMI.exception.Error as e:
430 msg.error('An exception occured when connecting to primary AMI: {0}'.format(e))
431 msg.debug('Exception: {0}'.format(e))
432 if 'please login' in str(e) or 'certificate expired' in str(e):
433 raise TransformAMIException(AMIerrorCode, 'Getting tag info from AMI failed with credential problem. '
434 'Please check your AMI account status.')
435 if 'Invalid amiTag' in str(e):
436 raise TransformAMIException(AMIerrorCode, 'Invalid AMI tag ({0}).'.format(tag))
437 raise TransformAMIException(AMIerrorCode, 'Getting tag info from AMI failed. See logfile for exception details.')
438
439 try:
440 trf = TrfConfig()
441 trf.name = result[0]['transformation']
442 trf.inputs=result[0].
get(
'inputs', {})
443 trf.outputs=result[0].
get(
'outputs', {})
444 trf.release = result[0][
'SWReleaseCache'].
replace(
'_',
',')
445
446 if 'phconfig' in result[0]:
447 trf.physics=deserialiseFromAMIString(result[0]['phconfig'])
448 else:
449 physics = {}
450 for k, v in result[0].items():
451 if 'Exec' in k:
452 execStrList = [execStr
for execStr
in convertToStr(v).
replace(
'" "',
'"" ""').
split(
'" "')]
453 physics[convertToStr(k)] = [remove_enclosing_quotes(execStr).
replace(
'\\"',
'"')
for execStr
in execStrList]
454 elif '" "' in v:
455 msg.info('found a quoted space (" ") in parameter value for %s, converting to list', k)
456 subStrList = [subStr
for subStr
in convertToStr(v).
replace(
'" "',
'"" ""').
split(
'" "')]
457 physics[convertToStr(k)] = [remove_enclosing_quotes(subStr).
replace(
'\\"',
'"')
for subStr
in subStrList]
458 else:
459 physics[convertToStr(k)] = convertToStr(remove_enclosing_quotes(v))
460
461 msg.debug('Result from AMI after string cleaning:')
462 msg.debug('%s', dumps(physics, indent = 4))
463
464 if suppressNonJobOptions:
465 for k in list(physics):
466 if k in ['inputs', 'outputs', 'productionStep', 'transformation', 'SWReleaseCache']:
467 physics.pop(k)
468
469 for k, v in physics.items():
470 if 'triggerConfig' in k or 'triggerConfigByRun' in k:
471 if ' ' in v:
472 physics[k] = v.replace(' ', ',')
473 msg.warning('Attempted to correct illegal trigger configuration string: {0} -> {1}'.format(v, physics[k]))
474
475 msg.debug("Checking for pseudo-argument internal to ProdSys...")
476 if 'extraParameter' in physics:
477 val = physics.pop('extraParameter')
478 msg.debug("Removed extraParamater=%s from arguments.", val)
479
480 msg.debug("Checking for input/output file arguments...")
481 for arg in list(physics):
482 if arg.lstrip('-').startswith('input') and arg.endswith('File'):
483 value = physics.pop(arg)
484 msg.debug("Found input file argument %s=%s.", arg, value)
485 trf.inFiles[arg] = value
486 elif arg.lstrip('-').startswith('output') and arg.endswith('File'):
487 value = physics.pop(arg)
488 msg.debug("Found output file argument %s=%s.", arg, value)
489 trf.outFiles[arg] = value
490
491 msg.debug("Checking for not set arguments...")
492 for arg, value in physics.items():
493 if value == "NONE" or value == "none" or value == ["NONE"]:
494 val = physics.pop(arg)
495 msg.debug("Removed %s=%s from arguments.", arg, val)
496
497 trf.physics = physics
498
499 if not isinstance(trf.physics, dict):
500 raise TransformAMIException(AMIerrorCode, "Bad result for tag's phconfig: {0}".format(trf.physics))
501
502 if trf.inFiles == {}:
503 if 'inputs' in result[0]:
504 trf.inFiles=deserialiseFromAMIString(result[0]['inputs'])
505 for inFileType, inFileName in trf.inFiles.items():
506
507
508 if inFileName == '' or inFileName =={} or inFileName == [] or inFileName == '{}':
509 trf.inFiles[inFileType] = getInputFileName(inFileType, tag)
510
511 if 'outputs' in result[0]:
512 outputs=deserialiseFromAMIString(result[0]['outputs'])
513 trf.outFiles=dict( (k, getOutputFileName(k.removeprefix('output').removesuffix('File')) ) for k in outputs )
514 trf.outfmts=[ outputs[k]['dstype'] for k in outputs ]
515 except KeyError as e:
516 raise TransformAMIException(AMIerrorCode, "Missing key in AMI data: {0}".format(e))
517 except Exception as e:
518 raise TransformAMIException(AMIerrorCode, "Got a very unexpected exception while parsing AMI outputs!"
519 " Please report.\nParsing:\n{0}\nRaised:\n{1}".format(result, e))
520
521
522 if '_tf.py' in trf.name:
523 trf.newTransform=True
524 else:
525 trf.newTransform=False
526
527 return [ trf ]
528
529
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
std::vector< std::string > split(const std::string &s, const std::string &t=":")