1
################################################################################
3
# Copyright (C) 2012-2016 Eric Conte, Benjamin Fuks
4
# The MadAnalysis development team, email: <ma5team@iphc.cnrs.fr>
6
# This file is part of MadAnalysis 5.
7
# Official website: <https://launchpad.net/madanalysis5>
9
# MadAnalysis 5 is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 3 of the License, or
12
# (at your option) any later version.
14
# MadAnalysis 5 is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with MadAnalysis 5. If not, see <http://www.gnu.org/licenses/>
22
################################################################################
28
class DelphesModule():
35
self.ModuleExecutionPaths=[]
40
class DelphesCardChecker():
42
def __init__(self,dirname,main):
43
self.dirname = dirname
47
def getNameCard(self):
48
if self.main.fastsim.package=="delphes":
49
cardname = self.main.fastsim.delphes.card
50
elif self.main.fastsim.package=="delphesMA5tune":
51
cardname = self.main.fastsim.delphesMA5tune.card
52
return self.dirname+"/Input/"+cardname
55
def checkPresenceCard(self):
56
logging.getLogger('MA5').debug("Check the presence of the Delphes card: "+self.getNameCard()+' ...')
57
if not os.path.isfile(self.getNameCard()):
58
logging.getLogger('MA5').error('DelphesCard is not found: '+self.getNameCard())
64
logging.getLogger('MA5').debug("Invite the user to edit the Delphes card: "+self.getNameCard()+' ...')
65
if self.main.forced or self.main.script:
68
logging.getLogger('MA5').info("Would you like to edit the Delphes Card? (Y/N)")
69
allowed_answers=['n','no','y','yes']
71
while answer not in allowed_answers:
72
answer=raw_input("Answer: ")
74
if answer=="no" or answer=="n":
77
# TO BE CODED PROPERLY AND CHECK IF THE COMMAND HAS WORKED
78
os.system(self.main.session_info.editor+" "+self.getNameCard())
82
def checkContentCard(self):
83
logging.getLogger('MA5').debug("Check the content of the Delphes card: "+self.getNameCard()+' ...')
85
self.extractContentCard()
86
test = self.decodeContentCard()
87
if test or self.main.forced or self.main.script:
90
logging.getLogger('MA5').info("Are you sure to go on with this Card? (Y/N)")
91
allowed_answers=['n','no','y','yes']
93
while answer not in allowed_answers:
94
answer=raw_input("Answer: ")
96
if answer=="no" or answer=="n":
97
return False # no, give up
102
def extractContentCard(self):
104
self.ModuleExecutionPaths=[]
108
input = open(self.getNameCard())
113
#isolating '=' character
114
line = line.replace('=',' = ')
115
line = line.replace('{',' { ')
116
line = line.replace('}',' } ')
121
#rejecting comment line
122
if line.startswith('#'):
125
#rejecting comment part of a line
127
line = line.split('#')[0]
138
self.ModuleExecutionPaths.append(split[0])
140
logging.getLogger("MA5").warning('Problem with Delphes card: incorrect syntax @ line '+str(counter))
142
if len(split)>=3 and split[0]=='module':
143
MyModule=DelphesModule()
144
MyModule.name = split[2]
145
MyModule.type = split[1]
147
self.Modules.append(MyModule)
148
if len(split)>=3 and split[0] in ['set','add'] and split[1].endswith('InputArray'):
149
if len(self.Modules)==0:
150
logging.getLogger("MA5").warning('Problem with Delphes card: InputArray before module definition @ line '+str(counter))
152
self.Modules[-1].inputs.append(split[2])
154
self.Modules[-1].outputs.append(split[3])
156
if len(split)>=3 and split[0]=='set' and split[1].endswith('OutputArray'):
157
if len(self.Modules)==0:
158
logging.getLogger("MA5").warning('Problem with Delphes card OutputArray before module definition @ line '+str(counter))
160
self.Modules[-1].outputs.append(split[2])
161
if len(split)>=3 and split[0]=='set' and split[1]=='PileUpFile' and module=='PileUpMerger':
162
self.PileUps.append(split[2])
163
if len(split)>=2 and split[0]=='set' and split[1]=='ExecutionPath':
168
def decodeContentCard(self):
169
# check that modules are declared
170
logging.getLogger("MA5").debug("- Check that the modules to execute are declared (#modules="+str(len(self.ModuleExecutionPaths))+")...")
172
for i in self.ModuleExecutionPaths:
174
for j in self.Modules:
179
logging.getLogger("MA5").warning("Problem with Delphes card: module "+item+" is not declared.")
183
logging.getLogger("MA5").debug("- Check the pile-up files (#files="+str(len(self.PileUps))+")...")
184
for item in self.PileUps:
185
if not os.path.isfile(item):
186
logging.getLogger("MA5").warning("Problem with Delphes card: the pile-up file "+item+" is not found.")
189
# check inputs and output
190
logging.getLogger("MA5").debug("- Check the input of modules...")
191
for module in self.Modules:
192
for input in module.inputs:
193
words=input.split('/')
195
logging.getLogger("MA5").warning("Problem with Delphes card: the module "+module.name+" has a bad syntax for the input collection: "+input)
199
theCollection=words[1]
203
for i in self.Modules:
204
if theModule==i.name:
208
if not ok and theModule!='Delphes':
209
logging.getLogger("MA5").warning("Problem with Delphes card: the module "+module.name+" has unknown InputArray module called: "+theModule)
211
elif theModule!='Delphes':
213
for j in outputModule.outputs:
218
logging.getLogger("MA5").warning("Problem with Delphes card: the module "+module.name+" has unknown InputArray label called: "+theCollection)