ExperimentFileXML.java

Go to the documentation of this file.
00001 
00002 //                                  //
00003 //  ExperimentFileXML.java                      //
00004 //                                  //
00005 //  experiment.ExperimentFileXML -- a file containing an experiment //
00006 //  $LastChangedDate: 2011-11-29 17:10:53 -0600 (Tue, 29 Nov 2011) $            //
00007 //                                  //
00008 //  (c) Copyright 2011 Rice University. All rights reserved.    //
00009 //                                  //
00011 
00012 
00013 
00014 
00015 package edu.rice.cs.hpc.data.experiment.xml;
00016 
00017 
00018 import edu.rice.cs.hpc.data.experiment.*;
00019 import edu.rice.cs.hpc.data.util.Constants;
00020 import edu.rice.cs.hpc.data.util.Grep;
00021 import edu.rice.cs.hpc.data.util.IUserData;
00022 
00023 import java.io.File;
00024 import java.io.FileInputStream;
00025 import java.io.IOException;
00026 import java.io.InputStream;
00027 
00028 
00029 
00030 
00032 //  CLASS EXPERIMENT-FILE-XML                                           //
00034 
00042 public class ExperimentFileXML extends ExperimentFile
00043 {
00044 
00045     private File file;
00046 
00047     public File getFile() 
00048     {
00049         return file;
00050     }
00051     
00052     public void setFile(File file)
00053     {
00054         this.file = file;
00055     }
00056     
00057     
00059 //  XML PARSING                                                         //
00061 
00086 public void parse(InputStream stream, String name,
00087         BaseExperiment experiment, boolean need_metrics, IUserData<String, String> userData)
00088         throws Exception {
00089     final Builder builder;
00090     if (need_metrics) {
00091         builder = new ExperimentBuilder2(experiment, name, userData);
00092     } else {
00093         builder = new BaseExperimentBuilder(experiment, name, userData);
00094     }
00095     // We assume it has already been GREP-ed by the server if it needs to be
00096 
00097     Parser parser = new Parser(name, stream, builder);
00098     parser.parse();
00099 
00100     if (builder.getParseOK() == Builder.PARSER_OK) {
00101         // set the file the same as the name of the database
00102         setFile(new File(name));
00103         // parsing is done successfully
00104     } else
00105         throw new InvalExperimentException(
00106                 "Parse error in Experiment XML at line " + 
00107                 builder.getParseErrorLineNumber());
00108 }
00109 
00110 
00111 /*************************************************************************
00112  *  Parses the file and returns the contained experiment subparts.
00113  *  The subparts are returned by adding them to given lists.
00114  *
00115  *  @param  experiment      Experiment object to own the parsed subparts.
00116  * @throws Exception 
00117  *
00118  ************************************************************************/
00119     
00120 public void parse(File file, BaseExperiment experiment, boolean need_metrics, IUserData<String, String> userData)
00121         throws  Exception
00122         {
00123     // get an appropriate input stream
00124     InputStream stream;
00125     String name = file.toString();
00126 
00127     // check if the argument "file" is really a file (old version) or a directory (new version)
00128     String directory, xmlFilePath;
00129     if (file.isDirectory()) {
00130         directory = file.getAbsolutePath(); // it's a database directory
00131         xmlFilePath = directory + File.separatorChar + Constants.DATABASE_FILENAME;
00132     } else {
00133         directory = file.getParent(); // it's experiment.xml file
00134         xmlFilePath = file.getAbsolutePath();
00135     }
00136 
00137     File XMLfile = new File(xmlFilePath);
00138     
00139     if (!XMLfile.canRead()) {
00140         throw new IOException("File does not exist or not readable: " + XMLfile.getAbsolutePath());
00141     }
00142     
00143     setFile(XMLfile);
00144     
00145     // parse the stream
00146     final Builder builder;
00147     if (need_metrics)
00148     {
00149         stream = new FileInputStream(XMLfile);
00150         builder = new ExperimentBuilder2(experiment, name, userData);
00151     }
00152     else
00153     {
00154         // if we don't need metrics, we should look at callpath.xml
00155         //  which is a light version of experiment.xml without metrics
00156         //  sax parser is not good enough in reading large xml file since
00157         //  it uses old technique of reader line by line. we should come
00158         //  up with a better xml parser.
00159         // note: this is a quick hack to fix slow xml reader in ibm bg something
00160         
00161         String callpathLoc = directory + File.separatorChar + "callpath.xml";
00162         File callpathFile = new File(callpathLoc);
00163         if (!callpathFile.exists())
00164         {
00165             Grep.grep(xmlFilePath, callpathLoc, "<M ", false);
00166             callpathFile = new File(callpathLoc);
00167         }
00168         stream = new FileInputStream(callpathFile);
00169         builder = new BaseExperimentBuilder(experiment, name, userData);
00170     }
00171     
00172     Parser parser = new Parser(name, stream, builder);
00173     parser.parse();
00174 
00175     if( builder.getParseOK() == Builder.PARSER_OK ) {
00176         // parsing is done successfully
00177     } else
00178         throw new InvalExperimentException(builder.getParseErrorLineNumber());          
00179         }
00180 
00181 
00182 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1