00001
00002
00003
00004 #include "HltSteering/StepSequencer.h"
00005
00006 #include "GaudiKernel/MsgStream.h"
00007 #include "GaudiKernel/Property.h"
00008 #include "GaudiKernel/ISvcLocator.h"
00009 #include "HltAlgorithms/IEFAlgorithm.h"
00010
00011 using HltProcessor::Sequence;
00012
00013 inline void findAlgTypeName(const std::string& property,
00014 std::string& SubAlg_type,
00015 std::string& SubAlg_NameParam)
00016 {
00017 int slash_pos = property.find_first_of("/");
00018 SubAlg_type = property.substr( 0, slash_pos );
00019 SubAlg_NameParam = (slash_pos > 0) ? property.substr( slash_pos + 1) : SubAlg_type;
00020 }
00021
00022 inline void findParamSet(const std::string& property,
00023 std::string& SubAlg_name,
00024 std::string& SubAlg_param)
00025 {
00026 int slash_pos = property.find_first_of("/");
00027 SubAlg_name = property.substr( 0, slash_pos );
00028 SubAlg_param = (slash_pos > 0) ? property.substr( slash_pos + 1) : SubAlg_name;
00029 }
00030
00031
00032 StepSequencer::StepSequencer(const std::string& name, ISvcLocator* pSvcLocator):
00033 Algorithm(name, pSvcLocator) {
00034 m_isEnabled = false;
00035 }
00036
00037
00038 StepSequencer::~StepSequencer() {
00039
00040
00041
00042
00043
00044
00045
00046
00047 }
00048
00050 void StepSequencer::reset()
00051 {
00052 MsgStream log( messageService(), name() );
00053 std::map<std::string, std::vector<Algorithm*> >::iterator it = m_AlgMap.begin();
00054 log << MSG::DEBUG << "the size of algorithm map is " << m_AlgMap.size() << endreq;
00055 for ( ; it != m_AlgMap.end(); it++) {
00056 log << MSG::DEBUG << "reset() of " << it->first << endreq;
00057 const std::vector<Algorithm*>& algs = it->second;
00058 int n = algs.size();
00059 for (int i = 0; i < n; i++) {
00060 if (IEFAlgorithm* ialg = dynamic_cast<IEFAlgorithm*>(algs[i])) {
00061
00062 ialg->reset();
00063 }
00064 }
00065 }
00066 }
00067
00068
00069 StatusCode StepSequencer::initSequencer( Sequence* sequence) {
00070 MsgStream log( messageService(), name() );
00071
00072 std::string SubAlg_type, SubAlg_name, SubAlg_param, SubAlg_NameParam,AlgNameFromConfig ;
00073 Algorithm* pAlg;
00074 Algorithm* bAlg;
00075
00076
00077 log<< MSG::DEBUG << "Sequence " << sequence->getSeqID()
00078 <<" has " << sequence->algoNum() << " algorithms " << endreq;
00079
00080 std::vector<Algorithm*> helpAlgVec;
00081 std::vector<std::string>::iterator algI = sequence->algoVector().begin();
00082
00083 for ( ; algI != sequence->algoVector().end(); algI++){
00084 std::string alg_def = *algI;
00085 log << MSG::DEBUG << "algorithm : " << alg_def << endreq;
00086 findAlgTypeName(alg_def,SubAlg_type,SubAlg_NameParam);
00087 findParamSet(SubAlg_NameParam,AlgNameFromConfig,SubAlg_param);
00088 SubAlg_name=AlgNameFromConfig+"_"+SubAlg_param;
00089
00090
00091 bool subAlgExist = doesExistAlready(SubAlg_name);
00092 if(!subAlgExist) {
00093 StatusCode sc = createSubAlgorithm(SubAlg_type, SubAlg_name, pAlg);
00094 if(sc.isFailure() ) {
00095 log << MSG::FATAL << alg_def <<" sub-algorithm create failed!" << endreq;
00096 return sc;
00097 }
00098 log << MSG::DEBUG << "created " << SubAlg_type << "/" << SubAlg_name << endreq;
00099 bAlg = dynamic_cast<Algorithm*>(pAlg);
00100 bAlg->initialize();
00101 bAlg->beginRun();
00102 StringProperty paramSet("ParamSetFile", SubAlg_param);
00103 bAlg->setProperty(paramSet);
00104
00105 helpAlgVec.push_back(bAlg);
00106 } else {
00107 pAlg = existingAlg(SubAlg_name);
00108 bAlg = dynamic_cast<Algorithm*>(pAlg);
00109
00110 StringProperty paramSet("ParamSetFile",SubAlg_param);
00111 bAlg->setProperty(paramSet);
00112 helpAlgVec.push_back(bAlg);
00113 }
00114 }
00115 m_AlgMap[sequence->getSeqID()] = helpAlgVec;
00116
00117 log << MSG::INFO << "Initialization of "<< name() << " completed successfully" << endreq;
00118 return StatusCode::SUCCESS;
00119 }
00120
00122
00123 Algorithm* StepSequencer::existingAlg (std::string subAlgName)
00124 {
00125 MsgStream log( messageService(), name() );
00126 Algorithm* exAlg;
00127 std::vector<Algorithm*>* subAlgms = subAlgorithms();
00128 std::vector<Algorithm*>::iterator it = subAlgms->begin();
00129 for ( ; it != subAlgms->end(); it++) {
00130 if(subAlgName==(*it)->name()) {
00131 log << subAlgName<<" already created, return pointer to it "<< endreq;
00132 return *it;
00133 }
00134 }
00135 return exAlg;
00136 }
00137
00139 bool StepSequencer::doesExistAlready(std::string aName)
00140 {
00141 MsgStream log( messageService(), name() );
00142 bool doesExist=false;
00143 std::vector<Algorithm*>* subAlgms = subAlgorithms();
00144
00145 if(subAlgms->size()==0) {
00146 doesExist=false;
00147 return doesExist;
00148 }
00149 else {
00150 std::vector<Algorithm*>::iterator it = subAlgms->begin();
00151 for ( ; it != subAlgms->end(); it++) {
00152 if(aName==(*it)->name()) {
00153 log << MSG::WARNING << aName <<" sub-algorithm already created" << endreq;
00154 doesExist=true;
00155 break;
00156 }
00157 }
00158 }
00159 return doesExist;
00160 }
00161
00163
00164 bool StepSequencer::execSequencer(const std::string& seqID)
00165 {
00166 MsgStream log( messageService(), name() );
00167 const std::vector<Algorithm*>& algVec = m_AlgMap[seqID];
00168
00169
00170
00171 log << MSG::DEBUG << "=============================" << endreq;
00172
00173 std::vector<Algorithm*>::const_iterator it = algVec.begin();
00174 for(; it != algVec.end(); it++) {
00175 StatusCode sc = (*it)->execute();
00176 if (sc.isFailure()) {
00177 log << MSG::ERROR << (*it)->name() << " execute failed" << endreq;
00178 return false;
00179 }
00180 }
00181
00182 return true;
00183 }
00184
00185 std::vector<Algorithm*> StepSequencer::searchAlgForEachTE_o( Sequence* seq )
00186 {
00187
00188 MsgStream log( messageService(), name() );
00189 std::string SubAlg_type, SubAlg_name, SubAlg_param, SubAlg_NameParam,AlgNameFromConfig;
00190
00191
00192
00193
00194
00195
00196
00197 vMatchAlg.clear();
00198 std::vector<std::string>::iterator It = seq->algoVector().begin();
00199 for ( ; It < seq->algoVector().end(); It++) {
00200 std::string alg_defin = *It;
00201 findAlgTypeName(alg_defin,SubAlg_type,SubAlg_NameParam);
00202 findParamSet(SubAlg_NameParam,AlgNameFromConfig,SubAlg_param);
00203 SubAlg_name=AlgNameFromConfig+"_"+SubAlg_param;
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 }
00214 return vMatchAlg;
00215 }