CMS 3D CMS Logo

FlagTxt Class Reference

Flags base that: 1. More...

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

Inheritance diagram for FlagTxt:

Flag Clonable Identifiable DAQFlagTxt DCSFlagTxt DQMFlagTxt GlobalFlagTxt TECFlagTxt TIBFlagTxt TIDFlagTxt TOBFlagTxt TriggerFlagTxt

List of all members.

Public Types

typedef std::list< FlagTxt * > LChildren

Public Member Functions

template<class T>
FlagTxtcreateChild ()
 Method that is responsible for Child Flags creation.
 FlagTxt ()
template<class T>
FlagTxtgetChild () 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)
FlagTxtoperator= (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_
FlagTxtpoParentFlag_
 --[ END ]--

Friends

class boost::serialization::access
 --[ BEGIN ]-- Serialization section: Text format
class FlagXML
 Grant access of FlagXML to children.


Detailed Description

Flags base that: 1.

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.


Member Typedef Documentation

typedef ClassIDBase::ID FlagTxt::FlagID [private]

Definition at line 140 of file FlagTxt.h.

typedef std::list<FlagTxt *> FlagTxt::LChildren

Definition at line 32 of file FlagTxt.h.

typedef std::multimap<FlagID,FlagTxt *> FlagTxt::MChildFlags [private]

Definition at line 141 of file FlagTxt.h.


Constructor & Destructor Documentation

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().

Parameters:
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().

Parameters:
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 }


Member Function Documentation

void FlagTxt::addChild ( FlagTxt poSubFlag  )  [private]

Add child flag into the container of subflags.

Parameters:
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 }

template<class T>
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.

Returns:
>0 Pointer to newly created flag 0 Invalid pointer in case child flag of given class is not allowed.

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   }

template<class T>
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.

Returns:
>0 Pointer to child flag if there is any available. 0 Invalid pointer in case child flag does not exist.

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   }

template<class T>
int FlagTxt::getChildren ( LChildren roLChildren  )  const [inline]

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]

Returns:
number of children available

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   }

virtual int FlagTxt::isChildValid ( const FlagTxt  )  const [inline, protected, virtual]

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.

Parameters:
poCHILD_CANDIDATE Pointer to child candidate object that should be checked for validity.
Returns:
Number of allowed children: -1 No limit 0 No children allowed 1 One child only ... N N children allowed (current number of children may be from zero up to given number)

Reimplemented in DAQFlagTxt, DCSFlagTxt, DQMFlagTxt, and GlobalFlagTxt.

Definition at line 127 of file FlagTxt.h.

Referenced by createChild().

00127                                                                        {
00128         
00129       // No children are allowed by default
00130       return 0;
00131     }

template<class Archive>
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   }

FlagTxt& FlagTxt::operator= ( const FlagTxt roFLAGTXT  )  [private]

prevent copy assignment

Parameters:
roFLAGTXT Flag to be copied
Returns:
Reference to current flag.

template<class Archive>
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   }

bool FlagTxt::setState ( const State reSTATE  )  [virtual]

Override base setState method to update parents state.

Parameters:
reSTATE State of flag to be set.
Returns:
true In case flag's state was changed false Otherwise

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 }

void FlagTxt::updateState ( const State reCHILD_STATE  )  [private]

Update parents state.

Given method specifies logic: how successors affect ancestors.

Parameters:
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 }


Friends And Related Function Documentation

friend class boost::serialization::access [friend]

--[ BEGIN ]-- Serialization section: Text format

Reimplemented in DAQFlagTxt, DCSFlagTxt, DQMFlagTxt, GlobalFlagTxt, TECFlagTxt, TIBFlagTxt, TIDFlagTxt, TOBFlagTxt, and TriggerFlagTxt.

Definition at line 176 of file FlagTxt.h.

friend class FlagXML [friend]

Grant access of FlagXML to children.

Used in conversion: Txt -> XML.

Definition at line 138 of file FlagTxt.h.


Member Data Documentation

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().


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