CMS 3D CMS Logo

main_txt.cc

Go to the documentation of this file.
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/GlobalFlagTxt.h"
00010 #include "CalibTracker/SiStripRunSummary/interface/SerializeTxt.h"
00011 #include "CalibTracker/SiStripRunSummary/interface/getFlagTree.h"
00012 
00013 const char  *pcFILE_TXT = "archive.txt";
00014 std::string  oFlagsStr  = "";
00015 
00016 void TXTtoFile() {
00017   std::cout << "--[ \033[1mTXTtoFile\033[0m ]----------------" << std::endl;
00018   GlobalFlagTxt oFlag( getTXTFlagTree());
00019 
00020   std::ofstream oSFileOut( pcFILE_TXT);
00021 
00022   SerializeTxt oSerializeTxt;
00023   if( oSerializeTxt.write( oSFileOut, oFlag)) {
00024     std::cout << "Flags Tree wrote to file: \033[1m" << pcFILE_TXT 
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_TXT << "\033[0m" << std::endl;
00029   }
00030   std::cout << std::endl;
00031 }
00032 
00033 void TXTtoStr() {
00034   std::cout << "--[ \033[1mTXTtoStr\033[0m ]----------------" << std::endl;
00035   GlobalFlagTxt oFlag( getTXTFlagTree());
00036 
00037   std::ostringstream oSStrOut;
00038 
00039   SerializeTxt oSerializeTxt;
00040   if( oSerializeTxt.write( oSStrOut, oFlag)) {
00041     oFlagsStr = oSStrOut.str();
00042 
00043     std::cout << "TXT 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 FiletoTXT() {
00056   std::cout << "--[ \033[1mFiletoTXT\033[0m ]----------------" << std::endl;
00057 
00058   std::ifstream oSFileIn( pcFILE_TXT);
00059 
00060   SerializeTxt oSerializeTxt;
00061   if( GlobalFlagTxt *poFlag = oSerializeTxt.read<GlobalFlagTxt>( oSFileIn)) {
00062     std::cout << "Read Flags Tree from file: \033[1m"
00063               << pcFILE_TXT << "\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_TXT << "\033[0m" << std::endl;
00068   }
00069 
00070   std::cout << std::endl;
00071 }
00072 
00073 void StrtoTXT() {
00074   std::cout << "--[ \033[1mStrtoTXT\033[0m ]----------------" << std::endl;
00075 
00076   std::istringstream oSStrIn( oFlagsStr);
00077 
00078   SerializeTxt oSerializeTxt;
00079   if( GlobalFlagTxt *poFlag = oSerializeTxt.read<GlobalFlagTxt>( 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 int main( int nArgc, char *pcArgv[]) {
00091   TXTtoFile();
00092   TXTtoStr ();
00093   FiletoTXT();
00094   StrtoTXT ();
00095 
00096   return 0;
00097 }

Generated on Tue Jun 9 17:25:52 2009 for CMSSW by  doxygen 1.5.4