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  from __future__ import absolute_import 
141  from __future__ import print_function 
142  import os 
143  import sys 
144  import re 
145  import shutil 
146  import string 
147  from time import time 
148  from six.moves import range 
149   
150  # 1 ############################################################### 
151 -def mod_file(mod_file,rule_file='',write='',opt={}):
152 153 if rule_file: #not a master asking 154 if type(mod_file)!=list: 155 mod_obj=Mod_file(opt=opt) 156 mod_obj.mod_one_file(mod_file,rule_file,write) 157 elif type(mod_file)==list: 158 #supress problem of output 159 if write=='': 160 write=['']*len(mod_file) 161 #supress problem if only one rule_file 162 if type(rule_file)!=list: 163 rule_file=[rule_file]*len(mod_file) 164 if type(rule_file)==str: 165 mod_obj=Mod_file(rule_file=rule_file,opt=opt) 166 for i in range(0,len(mod_file)): 167 mod_obj.mod_one_file(mod_file[i],mod_obj.dico,write[i]) 168 else: 169 mod_obj=Mod_file(opt=opt) 170 for i in range(0,len(mod_file)): 171 mod_obj.mod_one_file(mod_file[i],rule_file[i],write[i]) 172 else: 173 mod_obj=Mod_file(mod_file,opt=opt)
174 175 # 1 ###############################################################
176 -def mod_text(text,rule_file='',write=''):
177 178 179 mod_obj=Mod_file() 180 mod_obj.file='input text' 181 text=mod_obj.mod_one_text(text,rule_file,write) 182 return text
183 184 185 186 # 1 ###############################################################
187 -class Mod_file:
188 189 190 nowarning=[] 191 192 # 2 ###############################################################
193 - def __init__(self,main_file='',rule_file='',opt={}):
194 """ start the instruction of modification present in the main file if present """ 195 196 self.d_init=os.getcwd() 197 self.d_rule=os.getcwd() 198 self.d_main=os.getcwd() 199 200 self.failed=0 #tag to know if a tag is not modify 201 202 if opt: 203 for key,value in opt.items(): 204 exec('self.'+key+'='+str(value)+'') 205 206 if main_file: 207 #main_dir is the directory of the main_file 208 self.d_rule=os.path.dirname(os.path.realpath(main_file)) 209 self.d_main=self.d_rule 210 self.mod_all_file(os.path.basename(main_file)) 211 if rule_file: 212 self.extract_modif(rule_file)
213 214 215 216 # 2 ###############################################################
217 - def mod_all_file(self,rule_pos):
218 """ apply modification following manager main_file """ 219 220 self.go_to_main_dir() 221 222 #pattern for tree column in a line 223 opt_pattern=re.compile(r'''^\s*(?P<opt>\S+)\s*=\s*(?P<value>\S+)''') 224 Pattern=re.compile(r'''^\s*(?P<file>\S+)\s+(?P<rule>\S+)\s+(?P<write>\S*)\s*$''') 225 ff=open(rule_pos,'r') 226 227 while 1: 228 line=ff.readline() 229 if line=='': 230 break 231 if line[0]=='#': 232 continue 233 obj_opt=opt_pattern.search(line) 234 if obj_opt: 235 if obj_opt.group('opt')=='main_dir': 236 self.d_main=os.path.join(self.d_main,obj_opt.group('value')) 237 self.go_to_main_dir() 238 239 obj_pat=Pattern.search(line) 240 if obj_pat: 241 self.mod_one_file(obj_pat.group('file'),obj_pat.group('rule'),obj_pat.group('write')) 242 243 self.back_to_init_dir()
244 245 # 3 ###############################################################
246 - def mod_one_file(self,mod_file,rule_file,write=''):
247 """ modify the file mod_file with rule_file instruction output will ba place in write (same file by default)""" 248 start=time() 249 self.go_to_main_dir() 250 self.file=mod_file 251 252 ff=open(mod_file,'r') 253 text=ff.read() 254 ff.close() 255 if write: 256 self.mod_one_text(text,rule_file,write) 257 else: 258 self.mod_one_text(text,rule_file,mod_file) 259 self.back_to_init_dir() 260 stop=time() 261 #print 'time used to modifiy file:',stop-start,'s' 262 return
263 264 # 3 ###############################################################
265 - def mod_one_text(self,text,rule_file='',write=''):
266 """ modify the text with rule_file instruction output will be place in write (same file by default)""" 267 268 self.go_to_main_dir() 269 270 #print "modify ",mod_file.split('/')[-1] 271 if rule_file=='': 272 dico=self.dico 273 elif type(rule_file)!=dict: 274 self.extract_modif(rule_file) 275 else: 276 dico=rule_file 277 self.dico=dico 278 # print "dico", self.dico.keys() 279 280 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$ 281 end_file=re.compile(r'''\$\$\s*END\s+FILE\s*\$\$''') # $$ END FILE $$ 282 replace=re.compile(r'''\$(?P<maj>B)\$[ \t]*(?P<tag>\S+)[ \t]*\$E\$''',re.I) # $B$ TAG $E$ 283 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 284 285 ##treat global regexp 286 for key in self.dico.keys(): 287 if key.startswith('S-REGEXP'): 288 text=self.return_mod_text(key,text) 289 290 ##treat decomment module 291 for key in self.dico.keys(): 292 if key.startswith('S-DECOMMENT_'): 293 text=self.return_mod_text(key,text) 294 295 ##treat replacment 296 text_list=replace.split(text) 297 text_to_write=text_list.pop(0) 298 while len(text_list)>1: 299 maj=text_list.pop(0).isupper() 300 tag=text_list.pop(0) 301 text_to_write2=self.return_mod_text(tag,'') 302 text_to_write3=text_list.pop(0) 303 text_to_write=self.treat_begin_end_line(maj,text_to_write,text_to_write2,text_to_write3) 304 305 ##treat block part 306 text_list=begin_end.split(text_to_write) 307 text_to_write=text_list.pop(0) 308 multiple=0 #control 309 while len(text_list)>2: 310 maj=text_list.pop(0).isupper() 311 tag=text_list.pop(0) 312 text=text_list.pop(0) 313 if end_begin.search(text) and end_begin.search(text).group('tag')==tag: 314 mod_text=self.treat_multiple_tag(text,maj,tag) 315 else: 316 mod_text=self.return_mod_text(tag,text) 317 text_next=text_list.pop(0) 318 text_to_write=self.treat_begin_end_line(maj,text_to_write,mod_text,text_next) 319 320 321 ## treat end file: 322 if "S-END" in self.dico: 323 if not end_file.search(text_to_write): 324 text_to_write+=self.dico["S-END"] 325 326 ## restore diff affectation 327 text_to_write=text_to_write.replace('$B-DIFF$','$B$') 328 text_to_write=text_to_write.replace('$E-DIFF$','$E$') 329 330 ##check that only one type of end of line is in use 331 text_to_write=text_to_write.replace('\r\n','\n') 332 333 ##write output 334 if write: 335 ff=open(write,'w') 336 ff.writelines(text_to_write) 337 ff.close() 338 339 self.back_to_init_dir() 340 return text_to_write
341 342 # 4 #########################################################################
343 - def treat_begin_end_line(self,clearline,text_before,text,text_after):
344 345 346 if clearline and not self.failed: 347 output=text_to_write=text_before[:text_before.rfind('\n')]+'\n' 348 output+=text 349 output+='\n'+text_after[text_after.find('\n'):] 350 else: 351 output=text_before+text+text_after 352 353 self.failed=0 354 return output
355 356 # 4 #########################################################################
357 - def treat_multiple_tag(self,text,maj,tag):
358 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 359 360 split_text=end_begin.split(text) 361 text1=split_text.pop(0) 362 tag=split_text.pop(0) 363 mod_text=self.return_mod_text(tag,text1) 364 text_next=split_text.pop(0) 365 text_next=self.mod_one_text(text_next) 366 text_to_write=self.treat_begin_end_line(maj,'',mod_text,text_next) 367 maj=split_text.pop(0) 368 text2=split_text.pop(0) 369 mod_text=self.return_mod_text(tag,text2) 370 text_to_write=self.treat_begin_end_line(maj,text_to_write,mod_text,'') 371 372 return text_to_write
373 374 375 376 377 378 ############################################################################# 379 # Extract rule information # 380 ############################################################################# 381 382 # 2 ###############################################################
383 - def extract_modif(self,rule_file):
384 """put the information in a dictionary""" 385 try: 386 ff=open(rule_file,'r') 387 except: 388 ff=open(os.path.join(self.d_rule,rule_file),'r') 389 begin=re.compile(r'''^\$B\$\s?(?P<tag>\S+)\s?\$B\$''') 390 end=re.compile(r'''^\$E\$\s?(?P<tag>\S+)\s?\$E\$''') 391 comment=re.compile(r'''^##\**\s*$''') 392 special_begin=re.compile(r'''^\$(?P<tag>S-\S+)-B\$''') 393 special_end=re.compile(r'''^\$(?P<tag>S-\S+)-E\$''') 394 special=re.compile(r'''^\$(?P<tag>S-\S+)\$''') 395 self.dico={} 396 tag="" 397 replace_text="" 398 rec_mode=0 399 400 while 1: 401 line=ff.readline() 402 if line=='': 403 break 404 if comment.search(line): 405 continue 406 if special.search(line): 407 tag=special.search(line).group('tag') 408 self.dico[tag]='' 409 if begin.search(line) or special_begin.search(line): 410 try: 411 tag=begin.search(line).group('tag') 412 except: 413 tag=special_begin.search(line).group('tag') 414 if rec_mode: 415 print('error in ',rule_file,' wrong termination for ',tag,' rule') 416 sys.exit() 417 rec_mode=1 418 continue 419 if end.search(line) or special_end.search(line): 420 try: 421 tag=end.search(line).group('tag') 422 except: 423 tag=special_end.search(line).group('tag') 424 if rec_mode==0: 425 print('error in ',rule_file,'no initial tag:', tag) 426 sys.exit() 427 #detect one-line replacment => supress blank and '\n' 428 if replace_text.count('\n')==1: 429 replace_text=replace_text[:-1] 430 while replace_text.endswith(' '): 431 replace_text=replace_text[:-1] 432 self.dico[tag]=replace_text 433 tag="" 434 replace_text="" 435 rec_mode=0 436 continue 437 438 if rec_mode: 439 replace_text+=line 440 441 if rec_mode: 442 print('error in ',rule_file,' wrong end-file termination ') 443 sys.exit() 444 return self.dico
445 446 447 448 ############################################################################# 449 # tag treatment # 450 ############################################################################# 451 452 # 2 ###############################################################
453 - def return_mod_text(self,tag,text):
454 """ by default return the text linked to tag 455 special tag are S-TAG_OPT: OPT=OPT1+OPT2+OPT3+...""" 456 457 special_tag=re.compile(r'''S-(?P<tag>[^ \t\n\r\f\v_]+)_?(?P<opt>[^\t\n\r\f\v]*)''') # S-TAG_OPT 458 459 if not special_tag.search(tag): 460 try: 461 return self.dico[tag] 462 except: 463 if tag not in self.nowarning and self.nowarning != 'all': 464 print('WARNING: tag:',tag,' not defined in file ',self.file) 465 print('no modification done for this tag') 466 if text: 467 output = '$B$ '+tag+' $B$'+ self.mod_one_text(text)+' $E$ '+tag+' $E$' 468 else: 469 output = '$B$ '+tag+' $E$' 470 self.failed=1 471 return output 472 473 #SPECIAL TAG CASE 474 short_tag=special_tag.search(tag).group('tag') 475 opt=special_tag.search(tag).group('opt').split('+') 476 #be sure that some split are not with a echap tag 477 old='' 478 opt2=[] 479 for part in opt: 480 if len(part) and part[-1]=='\\' : 481 old=part[:-1]+'+' 482 else: 483 opt2.append(old+part) 484 old='' 485 opt=opt2 486 487 tag=short_tag.lower() 488 if tag=='comment': 489 text=self.comment_text(text,opt[0]) 490 elif tag=='del': 491 text=self.del_text(text) 492 elif tag=='regexp': 493 if len(opt)==2: 494 text=self.regexp_text(text,opt[0],opt[1]) 495 elif len(opt)==3: 496 text=self.regexp_text(text,opt[0],opt[1],opt[2]) 497 elif tag=='decomment': 498 text=self.decomment_text(text,opt[0]) 499 500 return text
501 502 # 3 ###############################################################
503 - def comment_text(self,text,comment_tag):
504 """ add comment_tag before each line """ 505 end_line=re.compile(r''' ''') 506 #print [text] 507 #print [text.split('\n')] 508 #print text 509 #print text.replace('\n','\n'+comment_tag+'\t') 510 511 text=comment_tag+'|\t'+text.replace('\n','\n'+comment_tag+'|\t') 512 if text[-3:]=="|\t\n": 513 text=text[-3:] 514 text=text.replace('\t',' ') 515 text2='' 516 for line in text.split('\n'): 517 if line=='': 518 continue 519 if len(line)<74: 520 if line[-1]=='\n': 521 line=line[:-1] 522 for i in range(len(line),73): 523 line+=' ' 524 line+='|\n' 525 else: 526 line+='\n' 527 text2+=line 528 529 line=comment_tag+'+'+71*'-'+'+\n' 530 531 return line+text2+line+'\n'
532 533 # 3 ###############################################################
534 - def decomment_text(self,text,comment_tag):
535 """ remove comment inserted by comment_text """ 536 537 carac_line=re.compile(comment_tag+'\+'+71*'-'+'\+') 538 539 def decomment_line(line,comment_tag): 540 if line[:6]==comment_tag+'| ': 541 line=line[6:] 542 else: 543 print([line[:6]]) 544 print('failed decomment') 545 546 if line[-1]=='|': 547 line=line[:-1] 548 return line
549 550 decomment=0 551 init_text=text.split('\n') 552 end_text='' 553 for line in init_text: 554 if carac_line.search(line): 555 decomment=not decomment 556 if decomment: 557 end_text+=comment_tag+' $B-DIFF$ S-COMMENT_'+comment_tag+' $B-DIFF$\n' 558 continue 559 else: 560 end_text+=comment_tag+' $E-DIFF$ S-COMMENT_'+comment_tag+' $E-DIFF$\n' 561 continue 562 if decomment: 563 # end_text+=line+'\n' 564 end_text+=decomment_line(line,comment_tag)+'\n' 565 else: 566 end_text+=line+'\n' 567 568 return end_text 569 return end_text
570 571 # 3 ###############################################################
572 - def del_text(self,text):
573 return ''
574 575 # 3 ###############################################################
576 - def regexp_text(self,text,exp,new,opt=''):
577 """ replace the text exp (python regular expression) with new""" 578 579 ### step A) remove escape '_' and '+' 580 ### step B) apply the modification 581 ### step C) return new text 582 583 ## Step A: remove escape '_' and '+' 584 exp=exp.replace('\\\\','@888@') #stupid security against string like (\\_) 585 exp=exp.replace('\_','_').replace('\+','+') 586 exp=exp.replace('@888@','\\\\') #end of the trick 587 588 589 # Step B: apply the modification 590 pattern=re.compile(exp,eval(opt)) 591 text=pattern.sub(new, text) 592 593 # Step C: return 594 return text
595 596 ############################################################################ 597 # positioning routine # 598 ############################################################################ 599 600 # 2 ###############################################################
601 - def back_to_init_dir(self):
602 os.chdir(self.d_init)
603 604 # 2 ###############################################################
605 - def go_to_main_dir(self):
606 os.chdir(self.d_main)
607 608 609 ######################################################################################################### 610 # TEST ################################################################################################# 611 ######################################################################################################### 612 if '__main__' == __name__: 613 614 import sys 615 sys.path.append('./Source/MadWeight/Python') 616 from . import create_run 617 import unittest 618 import os, shutil 619 620
621 - class TestMod_file(unittest.TestCase):
622 """ Test the the mod routines works correctly on MadWeight """ 623
624 - def setUp(self):
625 """ create a copy of the original file """ 626 shutil.copyfile('../Template/SubProcesses/cuts.f', './SubProcesses/cuts.bk')
627
628 - def tearDown(self):
629 os.system('rm -f ./SubProcesses/cuts.mod') 630 os.system('rm -f ./SubProcesses/cuts.bk') 631 os.system('rm -f ./SubProcesses/cuts.o')
632 633
634 - def test_cuts(self):
635 """ test if we can activate/desactivate the cuts """ 636 637 self.assertEqual(create_run.cut_is_active('cuts.bk'), 1) 638 self.assertEqual(create_run.bw_cut_is_active('cuts.bk'),1) 639 640 file_to_mod='./SubProcesses/cuts.bk' 641 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 642 #modify file 643 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 644 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 645 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 646 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 647 648 file_to_mod='./SubProcesses/cuts.mod' 649 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 650 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 651 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 652 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 653 654 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 655 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 656 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 657 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 658 659 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 660 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 661 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 662 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
663
664 - def test_mw_cuts(self):
665 666 file_to_mod ='./SubProcesses/cuts.bk' 667 rule= './Source/MadWeight/mod_file/mod_cuts' 668 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 669 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 670 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 671 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 672 673 file_to_mod='./SubProcesses/cuts.mod' 674 rule = './Source/MadWeight/mod_file/suppress_cuts_MW' 675 676 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 677 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 678 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 679 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 680 681 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 682 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 683 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 684 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 685 686 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 687 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 688 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 689 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 690 691 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 692 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 693 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 694 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
695
696 - def test_P_BW_cuts(self):
697 698 self.assertEqual(create_run.cut_is_active('cuts.bk'), 1) 699 self.assertEqual(create_run.bw_cut_is_active('cuts.bk'),1) 700 701 file_to_mod='./SubProcesses/cuts.bk' 702 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 703 #modify file 704 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 705 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 706 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 707 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 708 709 file_to_mod='./SubProcesses/cuts.mod' 710 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 711 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 712 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 713 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 714 715 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 716 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 717 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 718 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 719 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 720 721 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 722 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 723 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 724 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 725 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 726 727 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 728 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 729 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 730 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 731 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 732 733 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 734 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 735 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 736 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 737 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 738 739 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 740 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 741 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 742 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 743 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 744 745 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 746 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 747 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 748 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 749 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 750 751 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 752 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 753 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 754 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 755 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
756 757 # Next one will Fail but is not supose to be called whitout check of the second 758 #rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 759 #mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 760 #self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 761 #self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 762 763
764 - def test_MW_BW_cuts(self):
765 766 self.assertEqual(create_run.cut_is_active('cuts.bk'), 1) 767 self.assertEqual(create_run.bw_cut_is_active('cuts.bk'),1) 768 769 file_to_mod='./SubProcesses/cuts.bk' 770 rule= './Source/MadWeight/mod_file/mod_cuts' 771 mod_file(file_to_mod,rule, write='./SubProcesses/cuts.mod') 772 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 773 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'),1) 774 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 775 776 file_to_mod='./SubProcesses/cuts.mod' 777 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 778 #modify file 779 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 780 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 781 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 782 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 783 784 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 785 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 786 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 787 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 788 789 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 790 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 791 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 792 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 793 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 794 795 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 796 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 797 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 798 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 799 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 800 801 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 802 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 803 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 804 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 805 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 806 807 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 808 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 809 self.assertEqual(create_run.cut_is_active('cuts.mod'), 1) 810 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 811 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 812 813 rule='./Source/MadWeight/mod_file/suppress_cuts_MG' 814 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 815 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 816 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 1) 817 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read()) 818 819 rule='./Source/MadWeight/mod_file/suppress_BW_cuts' 820 mod_file(file_to_mod,rule,opt={'nowarning':"""['PASSCUTS','MW_NEW_DEF','DESACTIVATE_BW_CUT']"""}, write='./SubProcesses/cuts.mod') 821 self.assertEqual(create_run.cut_is_active('cuts.mod'), 0) 822 self.assertEqual(create_run.bw_cut_is_active('cuts.mod'), 0) 823 self.assertFalse('\n$B$' in open('./SubProcesses/cuts.mod').read())
824 825 826 827 unittest.main() 828