00001 package cedar.jetweb.html; 00002 00003 import java.io.PrintWriter; 00004 import java.io.BufferedWriter; 00005 import java.io.File; 00006 import java.io.IOException; 00007 00008 import java.text.SimpleDateFormat; 00009 import java.text.NumberFormat; 00010 00011 import java.util.Date; 00012 import java.util.Enumeration; 00013 import java.util.Vector; 00014 import java.util.List; 00015 import java.util.Iterator; 00016 import java.util.Map; 00017 import java.util.Map.Entry; 00018 import java.util.TreeMap; 00019 00020 import cedar.jetweb.*; 00021 import cedar.jetweb.model.*; 00022 import cedar.jetweb.model.paper.*; 00023 import cedar.jetweb.model.plots.*; 00024 import cedar.jetweb.model.fit.*; 00025 import cedar.jetweb.job.*; 00026 import cedar.jetweb.util.Match; 00027 import cedar.jetweb.hist.JetWebHist; 00028 import cedar.jetweb.generator.Generator; 00029 00037 public class HTMLModelWriter extends HTMLWriter { 00038 00048 public HTMLModelWriter(PrintWriter out, String newServletPath ){ 00049 00050 super(out,newServletPath); 00051 00052 } 00053 00054 public HTMLModelWriter(BufferedWriter out, String newServletPath ){ 00055 00056 super(out,newServletPath); 00057 00058 } 00059 00070 public HTMLModelWriter(String filename, String newServletPath ){ 00071 00072 super(filename,newServletPath); 00073 00074 } 00075 00076 00080 public void display(Model model) throws JetWebException { 00081 00082 00083 Integer modelId; 00084 if (model==null) { 00085 modelId = null; 00086 } else { 00087 modelId = new Integer(model.getId()); 00088 } 00089 00090 try { 00091 00092 ofile.write("<div class='jetweb-model'>"); 00093 00094 00095 if (verbose) { 00096 ofile.write("<p>A model defines a generator and its parameter settings.</p>"); 00097 } 00098 00099 00100 if (!verbose && !hidden){ 00101 openForm("POST", JetWebConfig.searchServletPath); 00102 } 00103 00104 // The Model ID 00105 if (!hidden) { 00106 ofile.write("Model ID: "); 00107 ofile.write(modelId.toString()); 00108 } 00109 00110 if (!modifiable && modelId != null) { 00111 ofile.write("<input type='HIDDEN' name='MODELID' value='"+modelId+"'>"); 00112 } 00113 00114 if (!hidden){ 00115 ofile.write(" Generator: "+model.getGenerator()); 00116 PDF pdf = model.getPhotonPDF(); 00117 00118 if(pdf!=null){ 00119 00120 String pdfName = pdf.getName(); 00121 if(pdfName!=null){ 00122 //ofile.write(" Generator: "+model.getGenerator()); 00123 ofile.write("; Photon PDF: " + 00124 pdfName); 00125 } 00126 } 00127 00128 pdf = model.getProtonPDF(); 00129 if(pdf!=null){ 00130 String pdfName = pdf.getName(); 00131 if(pdfName!=null){ 00132 ofile.write("; Proton PDF: " + 00133 pdfName); 00134 } 00135 } 00136 00137 ofile.write("<br>Model description: " +model.getDescription()); 00138 00139 if (!verbose) { 00140 ofile.write(HTMLUtils.writeSubmitButton("MODELIDGET", 00141 "Show all model parameters.", 00142 "Full details")); 00143 closeForm(); 00144 00145 } else { 00146 00147 00148 ofile.write("<div class='jetweb-buttons'>"); 00149 ofile.write("<h4>Available fits using this model</h4>"); 00150 // write out those fit ids as pointers. 00151 Vector<Fit> fits = Fit.getFits(model); 00152 for (Fit fit : fits){ 00153 Integer fitId = new Integer(fit.getId()); 00154 openForm("POST", JetWebConfig.searchServletPath); 00155 ofile.write("<input type='HIDDEN' name='FITID' value='"+fitId+"'>"); 00156 ofile.write(HTMLUtils.writeSubmitButton("FITIDGET", 00157 "Inspect this Fit", 00158 fitId.toString())); 00159 closeForm(); 00160 } 00161 ofile.write("</div>"); 00162 00163 ofile.newLine(); 00164 ofile.write("<div class='jetweb-buttons'>"); 00165 openForm("POST", JetWebConfig.searchServletPath); 00166 ofile.write("<input type='HIDDEN' name='MODELID' value='" 00167 +model.getId()+"'>"); 00168 ofile.write(HTMLUtils.writeSubmitButton("CHOOSEPROC","Request more data for this model","More data")); 00169 ofile.write(HTMLUtils.writeSubmitButton("SIMILARDATA","Request similar data for this model","Similar data")); 00170 closeForm(); 00171 00172 ofile.newLine(); 00173 openForm("POST", JetWebConfig.searchServletPath); 00174 ofile.write(HTMLUtils.writeSubmitButton("NONDEF","Show non-default parameters for this model","Non-default parameters")); 00175 ofile.write("<input type='HIDDEN' name='MODELID' value='"+model.getId()+"'>"); 00176 closeForm(); 00177 00178 openForm("POST", JetWebConfig.searchServletPath); 00179 ofile.write("Compare to another model :"); 00180 ofile.write("<input type='TEXT' name='MODEL2'/>"); 00181 ofile.write(HTMLUtils.writeSubmitButton("COMPAREMODEL","Compare this model to another model - give the model ID","GO")); 00182 ofile.write("<input type='HIDDEN' name='MODEL1' value='"+model.getId()+"'>"); 00183 closeForm(); 00184 00185 ofile.write("</div>"); 00186 00187 ofile.newLine(); 00188 00189 // write out the generator parameters. 00190 HTMLGeneratorWriter genOp = 00191 new HTMLGeneratorWriter(ofile,servletPath); 00192 genOp.setModifiable(modifiable); 00193 genOp.setVerbose(true); 00194 genOp.display(model.getGenerator()); 00195 00196 00197 00198 // write out the data available for this Model. 00199 ofile.write("<table width='100%'>"); 00200 for (MCProcessType proc : MCProcessType.getAll(true)){ 00201 00202 ofile.write("<tr class='jetweb-processtype'><td colspan='3'><p><b>"+proc.getMCProcessName() 00203 +" "+proc.getCollision().toString()+" data</b></p></td>"); 00204 ofile.write("</tr>"); 00205 00206 Vector<RunSeries> rsList = model.getRunSeries(proc); 00207 if (rsList.size()>0){ 00208 RunSeries runSeries = rsList.firstElement(); 00209 00210 ofile.write("<tr class='jetweb-summary'>"); 00211 ofile.write("<td><p>Generated samples for this process type</p></td>"); 00212 00213 00214 ofile.write("<td>Luminosity: "+dform.format(Math.abs( runSeries.getLumi())) 00215 +"pb<sup>-1</sup></td>"); 00216 00217 ofile.write("<td>"); 00218 openForm("POST", JetWebConfig.searchServletPath); 00219 ofile.write("<input type='HIDDEN' name='RUNSERIESID' value='"+runSeries.getId()+"'>"); 00220 ofile.write(HTMLUtils.writeSubmitButton("RSLOGS", 00221 "Inspect the logfiles for this fit and process.", 00222 "Log Files")); 00223 closeForm(); 00224 ofile.write("</td>"); 00225 ofile.write("</tr>"); 00226 ofile.newLine(); 00227 00228 } else { 00229 ofile.write("<tr><td colspan='3'>Nothing generated for this process type.</td></tr>"); 00230 ofile.newLine(); 00231 } 00232 00233 } 00234 ofile.write("</table>"); 00235 ofile.newLine(); 00236 00237 00238 } 00239 00240 00241 ofile.write("</div>"); 00242 00243 } 00244 00245 } catch (IOException ioe) { 00246 ioe.printStackTrace(System.out); 00247 throw new JetWebException(ioe); 00248 } 00249 00250 00251 } 00252 00297 public void listNonDefaults(Model m1) throws JetWebException { 00298 00299 try { 00300 Model mdef = new Model(); 00301 mdef.getGeneratorList().add(m1.getGenerator()); 00302 mdef.setDefaults(); 00303 00304 if (!m1.matches(mdef)){ 00305 String label1 = "Model "+m1.getId(); 00306 String label2 = "Default"; 00307 listNonMatchingParameters(label1,label2,m1.getNonMatchingParameters()); 00308 } else { 00309 ofile.write("All parameters are default for Model "+m1.getId()); 00310 } 00311 00312 } catch (Exception e){ 00313 System.out.println(": Exception in compare models "+e); 00314 e.printStackTrace(); 00315 throw new JetWebException(e,"Model"); 00316 } 00317 00318 } 00319 00325 public void listDifferences(Model m1, Model m2) throws JetWebException { 00326 00327 try { 00328 if (!m1.matches(m2)){ 00329 String label1 = "Model "+m1.getId(); 00330 String label2 = "Model "+m2.getId(); 00331 listNonMatchingParameters(label1,label2,m1.getNonMatchingParameters()); 00332 } else { 00333 ofile.write("All parameters are identical between Models "+m1.getId()+" and "+m2.getId()); 00334 } 00335 00336 } catch (Exception e){ 00337 System.out.println(": Exception in compare models "+e); 00338 e.printStackTrace(); 00339 throw new JetWebException(e,"Model"); 00340 } 00341 00342 00343 } 00344 00345 00349 public void listNonMatchingParameters(String label1, String label2, Enumeration<Match> params){ 00350 try { 00351 ofile.write("<table frame='border' width=100%>"); 00352 00353 00354 ofile.write("<tr>"); 00355 ofile.write("<th align='left'>Parameter</th>"); 00356 ofile.write("<th align='left'>"+label1+"</th>"); 00357 ofile.write("<th align='left'>"+label2+"</th>"); 00358 ofile.write("</tr>"); 00359 00360 while (params.hasMoreElements()){ 00361 Match param = (Match)params.nextElement(); 00362 00363 ofile.write("<tr>"); 00364 ofile.write("<td>"+param.getName()+"</td>"); 00365 ofile.write("<td>"+param.getValue1()+"</td>"); 00366 ofile.write("<td>"+param.getValue2()+"</td>"); 00367 ofile.write("</tr>"); 00368 } 00369 00370 ofile.write("</table>"); 00371 00372 } catch (IOException e){ 00373 System.out.println("problem writing form"); 00374 } 00375 } 00376 00380 public void display(Object object) throws JetWebException { 00381 00382 if (object instanceof Model){ 00383 display((Model)object); 00384 } else { 00385 throw new JetWebException("Attempt to display "+object,"Using "+this); 00386 } 00387 } 00388 00389 }
Generated Wed Jan 17 09:14:27 GMT 2007