<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>HippoDraw Class Library</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> <link rel="shortcut icon" href="hippoApp.ico"> </head><body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_d71d549033b3d00bbeb107001643b90a.html">xml</a> </div> </div> <div class="contents"> <h1>HiNTupleXML.cxx</h1><a href="HiNTupleXML_8cxx.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <a name="l00011"></a>00011 <span class="comment">// for have root cfitsio</span> <a name="l00012"></a>00012 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span> <a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#include "config.h"</span> <a name="l00014"></a>00014 <span class="preprocessor">#endif</span> <a name="l00015"></a>00015 <span class="preprocessor"></span> <a name="l00016"></a>00016 <span class="comment">// for truncation warning</span> <a name="l00017"></a>00017 <span class="preprocessor">#ifdef _MSC_VER</span> <a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">#include "msdevstudio/MSconfig.h"</span> <a name="l00019"></a>00019 <span class="preprocessor">#endif</span> <a name="l00020"></a>00020 <span class="preprocessor"></span> <a name="l00021"></a>00021 <span class="preprocessor">#include "<a class="code" href="HiNTupleXML_8h.html" title="HiNTupleXML class interface.">HiNTupleXML.h</a>"</span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="XmlController_8h.html" title="XmlController class interface.">XmlController.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="XmlElement_8h.html" title="XmlElement class interface.">XmlElement.h</a>"</span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="NTupleController_8h.html" title="hippodraw::NTupleController class interface">datasrcs/NTupleController.h</a>"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="NTuple_8h.html" title="hippodraw::NTuple class interface.">datasrcs/NTuple.h</a>"</span> <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="preprocessor">#ifdef HAVE_CFITSIO</span> <a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="FitsController_8h.html" title="hippodraw::FitsController class interface.">fits/FitsController.h</a>"</span> <a name="l00031"></a>00031 <span class="preprocessor">#endif</span> <a name="l00032"></a>00032 <span class="preprocessor"></span> <a name="l00033"></a>00033 <span class="preprocessor">#ifdef HAVE_ROOT</span> <a name="l00034"></a>00034 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="RootController_8h.html" title="hippodraw::RootController class interface.">root/RootController.h</a>"</span> <a name="l00035"></a>00035 <span class="preprocessor">#endif</span> <a name="l00036"></a>00036 <span class="preprocessor"></span> <a name="l00037"></a>00037 <span class="preprocessor">#include <fstream></span> <a name="l00038"></a>00038 <span class="preprocessor">#include <stdexcept></span> <a name="l00039"></a>00039 <a name="l00040"></a>00040 <span class="keyword">using</span> std::ifstream; <a name="l00041"></a>00041 <span class="keyword">using</span> std::runtime_error; <a name="l00042"></a>00042 <span class="keyword">using</span> std::string; <a name="l00043"></a>00043 <a name="l00044"></a>00044 <span class="keyword">using namespace </span>hippodraw; <a name="l00045"></a>00045 <a name="l00046"></a><a class="code" href="classhippodraw_1_1HiNTupleXML.html#a5f2500f1303c4203a29c09e65d3b11a1">00046</a> HiNTupleXML::HiNTupleXML ( <a class="code" href="classhippodraw_1_1XmlController.html" title="A base class that is the interface between GUI and the XML serialization and deserialization...">XmlController</a> * controller ) <a name="l00047"></a>00047 : <a class="code" href="classhippodraw_1_1BaseXML.html" title="A base class of XML element controllers.">BaseXML</a> ( <span class="stringliteral">"HiNTuple"</span>, controller ), <a name="l00048"></a>00048 m_name ( <span class="stringliteral">"name"</span> ) <a name="l00049"></a>00049 { <a name="l00050"></a>00050 } <a name="l00051"></a>00051 <a name="l00052"></a><a class="code" href="classhippodraw_1_1HiNTupleXML.html#a8dec0508ba556ce5ed589af1d50637ad">00052</a> <a class="code" href="classhippodraw_1_1XmlElement.html" title="A pure virtual base class of XML element wrapper.">XmlElement</a> * <a class="code" href="classhippodraw_1_1BaseXML.html#afa1d42a894a8739e0d120ed9c4383d38" title="Creates a new element node.">HiNTupleXML::createElement</a> ( <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> & ntuple ) <a name="l00053"></a>00053 { <a name="l00054"></a>00054 <a class="code" href="classhippodraw_1_1XmlElement.html" title="A pure virtual base class of XML element wrapper.">XmlElement</a> * tag = <a class="code" href="classhippodraw_1_1BaseXML.html#afa1d42a894a8739e0d120ed9c4383d38" title="Creates a new element node.">BaseXML::createElement</a> (); <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="keyword">const</span> <span class="keywordtype">void</span> * addr = reinterpret_cast < <span class="keyword">const</span> <span class="keywordtype">void</span> * > ( & ntuple ); <a name="l00057"></a>00057 <span class="keywordtype">int</span> <span class="keywordtype">id</span> = <a class="code" href="classhippodraw_1_1BaseXML.html#ae50d78be58d5938b4434515f4f037ece" title="The singleton XML controller object.">m_controller</a> -> getId ( addr ); <a name="l00058"></a>00058 <a class="code" href="classhippodraw_1_1BaseXML.html#aba09fa4e77f2c85cc12df1116cb5f31e" title="Sets the unique identification of the object.">setId</a> ( *tag, <span class="keywordtype">id</span> ); <a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="keyword">const</span> <span class="keywordtype">string</span> & full_name = ntuple.<a class="code" href="classhippodraw_1_1DataSource.html#a8cf4db36c9f3123506d73e98c4a93464" title="Returns the name of the data source.">getName</a> (); <a name="l00061"></a>00061 tag -> setAttribute ( <a class="code" href="classhippodraw_1_1HiNTupleXML.html#adb41893ba19e889e56c559f25fc1a68a" title="The tag name for the name attribute.">m_name</a>, full_name ); <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="keywordflow">return</span> tag; <a name="l00064"></a>00064 } <a name="l00065"></a>00065 <a name="l00068"></a><a class="code" href="classhippodraw_1_1HiNTupleXML.html#a2c0e8f4e41b1601b10a12e1cdd24386e">00068</a> <span class="keywordtype">string</span> <a class="code" href="classhippodraw_1_1HiNTupleXML.html#a2c0e8f4e41b1601b10a12e1cdd24386e" title="Returns the name of the HiNTuple object.">HiNTupleXML::getName</a> ( <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1XmlElement.html" title="A pure virtual base class of XML element wrapper.">XmlElement</a> & tag )<span class="keyword"> const</span> <a name="l00069"></a>00069 <span class="keyword"></span>{ <a name="l00070"></a>00070 <span class="keywordtype">string</span> name; <a name="l00071"></a>00071 <span class="keywordtype">bool</span> ok = tag.<a class="code" href="classhippodraw_1_1XmlElement.html#afa83a3518bac3d6ae2bc519084071fad" title="Sets value to the attribute name&#39;s value.">attribute</a> ( <a class="code" href="classhippodraw_1_1HiNTupleXML.html#adb41893ba19e889e56c559f25fc1a68a" title="The tag name for the name attribute.">m_name</a>, name ); <a name="l00072"></a>00072 <span class="preprocessor">#ifndef STRING_CLEAR_DEFECT // change to ifdef when M4 macro is implemented</span> <a name="l00073"></a>00073 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( ! ok ) name.erase ( name.begin(), name.end() ); <a name="l00074"></a>00074 <span class="preprocessor">#else</span> <a name="l00075"></a>00075 <span class="preprocessor"></span> <span class="keywordflow">if</span> ( ! ok ) name.clear(); <a name="l00076"></a>00076 <span class="preprocessor">#endif</span> <a name="l00077"></a>00077 <span class="preprocessor"></span> <a name="l00078"></a>00078 <span class="keywordflow">return</span> name; <a name="l00079"></a>00079 } <a name="l00080"></a>00080 <a name="l00081"></a>00081 <a name="l00082"></a>00082 <a name="l00083"></a>00083 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * <a name="l00084"></a>00084 <a class="code" href="classhippodraw_1_1HiNTupleXML.html#af39023c77b6e6c01ee8f4cc1d93ee915" title="Returns the DataSource corresponding to XmlElement.">HiNTupleXML::</a> <a name="l00085"></a><a class="code" href="classhippodraw_1_1HiNTupleXML.html#a7b9bca035abdf3544278bded342c2b47">00085</a> <a class="code" href="classhippodraw_1_1HiNTupleXML.html#af39023c77b6e6c01ee8f4cc1d93ee915" title="Returns the DataSource corresponding to XmlElement.">getObject</a> ( <span class="keyword">const</span> std::string fullname )<span class="keyword"> const</span> <a name="l00086"></a>00086 <span class="keyword"></span>{ <a name="l00087"></a>00087 <a name="l00088"></a>00088 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * ntuple = 0; <a name="l00089"></a>00089 <a name="l00090"></a>00090 <span class="keywordtype">string</span> filename; <a name="l00091"></a>00091 <span class="keywordtype">string</span> name; <a name="l00092"></a>00092 string::size_type pos = fullname.find_last_of ( <span class="stringliteral">":"</span> ); <a name="l00093"></a>00093 <span class="keywordflow">if</span> ( pos != string::npos && pos != 1 ) { <span class="comment">// for Windows "C:"</span> <a name="l00094"></a>00094 filename = fullname.substr ( 0, pos ); <a name="l00095"></a>00095 name = fullname.substr ( pos + 2 ); <a name="l00096"></a>00096 } <a name="l00097"></a>00097 <span class="keywordflow">else</span> { <a name="l00098"></a>00098 filename = fullname; <a name="l00099"></a>00099 } <a name="l00100"></a>00100 <a name="l00101"></a>00101 <span class="keywordtype">string</span> suffix; <a name="l00102"></a>00102 pos = filename.find_last_of ( <span class="stringliteral">"."</span> ); <a name="l00103"></a>00103 <span class="keywordflow">if</span> ( pos != string::npos ) { <a name="l00104"></a>00104 suffix = filename.substr ( pos + 1 ); <a name="l00105"></a>00105 } <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="keywordflow">if</span> ( suffix.empty () == false ) { <a name="l00108"></a>00108 <span class="keywordflow">if</span> ( suffix == <span class="stringliteral">"fits"</span> || suffix == <span class="stringliteral">"gz"</span> ) { <a name="l00109"></a>00109 <span class="preprocessor">#ifdef HAVE_CFITSIO</span> <a name="l00110"></a>00110 <span class="preprocessor"></span> <a class="code" href="classhippodraw_1_1FitsController.html" title="A Controller class for FITS files.">FitsController</a> * controller = <a class="code" href="classhippodraw_1_1FitsController.html#a127637b93f8a5e52504b68e98126219e" title="Returns the singleton instance of the FitsController.">FitsController::instance</a> (); <a name="l00111"></a>00111 ntuple = controller -> createNTuple ( filename, name ); <a name="l00112"></a>00112 <span class="preprocessor">#else</span> <a name="l00113"></a>00113 <span class="preprocessor"></span> <span class="keywordtype">string</span> what (<span class="stringliteral">"Can not open file\n"</span> ); <a name="l00114"></a>00114 what += filename + <span class="stringliteral">"\n"</span>; <a name="l00115"></a>00115 what += <span class="stringliteral">"because application was not built with FITS support"</span>; <a name="l00116"></a>00116 <span class="keywordflow">throw</span> runtime_error ( what ); <a name="l00117"></a>00117 <span class="preprocessor">#endif</span> <a name="l00118"></a>00118 <span class="preprocessor"></span> } <a name="l00119"></a>00119 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( suffix == <span class="stringliteral">"root"</span> ) { <a name="l00120"></a>00120 <span class="preprocessor">#ifdef HAVE_ROOT</span> <a name="l00121"></a>00121 <span class="preprocessor"></span> <a class="code" href="classhippodraw_1_1RootController.html" title="A Controller class for ROOT files.">RootController</a> * controller = <a class="code" href="classhippodraw_1_1RootController.html#a2f7a156f73540d35fb849101403bc947" title="Returns the singleton instance of the RootController.">RootController::instance</a> (); <a name="l00122"></a>00122 ntuple = controller -> createNTuple ( filename, name ); <a name="l00123"></a>00123 <span class="preprocessor">#else</span> <a name="l00124"></a>00124 <span class="preprocessor"></span> <span class="keywordtype">string</span> what ( <span class="stringliteral">"Can not open file\n"</span> ); <a name="l00125"></a>00125 what += filename + <span class="stringliteral">"\n"</span>; <a name="l00126"></a>00126 what += <span class="stringliteral">"because application was not bult with ROOT support"</span>; <a name="l00127"></a>00127 <span class="keywordflow">throw</span> runtime_error ( what ); <a name="l00128"></a>00128 <span class="preprocessor">#endif</span> <a name="l00129"></a>00129 <span class="preprocessor"></span> } <a name="l00130"></a>00130 <span class="keywordflow">else</span> { <a name="l00131"></a>00131 <a class="code" href="classhippodraw_1_1NTupleController.html" title="A singleton class that is the interface between GUI and the NTuple objects.">NTupleController</a> * controller = <a class="code" href="classhippodraw_1_1NTupleController.html#ae02f71abaf1f85101c7044455ca8ac1a" title="Returns the pointer to the singleton instance.">NTupleController::instance</a> (); <a name="l00132"></a>00132 ntuple = controller-><a class="code" href="classhippodraw_1_1NTupleController.html#a367a0129829b506b44f415cad946db40" title="Creates and registers an NTuple from data in file filename.">createNTuple</a> ( filename ); <a name="l00133"></a>00133 } <a name="l00134"></a>00134 } <a name="l00135"></a>00135 <a name="l00136"></a>00136 <span class="keywordflow">return</span> ntuple; <a name="l00137"></a>00137 } <a name="l00138"></a>00138 <a name="l00139"></a>00139 <a name="l00140"></a>00140 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1DataSource.html" title="Base class for DataSource.">DataSource</a> * <a name="l00141"></a>00141 <a class="code" href="classhippodraw_1_1HiNTupleXML.html#af39023c77b6e6c01ee8f4cc1d93ee915" title="Returns the DataSource corresponding to XmlElement.">HiNTupleXML::</a> <a name="l00142"></a><a class="code" href="classhippodraw_1_1HiNTupleXML.html#af39023c77b6e6c01ee8f4cc1d93ee915">00142</a> <a class="code" href="classhippodraw_1_1HiNTupleXML.html#af39023c77b6e6c01ee8f4cc1d93ee915" title="Returns the DataSource corresponding to XmlElement.">getObject</a> ( <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1XmlElement.html" title="A pure virtual base class of XML element wrapper.">XmlElement</a> & tag )<span class="keyword"> const</span> <a name="l00143"></a>00143 <span class="keyword"></span>{ <a name="l00144"></a>00144 <span class="keyword">const</span> <span class="keywordtype">string</span> fullname = <a class="code" href="classhippodraw_1_1HiNTupleXML.html#a2c0e8f4e41b1601b10a12e1cdd24386e" title="Returns the name of the HiNTuple object.">getName</a> ( tag ); <a name="l00145"></a>00145 <span class="keywordflow">if</span> ( fullname.empty() ) <span class="keywordflow">return</span> 0; <a name="l00146"></a>00146 <a name="l00147"></a>00147 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1HiNTupleXML.html#af39023c77b6e6c01ee8f4cc1d93ee915" title="Returns the DataSource corresponding to XmlElement.">getObject</a> ( fullname ); <a name="l00148"></a>00148 } </pre></div></div> <hr size="1"><address style="align: right;"><small> Generated for HippoDraw Class Library by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0> </a> </small></address> </body> </html>