File indexing completed on 2024-04-06 12:09:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 from __future__ import print_function
0027 import os, sys, datetime, shutil, optparse
0028
0029
0030
0031
0032
0033
0034 def mysystem(command,apply=1):
0035 print(command)
0036 if apply==1: return os.system(command)
0037 elif apply==0: return 0
0038 else:
0039 print('[electronStore.py] UNSUPPORTED ARGUMENT VALUE FOR mysystem(,apply):',apply)
0040 exit(1)
0041
0042
0043
0044
0045
0046
0047 class flushfile(object):
0048 def __init__(self,f):
0049 self.f = f
0050 def write(self,x):
0051 self.f.write(x)
0052 self.f.flush()
0053
0054 sys.stdout = flushfile(sys.stdout)
0055
0056
0057
0058
0059
0060
0061 if __name__ == "__main__":
0062
0063
0064
0065
0066
0067
0068 parser = optparse.OptionParser()
0069 parser.add_option("-f", "--force", dest="force", action="store_true", default=False,
0070 help="force the copy, even if the destination file already exists.")
0071 parser.add_option("-r", "--release", dest="release", action="store", default="current",
0072 help="release name of this set of histograms.")
0073 parser.add_option("-m", "--message", dest="message", action="store", default="",
0074 help="specific comment about this set of histograms")
0075 parser.add_option("-a", "--analyzers", dest="analyzers", action="store", default="",
0076 help="slash separated list of analyzers")
0077 parser.add_option("-c", "--configs", dest="configs", action="store", default="",
0078 help="slash separated list of cmsRun configurations")
0079 (options, args) = parser.parse_args()
0080
0081 if len(args)<2:
0082 print("[electronStore.py] I NEED AT LEAST TWO ARGUMENTS.")
0083 exit(2)
0084 store_file = args.pop(0)
0085 store_dir = args.pop()
0086 if len(args)>0: store_logs = ' '.join(args)
0087 else: store_logs = ''
0088
0089 analyzers = options.analyzers.split('/') ;
0090 configs = options.configs.split('/') ;
0091
0092
0093
0094
0095
0096
0097 if os.path.exists(store_dir)==False:
0098 os.makedirs(store_dir)
0099
0100
0101
0102
0103
0104
0105 if os.path.isfile(store_file)==True :
0106 print("STORE_FILE =",store_file)
0107 else :
0108 print("[electronStore.py] FILE DOES NOT EXIST :",store_file)
0109 exit(3)
0110
0111 if ( store_logs != '' ) :
0112 print("STORE_LOGS =",store_logs)
0113
0114
0115
0116
0117
0118
0119 output_file = store_dir+'/'+store_file
0120 if ( options.force==False and os.path.isfile(output_file)==True ) :
0121 print("[electronStore.py] ERROR: "+store_file+" ALREADY STORED IN "+store_dir+" !")
0122 exit(4)
0123
0124
0125
0126
0127
0128
0129 files = [ store_file ]
0130 for analyzer in analyzers:
0131 files.append('../plugins/'+analyzer+'.h')
0132 files.append('../plugins/'+analyzer+'.cc')
0133 for config in configs:
0134 files.append(config+'.py')
0135
0136 mysystem('cp '+' '.join(files)+' '+store_dir)
0137
0138 if ( store_logs != '' ) :
0139 mysystem('cp '+store_logs+' '+store_dir)
0140 mysystem('cd '+store_dir+' && gzip -f *.olog')
0141
0142
0143
0144
0145
0146
0147 store_url = store_dir.replace('/afs/cern.ch/cms/','http://cmsdoc.cern.ch/',1)
0148
0149 links = []
0150 for analyzer in analyzers:
0151 links.append('<a href="'+store_url+'/'+analyzer+'.h">'+analyzer+'.h</a>')
0152 links.append('<a href="'+store_url+'/'+analyzer+'.cc">'+analyzer+'.cc</a>')
0153 for config in configs:
0154 links.append('<a href="'+store_url+'/'+config+'.py">'+config+'.py</a>')
0155
0156 comment_file = open(store_dir+'/'+store_file+'.comment','w')
0157 print('The <a href="'+store_url+'/'+store_file+'">'+options.release+' histograms</a>', end=' ', file=comment_file)
0158 if (options.message!=''):
0159 print(' ('+options.message+')', end=' ', file=comment_file)
0160 print(' have been prepared with those analyzers and configurations: '+', '.join(links)+'.', end=' ', file=comment_file)
0161 print(file=comment_file)
0162 comment_file.close()
0163
0164
0165
0166
0167
0168
0169 exit(0)
0170
0171