00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 import os, sys, datetime, shutil, optparse
00027
00028
00029
00030
00031
00032
00033 def mysystem(command,apply=1):
00034 print command
00035 if apply==1: return os.system(command)
00036 elif apply==0: return 0
00037 else:
00038 print '[electronStore.py] UNSUPPORTED ARGUMENT VALUE FOR mysystem(,apply):',apply
00039 exit(1)
00040
00041
00042
00043
00044
00045
00046 class flushfile(object):
00047 def __init__(self,f):
00048 self.f = f
00049 def write(self,x):
00050 self.f.write(x)
00051 self.f.flush()
00052
00053 sys.stdout = flushfile(sys.stdout)
00054
00055
00056
00057
00058
00059
00060 if __name__ == "__main__":
00061
00062
00063
00064
00065
00066
00067 parser = optparse.OptionParser()
00068 parser.add_option("-f", "--force", dest="force", action="store_true", default=False,
00069 help="force the copy, even if the destination file already exists.")
00070 parser.add_option("-r", "--release", dest="release", action="store", default="current",
00071 help="release name of this set of histograms.")
00072 parser.add_option("-m", "--message", dest="message", action="store", default="",
00073 help="specific comment about this set of histograms")
00074 parser.add_option("-a", "--analyzers", dest="analyzers", action="store", default="",
00075 help="slash separated list of analyzers")
00076 parser.add_option("-c", "--configs", dest="configs", action="store", default="",
00077 help="slash separated list of cmsRun configurations")
00078 (options, args) = parser.parse_args()
00079
00080 if len(args)<2:
00081 print "[electronStore.py] I NEED AT LEAST TWO ARGUMENTS."
00082 exit(2)
00083 store_file = args.pop(0)
00084 store_dir = args.pop()
00085 if len(args)>0: store_logs = ' '.join(args)
00086 else: store_logs = ''
00087
00088 analyzers = options.analyzers.split('/') ;
00089 configs = options.configs.split('/') ;
00090
00091
00092
00093
00094
00095
00096 if os.path.exists(store_dir)==False:
00097 os.makedirs(store_dir)
00098
00099
00100
00101
00102
00103
00104 if os.path.isfile(store_file)==True :
00105 print "STORE_FILE =",store_file
00106 else :
00107 print "[electronStore.py] FILE DOES NOT EXIST :",store_file
00108 exit(3)
00109
00110 if ( store_logs != '' ) :
00111 print "STORE_LOGS =",store_logs
00112
00113
00114
00115
00116
00117
00118 output_file = store_dir+'/'+store_file
00119 if ( options.force==False and os.path.isfile(output_file)==True ) :
00120 print "[electronStore.py] ERROR: "+store_file+" ALREADY STORED IN "+store_dir+" !"
00121 exit(4)
00122
00123
00124
00125
00126
00127
00128 files = [ store_file ]
00129 for analyzer in analyzers:
00130 files.append('../plugins/'+analyzer+'.h')
00131 files.append('../plugins/'+analyzer+'.cc')
00132 for config in configs:
00133 files.append(config+'.py')
00134
00135 mysystem('cp '+' '.join(files)+' '+store_dir)
00136
00137 if ( store_logs != '' ) :
00138 mysystem('cp '+store_logs+' '+store_dir)
00139 mysystem('cd '+store_dir+' && gzip -f *.olog')
00140
00141
00142
00143
00144
00145
00146 store_url = store_dir.replace('/afs/cern.ch/cms/','http://cmsdoc.cern.ch/',1)
00147
00148 links = []
00149 for analyzer in analyzers:
00150 links.append('<a href="'+store_url+'/'+analyzer+'.h">'+analyzer+'.h</a>')
00151 links.append('<a href="'+store_url+'/'+analyzer+'.cc">'+analyzer+'.cc</a>')
00152 for config in configs:
00153 links.append('<a href="'+store_url+'/'+config+'.py">'+config+'.py</a>')
00154
00155 comment_file = open(store_dir+'/'+store_file+'.comment','w')
00156 print >>comment_file, 'The <a href="'+store_url+'/'+store_file+'">'+options.release+' histograms</a>',
00157 if (options.message!=''):
00158 print >>comment_file, ' ('+options.message+')',
00159 print >>comment_file, ' have been prepared with those analyzers and configurations: '+', '.join(links)+'.',
00160 print >>comment_file
00161 comment_file.close()
00162
00163
00164
00165
00166
00167
00168 exit(0)
00169
00170