HiNTupleXML.cxx
Go to the documentation of this file.
1 
11 // for have root cfitsio
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 // for truncation warning
17 #ifdef _MSC_VER
18 #include "msdevstudio/MSconfig.h"
19 #endif
20 
21 #include "HiNTupleXML.h"
22 
23 #include "XmlController.h"
24 #include "XmlElement.h"
25 
27 #include "datasrcs/NTuple.h"
28 
29 #ifdef HAVE_CFITSIO
30 #include "fits/FitsController.h"
31 #endif
32 
33 #ifdef HAVE_ROOT
34 #include "root/RootController.h"
35 #endif
36 
37 #include <fstream>
38 #include <stdexcept>
39 
40 using std::ifstream;
41 using std::runtime_error;
42 using std::string;
43 
44 using namespace hippodraw;
45 
47  : BaseXML ( "HiNTuple", controller ),
48  m_name ( "name" )
49 {
50 }
51 
53 {
55 
56  const void * addr = reinterpret_cast < const void * > ( & ntuple );
57  int id = m_controller -> getId ( addr );
58  setId ( *tag, id );
59 
60  const string & full_name = ntuple.getName ();
61  tag -> setAttribute ( m_name, full_name );
62 
63  return tag;
64 }
65 
68 string HiNTupleXML::getName ( const XmlElement & tag ) const
69 {
70  string name;
71  bool ok = tag.attribute ( m_name, name );
72 #ifndef STRING_CLEAR_DEFECT // change to ifdef when M4 macro is implemented
73  if ( ! ok ) name.erase ( name.begin(), name.end() );
74 #else
75  if ( ! ok ) name.clear();
76 #endif
77 
78  return name;
79 }
80 
81 
82 
83 const DataSource *
85 getObject ( const std::string fullname ) const
86 {
87 
88  const DataSource * ntuple = 0;
89 
90  string filename;
91  string name;
92  string::size_type pos = fullname.find_last_of ( ":" );
93  if ( pos != string::npos && pos != 1 ) { // for Windows "C:"
94  filename = fullname.substr ( 0, pos );
95  name = fullname.substr ( pos + 2 );
96  }
97  else {
98  filename = fullname;
99  }
100 
101  string suffix;
102  pos = filename.find_last_of ( "." );
103  if ( pos != string::npos ) {
104  suffix = filename.substr ( pos + 1 );
105  }
106 
107  if ( suffix.empty () == false ) {
108  if ( suffix == "fits" || suffix == "gz" ) {
109 #ifdef HAVE_CFITSIO
110  FitsController * controller = FitsController::instance ();
111  ntuple = controller -> createNTuple ( filename, name );
112 #else
113  string what ("Can not open file\n" );
114  what += filename + "\n";
115  what += "because application was not built with FITS support";
116  throw runtime_error ( what );
117 #endif
118  }
119  else if ( suffix == "root" ) {
120 #ifdef HAVE_ROOT
121  RootController * controller = RootController::instance ();
122  ntuple = controller -> createNTuple ( filename, name );
123 #else
124  string what ( "Can not open file\n" );
125  what += filename + "\n";
126  what += "because application was not bult with ROOT support";
127  throw runtime_error ( what );
128 #endif
129  }
130  else {
132  ntuple = controller->createNTuple ( filename );
133  }
134  }
135 
136  return ntuple;
137 }
138 
139 
140 const DataSource *
142 getObject ( const XmlElement & tag ) const
143 {
144  const string fullname = getName ( tag );
145  if ( fullname.empty() ) return 0;
146 
147  return getObject ( fullname );
148 }
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
static FitsController * instance()
Returns the singleton instance of the FitsController.
hippodraw::RootController class interface.
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
std::string getName(const XmlElement &tag) const
Returns the name of the HiNTuple object.
Definition: HiNTupleXML.cxx:68
XmlController class interface.
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
DataSource * createNTuple(const std::string &filename)
Creates and registers an NTuple from data in file filename.
void setId(XmlElement &tag, int id)
Sets the unique identification of the object.
Definition: BaseXML.cxx:64
hippodraw::NTuple class interface.
bool ok
Definition: CanvasView.cxx:163
hippodraw::FitsController class interface.
A singleton class that is the interface between GUI and the NTuple objects.
XmlController * m_controller
The singleton XML controller object.
Definition: BaseXML.h:60
static NTupleController * instance()
Returns the pointer to the singleton instance.
XmlElement class interface.
A Controller class for FITS files.
const DataSource * getObject(const XmlElement &tag) const
Returns the DataSource corresponding to XmlElement.
A base class of XML element controllers.
Definition: BaseXML.h:35
static RootController * instance()
Returns the singleton instance of the RootController.
std::string m_name
The tag name for the name attribute.
Definition: HiNTupleXML.h:38
hippodraw::NTupleController class interface
HiNTupleXML(const HiNTupleXML &)
A private copy constructor in order to avoid copying.
A Controller class for ROOT files.
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
HiNTupleXML class interface.
const std::string & getName() const
Returns the name of the data source.
Definition: DataSource.cxx:136
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen