00001 00012 #ifdef HAVE_CONFIG_H 00013 #include "config.h" 00014 #endif 00015 00016 // for truncation warning 00017 #ifdef _MSC_VER 00018 #include "msdevstudio/MSconfig.h" 00019 #endif 00020 00021 #include "HiNTupleXML.h" 00022 00023 #include "XmlController.h" 00024 #include "XmlElement.h" 00025 00026 #include "datasrcs/DataSourceException.h" 00027 #include "datasrcs/NTupleController.h" 00028 #include "datasrcs/NTuple.h" 00029 00030 #ifdef HAVE_CFITSIO 00031 #include "fits/FitsController.h" 00032 #endif 00033 00034 #ifdef HAVE_ROOT 00035 #include "root/RootController.h" 00036 #endif 00037 00038 using std::string; 00039 00040 HiNTupleXML::HiNTupleXML ( XmlController * controller ) 00041 : BaseXML ( "HiNTuple", controller ), 00042 m_name ( "name" ) 00043 { 00044 } 00045 00046 XmlElement * HiNTupleXML::createElement ( const DataSource & ntuple ) 00047 { 00048 XmlElement * tag = BaseXML::createElement (); 00049 00050 const void * addr = reinterpret_cast < const void * > ( & ntuple ); 00051 int id = m_controller -> getId ( addr ); 00052 setId ( *tag, id ); 00053 00054 const string & full_name = ntuple.getName (); 00055 tag -> setAttribute ( m_name, full_name ); 00056 00057 return tag; 00058 } 00059 00062 string HiNTupleXML::getName ( const XmlElement & tag ) const 00063 { 00064 string name; 00065 bool ok = tag.attribute ( m_name, name ); 00066 #ifndef STRING_CLEAR_DEFECT // change to ifdef when M4 macro is implemented 00067 if ( ! ok ) name.erase ( name.begin(), name.end() ); 00068 #else 00069 if ( ! ok ) name.clear(); 00070 #endif 00071 00072 return name; 00073 } 00074 00075 const DataSource * HiNTupleXML::getObject ( const XmlElement & tag ) const 00076 { 00077 const DataSource * ntuple = 0; 00078 const string fullname = getName ( tag ); 00079 if ( fullname.empty() ) return 0; 00080 00081 string filename; 00082 string name; 00083 string::size_type pos = fullname.find ( ":" ); 00084 if ( pos != string::npos ) { 00085 filename = fullname.substr ( 0, pos ); 00086 name = fullname.substr ( pos + 2 ); 00087 } 00088 else { 00089 filename = fullname; 00090 } 00091 00092 string suffix; 00093 pos = filename.find ( "." ); 00094 if ( pos != string::npos ) { 00095 suffix = filename.substr ( pos + 1 ); 00096 } 00097 00098 if ( suffix.empty () == false ) { 00099 if ( suffix == "fits" ) { 00100 #ifdef HAVE_CFITSIO 00101 FitsController * controller = FitsController::instance (); 00102 ntuple = controller -> createNTuple ( filename, name ); 00103 #else 00104 string what ("Can not open file\n" ); 00105 what += filename + "\n"; 00106 what += "because application was not built with FITS support"; 00107 throw DataSourceException ( what ); 00108 #endif 00109 } 00110 else if ( suffix == "root" ) { 00111 #ifdef HAVE_ROOT 00112 RootController * controller = RootController::instance (); 00113 ntuple = controller -> createNTuple ( filename, name ); 00114 #else 00115 string what ( "Can not open file\n" ); 00116 what += filename + "\n"; 00117 what += "because application was not bult with ROOT support"; 00118 throw DataSourceException ( what ); 00119 #endif 00120 } 00121 else { 00122 NTupleController * controller = NTupleController::instance (); 00123 ntuple = controller->createNTuple ( filename ); 00124 } 00125 } 00126 00127 return ntuple; 00128 }