CMS 3D CMS Logo

Classes | Functions
twikiExport Namespace Reference

Classes

class  Constituent
 
class  Material
 

Functions

def getTwiki (materials, config)
 
def main ()
 
def parseComment (comment)
 
def parseInFile (inFile, predefinedMaterials, config)
 
def readConfig (fileName)
 
def readMaterialFile (fileName)
 
def readSection (config, section)
 

Function Documentation

def twikiExport.getTwiki (   materials,
  config 
)

Definition at line 126 of file twikiExport.py.

References parseComment().

Referenced by main().

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

Definition at line 182 of file twikiExport.py.

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

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

Definition at line 116 of file twikiExport.py.

Referenced by getTwiki().

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

Definition at line 89 of file twikiExport.py.

References KineDebug3.count(), and createfilelist.int.

Referenced by main().

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

Definition at line 170 of file twikiExport.py.

References readSection().

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

Definition at line 152 of file twikiExport.py.

References split.

Referenced by main().

152 def readMaterialFile(fileName):
153  file = open(fileName,"r")
154  result = {}
155  for line in file:
156  if not line == "\n":
157  name = line.split('"')[1]
158  content = line.split('"')[2].split()
159  result[name] = content
160  return result
161 
162 #reads back one [section] of [config]
def readMaterialFile(fileName)
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().

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