Back to home page

Project CMSSW displayed by LXR

 
 

    


Warning, /CalibMuon/DTCalibration/scripts/dtCalibration is written in an unsupported language. File is not indexed.

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