/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventFilter/HltProcessor/HltConfig/HltConfig-01-01-05/src/HltConfigSvc.cxx

Go to the documentation of this file.
00001 #include "GaudiKernel/Kernel.h"
00002 #include "GaudiKernel/IInterface.h"
00003 #include "GaudiKernel/PropertyMgr.h"
00004 #include "GaudiKernel/StatusCode.h"
00005 //#include "GaudiKernel/ISvcFactory.h"
00006 #include "GaudiKernel/IIncidentSvc.h"
00007 //#include "GaudiKernel/Incident.h"
00008 #include "GaudiKernel/SvcFactory.h"
00009 #include "GaudiKernel/MsgStream.h"
00010 #include "GaudiKernel/SmartDataPtr.h"
00011 
00012 #include "EventModel/EventModel.h"
00013 #include "EventModel/Event.h"
00014 #include "EventModel/EventHeader.h"
00015 
00016 #include "HltConfig/HltConfigSvc.h"
00017 #include "GaudiKernel/IJobOptionsSvc.h"
00018 
00019 #include <iostream>
00020 #include <fstream>
00021 #include <utility>
00022 
00023 //static SvcFactory<HltConfigSvc> s_factory;
00024 //const SvcFactory& HltConfigSvcFactory = s_factory;
00025 using namespace HltProcessor;
00026 
00027 HltConfigSvc::HltConfigSvc( const std::string& name, ISvcLocator* sl ) : 
00028   Service(name, sl),
00029   m_dbsvc(0)
00030 {   
00031   m_propMgr.declareProperty( "FromDB", m_fromDatabase = true);
00032   m_propMgr.declareProperty( "seqListFile", m_seqListFile = "myseqlist.xml");
00033   m_propMgr.declareProperty( "sigListFile", m_sigListFile = "mysiglist.xml");  
00034     
00035   IJobOptionsSvc* jobSvc;
00036   Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
00037   jobSvc->setMyProperties("HltConfigSvc", &m_propMgr);
00038   jobSvc->release();
00039 }
00040 
00041 
00042 HltConfigSvc::~HltConfigSvc() {
00043   
00044 }
00045 
00046 StatusCode HltConfigSvc::queryInterface (const InterfaceID& riid, void** ppvIF ) 
00047 {
00048   if ( IID_IHltConfigSvc.versionMatch(riid) ) { 
00049 //    *ppvIF = static_cast<IHltConfigSvc*> (this); 
00050     *ppvIF = (HltConfigSvc*)this; 
00051   } else { 
00052     return Service::queryInterface(riid, ppvIF) ; 
00053   }
00054   return StatusCode::SUCCESS;
00055 }
00056 
00057 
00058 void HltConfigSvc::handle(const Incident& inc){
00059   MsgStream log( messageService(), name() );
00060   log << MSG::INFO << "handle: " << inc.type() << endreq;
00061 
00062   if ( inc.type() == "NewRun" ){
00063     if(m_fromDatabase){
00064       log << MSG::DEBUG << "start read from database" << endreq;
00065       StatusCode sc = GenFileFromDatabase();
00066       if (sc .isFailure() ) {
00067         log << MSG::ERROR << "Unable to read config from DatabaseSvc " << endreq;
00068         return;
00069       }
00070       //if(MyFrame::instance()) MyFrame::destruct();
00071       log << MSG::INFO << "sequenceListFileLocation= " << m_seqListFile << endreq;
00072       log << MSG::INFO << "signatureListFileLocation= " << m_sigListFile << endreq;
00073       MyFrame::instance()->init(m_seqListFile, m_sigListFile);
00074       MyFrame::instance()->final();
00075     }
00076   }
00077 }
00078 
00079 StatusCode HltConfigSvc::initialize ( ) 
00080 {
00081 
00082   MsgStream log(messageService(), name());
00083   log << MSG::INFO << name() << ": Start of initialisation" << endreq;
00084 
00085   IIncidentSvc* incsvc;
00086   StatusCode sc = service("IncidentSvc", incsvc);
00087   int priority = 100;
00088   if( sc.isSuccess() ){
00089     incsvc -> addListener(this, "NewRun", priority);
00090   }
00091   else{
00092     log << MSG::FATAL << "Cannot find IncidentSvc" << endreq;
00093     return sc;
00094   }
00095 
00096   if(m_fromDatabase){
00097     sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
00098     if (sc .isFailure() ) {
00099       log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
00100       return sc;
00101     }
00102   }
00103 
00104   sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
00105   if (sc .isFailure() ) {
00106     log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
00107     return sc;
00108   }
00109 
00110   if (MyFrame::instance() == 0)
00111     log << MSG::INFO << "MyFrame::instance() == 0" << endreq;
00112   if(!m_fromDatabase){
00113     log << MSG::ALWAYS << "Read config from files" << endreq;
00114     MyFrame::instance()->init(m_seqListFile, m_sigListFile);
00115     // Finalize Frame. New version with singleton
00116     MyFrame::instance()->final();
00117   }
00118   return StatusCode::SUCCESS;
00119 }
00120 
00121 
00122 const std::vector<std::pair<Signature*,Sequence*> >& HltConfigSvc::retrieve()
00123 {
00124 // Get the final vector object and play around with it.     
00125 //std::vector<std::pair<Signature*,Sequence*> > m_Vector = MyFrame::instance()->getTablesVector();
00126   return MyFrame::instance()->getTablesVector();
00127 }
00128 
00129 StatusCode HltConfigSvc::finalize ( ) 
00130 {
00131   MsgStream log(messageService(), name());
00132   //MyFrame::destruct();
00133   log << MSG::INFO << name() << " finalized successfully" << endreq;
00134   return StatusCode::SUCCESS;
00135 }
00136 
00137 StatusCode HltConfigSvc::GenFileFromDatabase(){
00138   MsgStream log(messageService(), name());
00139   if(!m_dbsvc){
00140     log << MSG::FATAL << " m_dbsvc=0" << endreq;
00141     return StatusCode::FAILURE;
00142   } 
00143   
00144   SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
00145   int  run = eventHeader->runNumber();
00146   
00147   log << MSG::INFO << "run=" << run << endreq;
00148 
00149   char stmt1[200];
00150   sprintf(stmt1,"select efconfig_id from RunParams where run_number = %d",abs(run));
00151  
00152   DatabaseRecordVector res;
00153   int row_no = m_dbsvc->query("RunInfo",stmt1,res);
00154   if(!row_no){
00155     log << MSG::ERROR<<"search errror"<<endreq;
00156     return StatusCode::FAILURE;
00157   }
00158   long int efId=atoi((*res[0])["efconfig_id"]);
00159 
00160   char stmt2[200];
00161   sprintf(stmt2,"select Seqlist_dtd,Siglist_dtd,Seqlist_xml,Siglist_xml from EFConfInfo where EFConfId = %ld", efId);
00162 
00163   res.clear();
00164   row_no = m_dbsvc->query("configdb",stmt2,res);
00165   if(!row_no){
00166     log << MSG::ERROR<<"search errror"<<endreq;
00167     return StatusCode::FAILURE;
00168   }
00169   
00170   long int seq_dtd,sig_dtd,seq_xml,sig_xml;
00171   seq_dtd=atoi((*res[0])["Seqlist_dtd"]);
00172   seq_dtd=18;
00173   sig_dtd=atoi((*res[0])["Siglist_dtd"]);
00174   sig_dtd=15;
00175   seq_xml=atoi((*res[0])["Seqlist_xml"]);
00176   sig_xml=atoi((*res[0])["Siglist_xml"]);
00177 
00178   ofstream outfile;
00179 
00180   char stmt3[200];
00181   sprintf(stmt3,"select FileName,FileText from EFfile where EFfileId = %ld", seq_dtd);
00182   res.clear();
00183   row_no = m_dbsvc->query("configdb",stmt3,res);
00184   if(!row_no){
00185     log << MSG::ERROR<<"search errror"<<endreq;
00186     return StatusCode::FAILURE;
00187   }
00188   outfile.open((*res[0])["FileName"],ios_base::out);
00189   outfile << (*res[0])["FileText"];
00190   outfile.close();
00191 
00192   char stmt4[200];
00193   sprintf(stmt4,"select FileName,FileText from EFfile where EFfileId = %ld", sig_dtd);
00194   res.clear();
00195   row_no = m_dbsvc->query("configdb",stmt4,res);
00196   if(!row_no){
00197     log << MSG::ERROR<<"search errror"<<endreq;
00198     return StatusCode::FAILURE;
00199   }
00200   outfile.open((*res[0])["FileName"],ios_base::out);
00201   outfile << (*res[0])["FileText"];
00202   outfile.close();
00203 
00204   char stmt5[200];
00205   sprintf(stmt5,"select FileName,FileText from EFfile where EFfileId = %ld", seq_xml);
00206   res.clear();
00207   row_no = m_dbsvc->query("configdb",stmt5,res);
00208   if(!row_no){
00209     log << MSG::ERROR<<"search errror"<<endreq;
00210     return StatusCode::FAILURE;
00211   }
00212   outfile.open((*res[0])["FileName"],ios_base::out);
00213   outfile << (*res[0])["FileText"];
00214   outfile.close();
00215   m_seqListFile = string((*res[0])["FileName"]);
00216   
00217   char stmt6[200];
00218   sprintf(stmt6,"select FileName,FileText from EFfile where EFfileId = %ld", sig_xml);
00219   res.clear();
00220   row_no = m_dbsvc->query("configdb",stmt6,res);
00221   if(!row_no){
00222     log << MSG::ERROR<<"search errror"<<endreq;
00223     return StatusCode::FAILURE;
00224   }
00225   outfile.open((*res[0])["FileName"],ios_base::out);
00226   outfile << (*res[0])["FileText"];
00227   outfile.close();
00228   m_sigListFile = string((*res[0])["FileName"]);
00229 
00230   return StatusCode::SUCCESS;  
00231 }

Generated on Tue Nov 29 23:12:05 2016 for BOSS_7.0.2 by  doxygen 1.4.7