Package madgraph :: Package madweight :: Module mod_file
[hide private]
[frames] | no frames]

Source Code for Module madgraph.madweight.mod_file

  1  #!/usr/bin/env python  
  2  #################################################################################################### 
  3  #################################################################################################### 
  4  ##                                                                                                ## 
  5  ##                                    MOD FILE MODULE                                             ## 
  6  ##                                                                                                ## 
  7  #################################################################################################### 
  8  #################################################################################################### 
  9  ##                                                                                                ## 
 10  ##    Author: Mattelaer Olivier                                                                   ## 
 11  ##    Institution: UCL-CP3                                                                        ## 
 12  ##    contact: omattelaer@uclouvain.be                                                            ## 
 13  ##                                                                                                ## 
 14  ##    last modification: 01/06/10                                                                 ## 
 15  ##    tag release:       1.4                                                                      ## 
 16  ##                                                                                                ## 
 17  #################################################################################################### 
 18  ##                                                                                                ## 
 19  ##                                         MANUAL                                                 ## 
 20  ##                                                                                                ## 
 21  #################################################################################################### 
 22  ##                                                                                                ## 
 23  ##  This module is dedicated to modified file in planified way. The file must have tag in order   ## 
 24  ##     to perform the needed modifications.  All tag are in the following syntax:                 ## 
 25  ##      $B$ NAME $B$ -> begin of a block to modify with RULE=NAME                                 ## 
 26  ##      $E$ NAME $E$ -> end of the block to modify with RULE=NAME                                 ## 
 27  ##      $B$ NAME $E$ -> replace tag by RULE=NAME                                                  ## 
 28  ##  Some character are reserved:                                                                  ## 
 29  ##   'S-','_' and '+'                                                                             ## 
 30  ##   'S-': indicates a special tag (see later). Don't start name with this two caracter           ## 
 31  ##   '_' : indicates begin of option in special tag, use freely if you are not in this case       ## 
 32  ##   '+' : for splitting different option value (use freely elsewhere)                            ## 
 33  ##                                                                                                ## 
 34  ##  This is the special expression authorized in NAME (all start with S-)                         ##                                             
 35  ##                                                                                                ## 
 36  ##  S-END:(only in rule) add the text in end (no tag needed)                                      ## 
 37  ##  S-DEl:(in mod_file) supress this part of the file                                             ## 
 38  ##  S-COMMENT_?: start commenting the defined region.                                             ## 
 39  ##      The comment tag will be the value in place of the '?'. the '?' Can not contain '+' or '_' ## 
 40  ##  S-DECOMMENT_?:(only in rule) inverse the comment procedure apply with S-COMMENT (go back to   ## 
 41  ##                original line)                                                                  ## 
 42  ##  S-REGEX_exp+new[+opt]: regular expression to move an expression to another.                   ## 
 43  ##        "exp": a Python regular expression for the text to modify                               ## 
 44  ##        "new": the new expression to write                                                      ## 
 45  ##        "opt": python option for regular option (the one in re.compile)                         ## 
 46  ##      if this rule appear in rule file, the modification appear in the complete file.           ## 
 47  ##      no '_' or '+' are autorized in "exp" or "new". those one can be echap with '\'            ## 
 48  ##                                                                                                ## 
 49  ##  Priority order                                                                                ## 
 50  ##     if a step define a tag that will in a future step the modification on the tag will be done ## 
 51  ##     if you want to prevent this create the tag with $B-DIFF$ and with $E-DIFF$                 ## 
 52  ##                                                                                                ## 
 53  ##     1) we first apply the global REGEXP                                                        ## 
 54  ##     2) we apply decomment module                                                               ## 
 55  ##     3) we apply the modification for $B$ NAME $E$                                              ## 
 56  ##     4) we apply the modification for $B$ NAME $B$ TEXT $E$ NAME $E$                            ## 
 57  ##     5) we convert the $ ?-DIFF$ in normal tag                                                  ## 
 58  ##                                                                                                ## 
 59  #################################################################################################### 
 60  ##                                                                                                ## 
 61  ## Exemple of use:                                                                                ## 
 62  ## 1) with a master file                                                                          ## 
 63  ##                                                                                                ## 
 64  ##    import mod_file                                                                             ## 
 65  ##                                                                                                ## 
 66  ##    mod_file.mod_file(./master_file.txt)                                                        ## 
 67  ##                                                                                                ## 
 68  ## 2) without master file                                                                         ## 
 69  ##                                                                                                ## 
 70  ##    import mod_file                                                                             ## 
 71  ##                                                                                                ## 
 72  ##    mod_file.mod_file(file_to_change,rule,[write=''])                                           ## 
 73  ##       file_to_change: can be string or list of file                                            ## 
 74  ##       rule: position of the rule-file. You can also use a list of rule files (this must have   ## 
 75  ##              the same length than file_to_change list                                          ## 
 76  ##                                                                                                ## 
 77  #################################################################################################### 
 78  ##                                                                                                ## 
 79  ##  master file                                                                                   ## 
 80  ##      is a file with tree column corresponding to mod_file/rule_file/write the write is         ## 
 81  ##      not optional in file.  Comment start with # in this file                                  ## 
 82  ##                                                                                                ## 
 83  ##  rule file                                                                                     ## 
 84  ##      in this file, you can defined, what are the new text to for each tag. Syntax is:          ## 
 85  ##      $B$ NAME $B$                                                                              ## 
 86  ##             CONTENT                                                                            ## 
 87  ##      $E$ NAME $E$                                                                              ## 
 88  ##                                                                                                ## 
 89  #################################################################################################### 
 90  ##                                                                                                ## 
 91  ##   modification list:                                                                           ## 
 92  ##                                                                                                ## 
 93  ##     01/06/10: - make the modification inside a unknow blok                                     ## 
 94  ##               - add a test suite for MadWeight case                                            ## 
 95  ##                                                                                                ## 
 96  ##     29/09/09: - differentiate $b$...$b$ from $B$...$B$ (gestion of end of line)                ##  
 97  ##                                                                                                ## 
 98  ##     22/05/09: - add decomment option                                                           ## 
 99  ##               - ensure that all end of line use tag \n                                         ## 
