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