CMS 3D CMS Logo

PythonFormWriter.h

Go to the documentation of this file.
00001 #ifndef FWCore_ParameterSet_PythonFormWriter_h
00002 #define FWCore_ParameterSet_PythonFormWriter_h
00003 
00004 
00005 //------------------------------------------------------------
00006 // $Id: PythonFormWriter.h,v 1.15 2007/06/14 04:56:00 wmtan Exp $
00007 //
00008 //
00009 // PythonFormWriter defines a class that is to be used to walk the
00010 // node tree produced by the configuration file parser, and to write
00011 // that configuration tree in the Python exchange format, as
00012 // documented in the file
00013 // FWCore/Framework/ParameterSet/test/complete.pycfg
00014 //
00015 // CAVEATS:
00016 //
00017 //
00018 //   1. It may be best to replace this whole thing with a Python
00019 //   module that just uses the parse tree; such a module can be
00020 //   written using boost::python. A more sensible interface to the
00021 //   parse tree would be very useful if this is to be done.
00022 //
00023 //   2. Few if any of the transformation planned for configuration
00024 //   files are currently done, or done at the right level (by
00025 //   manipulating the parse tree itself, rather than being done during
00026 //   walking of the tree). This means few such transformations are
00027 //   supported by this class.
00028 //
00029 //------------------------------------------------------------
00030 #include <map>
00031 #include <stack>
00032 #include <string>
00033 
00034 #include "FWCore/ParameterSet/interface/Visitor.h"
00035 #include "FWCore/ParameterSet/interface/ModuleNode.h"
00036 
00037 namespace edm
00038 {
00039   namespace pset
00040   {
00041 
00042     class ParseTree;
00043 
00044     class PythonFormWriter : public Visitor
00045     {
00046     public:
00047       PythonFormWriter();
00048 
00049       // Virtual interface inherited from Visitor
00050       virtual ~PythonFormWriter();
00051 
00052       virtual void visitUsing(const UsingNode&);
00053       virtual void visitString(const StringNode&);
00054       virtual void visitEntry(const EntryNode&);
00055       virtual void visitVEntry(const VEntryNode&);
00056       virtual void visitContents(const ContentsNode&);
00057       virtual void visitInclude(const IncludeNode&);
00058       virtual void visitPSet(const PSetNode&);
00059       virtual void visitVPSet(const VPSetNode&);
00060       virtual void visitModule(const ModuleNode&);
00061       virtual void visitWrapper(const WrapperNode&);
00062       virtual void visitOperator(const OperatorNode&); 
00063       virtual void visitOperand(const OperandNode&); 
00064       
00065 
00066       // Function to be called from the 'outside', to walk the given
00067       // node tree and write the Python format of this configuration
00068       // to the given ostream.
00069       void write(ParseTree& parsetree, std::ostream& out);
00070 
00071     private:
00072       // common code for PSet & ContentsNodes
00073       void writeCompositeNode(const CompositeNode & n);
00074 
00076       void writeCommaSeparated(const CompositeNode & n);
00077 
00078       void writeCommaSeparated(const std::list<std::string> & names,
00079                                bool addQuotes, std::ostream & out);
00080 
00082       void writeType(const std::string & type, std::ostream & out);
00083 
00085       void writeNames(const std::list<std::string> & names,
00086                       std::ostream & out);
00087      
00089       void doSchedule(std::ostream & out);
00090 
00092       void writeSchedule(std::ostream & out);
00093 
00094       // Mapping type of module to printable contents
00095       typedef std::map<std::string, std::list<std::string> > ModuleCache;
00096 
00097       std::string             procname_;
00098       std::stack<std::string> moduleStack_;
00099       ModuleCache             modules_;
00100       std::list<std::string>  outputModuleNames_;
00101       std::list<std::string>  modulesWithSecSources_;
00102       std::list<std::string>  triggerPaths_;
00103       std::list<std::string>  endPaths_;
00104       
00105     }; // struct PythonFormWriter
00106   } // namespace pset
00107 } // namespace edm
00108 
00109 #endif

Generated on Tue Jun 9 17:36:29 2009 for CMSSW by  doxygen 1.5.4