BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
StepSequencer.cxx
Go to the documentation of this file.
1/********************************************************************
2NAME: StepSequencer.cxx
3********************************************************************/
5// INCLUDE GAUDI HEADER FILES:
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/Property.h"
8#include "GaudiKernel/ISvcLocator.h"
10
12
13inline void findAlgTypeName(const std::string& property,
14 std::string& SubAlg_type,
15 std::string& SubAlg_NameParam)
16{
17 int slash_pos = property.find_first_of("/");
18 SubAlg_type = property.substr( 0, slash_pos );
19 SubAlg_NameParam = (slash_pos > 0) ? property.substr( slash_pos + 1) : SubAlg_type;
20}
21
22inline void findParamSet(const std::string& property,
23 std::string& SubAlg_name,
24 std::string& SubAlg_param)
25{
26 int slash_pos = property.find_first_of("/");
27 SubAlg_name = property.substr( 0, slash_pos );
28 SubAlg_param = (slash_pos > 0) ? property.substr( slash_pos + 1) : SubAlg_name;
29}
30
31// CONSTRUCTOR:
32StepSequencer::StepSequencer(const std::string& name, ISvcLocator* pSvcLocator):
33 Algorithm(name, pSvcLocator) {
34 m_isEnabled = false;
35}
36
37// DESTRUCTOR:
39 /*
40 std::vector<Algorithm*>* subAlgms = subAlgorithms();
41 std::vector<Algorithm *>::iterator it;
42 for (it = subAlgms->begin(); it != subAlgms->end(); it++) {
43 std::cout << *it << (*it)->name() << std::endl;
44 (*it)->release();
45 }
46 */
47}
48
49/////////////////////////////////////////////////////////////////
51{
52 MsgStream log( messageService(), name() );
53 std::map<std::string, std::vector<Algorithm*> >::iterator it = m_AlgMap.begin();
54 log << MSG::DEBUG << "the size of algorithm map is " << m_AlgMap.size() << endreq;
55 for ( ; it != m_AlgMap.end(); it++) {
56 log << MSG::DEBUG << "reset() of " << it->first << endreq;
57 const std::vector<Algorithm*>& algs = it->second;
58 int n = algs.size();
59 for (int i = 0; i < n; i++) {
60 if (IEFAlgorithm* ialg = dynamic_cast<IEFAlgorithm*>(algs[i])) {
61 //std::cout << " @reset(): " << algs[i]->name() << " p: " << ialg << std::endl;
62 ialg->reset();
63 }
64 }
65 }
66}
67
68// INITIALIZE METHOD:
69StatusCode StepSequencer::initSequencer( Sequence* sequence) {
70 MsgStream log( messageService(), name() );
71
72 std::string SubAlg_type, SubAlg_name, SubAlg_param, SubAlg_NameParam,AlgNameFromConfig ;
73 Algorithm* pAlg;
74 Algorithm* bAlg;
75
76 //read in algorithms in sequence and initialize them
77 log<< MSG::DEBUG << "Sequence " << sequence->getSeqID()
78 <<" has " << sequence->algoNum() << " algorithms " << endreq;
79
80 std::vector<Algorithm*> helpAlgVec;
81 std::vector<std::string>::iterator algI = sequence->algoVector().begin();
82
83 for ( ; algI != sequence->algoVector().end(); algI++){
84 std::string alg_def = *algI;
85 log << MSG::DEBUG << "algorithm : " << alg_def << endreq;
86 findAlgTypeName(alg_def,SubAlg_type,SubAlg_NameParam);
87 findParamSet(SubAlg_NameParam,AlgNameFromConfig,SubAlg_param);
88 SubAlg_name=AlgNameFromConfig+"_"+SubAlg_param;
89
90 //check if the name exists, don't create again the subalgorithm, just added to the AlgoTePairs vector
91 bool subAlgExist = doesExistAlready(SubAlg_name);
92 if(!subAlgExist) {
93 StatusCode sc = createSubAlgorithm(SubAlg_type, SubAlg_name, pAlg);
94 if(sc.isFailure() ) {
95 log << MSG::FATAL << alg_def <<" sub-algorithm create failed!" << endreq;
96 return sc;
97 }
98 log << MSG::DEBUG << "created " << SubAlg_type << "/" << SubAlg_name << endreq;
99 bAlg = dynamic_cast<Algorithm*>(pAlg);
100 bAlg->initialize();
101 bAlg->beginRun();
102 StringProperty paramSet("ParamSetFile", SubAlg_param);
103 bAlg->setProperty(paramSet);
104
105 helpAlgVec.push_back(bAlg);
106 } else {
107 pAlg = existingAlg(SubAlg_name);
108 bAlg = dynamic_cast<Algorithm*>(pAlg);
109 //bAlg->set_isReRunable();
110 StringProperty paramSet("ParamSetFile",SubAlg_param);
111 bAlg->setProperty(paramSet);
112 helpAlgVec.push_back(bAlg);
113 }
114 }
115 m_AlgMap[sequence->getSeqID()] = helpAlgVec;
116
117 log << MSG::INFO << "Initialization of "<< name() << " completed successfully" << endreq;
118 return StatusCode::SUCCESS;
119}
120
121/////////////////////////////////////////////////////////////////
122
123Algorithm* StepSequencer::existingAlg (std::string subAlgName)
124{
125 MsgStream log( messageService(), name() );
126 Algorithm* exAlg;
127 std::vector<Algorithm*>* subAlgms = subAlgorithms();
128 std::vector<Algorithm*>::iterator it = subAlgms->begin();
129 for ( ; it != subAlgms->end(); it++) {
130 if(subAlgName==(*it)->name()) {
131 log << subAlgName<<" already created, return pointer to it "<< endreq;
132 return *it;
133 }
134 }
135 return exAlg;
136}
137
138/////////////////////////////////////////////////////////////////
139bool StepSequencer::doesExistAlready(std::string aName)
140{
141 MsgStream log( messageService(), name() );
142 bool doesExist=false;
143 std::vector<Algorithm*>* subAlgms = subAlgorithms();
144
145 if(subAlgms->size()==0) {
146 doesExist=false;
147 return doesExist;
148 }
149 else {
150 std::vector<Algorithm*>::iterator it = subAlgms->begin();
151 for ( ; it != subAlgms->end(); it++) {
152 if(aName==(*it)->name()) {
153 log << MSG::WARNING << aName <<" sub-algorithm already created" << endreq;
154 doesExist=true;
155 break;
156 }
157 }
158 }
159 return doesExist;
160}
161
162////////////////////////////////////////////////////////////
163// MY EXECUTE METHOD:
164bool StepSequencer::execSequencer(const std::string& seqID)
165{
166 MsgStream log( messageService(), name() );
167 const std::vector<Algorithm*>& algVec = m_AlgMap[seqID];
168 /*log << MSG::DEBUG << " Execute Sequencer on a step with "
169 << algVec.size() << " algorithms." << endreq;*/
170
171 log << MSG::DEBUG << "=============================" << endreq;
172
173 std::vector<Algorithm*>::const_iterator it = algVec.begin();
174 for(; it != algVec.end(); it++) {
175 StatusCode sc = (*it)->execute();
176 if (sc.isFailure()) {
177 log << MSG::ERROR << (*it)->name() << " execute failed" << endreq;
178 return false;
179 }
180 }
181
182 return true;
183}
184
185std::vector<Algorithm*> StepSequencer::searchAlgForEachTE_o( Sequence* seq )
186{
187
188 MsgStream log( messageService(), name() );
189 std::string SubAlg_type, SubAlg_name, SubAlg_param, SubAlg_NameParam,AlgNameFromConfig;
190
191 /* std::string n=name();
192 std::string::size_type p_end, p_begin;
193 p_end=n.size();
194 p_begin=p_end-3;
195 std::string instance=n.substr( p_begin, p_end);*/
196
197 vMatchAlg.clear();
198 std::vector<std::string>::iterator It = seq->algoVector().begin();
199 for ( ; It < seq->algoVector().end(); It++) {
200 std::string alg_defin = *It;
201 findAlgTypeName(alg_defin,SubAlg_type,SubAlg_NameParam);
202 findParamSet(SubAlg_NameParam,AlgNameFromConfig,SubAlg_param);
203 SubAlg_name=AlgNameFromConfig+"_"+SubAlg_param;
204
205 /*std::vector<std::pair<Algorithm*,HltElement* > >::iterator I;
206 for(I=AlgoTEPairs.begin();I!=AlgoTEPairs.end();++I) {
207
208 if( SubAlg_name==(I->first)->name() && (I->second)->label()==seq->outputLabel() ) {
209 matchAlg=I->first;
210 vMatchAlg.push_back(matchAlg);
211 }
212 }*/
213 }
214 return vMatchAlg;
215}
const Int_t n
void findParamSet(const std::string &property, std::string &SubAlg_name, std::string &SubAlg_param)
void findAlgTypeName(const std::string &property, std::string &SubAlg_type, std::string &SubAlg_NameParam)
int algoNum() const
Retrieve number of algorithms.
Definition Sequence.cxx:18
const std::string & getSeqID() const
Definition Sequence.h:25
std::vector< std::string > & algoVector()
Retrieve algorithm vector reference.
Definition Sequence.cxx:13
StepSequencer(const std::string &name, ISvcLocator *pSvcLocator)
Algorithm * existingAlg(std::string)
bool doesExistAlready(std::string)
StatusCode initSequencer(HltProcessor::Sequence *)
std::vector< Algorithm * > searchAlgForEachTE_o(HltProcessor::Sequence *)
bool execSequencer(const std::string &seqID)