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 }

Generated for HippoDraw Class Library by doxygen