CMS 3D CMS Logo

FlagXML.cc

Go to the documentation of this file.
00001 // Author : Samvel Khalatian (samvel at fnal dot gov)
00002 // Created: 05/31/07
00003 // License: GPL
00004 
00005 #include "CalibTracker/SiStripRunSummary/interface/FlagXML.h"
00006 #include "CalibTracker/SiStripRunSummary/interface/FlagTxt.h"
00007 
00008 // --[ FLAGXML ]---------------------------------------------------------------
00009 //                                                  --[ PUBLIC ]--
00010 FlagXML::~FlagXML() {
00011   // Memory Clean Up: remove all children
00012   for( MChildFlags::const_iterator oIter = oMChildFlags_.begin();
00013        oIter != oMChildFlags_.end();
00014        ++oIter) {
00015 
00016     delete oIter->second;
00017   }
00018 }
00019 
00020 bool FlagXML::setState( const State &reSTATE) {
00021   bool bResult = Flag::setState( reSTATE);
00022 
00023   // Update parent value only in case child state modified and parent exists.
00024   if( bResult && poParentFlag_) {
00025     poParentFlag_->updateState( reSTATE);
00026   }
00027 
00028   return bResult;
00029 }
00030 
00031 //                                                  --[ PROTECTED ]--
00032 FlagXML::FlagXML( const FlagXML &roFLAGXML)
00033   : Flag( roFLAGXML)
00034 {
00035   poParentFlag_ = 0;
00036 
00037   // Clone all children.
00038   for( MChildFlags::const_iterator oIter = roFLAGXML.oMChildFlags_.begin();
00039        oIter != roFLAGXML.oMChildFlags_.end();
00040        ++oIter) {
00041 
00042     FlagXML *poFlagClone = dynamic_cast<FlagXML *>( oIter->second->clone());
00043 
00044     // Parent will be set by addChild(...)
00045     addChild( poFlagClone);
00046   }
00047 }
00048 
00049 FlagXML::FlagXML( const FlagTxt &roFLAGTXT)
00050   : Flag( roFLAGTXT),
00051     poParentFlag_( 0) {
00052 
00053   // Take care of Children
00054   for( FlagTxt::MChildFlags::const_iterator oIter = 
00055          roFLAGTXT.oMChildFlags_.begin();
00056        oIter != roFLAGTXT.oMChildFlags_.end();
00057        ++oIter) {
00058 
00059     FlagXML *poNewChild = dynamic_cast<FlagXML *>( oIter->second->cloneXML());
00060 
00061     // Parent will be set by addChild(...)
00062     addChild( poNewChild);
00063   }
00064 }
00065 
00066 //                                                  --[ PRIVATE ]--
00067 void FlagXML::updateState( const State &reCHILD_STATE) {
00068   switch( reCHILD_STATE) {
00069     case UNKNOWN:
00070       // Do nothing: Unknown state does not affect child nor parent
00071       break;
00072     case ERROR:
00073       // Child changed to ERROR state
00074       if( ERROR != eState_) {
00075         setState( ERROR);
00076       }
00077       break;
00078     case OK:
00079     {
00080       // Child changed to OK state
00081       State eNewState = OK;
00082 
00083       // Loop over children and check if all of them are OK now or UNKNOWN.
00084       for( MChildFlags::const_iterator oIter = oMChildFlags_.begin();
00085            oIter != oMChildFlags_.end();
00086            ++oIter) {
00087 
00088         if( ERROR == oIter->second->getState()) {
00089           eNewState = ERROR;
00090 
00091           // One ERROR child flag is enough for parent to be set into the same
00092           // state
00093           break;
00094         }
00095       } // End loop over children
00096 
00097       // So, did state change?
00098       if( eNewState != eState_) {
00099         setState( eNewState);
00100       }
00101       break;
00102     }
00103     default:
00104       // Unsupported State
00105       break;
00106   }
00107 }
00108 
00109 void FlagXML::addChild( FlagXML *poSubFlag) {
00110   poSubFlag->poParentFlag_ = this;
00111   oMChildFlags_.insert( std::make_pair( poSubFlag->getID(), poSubFlag));
00112 }

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