CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
HltConfigSvc.cxx
Go to the documentation of this file.
1#include "GaudiKernel/Kernel.h"
2#include "GaudiKernel/IInterface.h"
3#include "GaudiKernel/PropertyMgr.h"
4#include "GaudiKernel/StatusCode.h"
5//#include "GaudiKernel/ISvcFactory.h"
6#include "GaudiKernel/IIncidentSvc.h"
7//#include "GaudiKernel/Incident.h"
8#include "GaudiKernel/SvcFactory.h"
9#include "GaudiKernel/MsgStream.h"
10#include "GaudiKernel/SmartDataPtr.h"
11
13#include "EventModel/Event.h"
15
17#include "GaudiKernel/IJobOptionsSvc.h"
18
19#include <iostream>
20#include <fstream>
21#include <utility>
22
23//static SvcFactory<HltConfigSvc> s_factory;
24//const SvcFactory& HltConfigSvcFactory = s_factory;
25using namespace HltProcessor;
26
27HltConfigSvc::HltConfigSvc( const std::string& name, ISvcLocator* sl ) :
28 Service(name, sl),
29 m_dbsvc(0)
30{
31 m_propMgr.declareProperty( "FromDB", m_fromDatabase = true);
32 m_propMgr.declareProperty( "seqListFile", m_seqListFile = "myseqlist.xml");
33 m_propMgr.declareProperty( "sigListFile", m_sigListFile = "mysiglist.xml");
34
35 IJobOptionsSvc* jobSvc;
36 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
37 jobSvc->setMyProperties("HltConfigSvc", &m_propMgr);
38 jobSvc->release();
39}
40
41
45
46StatusCode HltConfigSvc::queryInterface (const InterfaceID& riid, void** ppvIF )
47{
48 if ( IID_IHltConfigSvc.versionMatch(riid) ) {
49// *ppvIF = static_cast<IHltConfigSvc*> (this);
50 *ppvIF = (HltConfigSvc*)this;
51 } else {
52 return Service::queryInterface(riid, ppvIF) ;
53 }
54 return StatusCode::SUCCESS;
55}
56
57
58void HltConfigSvc::handle(const Incident& inc){
59 MsgStream log( messageService(), name() );
60 log << MSG::INFO << "handle: " << inc.type() << endreq;
61
62 if ( inc.type() == "NewRun" ){
63 if(m_fromDatabase){
64 log << MSG::DEBUG << "start read from database" << endreq;
65 StatusCode sc = GenFileFromDatabase();
66 if (sc .isFailure() ) {
67 log << MSG::ERROR << "Unable to read config from DatabaseSvc " << endreq;
68 return;
69 }
70 //if(MyFrame::instance()) MyFrame::destruct();
71 log << MSG::INFO << "sequenceListFileLocation= " << m_seqListFile << endreq;
72 log << MSG::INFO << "signatureListFileLocation= " << m_sigListFile << endreq;
73 MyFrame::instance()->init(m_seqListFile, m_sigListFile);
75 }
76 }
77}
78
80{
81
82 MsgStream log(messageService(), name());
83 log << MSG::INFO << name() << ": Start of initialisation" << endreq;
84
85 IIncidentSvc* incsvc;
86 StatusCode sc = service("IncidentSvc", incsvc);
87 int priority = 100;
88 if( sc.isSuccess() ){
89 incsvc -> addListener(this, "NewRun", priority);
90 }
91 else{
92 log << MSG::FATAL << "Cannot find IncidentSvc" << endreq;
93 return sc;
94 }
95
96 if(m_fromDatabase){
97 sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
98 if (sc .isFailure() ) {
99 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
100 return sc;
101 }
102 }
103
104 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
105 if (sc .isFailure() ) {
106 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
107 return sc;
108 }
109
110 if (MyFrame::instance() == 0)
111 log << MSG::INFO << "MyFrame::instance() == 0" << endreq;
112 if(!m_fromDatabase){
113 log << MSG::ALWAYS << "Read config from files" << endreq;
114 MyFrame::instance()->init(m_seqListFile, m_sigListFile);
115 // Finalize Frame. New version with singleton
117 }
118 return StatusCode::SUCCESS;
119}
120
121
122const std::vector<std::pair<Signature*,Sequence*> >& HltConfigSvc::retrieve()
123{
124// Get the final vector object and play around with it.
125//std::vector<std::pair<Signature*,Sequence*> > m_Vector = MyFrame::instance()->getTablesVector();
127}
128
130{
131 MsgStream log(messageService(), name());
132 //MyFrame::destruct();
133 log << MSG::INFO << name() << " finalized successfully" << endreq;
134 return StatusCode::SUCCESS;
135}
136
138 MsgStream log(messageService(), name());
139 if(!m_dbsvc){
140 log << MSG::FATAL << " m_dbsvc=0" << endreq;
141 return StatusCode::FAILURE;
142 }
143
144 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
145 int run = eventHeader->runNumber();
146
147 log << MSG::INFO << "run=" << run << endreq;
148
149 char stmt1[200];
150 sprintf(stmt1,"select efconfig_id from RunParams where run_number = %d",abs(run));
151
153 int row_no = m_dbsvc->query("RunInfo",stmt1,res);
154 if(!row_no){
155 log << MSG::ERROR<<"search errror"<<endreq;
156 return StatusCode::FAILURE;
157 }
158 long int efId=atoi((*res[0])["efconfig_id"]);
159
160 char stmt2[200];
161 sprintf(stmt2,"select Seqlist_dtd,Siglist_dtd,Seqlist_xml,Siglist_xml from EFConfInfo where EFConfId = %ld", efId);
162
163 res.clear();
164 row_no = m_dbsvc->query("configdb",stmt2,res);
165 if(!row_no){
166 log << MSG::ERROR<<"search errror"<<endreq;
167 return StatusCode::FAILURE;
168 }
169
170 long int seq_dtd,sig_dtd,seq_xml,sig_xml;
171 seq_dtd=atoi((*res[0])["Seqlist_dtd"]);
172 seq_dtd=18;
173 sig_dtd=atoi((*res[0])["Siglist_dtd"]);
174 sig_dtd=15;
175 seq_xml=atoi((*res[0])["Seqlist_xml"]);
176 sig_xml=atoi((*res[0])["Siglist_xml"]);
177
178 ofstream outfile;
179
180 char stmt3[200];
181 sprintf(stmt3,"select FileName,FileText from EFfile where EFfileId = %ld", seq_dtd);
182 res.clear();
183 row_no = m_dbsvc->query("configdb",stmt3,res);
184 if(!row_no){
185 log << MSG::ERROR<<"search errror"<<endreq;
186 return StatusCode::FAILURE;
187 }
188 outfile.open((*res[0])["FileName"],ios_base::out);
189 outfile << (*res[0])["FileText"];
190 outfile.close();
191
192 char stmt4[200];
193 sprintf(stmt4,"select FileName,FileText from EFfile where EFfileId = %ld", sig_dtd);
194 res.clear();
195 row_no = m_dbsvc->query("configdb",stmt4,res);
196 if(!row_no){
197 log << MSG::ERROR<<"search errror"<<endreq;
198 return StatusCode::FAILURE;
199 }
200 outfile.open((*res[0])["FileName"],ios_base::out);
201 outfile << (*res[0])["FileText"];
202 outfile.close();
203
204 char stmt5[200];
205 sprintf(stmt5,"select FileName,FileText from EFfile where EFfileId = %ld", seq_xml);
206 res.clear();
207 row_no = m_dbsvc->query("configdb",stmt5,res);
208 if(!row_no){
209 log << MSG::ERROR<<"search errror"<<endreq;
210 return StatusCode::FAILURE;
211 }
212 outfile.open((*res[0])["FileName"],ios_base::out);
213 outfile << (*res[0])["FileText"];
214 outfile.close();
215 m_seqListFile = string((*res[0])["FileName"]);
216
217 char stmt6[200];
218 sprintf(stmt6,"select FileName,FileText from EFfile where EFfileId = %ld", sig_xml);
219 res.clear();
220 row_no = m_dbsvc->query("configdb",stmt6,res);
221 if(!row_no){
222 log << MSG::ERROR<<"search errror"<<endreq;
223 return StatusCode::FAILURE;
224 }
225 outfile.open((*res[0])["FileName"],ios_base::out);
226 outfile << (*res[0])["FileText"];
227 outfile.close();
228 m_sigListFile = string((*res[0])["FileName"]);
229
230 return StatusCode::SUCCESS;
231}
double abs(const EvtComplex &c)
const std::vector< std::pair< Signature *, Sequence * > > & retrieve()
virtual StatusCode finalize()
StatusCode GenFileFromDatabase()
virtual void handle(const Incident &)
HltConfigSvc(const std::string &name, ISvcLocator *sl)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIF)
virtual StatusCode initialize()
static MyFrame * instance()
Definition MyFrame.cxx:22
const std::vector< std::pair< Signature *, Sequence * > > & getTablesVector() const
Definition MyFrame.cxx:390
void init(const std::string, const std::string)
Definition MyFrame.cxx:58
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0