test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
twikiExport Namespace Reference

Classes

class  Constituent
 
class  Material
 

Functions

def getTwiki
 
def main
 
def parseComment
 
def parseInFile
 
def readConfig
 
def readMaterialFile
 
def readSection
 

Function Documentation

def twikiExport.getTwiki (   materials,
  config 
)

Definition at line 126 of file twikiExport.py.

References parseComment().

Referenced by main().

127 def getTwiki(materials,config):
128  result = config["twiki"]["pagename"]+"\n"
129  result += "%TOC%\n\n"
130  for mat in materials:
131  result += config["twiki"]["heading"]+mat.theName+"\n"
132  result += "short Description: *"+mat.theDescription+"* <br>\n"
133  result += "Mass: %.3fg\n" % mat.getMass()
134  result += config["twiki"]["tableformat"]+'\n'
135  result += "| ** | *Volume* | *Density* | *X<sub>0</sub>* | *&lambda;<sub>0</sub>* |\n"
136  result += "| ** | *cms<sup>3</sup>* | *g cm<sup>-3</sup>* | *cm* | *cm* |\n"
137  result += "| Real | %(Volume).3f | %(Density).3f | %(X0).3f | %(L0).3f |\n" % mat.getRealValues()
138  result += "| Simulation | %(Volume).3f | %(Density).3f | %(X0).3f | %(L0).3f |\n" % mat.getSimValues()
139  result += "\n"+config["twiki"]["subheading"]+"Comments\n"
140  result += parseComment(mat.theComment)
141  result += "\n---+++!!Material\n"
142  result += config["twiki"]["tableformat"]+'\n'
143  result += " | *Description* | *Material Name* | *Volume* | *Mass* | *Count* | *Type* | *X<sub>0</sub>* | *&lambda;<sub>0</sub>* |\n"
144  result += ' | ** | ** | *cm<sup>3</sup>* | *g* | ** | ** | *g cm<sup>-2</sup>* | *g cm<sup>-2</sup>* |\n'
145  for const in mat.theConstituents:
146  result += " | =%s= | =%s= | %.2e | %.2e | %.2f | %s | %.2f | %.2f |\n" % ( const.theDescription , const.theName , const.theVolume , const.theMass , const.theCount , const.theType , const.theX0 , const.theL0 )
147 # result += " | ="+const.theDescription+"= | ="+const.theName+"= | "+str(const.theVolume)+" | "+str(const.theMass)+" | "+str(const.theCount)+" | "+const.theType+" | "+str(const.theX0)+" | "+str(const.theL0)+" |\n"
148  result += "\n"
149 
150  return result
151 
#reads mixed_materials.input and pure_materials.input
def parseComment
Definition: twikiExport.py:116
def twikiExport.main ( )

Definition at line 182 of file twikiExport.py.

References getTwiki(), parseInFile(), and readMaterialFile().

183 def main():
184  optParser = optparse.OptionParser()
185  optParser.add_option("-i", "--input", dest="inFile",
186  help="the .in material description that is the input", metavar="INPUT")
187  optParser.add_option("-o", "--output", dest="output",
188  help="the file to put the twiki formated output in (default: <.in-Filename>.twiki)", metavar="TWIKIOUT")
189  optParser.add_option("-c", "--config", dest="config",
190  help="configuration to use (default twikiConfig.ini)", metavar="CONFIG")
191 
192  (options, args) = optParser.parse_args()
193 
194  if options.inFile == None:
195  raise Exception("no .in File given!")
196  if options.output == None:
197  options.output = options.inFile.replace(".in",".twiki")
198  if options.config == None:
199  options.config = "twikiConfig.ini"
200 
201  config = readConfig(options.config)
202 
203  predefinedMaterials = {}
204  predefinedMaterials.update( readMaterialFile("pure_materials.input") )
205  predefinedMaterials.update( readMaterialFile("mixed_materials.input") )
206 
207  inFile = open(options.inFile,"r")
208  inFileContent = inFile.read()
209  inFile.close()
210 
211  materials = parseInFile(inFileContent, predefinedMaterials, config)
212  twikiString = getTwiki(materials, config)
213 
214  outFile = open(options.output,"w")
215  outFile.write(twikiString)
216  outFile.close()
217 
218 main()
def readMaterialFile
Definition: twikiExport.py:152
def parseInFile
Definition: twikiExport.py:89
Definition: main.py:1
def twikiExport.parseComment (   comment)

Definition at line 116 of file twikiExport.py.

Referenced by getTwiki().

117 def parseComment(comment):
118  result = ""
119  if comment.find("<twiki>") >= 0:
120  result = comment.split("twiki>")[1][:-2]
121  else:
122  result += "<verbatim>\n"
123  result += comment
124  result += "</verbatim>\n"
125  return result
def parseComment
Definition: twikiExport.py:116
def twikiExport.parseInFile (   inFile,
  predefinedMaterials,
  config 
)

Definition at line 89 of file twikiExport.py.

References KineDebug3.count().

Referenced by main().

89 
90 def parseInFile(inFile, predefinedMaterials, config):
91  comment = ""
92  materials = []
93  i = 0
94  for line in inFile.split("\n"):
95  i=i+1
96  if i < int(config["parsing"]["intro"]):
97  continue
98  if not line == "" and line[0] == "#":
99  material = Material( line , comment )
100  if not material.theName == "END":
101  materials.append( material )
102  comment = ""
103 
104  #print "Name: "+name+" Description: "+description+" mcVolume: "+str(mcVolume)
105  elif not line == "" and line[0] == "*":
106 
107  materials[-1].addConstituent(line, predefinedMaterials)
108  else:
109  ignore = False
110  for char in config["parsing"]["ignorelines"]:
111  if len(line.strip()) == line.strip().count(char) and not len(line) == 0:
112  ignore = True
113  if not ignore:
114  comment += line+"\n"
115  return materials
def parseInFile
Definition: twikiExport.py:89
def twikiExport.readConfig (   fileName)

Definition at line 170 of file twikiExport.py.

References readSection().

171 def readConfig(fileName):
172  config = ConfigParser.ConfigParser()
173  config.read(fileName)
174  result = {}
175 # result["general"] = readSection("general")
176  result["parsing"] = readSection(config,"parsing")
177  result["twiki"] = readSection(config,"twiki")
178 
179  return result
180 
181 
#main
def twikiExport.readMaterialFile (   fileName)

Definition at line 152 of file twikiExport.py.

References split.

Referenced by main().

153 def readMaterialFile(fileName):
154  file = open(fileName,"r")
155  result = {}
156  for line in file:
157  if not line == "\n":
158  name = line.split('"')[1]
159  content = line.split('"')[2].split()
160  result[name] = content
161  return result
162 
#reads back one [section] of [config]
def readMaterialFile
Definition: twikiExport.py:152
double split
Definition: MVATrainer.cc:139
def twikiExport.readSection (   config,
  section 
)

Definition at line 163 of file twikiExport.py.

Referenced by readConfig().

164 def readSection(config,section):
165  result = {}
166  for option in config.options(section):
167  result[option] = config.get(section,option)
168  return result
169 
# reads the twikiConfig.ini