#include <CalibTracker/SiStripRunSummary/interface/FlagTxt.h>
Public Types | |
typedef std::list< FlagTxt * > | LChildren |
Public Member Functions | |
template<class T> | |
FlagTxt * | createChild () |
Method that is responsible for Child Flags creation. | |
FlagTxt () | |
template<class T> | |
FlagTxt * | getChild () const |
Search for a specific child flag of given class if there is any available among children. | |
template<class T> | |
int | getChildren (LChildren &roLChildren) const |
Search for children that are instances of the same class. | |
virtual bool | setState (const State &reSTATE) |
Override base setState method to update parents state. | |
virtual | ~FlagTxt () |
Protected Member Functions | |
FlagTxt (const FlagXML &roFLAGXML) | |
Construct flag from another. | |
FlagTxt (const FlagTxt &roFLAGTXT) | |
Construct flag from another. | |
virtual int | isChildValid (const FlagTxt *) const |
Specify policy of current flag: can it have any children? Should be overriden by successors. | |
Private Types | |
typedef ClassIDBase::ID | FlagID |
typedef std::multimap< FlagID, FlagTxt * > | MChildFlags |
Private Member Functions | |
void | addChild (FlagTxt *poSubFlag) |
Add child flag into the container of subflags. | |
template<class Archive> | |
void | load (Archive &roArchive, const unsigned int &rnVersion) |
FlagTxt & | operator= (const FlagTxt &roFLAGTXT) |
prevent copy assignment | |
template<class Archive> | |
void | save (Archive &roArchive, const unsigned int &rnVersion) const |
--[ BEGIN ]-- Serialization section: Text format | |
void | updateState (const State &reCHILD_STATE) |
Update parents state. | |
Private Attributes | |
MChildFlags | oMChildFlags_ |
FlagTxt * | poParentFlag_ |
--[ END ]-- | |
Friends | |
class | boost::serialization::access |
--[ BEGIN ]-- Serialization section: Text format | |
class | FlagXML |
Grant access of FlagXML to children. |
Knows how to serialize Flags Tree in text/binary formats. 2. Holds children and responsible for their creation and access. 3. Tracks Children change state in order to update state of parent. [aka recursive set State].
Definition at line 30 of file FlagTxt.h.
typedef ClassIDBase::ID FlagTxt::FlagID [private] |
typedef std::list<FlagTxt *> FlagTxt::LChildren |
typedef std::multimap<FlagID,FlagTxt *> FlagTxt::MChildFlags [private] |
FlagTxt::FlagTxt | ( | ) | [inline] |
Definition at line 34 of file FlagTxt.h.
References poParentFlag_.
00034 : Flag() { poParentFlag_ = 0; }
FlagTxt::~FlagTxt | ( | ) | [virtual] |
Definition at line 10 of file FlagTxt.cc.
References oMChildFlags_.
00010 { 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 }
FlagTxt::FlagTxt | ( | const FlagTxt & | roFLAGTXT | ) | [protected] |
Construct flag from another.
Used by cloneXXX().
roFLAGTXT | Flag to be copied. |
Definition at line 32 of file FlagTxt.cc.
References addChild(), oMChildFlags_, and poParentFlag_.
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 }
FlagTxt::FlagTxt | ( | const FlagXML & | roFLAGXML | ) | [protected] |
Construct flag from another.
Used by cloneXXX().
roFLAGXML | Flag to be copied. |
Definition at line 49 of file FlagTxt.cc.
References addChild(), FlagXML::oMChildFlags_, and poParentFlag_.
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 }
Add child flag into the container of subflags.
poSubFlag | Flag to be added |
Definition at line 110 of file FlagTxt.cc.
References Identifiable::getID(), oMChildFlags_, and poParentFlag_.
Referenced by createChild(), FlagTxt(), and load().
00110 { 00111 poSubFlag->poParentFlag_ = this; 00112 oMChildFlags_.insert( std::make_pair( poSubFlag->getID(), poSubFlag)); 00113 }
FlagTxt * FlagTxt::createChild | ( | ) | [inline] |
Method that is responsible for Child Flags creation.
Create child flag of desired class.
Its tasks are: 1. Check if Child Flag of given type is allowed 2. Create Child Flag in case (1.) is true 3. Set newly created child flags parent.
Definition at line 201 of file FlagTxt.h.
References addChild(), ClassID< T >::get(), Flag::getState(), isChildValid(), and updateState().
Referenced by getTXTFlagTree().
00201 { 00202 FlagTxt *poResult = 0; 00203 00204 try { 00205 // Create object of requested class: may throw exception 00206 FlagTxt *poFlag = new T(); 00207 00208 // Get number of allowed children 00209 int nChildFlags = isChildValid( poFlag); 00210 00211 FlagID nID = ClassID<T>::get(); 00212 00213 switch( nChildFlags) { 00214 case 0: 00215 // No child flags allowed 00216 delete poFlag; 00217 break; 00218 case -1: 00219 // No limit on child flags 00220 { 00221 // Parent will be set by addChild(...) 00222 addChild( poFlag); 00223 00224 // Update parent state: child may be put into ERROR state by 00225 // default (this is specified in Flag class). Unfortunately 00226 // parent won't be updated 00227 updateState( poFlag->getState()); 00228 00229 poResult = poFlag; 00230 } 00231 break; 00232 default: 00233 // All other cases 00234 { 00235 if( 0 < nChildFlags) { 00236 // Check if Flag already exists 00237 std::pair<MChildFlags::const_iterator, 00238 MChildFlags::const_iterator> oFoundChildren = 00239 oMChildFlags_.equal_range( nID); 00240 00241 if( nChildFlags > std::distance( oFoundChildren.first, 00242 oFoundChildren.second)) { 00243 00244 // Parent will be set by addChild(...) 00245 addChild( poFlag); 00246 00247 // Update parent state: child may be put into ERROR state by 00248 // default (this is specified in Flag class). Unfortunately 00249 // parent won't be updated 00250 updateState( poFlag->getState()); 00251 00252 poResult = poFlag; 00253 } else { 00254 // No more child tags are allowed 00255 delete poFlag; 00256 } 00257 } else { 00258 // Unsupported value of child flags returned 00259 delete poFlag; 00260 }// End check if nChildFlags is positive 00261 } 00262 break; 00263 } // End switch( nChildFlags) 00264 } catch(...) { 00265 // Ups, trying to create child of Flag that is not inherited from 00266 // given class :[ 00267 } 00268 00269 return poResult; 00270 }
FlagTxt * FlagTxt::getChild | ( | ) | const [inline] |
Search for a specific child flag of given class if there is any available among children.
Extract child flag of desired class.
Flag should be first created with createChild() method.
Definition at line 277 of file FlagTxt.h.
References ClassID< T >::get(), and oMChildFlags_.
Referenced by operator<<().
00277 { 00278 // Get Class ID 00279 FlagID nID = ClassID<T>::get(); 00280 00281 // Find appropriate child 00282 std::pair<MChildFlags::const_iterator, MChildFlags::const_iterator> 00283 oFoundChildren = oMChildFlags_.equal_range( nID); 00284 00285 // Return found child or invalid pointer in case child can not be found 00286 FlagTxt *poChild = 0; 00287 if( 1 == std::distance( oFoundChildren.first, oFoundChildren.second)) { 00288 // One child was found: copy pointer. 00289 // [ToDo: add support for several allowed children] 00290 poChild = oFoundChildren.first->second; 00291 } 00292 00293 return poChild; 00294 }
Search for children that are instances of the same class.
Extract child flags of desired class.
Flags should be first created with createChild() method. Method also can be used as a getChild but might be inconvenient since it adds std::list overhead
[CAUTION: Variable will be overwritten (!) Anything contained there will be removed]
Definition at line 301 of file FlagTxt.h.
References ClassID< T >::get(), and oMChildFlags_.
00301 { 00302 // Get Class ID 00303 FlagID nID = ClassID<T>::get(); 00304 00305 // Find appropriate children 00306 std::pair<MChildFlags::const_iterator, MChildFlags::const_iterator> 00307 oFoundChildren = oMChildFlags_.equal_range( nID); 00308 00309 // Return found child or invalid pointer in case child can not be found 00310 // Return list of found children or empty one if children can not be 00311 // found 00312 roLChildren.clear(); 00313 if( 0 < std::distance( oFoundChildren.first, oFoundChildren.second)) { 00314 // A number of children was found: copy them into a list and return it 00315 while( oFoundChildren.first != oFoundChildren.second) { 00316 roLChildren.push_back( ( oFoundChildren.first++)->second); 00317 } 00318 } // End check if any children are found 00319 00320 return roLChildren.size(); 00321 }
Specify policy of current flag: can it have any children? Should be overriden by successors.
Use:
dynamic_cast<const AllowedSubFlagClass *>( poCHILD_CANDIDATE)
expression to check if child is allowed.
poCHILD_CANDIDATE | Pointer to child candidate object that should be checked for validity. |
Reimplemented in DAQFlagTxt, DCSFlagTxt, DQMFlagTxt, and GlobalFlagTxt.
Definition at line 127 of file FlagTxt.h.
Referenced by createChild().
void FlagTxt::load | ( | Archive & | roArchive, | |
const unsigned int & | rnVersion | |||
) | [inline, private] |
Definition at line 350 of file FlagTxt.h.
References addChild(), Flag::eState_, and Flag::oComment_.
00350 { 00351 roArchive & eState_; 00352 roArchive & oComment_; 00353 00354 // Read Child Flags: regular list will be extracted. 00355 LChildren oLChildren; 00356 roArchive & oLChildren; 00357 00358 // Reconstruct map of child flags since IDs of classes are runtime 00359 // dependent. 00360 for( LChildren::const_iterator oIter = oLChildren.begin(); 00361 oIter != oLChildren.end(); 00362 ++oIter) { 00363 00364 // Parent will be set by addChild(...) 00365 addChild( *oIter); 00366 } 00367 }
void FlagTxt::save | ( | Archive & | roArchive, | |
const unsigned int & | rnVersion | |||
) | const [inline, private] |
--[ BEGIN ]-- Serialization section: Text format
Definition at line 330 of file FlagTxt.h.
References Flag::eState_, Flag::oComment_, and oMChildFlags_.
00330 { 00331 roArchive & eState_; 00332 roArchive & oComment_; 00333 00334 // Copy Child Flags into list: we can not save map since IDs of classes 00335 // are runtime dependent. Solution: save pure list of child flags. And 00336 // Recreate map on reading the list from archive. 00337 LChildren oLChildren; 00338 for( MChildFlags::const_iterator oIter = oMChildFlags_.begin(); 00339 oIter != oMChildFlags_.end(); 00340 ++oIter) { 00341 00342 oLChildren.push_back( oIter->second); 00343 } 00344 00345 // Save Child Flags 00346 roArchive & oLChildren; 00347 }
Override base setState method to update parents state.
reSTATE | State of flag to be set. |
Reimplemented from Flag.
Definition at line 20 of file FlagTxt.cc.
References poParentFlag_, Flag::setState(), and updateState().
Referenced by updateState().
00020 { 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 }
Update parents state.
Given method specifies logic: how successors affect ancestors.
reCHILD_STATE | New state (changed) of Child flag |
Definition at line 68 of file FlagTxt.cc.
References Flag::ERROR, Flag::eState_, Flag::OK, oMChildFlags_, setState(), and Flag::UNKNOWN.
Referenced by createChild(), and setState().
00068 { 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 }
friend class boost::serialization::access [friend] |
--[ BEGIN ]-- Serialization section: Text format
Reimplemented in DAQFlagTxt, DCSFlagTxt, DQMFlagTxt, GlobalFlagTxt, TECFlagTxt, TIBFlagTxt, TIDFlagTxt, TOBFlagTxt, and TriggerFlagTxt.
friend class FlagXML [friend] |
MChildFlags FlagTxt::oMChildFlags_ [private] |
Definition at line 191 of file FlagTxt.h.
Referenced by addChild(), FlagTxt(), FlagXML::FlagXML(), getChild(), getChildren(), save(), updateState(), and ~FlagTxt().
FlagTxt* FlagTxt::poParentFlag_ [private] |
--[ END ]--
Definition at line 190 of file FlagTxt.h.
Referenced by addChild(), FlagTxt(), and setState().