100  ##                                                                                                ## 
101  ##     11/11/08: - modify documentation                                                           ## 
102  ##               - authorize differate affectation with B-DIFF                                    ##  
103  ##                                                                                                ## 
104  ##     31/01/08: - pass in object                                                                 ## 
105  ##               - add S-comment super tag                                                        ## 
106  ##               - add S-del super tag                                                            ## 
107  ##               - pass in isolated module                                                        ## 
108  ##               - create documentation                                                           ## 
109  ##               - replace tag can be inserted in a line                                          ## 
110  ##                                                                                                ## 
111  ##    23/06/08:  - add S-REGEXP super tag                                                         ## 
112  ##               - add function list                                                              ## 
113  ##               - differentiate $B$...$E$ with $b$...$e$                                         ## 
114  ##                    the first supress the full tag line                                         ## 
115  ##                                                                                                ## 
116  #################################################################################################### 
117  ##                                                                                                ## 
118  ##                                      Function                                                  ## 
119  ##                                      --------                                                  ## 
120  ##                                                                                                ## 
121  ##    mod_file                                                                                    ## 
122  ##    mod_text                                                                                    ## 
123  ##    Mod_file                                                                                    ## 
124  ##    |    + init                                                                                 ## 
125  ##    |    + mod_all_file                                                                         ## 
126  ##    |    |    +    mod_one_file                                                                 ## 
127  ##    |    |    +    mod_one_text                                                                 ## 
128  ##    |    |    +     +  treat_begin_end_line                                                     ##  
129  ##    |    + extract_modif                                                                        ## 
130  ##    |    + return_mod_text                                                                      ## 
131  ##    |    |    +    comment_text                                                                 ## 
132  ##    |    |    +    del_text                                                                     ## 
133  ##    |    |    +    regexp_text                                                                  ## 
134  ##    |    + back_to_init_dir                                                                     ## 
135  ##    |    + go_to_main_dir                                                                       ## 
136  ##                                                                                                ## 
137  #################################################################################################### 
138   
139  # Module 
140  import os 
141  import sys 
142  import re 
143  import shutil 
144  import string 
145  from time import time 
146   
147  # 1 ############################################################### 
148 -def mod_file(mod_file,rule_file='',write='',opt={}):
149 150 if rule_file: #not a master asking 151 if type(mod_file)!=list: 152 mod_obj=Mod_file(opt=opt) 153 mod_obj.mod_one_file(mod_file,rule_file,write) 154 elif type(mod_file)==list: 155 #supress problem of output 156 if write=='': 157 write=['']*len(mod_file) 158 #supress problem if only one rule_file 159 if type(rule_file)!=list: 160 rule_file=[rule_file]*len(mod_file) 161 if type(rule_file)==str: 162 mod_obj=Mod_file(rule_file=rule_file,opt=opt) 163 for i in range(0,len(mod_file)): 164 mod_obj.mod_one_file(mod_file[i],mod_obj.dico,write[i]) 165 else: 166 mod_obj=Mod_file(opt=opt) 167 for i in range(0,len(mod_file)): 168 mod_obj.mod_one_file(mod_file[i],rule_file[i],write[i]) 169 else: 170 mod_obj=Mod_file(mod_file,opt=opt)
171 172 # 1 ###############################################################
173 -def mod_text(text,rule_file='',write=''):
174 175 176 mod_obj=Mod_file() 177 mod_obj.file='input text' 178 text=mod_obj.mod_one_text(text,rule_file,write) 179 return text
180 181 182 183 # 1 ###############################################################
184 -class Mod_file:
185 186 187 nowarning=[] 188 189 # 2 ###############################################################
190 - def __init__(self,main_file='',rule_file='',opt={}):
191 """ start the instruction of modification present in the main file if present """ 192 193 self.d_init=os.getcwd() 194 self.d_rule=os.getcwd() 195 self.d_main=os.getcwd() 196 197 self.failed=0 #tag to know if a tag is not modify 198 199 if opt: 200 for key,value in opt.items(): 201 exec('self.'+key+'='+str(value)+'') 202 203 if main_file: 204 #main_dir is the directory of the main_file 205 self.d_rule=os.path.dirname(os.path.realpath(main_file)) 206 self.d_main=self.d_rule 207 self.mod_all_file(os.path.basename(main_file)) 208 if rule_file: 209 self.extract_modif(rule_file)
210 211 212 213 # 2 ###############################################################
214 - def mod_all_file(self,rule_pos):
215 """ apply modification following manager main_file """ 216 217 self.go_to_main_dir() 218 219 #pattern for tree column in a line 220 opt_pattern=re.compile(r'''^\s*(?P<opt>\S+)\s*=\s*(?P<value>\S+)''') 221 Pattern=re.compile(r'''^\s*(?P<file>\S+)\s+(?P<rule>\S+)\s+(?P<write>\S*)\s*$''') 222 ff=open(rule_pos,'r') 223 224 while 1: 225 line=ff.readline() 226 if line=='': 227 break 228 if line[0]=='#': 229 continue 230 obj_opt=opt_pattern.search(line) 231 if obj_opt: 232 if obj_opt.group('opt')=='main_dir': 233 self.d_main=os.path.join(self.d_main,obj_opt.group('value')) 234 self.go_to_main_dir() 235 236 obj_pat=Pattern.search(line) 237 if obj_pat: 238 self.mod_one_file(obj_pat.group('file'),obj_pat.group('rule'),obj_pat.group('write')) 239 240 self.back_to_init_dir()
241 242 # 3 ###############################################################
243 - def mod_one_file(self,mod_file,rule_file,write=''):
244 """ modify the file mod_file with rule_file instruction output will ba place in write (same file by default)""" 245 start=time() 246 self.go_to_main_dir() 247 self.file=mod_file 248 249 ff=open(mod_file,'r') 250 text=ff.read() 251 ff.close() 252 if write: 253 self.mod_one_text(text,rule_file,write) 254 else: 255 self.mod_one_text(text,rule_file,mod_file) 256 self.back_to_init_dir() 257 stop=time() 258 #print 'time used to modifiy file:',stop-start,'s' 259 return
260 261 # 3 ###############################################################
262 - def mod_one_text(self,text,rule_file='',write=''):
263 """ modify the text with rule_file instruction output will be place in write (same file by default)""" 264 265 self.go_to_main_dir() 266 267 #print "modify ",mod_file.split('/')[-1] 268 if rule_file=='': 269 dico=self.dico 270 elif type(rule_file)!=dict: 271 self.extract_modif(rule_file) 272 else: 273 dico=rule_file 274 self.dico=dico 275 # print "dico", self.dico.keys() 276 277 begin_end=re.compile(r'''\$(?P<maj>B)\$\s?(?P<tag>\S+)\s?\$B\$(?P<text>.*)\$E\$\s?(?P=tag)\s?\$E\$''',re.S+re.I) # $B$ TAG $B$ TEXT $E$ TAG $E$ 278 end_file=re.compile(r'''\$\$\s*END\s+FILE\s*\$\$''') # $$ END FILE $$ 279 replace=re.compile(r'''\$(?P<maj>B)\$[ \t]*(?P<tag>\S+)[ \t]*\$E\$''',re.I) # $B$ TAG $E$ 280 end_begin=re.compile(r'''\$(?P<maj>E)\$\s?(?P<tag>\S+)\s?\$E\$(?P<text>.*)\$B\$\s?(?P=tag)\s?\$B\$''',re.S+re.I) # $E$ TAG $E$ TEXT $B$ TAG $B$ -> in case of multiple tag 281 282 ##treat global regexp 283 for key in self.dico.keys(): 284 if key.startswith('S-REGEXP'): 285 text=self.return_mod_text(key,text) 286 287 ##treat decomment module 288 for key in self.dico.keys(): 289 if key.startswith('S-DECOMMENT_'): 290 text=self.return_mod_text(key,text) 291 292 ##treat replacment 293 text_list=replace.split(text) 294 text_to_write=text_list.pop(0) 295 while len(text_list)>1: 296 maj=text_list.pop(0).isupper() 297 tag=text_list.pop(0) 298 text_to_write2=self.return_mod_text(tag,'') 299 text_to_write3=text_list.pop(0) 300 text_to_write=self.treat_begin_end_line(maj,text_to_write,text_to_write2,text_to_write3) 301 302 ##treat block part 303 text_list=begin_end.split(text_to_write) 304 text_to_write=text_list.pop(0) 305 multiple=0 #control 306 while len(text_list)>2: 307 maj=text_list.pop(0).isupper() 308 tag=text_list.pop(0) 309 text=text_list.pop(0) 310 if end_begin.search(text) and end_begin.search(text).group('tag')==tag: 311 mod_text=self.treat_multiple_tag(text,maj,tag) 312 else: 313 mod_text=self.return_mod_text(tag,text) 314 text_next=text_list.pop(0) 315 text_to_write=self.treat_begin_end_line(maj,text_to_write,mod_text,text_next) 316 317 318 ## treat end file: 319 if self.dico.has_key("S-END"): 320 if not end_file.search(text_to_write): 321 text_to_write+=self.dico["S-END"] 322 323 ## restore diff affectation 324 text_to_write=text_to_write.replace('$B-DIFF$','$B$') 325 text_to_write=text_to_write.replace('$E-DIFF$','$E$') 326 327 ##check that only one type of end of line is in use 328 text_to_write=text_to_write.replace('\r\n','\n') 329 330 ##write output 331 if write: 332 ff=open(write,'w') 333 ff.writelines(text_to_write) 334 ff.close() 335 336 self.back_to_init_dir() 337 return text_to_write
338 339 # 4 #########################################################################
340 - def treat_begin_end_line(self,clearline,text_before,text,text_after):
341 342 343 if clearline and not self.failed: 344 output=text_to_write=text_before[:text_before.rfind('\n')]+'\n' 345 output+=text 346 output+='\n'+text_after[text_after.find('\n'):] 347 else: 348 output=text_before+text+text_after 349 350 self.failed=0 351 return output
352 353 # 4 #########################################################################
354 - def treat_multiple_tag(self,text,maj,tag):
355 end_begin=re.compile(r'''\$E\$\s?(?P<tag>\S+)\s?\$E\$(?P<text>.*)\$(?P<maj>B)\$\s?(?P=tag)\s?\$B\$''',re.S+re.I) # $E$ TAG $E$ TEXT $B$ TAG $B$ -> in case of multiple tag 356 357 split_text=end_begin.split(text) 358 text1=split_text.pop(0) 359 tag=split_text.pop(0) 360 mod_text=self.return_mod_text(tag,text1) 361 text_next=split_text.pop(0) 362 text_next=self.mod_one_text(text_next) 363 text_to_write=self.treat_begin_end_line(maj,'',mod_text,text_next) 364 maj=split_text.pop(0) 365 text2=split_text.pop(0) 366 mod_text=self.return_mod_text(tag,text2) 367 text_to_write=self.treat_begin_end_line(maj,text_to_write,mod_text,'') 368 369 return text_to_write
370 371 372 373 374 375 ############################################################################# 376 # Extract rule information # 377 ############################################################################# 378 379 # 2 ###############################################################
380 - def extract_modif(self,rule_file):
381 """put the information in a dictionary""" 382 try: 383 ff=open(rule_file,'r') 384 except: 385 ff=open(os.path.join(self.d_rule,rule_file),'r') 386 begin=re.compile(r'''^\$B\$\s?(?P<tag>\S+)\s?\$B\$''') 387 end=re.compile(r'''^\$E\$\s?(?P<tag>\S+)\s?\$E\$''') 388 comment=re.compile(r'''^##\**\s*$''') 389 special_begin=re.compile(r'''^\$(?P<tag>S-\S+)-B\$''') 390 special_end=re.compile(r'''^\$(?P<tag>S-\S+)-E\$''') 391 special=re.compile(r'''^\$(?P<tag>S-\S+)\$''') 392 self.dico={} 393 tag="" 394 replace_text="" 395 rec_mode=0 396 397 while 1: 398 line=ff.readline() 399 if line=='': 400 break 401 if comment.search(line): 402 continue 403 if special.search(line): 404 tag=special.search(line).group('tag') 405 self.dico[tag]='' 406 if begin.search(line) or special_begin.search(line): 407 try: 408 tag=begin.search(line).group('tag') 409 except: 410 tag=special_begin.search(line).group('tag') 411 if rec_mode: 412 print 'error in ',rule_file,' wrong termination for ',tag,' rule' 413 sys.exit() 414 rec_mode=1 415 continue 416 if end.search(line) or special_end.search(line): 417 try: 418 tag=end.search(line).group('tag') 419 except: 420 tag=special_end.search(line).group('tag') 421 if rec_mode==0: 422 print 'error in ',rule_file,'no initial tag:', tag 423 sys.exit() 424 #detect one-line replacment => supress blank and '\n' 425 if replace_text.count('\n')==1: 426 replace_text=replace_text[:-1] 427 while replace_text.endswith(' '): 428 replace_text=replace_text[:-1] 429 self.dico[tag]=replace_text 430 tag="" 431 replace_text="" 432 rec_mode=0 433 continue 434 435 if rec_mode: 436 replace_text+=line 437 438 if rec_mode: 439 print 'error in ',rule_file,' wrong end-file termination ' 440 sys.exit() 441 return self.dico
442 443 444 445 ############################################################################# 446 # tag treatment # 447 ############################################################################# 448 449 # 2 ###############################################################
450 - def return_mod_text(self,tag,text):
451 """ by default return the text linked to tag 452 special tag are S-TAG_OPT: OPT=OPT1+OPT2+OPT3+...""" 453 454 special_tag=re.compile(r'''S-(?P<tag>[^ \t\n\r\f\v_]+)_?(?P<opt>[^\t\n\r\f\v]*)''') # S-TAG_OPT 455 456 if not special_tag.search(tag): 457 try: 458 return self.dico[tag] 459 except: 460 if tag not in self.nowarning and self.nowarning != 'all': 461 print 'WARNING: tag:',tag,' not defined in file ',self.file 462 print 'no modification done for this tag' 463 if text: 464 output = '$B$ '+tag+' $B$'+ self.mod_one_text(text)+' $E$ '+tag+' $E$' 465 else: 466 output = '$B$ '+tag+' $E$' 467 self.failed=1 468 return output 469 470 #SPECIAL TAG CASE 471 short_tag=special_tag.search(tag).group('tag') 472 opt=special_tag.search(tag).group('opt').split('+') 473 #be sure that some split are not with a echap tag 474 old='' 475 opt2=[] 476 for part in opt: 477 if len(part) and part[-1]=='\\' : 478 old=part[:-1]+'+' 479 else: 480 opt2.append(old+part) 481 old='' 482 opt=opt2 483 484 tag=short_tag.lower() 485 if tag=='comment': 486 text=self.comment_text(text,opt[0]) 487 elif tag=='del': 488 text=self.del_text(text) 489 elif tag=='regexp': 490 if len(opt)==2: 491 text=self.regexp_text(text,opt[0],opt[1]) 492 elif len(opt)==3: 493 text=self.regexp_text(text,opt[0],opt[1],opt[2]) 494 elif tag=='decomment': 495 text=self.decomment_text(text,opt[0]) 496 497 return text
498 499 # 3 ###############################################################
500 - def comment_text(self,text,comment_tag):
501 """ add comment_tag before each line """ 502 end_line=re.compile(r''' ''') 503 #print [text] 504 #print [text.split('\n')] 505 #print text 506 #print text.replace('\n','\n'+comment_tag+'\t') 507 508 text=comment_tag+'|\t'+text.replace('\n','\n'+comment_tag+'|\t') 509 if text[-3:]=="|\t\n": 510 text=text[-3:] 511 text=text.replace('\t',' ') 512 text2='' 513 for line in text.split('\n'): 514 if line=='': 515 continue 516 if len(line)<74: 517 if line[-1]=='\n': 518 line=line[:-1] 519 for i in range(len(line),73): 520 line+=' ' 521 line+='|\n' 522 else: 523 line+='\n' 524 text2+=line 525 526 line=comment_tag+'+'+71*'-'+'+\n' 527 528 return line+text2+line+'\n'
529 530 # 3 ###############################################################
531 - def decomment_text(self,text,comment_tag):
532 """ remove comment inserted by comment_text """ 533 534 carac_line=re.compile(comment_tag+'\+'+71*'-'+'\+') 535 536 def decomment_line(line,comment_tag): 537 if line[:6]==comment_tag+'| ': 538 line=line[6:] 539 else: 540 print [line[:6]] 541 print 'failed decomment' 542 543 if line[-1]=='|': 544 line=line[:-1] 545 return line
546 547 decomment=0 548 init_text=text.split('\n') 549 end_text='' 550 for line in init_text: 551 if carac_line.search(line): 552 decomment=not decomment 553 if decomment: 554 end_text+=comment_tag+' $B-DIFF$ S-COMMENT_'+comment_tag+' $B-DIFF$\n' 555 continue 556 else: 557 end_text+=comment_tag+' $E-DIFF$ S-COMMENT_'+comment_tag+' $E-DIFF$\n' 558 continue 559 if decomment: 560 # end_text+=line+'\n' 561 end_text+=decomment_line(line,comment_tag)+'\n' 562 else: 563 end_text+=line+'\n' 564 565 return end_text 566 return end_text
567 568 # 3 ###############################################################
569 - def del_text(self,text):
570 return ''
571 572 # 3 ###############################################################
573 - def regexp_text(self,text,exp,new,opt=''):
574 """ replace the text exp (python regular expression) with new""" 575 576 ### step A) remove escape '_' and '+' 577 ### step B) apply the modification 578 ### step C) return new text 579 580 ## Step A: remove escape '_' and '+' 581 exp=exp.replace('\\\\','@888@') #stupid security against string like (\\_) 582 exp=exp.replace('\_','_').replace('\+','+') 583 exp=exp.replace('@888@','\\\\') #end of the trick 584 585 586 # Step B: apply the modification 587 pattern=re.compile(exp,eval(opt)) 588 text=pattern.sub(new, text) 589 590 # Step C: return 591 return text
592 593 ############################################################################ 594 # positioning routine # 595 ############################################################################ 596 597 # 2 ###############################################################
598 - def back_to_init_dir(self):
599 os.chdir(self.d_init)
600 601 # 2 ###############################################################
602 - def go_to_main_dir(self):
603 os.chdir(self.d_main)
604 605 606 ######################################################################################################### 607 # TEST ################################################################################################# 608 ######################################################################################################### 609 if '__main__' == __name__: 610 611 import sys 612 sys.path.append('./Source/MadWeight/Python') 613 import create_run 614 import unittest 615 import os, shutil 616 617
618 - class TestMod_file(unittest.TestCase):
619 """ Test the the mod routines works correctly on MadWeight """ 620
621 - def setUp(self):
622 """ create a copy of the original file """ 623 shutil.copyfile('../Template/SubProcesses/cuts.f', './SubProcesses/cuts.bk')
624
625 - def tearDown(self):
626 os.system('rm -f ./SubProcesses/cuts.mod') 627 os.system('rm -f ./SubProcesses/cuts.bk') 628 os.system('rm -f ./SubProcesses/cuts.o')
629 630
631 - def test_cuts(self):
632 """ test if we can activate/desactivate the cuts """ 633 634 self.assertEqual(create_run.cut_is_active('cuts.bk'), 1) 635 self.assertEqual(create_run.bw_cut_is_active('cuts.bk'),1) 636 637 file_to_mod='./SubProcesses/cuts.bk' 638 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 639 #modify file 640 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 641 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 642 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 643 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 644 645 file_to_mod='./SubProcesses/cuts.mod' 646 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 647 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 648 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 649 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 650 651 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 652 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 653 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 654 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 655 656 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 657 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 658 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 659 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
660
661 - def test_mw_cuts(self):
662 663 file_to_mod ='./SubProcesses/cuts.bk' 664 rule= './Source/MadWeight/mod_file/mod_cuts' 665 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 666 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 667 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 668 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 669 670 file_to_mod='./SubProcesses/cuts.mod' 671 rule = './Source/MadWeight/mod_file/suppress_cuts_MW' 672 673 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 674 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 675 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 676 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 677 678 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 679 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 680 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 681 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 682 683 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 684 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 685 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 686 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 687 688 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 689 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 690 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 691 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
692
693 - def test_P_BW_cuts(self):
694 695 self.assertEqual(create_run.cut_is_active('cuts.bk'), 1) 696 self.assertEqual(create_run.bw_cut_is_active('cuts.bk'),1) 697 698 file_to_mod='./SubProcesses/cuts.bk' 699 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 700 #modify file 701 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 702 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 703 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 704 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 705 706 file_to_mod='./SubProcesses/cuts.mod' 707 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 708 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 709 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 710 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 711 712 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 713 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 714 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 715 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 716 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 717 718 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 719 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 720 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 721 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 722 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 723 724 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 725 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 726 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 727 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 728 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 729 730 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 731 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 732 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 733 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 734 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 735 736 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 737 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 738 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 739 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 740 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 741 742 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 743 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 744 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 745 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 746 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 747 748 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 749 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 750 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 751 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 752 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
753 754 # Next one will Fail but is not supose to be called whitout check of the second 755 #rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 756 #mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 757 #self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 758 #self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 759 760
761 - def test_MW_BW_cuts(self):
762 763 self.assertEqual(create_run.cut_is_active('cuts.bk'), 1) 764 self.assertEqual(create_run.bw_cut_is_active('cuts.bk'),1) 765 766 file_to_mod='./SubProcesses/cuts.bk' 767 rule= './Source/MadWeight/mod_file/mod_cuts' 768 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 769 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 770 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 771 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 772 773 file_to_mod='./SubProcesses/cuts.mod' 774 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 775 #modify file 776 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 777 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 778 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 779 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 780 781 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 782 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 783 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 784 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 785 786 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 787 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 788 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 789 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 790 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 791 792 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 793 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 794 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 795 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 796 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 797 798 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 799 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 800 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 801 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 802 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 803 804 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 805 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 806 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 807 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 808 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 809 810 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 811 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 812 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 813 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 814 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 815 816 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 817 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 818 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 819 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 820 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
821 822 823 824 unittest.main() 825