Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

Sequencer.cpp

Go to the documentation of this file.
00001 // Sequencer class
00002 // Implements:
00003 // 1) Common functionality of IInterface
00004 // 2) Default behavior for the IAlgorithm
00005 
00006 #include "GaudiAlg/Sequencer.h"
00007 
00008 #include "GaudiKernel/IAlgManager.h"
00009 #include "GaudiKernel/ISvcLocator.h"
00010 #include "GaudiKernel/AlgFactory.h"
00011 #include "GaudiKernel/MsgStream.h"
00012 #include "GaudiKernel/Chrono.h"
00013 #include "GaudiKernel/Stat.h"
00014 #include "GaudiKernel/GaudiException.h"
00015 
00016 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
00017 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
00018 
00022 Sequencer::Sequencer( const std::string& name, ISvcLocator* pSvcLocator )
00023 : Algorithm( name, pSvcLocator ),
00024   m_branchFilterPassed( false )
00025 {
00026 
00027   // Create vector of branch algorithms
00028   m_branchAlgs = new std::vector<Algorithm*>();
00029 
00030   // Declare Sequencer properties with their defaults
00031   declareProperty( "Members", m_names );
00032   declareProperty( "BranchMembers", m_branchNames );
00033   declareProperty( "StopOverride", m_stopOverride=false );
00034 
00035   // Associate action handlers with the "Members" and "BranchMembers" properties
00036   m_names.declareUpdateHandler      ( &Sequencer::membershipHandler      , this );
00037   m_branchNames.declareUpdateHandler( &Sequencer::branchMembershipHandler, this );
00038 
00039 }
00040 
00044 Sequencer::~Sequencer()
00045 {
00046   delete m_branchAlgs;
00047 }
00048 
00049 StatusCode
00050 Sequencer::initialize()
00051 {
00052   StatusCode result = StatusCode::SUCCESS;
00053   MsgStream log( msgSvc( ), name( ) );
00054 
00055   std::vector<Algorithm*>* theAlgs;
00056   std::vector<Algorithm*>::iterator it;
00057   std::vector<Algorithm*>::iterator itend;
00058 
00059   result = decodeMemberNames();
00060   if( result.isFailure() ) {
00061     log << MSG::ERROR << "Unable to configure one or more sequencer members " << endmsg;
00062     return result;
00063   }
00064   result = decodeBranchMemberNames();
00065   if( result.isFailure() ) {
00066     log << MSG::ERROR << "Unable to configure one or more branch members " << endmsg;
00067     return result;
00068   }
00069 
00070   // Loop over all sub-algorithms
00071   theAlgs = subAlgorithms( );
00072   itend   = theAlgs->end( );
00073   for (it = theAlgs->begin(); it != itend; it++) {
00074     Algorithm* theAlgorithm = (*it);
00075     result = theAlgorithm->sysInitialize( );
00076     if( result.isFailure() ) {
00077       log << MSG::ERROR << "Unable to initialize Algorithm " << theAlgorithm->name() << endmsg;
00078       return result;
00079     }
00080   }
00081 
00082   // Loop over all branches
00083   theAlgs = branchAlgorithms( );
00084   itend   = theAlgs->end( );
00085   for (it = theAlgs->begin(); it != itend; it++) {
00086     Algorithm* theAlgorithm = (*it);
00087     result = theAlgorithm->sysInitialize( );
00088     if( result.isFailure() ) {
00089       log << MSG::ERROR << "Unable to initialize Algorithm " << theAlgorithm->name() << endmsg;
00090       return result;
00091     }
00092   }
00093 
00094   return result;
00095 }
00096 
00097 StatusCode
00098 Sequencer::reinitialize()
00099 {
00100   // Bypass the loop if this sequencer is disabled
00101   if ( isEnabled( ) ) {
00102 
00103     // Loop over all members calling their reinitialize functions
00104     // if they are not disabled.
00105     std::vector<Algorithm*>* theAlgms = subAlgorithms( );
00106     std::vector<Algorithm*>::iterator it;
00107     std::vector<Algorithm*>::iterator itend = theAlgms->end( );
00108     for (it = theAlgms->begin(); it != itend; it++) {
00109       Algorithm* theAlgorithm = (*it);
00110       if ( ! theAlgorithm->isEnabled( ) ) {
00111         theAlgorithm->reinitialize( ).ignore();
00112       }
00113     }
00114     // Loop over all branch members calling their reinitialize functions
00115     // if they are not disabled.
00116     theAlgms = branchAlgorithms( );
00117     itend    = theAlgms->end( );
00118     for (it = theAlgms->begin(); it != itend; it++) {
00119       Algorithm* theAlgorithm = (*it);
00120       if ( ! theAlgorithm->isEnabled( ) ) {
00121         theAlgorithm->reinitialize( ).ignore();
00122       }
00123     }
00124 
00125   }
00126   return StatusCode::SUCCESS;
00127 }
00128 
00129 StatusCode
00130 Sequencer::execute()
00131 {
00132   StatusCode result = StatusCode::SUCCESS;
00133   MsgStream log( msgSvc( ), name( ) );
00134 
00135   ON_DEBUG log << MSG::DEBUG << name( ) << " Sequencer::execute( )" << endmsg;
00136 
00137   // Bypass the loop if this sequencer is disabled or has already been executed
00138   if ( isEnabled( ) && ! isExecuted( ) ) {
00139     Algorithm* lastAlgorithm;
00140     result = execute( subAlgorithms( ), m_isInverted, lastAlgorithm );
00141     if ( result.isSuccess( ) ) {
00142       bool passed = filterPassed( );
00143       if ( ! passed && ! isStopOverride( ) ) {
00144 
00145         // Filter failed and stop override not set. Execute the
00146         // branch if there is one associated with the filter
00147         // algorithm that failed. Note that the first member on
00148         // the branch is the failing algorithm and so should
00149         // be skipped.
00150         std::vector<Algorithm*>* theAlgs = branchAlgorithms( );
00151         if ( theAlgs->size( ) > 0 ) {
00152           Algorithm* branchAlgorithm = (*theAlgs)[0];
00153           if ( lastAlgorithm == branchAlgorithm ) {
00154 
00155             // Branch specified - Loop over branch members
00156             result = execute( branchAlgorithms( ),
00157                               m_isBranchInverted,
00158                               lastAlgorithm, 1 );
00159             if ( result.isSuccess( ) ) {
00160 
00161               // The final filter passed state will be set true if either
00162               // of the main or branches passed, otherwise false.
00163 
00164               // Save the branch  filter passed state.
00165               setBranchFilterPassed( filterPassed( ) ).ignore();
00166             }
00167           }
00168         }
00169       }
00170     }
00171 
00172     // Prevent multiple executions of this sequencer for the current event
00173     setExecuted( true );
00174   }
00175   return result;
00176 }
00177 
00178 StatusCode
00179 Sequencer::finalize()
00180 {
00181   // Loop over all branch members calling their finalize functions
00182   // if they are not disabled. Note that the Algorithm::sysFinalize
00183   // function already does this for the main members.
00184   std::vector<Algorithm*>* theAlgs = branchAlgorithms( );
00185   std::vector<Algorithm*>::iterator it;
00186   std::vector<Algorithm*>::iterator itend = theAlgs->end( );
00187   for (it = theAlgs->begin(); it != itend; it++) {
00188     Algorithm* theAlgorithm = (*it);
00189     if (theAlgorithm->sysFinalize( ).isFailure()) {
00190       MsgStream log( msgSvc( ), name( ) );
00191       log << MSG::ERROR << "Unable to finalize Algorithm "
00192           << theAlgorithm->name() << endmsg;
00193     }
00194   }
00195   return StatusCode::SUCCESS;
00196 }
00197 
00198 StatusCode
00199 Sequencer::start()
00200 {
00201   StatusCode result = StatusCode::SUCCESS;
00202   MsgStream log( msgSvc( ), name( ) );
00203 
00204   std::vector<Algorithm*>* theAlgs;
00205   std::vector<Algorithm*>::iterator it;
00206   std::vector<Algorithm*>::iterator itend;
00207 
00208   // Loop over all sub-algorithms
00209   theAlgs = subAlgorithms( );
00210   itend   = theAlgs->end( );
00211   for (it = theAlgs->begin(); it != itend; it++) {
00212     Algorithm* theAlgorithm = (*it);
00213     result = theAlgorithm->sysStart( );
00214     if( result.isFailure() ) {
00215       log << MSG::ERROR << "Unable to start Algorithm " << theAlgorithm->name() << endmsg;
00216       return result;
00217     }
00218   }
00219 
00220   // Loop over all branches
00221   theAlgs = branchAlgorithms( );
00222   itend   = theAlgs->end( );
00223   for (it = theAlgs->begin(); it != itend; it++) {
00224     Algorithm* theAlgorithm = (*it);
00225     result = theAlgorithm->sysStart( );
00226     if( result.isFailure() ) {
00227       log << MSG::ERROR << "Unable to start Algorithm " << theAlgorithm->name() << endmsg;
00228       return result;
00229     }
00230   }
00231 
00232   return result;
00233 }
00234 
00235 StatusCode
00236 Sequencer::stop()
00237 {
00238   // Loop over all branch members calling their finalize functions
00239   // if they are not disabled.
00240   std::vector<Algorithm*>* theAlgs;
00241   std::vector<Algorithm*>::iterator it;
00242   std::vector<Algorithm*>::iterator itend;
00243 
00244   theAlgs = subAlgorithms( );
00245   itend   = theAlgs->end( );
00246   for (it = theAlgs->begin(); it != itend; it++) {
00247     Algorithm* theAlgorithm = (*it);
00248     if (theAlgorithm->sysStop( ).isFailure()) {
00249       MsgStream log( msgSvc( ), name( ) );
00250       log << MSG::ERROR << "Unable to stop Algorithm "
00251           << theAlgorithm->name() << endmsg;
00252     }
00253   }
00254 
00255   theAlgs = branchAlgorithms( );
00256   itend   = theAlgs->end( );
00257   for (it = theAlgs->begin(); it != itend; it++) {
00258     Algorithm* theAlgorithm = (*it);
00259     if (theAlgorithm->sysStop( ).isFailure()) {
00260       MsgStream log( msgSvc( ), name( ) );
00261       log << MSG::ERROR << "Unable to stop Algorithm "
00262           << theAlgorithm->name() << endmsg;
00263     }
00264   }
00265   return StatusCode::SUCCESS;
00266 }
00267 
00268 StatusCode
00269 Sequencer::beginRun()
00270 {
00271   StatusCode result = StatusCode::SUCCESS;
00272   MsgStream log( msgSvc( ), name( ) );
00273 
00274   // Bypass the loop if this sequencer is disabled
00275   if ( isEnabled( ) ) {
00276 
00277     // Loop over all members calling their sysInitialize functions
00278     // if they are not disabled. Note that the Algoriithm::sysInitialize
00279     // function protects this from affecting Algorithms that have already
00280     // been initialized.
00281     std::vector<Algorithm*>* theAlgs = subAlgorithms( );
00282     std::vector<Algorithm*>::iterator it;
00283     std::vector<Algorithm*>::iterator itend = theAlgs->end( );
00284     for (it = theAlgs->begin(); it != itend; it++) {
00285       Algorithm* theAlgorithm = (*it);
00286       result = theAlgorithm->sysInitialize( );
00287       if( result.isFailure() ) {
00288         log << MSG::ERROR << "Unable to initialize Algorithm " << theAlgorithm->name() << endmsg;
00289         break;
00290       }
00291       result = theAlgorithm->sysStart( );
00292       if( result.isFailure() ) {
00293         log << MSG::ERROR << "Unable to start Algorithm " << theAlgorithm->name() << endmsg;
00294         break;
00295       }
00296     }
00297 
00298     // Loop over all members calling their beginRun functions
00299     // if they are not disabled.
00300     for (it = theAlgs->begin(); it != itend; it++) {
00301       Algorithm* theAlgorithm = (*it);
00302       if ( ! theAlgorithm->isEnabled( ) ) {
00303         theAlgorithm->beginRun( ).ignore();
00304       }
00305     }
00306 
00307     // Loop over all branch members calling their sysInitialize functions
00308     // if they are not disabled. Note that the Algoriithm::sysInitialize
00309     // function protects this from affecting Algorithms that have already
00310     // been initialized.
00311     theAlgs = branchAlgorithms( );
00312     itend   = theAlgs->end( );
00313     for (it = theAlgs->begin(); it != itend; it++) {
00314       Algorithm* theAlgorithm = (*it);
00315       result = theAlgorithm->sysInitialize( );
00316       if( result.isFailure() ) {
00317         log << MSG::ERROR << "Unable to initialize Algorithm " << theAlgorithm->name() << endmsg;
00318         break;
00319       }
00320       result = theAlgorithm->sysStart( );
00321       if( result.isFailure() ) {
00322         log << MSG::ERROR << "Unable to start Algorithm " << theAlgorithm->name() << endmsg;
00323         break;
00324       }
00325     }
00326 
00327     // Loop over all branch members calling their beginRun functions
00328     // if they are not disabled.
00329     for (it = theAlgs->begin(); it != itend; it++) {
00330       Algorithm* theAlgorithm = (*it);
00331       if ( ! theAlgorithm->isEnabled( ) ) {
00332         theAlgorithm->beginRun( ).ignore();
00333       }
00334     }
00335   }
00336   return StatusCode::SUCCESS;
00337 }
00338 
00339 StatusCode
00340 Sequencer::endRun()
00341 {
00342   // Bypass the loop if this sequencer is disabled
00343   if ( isEnabled( ) ) {
00344 
00345     // Loop over all members calling their endRun functions
00346     // if they are not disabled.
00347     std::vector<Algorithm*>* theAlgms = subAlgorithms( );
00348     std::vector<Algorithm*>::iterator it;
00349     std::vector<Algorithm*>::iterator itend = theAlgms->end( );
00350     for (it = theAlgms->begin(); it != itend; it++) {
00351       Algorithm* theAlgorithm = (*it);
00352       if ( ! theAlgorithm->isEnabled( ) ) {
00353         theAlgorithm->endRun( ).ignore();
00354       }
00355     }
00356     // Loop over all branch members calling their endRun functions
00357     // if they are not disabled.
00358     theAlgms = branchAlgorithms( );
00359     itend    = theAlgms->end( );
00360     for (it = theAlgms->begin(); it != itend; it++) {
00361       Algorithm* theAlgorithm = (*it);
00362       if ( ! theAlgorithm->isEnabled( ) ) {
00363         theAlgorithm->endRun( ).ignore();
00364       }
00365     }
00366   }
00367   return StatusCode::SUCCESS;
00368 }
00369 
00370 void
00371 Sequencer::resetExecuted( )
00372 {
00373   Algorithm::resetExecuted( );
00374 
00375   // Loop over all members calling their resetExecuted functions
00376   // if they are not disabled.
00377   std::vector<Algorithm*>* subAlgms = subAlgorithms( );
00378   std::vector<Algorithm*>::iterator it;
00379   std::vector<Algorithm*>::iterator itend = subAlgms->end( );
00380   for (it = subAlgms->begin(); it != itend; it++) {
00381     Algorithm* theAlgorithm = (*it);
00382     theAlgorithm->resetExecuted( );
00383   }
00384 
00385   // Loop over all branch members calling their resetExecuted functions
00386   // if they are not disabled.
00387   subAlgms = branchAlgorithms( );
00388   itend    = subAlgms->end( );
00389   for (it = subAlgms->begin(); it != itend; it++) {
00390     Algorithm* theAlgorithm = (*it);
00391     theAlgorithm->resetExecuted( );
00392   }
00393 
00394   // Reset the branch filter passed flag
00395   m_branchFilterPassed = false;
00396 }
00397 
00398 bool
00399 Sequencer::branchFilterPassed( ) const
00400 {
00401   return m_branchFilterPassed;
00402 }
00403 
00404 StatusCode
00405 Sequencer::setBranchFilterPassed( bool state )
00406 {
00407   m_branchFilterPassed = state;
00408   return StatusCode::SUCCESS;
00409 }
00410 
00411 bool
00412 Sequencer::isStopOverride( ) const
00413 {
00414   return m_stopOverride.value( );
00415 }
00416 
00417 StatusCode
00418 Sequencer::append( Algorithm* pAlgorithm )
00419 {
00420   StatusCode result = append( pAlgorithm, subAlgorithms( ) );
00421   return result;
00422 }
00423 
00424 StatusCode
00425 Sequencer::appendToBranch( Algorithm* pAlgorithm )
00426 {
00427   StatusCode result = append( pAlgorithm, branchAlgorithms( ) );
00428   return result;
00429 }
00430 
00431 StatusCode
00432 Sequencer::createAndAppend( const std::string& type,
00433                             const std::string& name,
00434                             Algorithm*& pAlgorithm )
00435 {
00436   StatusCode result = createAndAppend( type, name, pAlgorithm, subAlgorithms( ) );
00437   return result;
00438 }
00439 
00440 StatusCode
00441 Sequencer::createAndAppendToBranch( const std::string& type,
00442                                     const std::string& name,
00443                                     Algorithm*& pAlgorithm )
00444 {
00445   StatusCode result = createAndAppend( type, name, pAlgorithm, branchAlgorithms( ) );
00446   return result;
00447 }
00448 
00449 StatusCode
00450 Sequencer::remove( Algorithm* pAlgorithm )
00451 {
00452   std::string theName = pAlgorithm->name( );
00453   StatusCode result = remove( theName );
00454   return result;
00455 }
00456 
00457 StatusCode
00458 Sequencer::remove( const std::string& algname )
00459 {
00460   StatusCode result = remove( algname, subAlgorithms( ) );
00461   return result;
00462 }
00463 
00464 StatusCode
00465 Sequencer::removeFromBranch( Algorithm* pAlgorithm )
00466 {
00467   std::string theName = pAlgorithm->name( );
00468   StatusCode result = removeFromBranch( theName );
00469   return result;
00470 }
00471 
00472 StatusCode
00473 Sequencer::removeFromBranch( const std::string& algname )
00474 {
00475   StatusCode result = remove( algname, branchAlgorithms( ) );
00476   return result;
00477 }
00478 
00479 std::vector<Algorithm*>*
00480 Sequencer::branchAlgorithms( ) const {
00481   return m_branchAlgs;
00482 }
00483 
00484 StatusCode
00485 Sequencer::decodeMemberNames( )
00486 {
00487   StatusCode result = StatusCode::SUCCESS;
00488 
00489   // Decode the membership list
00490   result = decodeNames( m_names,
00491                         subAlgorithms( ),
00492                         m_isInverted );
00493 
00494   return result;
00495 }
00496 
00497 void
00498 Sequencer::membershipHandler( Property& /* theProp */ )
00499 {
00500   if ( isInitialized() ) decodeMemberNames();
00501 }
00502 
00503 StatusCode
00504 Sequencer::decodeBranchMemberNames( )
00505 {
00506   StatusCode result = StatusCode::SUCCESS;
00507 
00508   // Decode the branch membership list
00509   result = decodeNames( m_branchNames,
00510                         branchAlgorithms( ),
00511                         m_isBranchInverted );
00512 
00513   return result;
00514 }
00515 
00516 void
00517 Sequencer::branchMembershipHandler( Property& /* theProp */ )
00518 {
00519   if ( isInitialized() ) decodeBranchMemberNames();
00520 }
00521 
00526 StatusCode
00527 Sequencer::append( Algorithm* pAlgorithm,
00528                    std::vector<Algorithm*>* theAlgs )
00529 {
00530   StatusCode result = StatusCode::SUCCESS;
00531   // Check that the specified algorithm doesn't already exist in the membership list
00532   std::vector<Algorithm*>::iterator it;
00533   std::vector<Algorithm*>::iterator itend = theAlgs->end( );
00534   for (it = theAlgs->begin(); it != itend; it++) {
00535     Algorithm* theAlgorithm = (*it);
00536     if ( theAlgorithm == pAlgorithm ) {
00537       result = StatusCode::FAILURE;
00538       break;
00539     }
00540   }
00541   if ( result.isSuccess( ) ) {
00542     theAlgs->push_back( pAlgorithm );
00543     pAlgorithm->addRef();
00544   }
00545   return result;
00546 }
00547 
00548 StatusCode
00549 Sequencer::createAndAppend( const std::string& type,
00550                                 const std::string& algName,
00551                                 Algorithm*& pAlgorithm,
00552                                 std::vector<Algorithm*>* theAlgs )
00553 {
00554   StatusCode result = StatusCode::FAILURE;
00555   MsgStream log( msgSvc( ), name( ) );
00556   SmartIF<IAlgManager> theAlgMgr(serviceLocator()->service("ApplicationMgr"));
00557   if ( theAlgMgr.isValid() ) {
00558     IAlgorithm* tmp;
00559     result = theAlgMgr->createAlgorithm( type, algName, tmp );
00560     if ( result.isSuccess( ) ) {
00561       try{
00562         pAlgorithm = dynamic_cast<Algorithm*>(tmp);
00563         theAlgs->push_back( pAlgorithm );
00564       } catch(...){
00565         log << MSG::ERROR << "Unable to create Algorithm " << algName << endmsg;
00566         result = StatusCode::FAILURE;
00567       }
00568     }
00569   }
00570   return result;
00571 }
00572 
00573 StatusCode
00574 Sequencer::decodeNames( StringArrayProperty& theNames,
00575                         std::vector<Algorithm*>* theAlgs,
00576                         std::vector<bool>& theLogic )
00577 {
00578   StatusCode result;
00579   MsgStream log( msgSvc( ), name( ) );
00580   SmartIF<IAlgManager> theAlgMgr(serviceLocator()->service("ApplicationMgr"));
00581   if ( theAlgMgr.isValid() ) {
00582     // Clear the existing list of algorithms
00583     theAlgs->clear( );
00584 
00585     // Build the list of member algorithms from the contents of the
00586     // theNames list.
00587     const std::vector<std::string>& theNameVector = theNames.value( );
00588     std::vector<std::string>::const_iterator it;
00589     std::vector<std::string>::const_iterator itend = theNameVector.end( );
00590     for (it = theNameVector.begin(); it != itend; it++) {
00591 
00592       // Parse the name for a syntax of the form:
00593       //
00594       // <type>/<name>
00595       //
00596       // Where <name> is the algorithm instance name, and <type> is the
00597       // algorithm class type (being a subclass of Algorithm).
00598       const Gaudi::Utils::TypeNameString typeName(*it);
00599       std::string theName = typeName.name();
00600       std::string theType = typeName.type();
00601 
00602       // Parse the name for a syntax of the form:
00603       //
00604       // <name>:invert
00605       //
00606       // Where <name> is the algorithm instance name and ":invert"
00607       // indicates that the filter passed logic is inverted.
00608       bool isInverted = false;
00609       std::string::size_type invert = theName.find_first_of( ":" );
00610       // Skip all occurrences of "::" (allow namespaces)
00611       while ( std::string::npos != invert
00612               && invert < (theName.size() - 1) && theName[invert+1] == ':' )
00613         invert = theName.find_first_of( ":", invert+2 );
00614       if ( std::string::npos != invert ) {
00615         if ( theName == theType ) {
00616           // This means that we got something like "Type:invert",
00617           // so we have to strip the ":invert" from the type too.
00618           theType = theType.substr( 0, invert );
00619         }
00620         theName = theName.substr( 0, invert );
00621         isInverted = true;
00622       }
00623       // Check whether the supplied name corresponds to an existing
00624       // Algorithm object.
00625       SmartIF<IAlgorithm>& theIAlg = theAlgMgr->algorithm(theName, false);
00626       Algorithm*  theAlgorithm = 0;
00627       StatusCode status = StatusCode::SUCCESS;
00628       if ( theIAlg.isValid() ) {
00629         try{
00630           theAlgorithm = dynamic_cast<Algorithm*>(theIAlg.get());
00631         } catch(...){
00632           log << MSG::WARNING << theName << " is not an Algorithm - Failed dynamic cast" << endmsg;
00633           theAlgorithm = 0; // release
00634         }
00635       }
00636       if ( theAlgorithm ) {
00637 
00638         // The specified Algorithm already exists - just append it to the membership list.
00639         status = append( theAlgorithm, theAlgs );
00640         if ( status.isSuccess( ) ) {
00641           ON_DEBUG log << MSG::DEBUG << theName << " already exists - appended to member list" << endmsg;
00642         } else {
00643           log << MSG::WARNING << theName << " already exists - append failed!!!" << endmsg;
00644           result = StatusCode::FAILURE;
00645         }
00646       } else {
00647 
00648         // The specified name doesn't exist - create a new object of the specified type
00649         // and append it to the membership list.
00650         status = createAndAppend( theType, theName, theAlgorithm, theAlgs );
00651         if ( status.isSuccess( ) ) {
00652           ON_DEBUG log << MSG::DEBUG << theName << " doesn't exist - created and appended to member list" << endmsg;
00653         } else {
00654           log << MSG::WARNING << theName << " doesn't exist - creation failed!!!" << endmsg;
00655           result = StatusCode::FAILURE;
00656         }
00657       }
00658       if ( status.isSuccess( ) ) {
00659         theLogic.push_back( isInverted );
00660       }
00661     }
00662 
00663   }
00664   // Print membership list
00665   if ( result.isSuccess() && theAlgs->size() != 0 ) {
00666     log << MSG::INFO << "Member list: ";
00667     std::vector<Algorithm*>::iterator ai = theAlgs->begin();
00668     std::vector<bool>::iterator li = theLogic.begin();
00669     for ( ; ai != theAlgs->end(); ++ai, ++li ) {
00670 
00671       if ( ai != theAlgs->begin() ) log << ", ";
00672 
00673       if ( (*ai)->name() == System::typeinfoName(typeid(**ai)) )
00674         log << (*ai)->name();
00675       else
00676         log << System::typeinfoName(typeid(**ai)) << "/" << (*ai)->name();
00677 
00678       if (*li) log << ":invert";
00679     }
00680     log << endmsg;
00681   }
00682   return result;
00683 }
00684 
00685 StatusCode
00686 Sequencer::execute( std::vector<Algorithm*>* theAlgs,
00687                     std::vector<bool>& theLogic,
00688                     Algorithm*& lastAlgorithm,
00689                     unsigned int first )
00690 {
00691   StatusCode result = StatusCode::SUCCESS;
00692 
00693   // Loop over all algorithms calling their execute functions if they
00694   // are (a) not disabled, and (b) aren't already executed. Note that
00695   // in the latter case the filter state is still examined. Terminate
00696   // the loop if an algorithm indicates that it's filter didn't pass.
00697   unsigned int size = theAlgs->size( );
00698   for (unsigned int i = first; i < size; i++) {
00699     lastAlgorithm = (*theAlgs)[i];
00700     result = executeMember( lastAlgorithm );
00701     if ( result.isSuccess( ) ) {
00702 
00703       // Take the filter passed status of this algorithm as my own status.
00704       // Note that we take into account inverted logic.
00705       bool passed = lastAlgorithm->filterPassed( );
00706       bool isInverted = theLogic[i];
00707       if ( isInverted ) {
00708         passed = ! passed;
00709       }
00710       setFilterPassed( passed );
00711 
00712       // The behaviour when the filter fails depends on the StopOverride property.
00713       // The default action is to stop processing, but this default can be
00714       // overridden by setting the "StopOverride" property to true.
00715       if ( ! isStopOverride( ) ) {
00716         if ( ! passed ) break;
00717       }
00718     } else {
00719       break;
00720     }
00721   }
00722   return result;
00723 }
00724 
00725 StatusCode
00726 Sequencer::executeMember( Algorithm* theAlgorithm )
00727 {
00728   StatusCode result = StatusCode::SUCCESS;
00729   if ( theAlgorithm->isEnabled( ) ) {
00730     if ( ! theAlgorithm->isExecuted( ) ) {
00731       result = theAlgorithm->sysExecute( );
00732 
00733       // Set the executed state of the algorithm.
00734       // I think this should be done by the algorithm itself, but just in case...
00735       theAlgorithm->setExecuted( true );
00736     }
00737   }
00738   return result;
00739 }
00740 
00741 StatusCode
00742 Sequencer::remove( const std::string& algname, std::vector<Algorithm*>* theAlgs )
00743 {
00744   MsgStream log( msgSvc( ), name( ) );
00745   StatusCode result = StatusCode::FAILURE;
00746 
00747   // Test that the algorithm exists in the member list
00748   std::vector<Algorithm*>::iterator it;
00749   std::vector<Algorithm*>::iterator itend = theAlgs->end( );
00750   for (it = theAlgs->begin(); it != itend; it++) {
00751     Algorithm* theAlgorithm = (*it);
00752     if ( theAlgorithm->name( ) == algname ) {
00753 
00754       // Algorithm with specified name exists in the algorithm list - remove it
00755       // THIS ISN'T IMPLEMENTED YET!!!!
00756       log << MSG::INFO <<"Sequencer::remove( ) isn't implemented yet!!!!!" << endmsg;
00757       result = StatusCode::SUCCESS;
00758       break;
00759     }
00760   }
00761   return result;
00762 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:26 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004