CMS 3D CMS Logo

FlagTxt.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/FlagTxt.h"
00006 #include "CalibTracker/SiStripRunSummary/interface/FlagXML.h"
00007 
00008 // --[ FLAGTXT ]---------------------------------------------------------------
00009 //                                                  --[ PUBLIC ]--
00010 FlagTxt::~FlagTxt() {
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 FlagTxt::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 FlagTxt::FlagTxt( const FlagTxt &roFLAGTXT)
00033   : Flag( roFLAGTXT) 
00034 {
00035   poParentFlag_ = 0;
00036 
00037   // Clone all children.
00038   for( MChildFlags::const_iterator oIter = roFLAGTXT.oMChildFlags_.begin();
00039        oIter != roFLAGTXT.oMChildFlags_.end();
00040        ++oIter) {
00041 
00042     FlagTxt *poFlagClone = dynamic_cast<FlagTxt *>( oIter->second->clone());
00043 
00044     // Parent will be set by addChild(...)
00045     addChild( poFlagClone);
00046   }
00047 }
00048 
00049 FlagTxt::FlagTxt( const FlagXML &roFLAGXML)
00050   : Flag( roFLAGXML)
00051 {
00052   poParentFlag_ = 0;
00053 
00054   // Take care of Children
00055   for( FlagXML::MChildFlags::const_iterator oIter = 
00056          roFLAGXML.oMChildFlags_.begin();
00057        oIter != roFLAGXML.oMChildFlags_.end();
00058        ++oIter) {
00059 
00060     FlagTxt *poNewChild = dynamic_cast<FlagTxt *>( oIter->second->cloneTxt());
00061 
00062     // Parent will be set by addChild(...)
00063     addChild( poNewChild);
00064   }
00065 }
00066 
00067 //                                                  --[ PRIVATE ]--
00068 void FlagTxt::updateState( const State &reCHILD_STATE) {
00069   switch( reCHILD_STATE) {
00070     case UNKNOWN:
00071       // Do nothing: Unknown state does not affect child nor parent
00072       break;
00073     case ERROR:
00074       // Child changed to ERROR state
00075       if( ERROR != eState_) {
00076         setState( ERROR);
00077       }
00078       break;
00079     case OK:
00080     {
00081       // Child changed to OK state
00082       State eNewState = OK;
00083 
00084       // Loop over children and check if all of them are OK now or UNKNOWN.
00085       for( MChildFlags::const_iterator oIter = oMChildFlags_.begin();
00086            oIter != oMChildFlags_.end();
00087            ++oIter) {
00088 
00089         if( ERROR == oIter->second->getState()) {
00090           eNewState = ERROR;
00091 
00092           // One ERROR child flag is enough for parent to be set into the same
00093           // state
00094           break;
00095         }
00096       } // End loop over children
00097 
00098       // So, did state change?
00099       if( eNewState != eState_) {
00100         setState( eNewState);
00101       }
00102       break;
00103     }
00104     default:
00105       // Unsupported State
00106       break;
00107   }
00108 }
00109 
00110 void FlagTxt::addChild( FlagTxt *poSubFlag) {
00111   poSubFlag->poParentFlag_ = this;
00112   oMChildFlags_.insert( std::make_pair( poSubFlag->getID(), poSubFlag));
00113 }

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