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