CMS 3D CMS Logo

SerializeBase Class Reference

Generic Base for Manager classes that save/read any child FlagTxt class in/from output/input stream in form of text, binary stream or even XML. More...

#include <CalibTracker/SiStripRunSummary/interface/SerializeBase.h>

Inheritance diagram for SerializeBase:

SerializeBin SerializeTxt

List of all members.

Public Member Functions

FlagTxtgetFlag ()
 Get pointer to last read Flag if there is any available.
template<class T>
T * read (std::istream &roIn)
 Generic method for reading FlagTxt from stream.
 SerializeBase ()
bool write (std::ostream &roOut, const FlagTxt &roFLAGTXT) const
 Generic method for saving any FlagTxt anchestor in output stream that may be ostringstream, ofstream, etc.
virtual ~SerializeBase ()

Private Member Functions

virtual void readFlag (FlagTxt *poFlagTxt, std::istream &roIn)=0
 Perform actual flag read.
virtual void writeFlag (std::ostream &roOut, const FlagTxt &roFLAGTXT) const =0
 Perform actual flag wtore operation.

Private Attributes

FlagTxtpoFlagTxt_


Detailed Description

Generic Base for Manager classes that save/read any child FlagTxt class in/from output/input stream in form of text, binary stream or even XML.

Definition at line 22 of file SerializeBase.h.


Constructor & Destructor Documentation

SerializeBase::SerializeBase (  ) 

Definition at line 13 of file SerializeBase.cc.

References poFlagTxt_.

00013                              {
00014   poFlagTxt_ = 0;
00015 }

SerializeBase::~SerializeBase (  )  [virtual]

Definition at line 17 of file SerializeBase.cc.

References poFlagTxt_.

00017                               {
00018   if( poFlagTxt_) {
00019     delete poFlagTxt_;
00020   }
00021 }


Member Function Documentation

FlagTxt* SerializeBase::getFlag (  )  [inline]

Get pointer to last read Flag if there is any available.

Returns:
>0 Pointer to valid Flag 0 If Flag was not read or failed to do so

Definition at line 73 of file SerializeBase.h.

References poFlagTxt_.

00073 { return poFlagTxt_; }

template<class T>
T * SerializeBase::read ( std::istream &  roIn  )  [inline]

Generic method for reading FlagTxt from stream.

Class T should be the Flags class to be read. In given case different Trees can be read with the same manager SerializeTxt, e.g.:

DQMFlagTxt *poFlag = oSerializeTxt.read<DQMFlagTxt>( oIn); TIBFlagTxt *poFlag = oSerializeTxt.read<TIBFlagTxt>( oIn);

of course it is assumed that stream contains given flag stored. Trying to read incorrect flag would lead to exception that is caught by manager and NULL pointer is returned.

Parameters:
roIn Input stream containing saved Tree
Returns:
>0 Valud pointer to read Flags Tree on success. [Note: Object will be deleted by SerializeTxt automatically in destructor (!!!) or next attempt to read flag. Do not handle manually - copy it for further use] 0 Otherwise

Definition at line 103 of file SerializeBase.h.

References poFlagTxt_, and readFlag().

Referenced by FiletoBIN(), FiletoTXT(), StrtoBIN(), and StrtoTXT().

00103                                                           {
00104   if( poFlagTxt_) {
00105     delete poFlagTxt_;
00106     poFlagTxt_ = 0;
00107   }
00108 
00109   // [Note: Object will be deleted by SerializeTxt (!)]
00110   T *poT = new T();
00111 
00112   // Check if this is actually child class of FlagTxt
00113   if( FlagTxt *poFlagTxt = dynamic_cast<FlagTxt *>( poT)) {
00114 
00115     // Attempt to read flag from tree
00116     try {
00117       readFlag( poFlagTxt, roIn);
00118 
00119       poFlagTxt_ = poFlagTxt;
00120     } catch( ...) { 
00121       // Failed: maybe stream contains other flag saved - not T?
00122       delete poT;
00123       poT = 0;
00124     }
00125   } else {
00126     // Not a child
00127     delete poT;
00128     poT = 0;
00129   }
00130 
00131   return poT;
00132 }

virtual void SerializeBase::readFlag ( FlagTxt poFlagTxt,
std::istream &  roIn 
) [private, pure virtual]

Perform actual flag read.

Used by template read method to overcome compilation problems with include of boost/archive/text_i(o)archive.hpp from header [should be included only once from cpp]. Should be implemented by anchestors.

Parameters:
poFlagTxt Pointer to FlagTxt anchestor to be saved in output stream
roIn Output stream where flag will be saved

Implemented in SerializeTxt, and SerializeBin.

Referenced by read().

bool SerializeBase::write ( std::ostream &  roOut,
const FlagTxt roFLAGTXT 
) const

Generic method for saving any FlagTxt anchestor in output stream that may be ostringstream, ofstream, etc.

Type will be handled by boost::serialization library automatially.

Parameters:
roOut Output stream where flag will be saved
roFLAGTXT Flag reference to be saved
Returns:
true On success false Otherwise

Definition at line 23 of file SerializeBase.cc.

References writeFlag().

Referenced by SiStripRunSummaryWrite::algoEndJob(), BINtoFile(), BINtoStr(), TXTtoFile(), and TXTtoStr().

00025 {
00026   bool bResult = false;
00027 
00028   try {
00029     writeFlag( roOut, roFLAGTXT);
00030 
00031     bResult = true;
00032   } catch( ...) {
00033     // Failed to write Flag into output stream
00034   }
00035 
00036   return bResult;
00037 }

virtual void SerializeBase::writeFlag ( std::ostream &  roOut,
const FlagTxt roFLAGTXT 
) const [private, pure virtual]

Perform actual flag wtore operation.

Method should be implemented by anchestor.

Parameters:
roOut Output stream where flags tree will be saved
roFLAGTXT Reference to flag to be stored

Implemented in SerializeTxt, and SerializeBin.

Referenced by write().


Member Data Documentation

FlagTxt* SerializeBase::poFlagTxt_ [private]

Definition at line 100 of file SerializeBase.h.

Referenced by getFlag(), read(), SerializeBase(), and ~SerializeBase().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:31:31 2009 for CMSSW by  doxygen 1.5.4