Warning, /CalibMuon/DTCalibration/scripts/dtCalibration is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env python3
0002 import sys,os,time,datetime,logging
0003 import argparse
0004 from termcolor import colored
0005
0006 from CalibMuon.DTCalibration.Workflow.DTCalibrationWorker import DTCalibrationWorker
0007
0008
0009 log = logging.getLogger(__name__)
0010 log_choices = [ 'ERROR', 'WARNING', 'INFO', 'DEBUG' ]
0011 date = '%F %H:%M:%S'
0012 log_file_name = 'dtCalibration_'
0013 log_file_name += datetime.datetime.now().strftime( "%Y-%m-%d_%H.%M.%S" ) + '.log'
0014
0015 def main():
0016 options = parse_command_line()
0017 # setup logging
0018 setupLogging(options)
0019
0020 # echo the command line used to run calibration to the log file
0021 log.info("DT Calibration started with command:")
0022 log.info(" ".join(sys.argv))
0023
0024 start = time.time()
0025 print(colored("[DT Calibration starting]", 'cyan', attrs = ["bold"]))
0026 print(f"Running at {options.working_dir}")
0027
0028 #stdout_original = sys.stdout
0029 #sys.stdout = logOut
0030
0031 dtCalibWorker = DTCalibrationWorker(options)
0032 local_path = dtCalibWorker.run()
0033
0034 # move the log file to the working directory to avoid cluttering up the base directory
0035 print(f"Job dir is {local_path}")
0036 print(f"Log file is {log_file_name}")
0037 os.rename(log_file_name,local_path+log_file_name)
0038
0039 #sys.stdout = stdout_original
0040 stop = time.time()
0041 print(colored("[DT Calibration finished]", 'green', attrs = ["bold"]))
0042 print(f"Time elapsed was {stop-start:.2f} seconds")
0043
0044 def setupLogging(options):
0045 #setup logging
0046 format = '%(levelname)s (%(name)s) [%(asctime)s]: %(message)s'
0047 #logging.basicConfig( level=logging.getLevelName(options.debug), format=format, datefmt=date )
0048 logging.basicConfig(filename=log_file_name, level=logging.DEBUG, format=format, datefmt=date )
0049 log.setLevel(logging.getLevelName(options.debug))
0050 #formatter = logging.Formatter( format )
0051 #hdlr = logging.FileHandler( log_file_name, mode='w' )
0052 #hdlr.setFormatter( formatter )
0053 #log.addHandler( hdlr )
0054 logging.getLogger('CRAB3').propagate = False # Avoid any CRAB message to propagate up to the handlers of the root logger.
0055
0056
0057 def parse_command_line():
0058 ''' Setup command line options using prog command [options] sheme '''
0059 # This is the main parser instance. This parser will be called to parse the passed args
0060 descr = "Main script to perform various DT calibration tasks.\n"
0061 descr += "Choose a workflow, in some cases a workflow mode and a command\n"
0062 descr += "example dtCalibration ttrig timeboxes submit"
0063 main_parser = argparse.ArgumentParser(description=descr)
0064 main_parser.add_argument( '--debug',
0065 metavar='LEVEL', default='INFO',
0066 choices=log_choices,
0067 help='Set the debug level. Allowed values: ' +
0068 ', '.join( log_choices ) + ' [default: %(default)s]' )
0069 DTCalibrationWorker.add_arguments( main_parser )
0070
0071 return main_parser.parse_args()
0072
0073
0074 if __name__ == '__main__':
0075 main()