File indexing completed on 2024-11-26 02:34:11
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 import os, sys, datetime, shutil, optparse
0025
0026
0027
0028
0029
0030
0031 def mysystem(command,apply=1):
0032 print(command)
0033 if apply==1: return os.system(command)
0034 elif apply==0: return 0
0035 else:
0036 print('[electronStore.py] UNSUPPORTED ARGUMENT VALUE FOR mysystem(,apply):',apply)
0037 exit(1)
0038
0039
0040
0041
0042
0043
0044 class flushfile(object):
0045 def __init__(self,f):
0046 self.f = f
0047 def write(self,x):
0048 self.f.write(x)
0049 self.f.flush()
0050
0051 sys.stdout = flushfile(sys.stdout)
0052
0053
0054
0055
0056
0057
0058 if __name__ == "__main__":
0059
0060
0061
0062
0063
0064
0065 parser = optparse.OptionParser()
0066 parser.add_option("-c", "--cfg", dest="config", action="store", default="electronCompare.txt",
0067 help="the configuration file describe which histogram must be displayed and how")
0068 parser.add_option("-t", "--title", dest="title", action="store", default="",
0069 help="the title of the page")
0070 parser.add_option("-r", "--red-name", dest="red", action="store", default="",
0071 help="short name of the red histograms")
0072 parser.add_option("-b", "--blue-name", dest="blue", action="store", default="",
0073 help="short name of the blue histograms")
0074 (options, args) = parser.parse_args()
0075
0076 if len(args)<2:
0077 print("[electronStore.py] I NEED AT LEAST TWO ARGUMENTS.")
0078 exit(2)
0079
0080 red_file = args.pop(0)
0081 web_dir = args.pop()
0082
0083 if not '/afs/cern.ch/cms/' in web_dir:
0084 print("local : ", web_dir)
0085 web_url = web_dir
0086 else:
0087 web_url = web_dir.replace('/afs/cern.ch/cms/','http://cmsdoc.cern.ch/',1)
0088 if len(args)>0 :
0089 blue_file = args.pop(0)
0090 else :
0091 blue_file = ''
0092
0093
0094
0095
0096
0097
0098
0099 if os.path.exists(web_dir+'/gifs')==False:
0100 os.makedirs(web_dir+'/gifs')
0101
0102
0103 red_base = os.path.basename(red_file)
0104 if os.path.isfile(red_file)==True :
0105 print('RED FILE =',red_file)
0106 if os.path.isfile(red_base)==True and os.path.getmtime(red_base)>os.path.getmtime(red_file) :
0107 print('[electronCompare.py] did you forget to store '+red_base+' ?')
0108 else :
0109 print("[electronCompare.py] FILE NOT FOUND :",red_file)
0110 if os.path.isfile(red_base)==True :
0111 print('[electronCompare.py] did you forget to store '+red_base+' ?')
0112 exit(3)
0113
0114
0115 if blue_file!='' :
0116 if os.path.isfile(blue_file)==True :
0117 print('BLUE FILE =',blue_file)
0118 else :
0119 print('[electronCompare.py] file not found :',blue_file)
0120 blue_file = ''
0121 else :
0122 print("[electronCompare.py] no blue histograms to compare with.")
0123
0124
0125
0126
0127
0128
0129 (red_head,red_tail) = os.path.split(red_file)
0130 red_long_name = os.path.basename(red_head)+'/'+red_tail
0131 (blue_head,blue_tail) = os.path.split(blue_file)
0132 blue_long_name = os.path.basename(blue_head)+'/'+blue_tail
0133 if options.red=='' :
0134 options.red = red_long_name
0135 if options.blue=='' :
0136 options.blue = blue_long_name
0137 if options.title=='' :
0138 options.title = red_long_name+' vs '+blue_long_name
0139
0140 (red_hd, red_release) = os.path.split(red_head)
0141 (blue_hd, blue_release) = os.path.split(blue_head)
0142
0143
0144
0145
0146
0147 mysystem('cp -f electronCompare.C '+options.config+' '+web_dir)
0148
0149 os.environ['CMP_DIR'] = web_dir
0150 os.environ['CMP_URL'] = web_url
0151 os.environ['CMP_TITLE'] = options.title
0152 os.environ['CMP_RED_FILE'] = red_file
0153 os.environ['CMP_BLUE_FILE'] = blue_file
0154 os.environ['CMP_RED_NAME'] = options.red
0155 os.environ['CMP_BLUE_NAME'] = options.blue
0156 os.environ['CMP_RED_COMMENT'] = red_file+'.comment'
0157 os.environ['CMP_BLUE_COMMENT'] = blue_file+'.comment'
0158 os.environ['CMP_CONFIG'] = options.config
0159 os.environ['CMP_RED_RELEASE'] = red_release
0160 os.environ['CMP_BLUE_RELEASE'] = blue_release
0161
0162 mysystem('root -b -l -q electronCompare.C')
0163
0164 print("You can access the files here:",web_dir)
0165 print("You can browse your validation plots here:",web_url+'/')