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