def __init__(self,name='acceptance'): """read the card""" MW_param.go_to_main_dir() self.MWparam=MW_param.MW_info('MadWeight_card.dat') self.name=name self.dir=os.getcwd().split('/')[-1] os.system('mkdir Events/'+self.MWparam.name) os.system('mkdir Events/'+self.MWparam.name+'/Acceptance') create_param.Param_card(run_name=self.MWparam) self.MWparam.update_nb_card() os.chdir('..')
def write_card(self,name): """write the param_card with name $name """ if 1: #try: num=int(name[11:-4]) self.create_info_line(num) #except: # pass MW_param.go_to_main_dir() ff=open('./Cards/'+name,'w') if self.source: #charge the comment from the original card gg=open('./Cards/'+self.source,'r') while 1: line=gg.readline() if line=='': break if line[0]=="#": ff.writelines(line) else: break gg.close() decay=0 for key in self.info.keys(): if key in ['decay','br']: decay=1 continue if key=="comment": continue text=self.create_blok_text(key) ff.writelines(text) if decay: text=self.create_decay_text() ff.writelines(text) ff.close() self.creating_card+=1
def write_card(self, name): """write the param_card with name $name """ if 1: #try: num = int(name[11:-4]) self.create_info_line(num) #except: # pass MW_param.go_to_main_dir() ff = open('./Cards/' + name, 'w') if self.source: #charge the comment from the original card gg = open('./Cards/' + self.source, 'r') while 1: line = gg.readline() if line == '': break if line[0] == "#": ff.writelines(line) else: break gg.close() decay = 0 for key in self.info.keys(): if key in ['decay', 'br']: decay = 1 continue if key == "comment": continue text = self.create_blok_text(key) ff.writelines(text) if decay: text = self.create_decay_text() ff.writelines(text) ff.close() self.creating_card += 1
def FindCardName(self,tag): if tag in list(dico.keys()): if '.' not in dico[tag]: return dico[tag]+'.dat' else: return dico[tag] else: import time out=tag.split('_',1) name=self.FindCardName(out[0]) return name.split('.',1)[0]+'_'+out[1]+'.dat' if __name__=='__main__': import MW_param MW_param.go_to_main_dir() opt=sys.argv print(opt) if len(opt)<2: name=input('enter the run name to restore or the position of a banner file\n') else: name=opt[1] if ('/' not in name): ban=banner('./Events/'+name+'/'+name+'_banner.txt') pos='./Events/'+name+'/' else: ban=banner(name) pos='/'.join([part for part in name.split('/')[:-1]]) ban.split()
""" read the file to find the requested change of variable""" found=0 for line in file(filepos): if found: name=line.split()[0] #remove blank spae,end of line,... return name if line.startswith('# Begin transfer_function'): found=1 ########################### TEST ################################# if(__name__=="__main__"): import MW_param MW_param.go_to_main_dir() P_dir,MW_dir=MW_param.detect_SubProcess(P_mode=1) opt=sys.argv if len(opt)<2: listdir=os.listdir('./Source/MadWeight/transfer_function/data') print 'Available TF function:\n ', print '\n '.join([content[3:-4] for content in listdir if (content.startswith('TF') and content.endswith('dat'))]) name=raw_input('Choose your Transfer Function\n') else: name=opt[1] if name in ['proc_card.dat','auto']: name=extract_tf_name('./Cards/proc_card.dat') if len(opt)==3: made_make=int(opt[2])