00001 // Author : Samvel Khalatian (samvel at fnal dot gov) 00002 // Created: 07/15/07 00003 // License: GPL 00004 00005 #include <iostream> 00006 #include <fstream> 00007 #include <sstream> 00008 00009 #include "CalibTracker/SiStripRunSummary/interface/GlobalFlagXML.h" 00010 #include "CalibTracker/SiStripRunSummary/interface/SerializeXML.h" 00011 #include "CalibTracker/SiStripRunSummary/interface/getFlagTree.h" 00012 00013 const char *pcFILE_XML = "archive.xml"; 00014 std::string oFlagsStr = ""; 00015 00016 void XMLtoFile() { 00017 std::cout << "--[ \033[1mXMLtoFile\033[0m ]----------------" << std::endl; 00018 GlobalFlagXML oFlag( getXMLFlagTree()); 00019 00020 std::ofstream oSFileOut( pcFILE_XML); 00021 00022 SerializeXML oSerializeXML; 00023 if( oSerializeXML.write( oSFileOut, oFlag)) { 00024 std::cout << "Flags Tree wrote to file: \033[1m" << pcFILE_XML 00025 << "\033[0m" << std::endl; 00026 } else { 00027 std::cout << "[\033[31merror\033[0m] Could not write Flags Tree to file: " 00028 << "\033[1m" << pcFILE_XML << "\033[0m" << std::endl; 00029 } 00030 std::cout << std::endl; 00031 } 00032 00033 void XMLtoStr() { 00034 std::cout << "--[ \033[1mXMLtoStr\033[0m ]----------------" << std::endl; 00035 GlobalFlagXML oFlag( getXMLFlagTree()); 00036 00037 std::ostringstream oSStrOut; 00038 00039 SerializeXML oSerializeXML; 00040 if( oSerializeXML.write( oSStrOut, oFlag)) { 00041 oFlagsStr = oSStrOut.str(); 00042 00043 std::cout << "XML String representing Falgs Tree..." 00044 << std::endl 00045 << "\033[1;32m" 00046 << oFlagsStr << "\033[0m" << std::endl; 00047 } else { 00048 std::cout << "[\033[31merror\033[0m] Could not write Flags to string " 00049 << std::endl; 00050 } 00051 00052 std::cout << std::endl; 00053 } 00054 00055 void FiletoXML() { 00056 std::cout << "--[ \033[1mFiletoXML\033[0m ]----------------" << std::endl; 00057 00058 std::ifstream oSFileIn( pcFILE_XML); 00059 00060 SerializeXML oSerializeXML; 00061 if( GlobalFlagXML *poFlag = oSerializeXML.read<GlobalFlagXML>( oSFileIn)) { 00062 std::cout << "Read Flags Tree from file: \033[1m" 00063 << pcFILE_XML << "\033[0m" << std::endl; 00064 std::cout << "\033[1;32m" << *poFlag << "\033[0m" << std::endl; 00065 } else { 00066 std::cout << "[\033[31merror\033[0m] Could not read Flags Tree from file: " 00067 << "\033[1m" << pcFILE_XML << "\033[0m" << std::endl; 00068 } 00069 00070 std::cout << std::endl; 00071 } 00072 00073 void StrtoXML() { 00074 std::cout << "--[ \033[1mStrtoXML\033[0m ]----------------" << std::endl; 00075 00076 std::istringstream oSStrIn( oFlagsStr); 00077 00078 SerializeXML oSerializeXML; 00079 if( GlobalFlagXML *poFlag = oSerializeXML.read<GlobalFlagXML>( oSStrIn)) { 00080 std::cout << "Read Flags Tree from string" << std::endl; 00081 std::cout << "\033[1;32m" << *poFlag << "\033[0m" << std::endl; 00082 } else { 00083 std::cout << "[\033[31merror\033[0m] Could not read Flags from string " 00084 << std::endl; 00085 } 00086 00087 std::cout << std::endl; 00088 } 00089 00090 00091 int main( int nArgc, char *pcArgv[]) { 00092 XMLtoFile(); 00093 XMLtoStr (); 00094 FiletoXML(); 00095 StrtoXML (); 00096 00097 return 0; 00098 }