BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
DetVerSvc.cxx
Go to the documentation of this file.
1#include "DetVerSvc/DetVerSvc.h"
2#include "GaudiKernel/SmartIF.h"
3#include "GaudiKernel/IJobOptionsSvc.h"
4#include "GaudiKernel/MsgStream.h"
5#include <fstream>
6#include <dlfcn.h>
7
8namespace DetVerSvcPack {
9 int (*pf_helper)(ISvcLocator*);
10}
11
12DetVerSvc::DetVerSvc(const std::string& name, ISvcLocator* svcloc)
13 : Service(name, svcloc),
14 m_phase(-1)
15{
16 declareProperty("Config", m_conf);
17}
18
20{
21}
22
23StatusCode DetVerSvc::queryInterface(const InterfaceID& riid, void** ppvInterface)
24{
25 if ( IID_IDetVerSvc.versionMatch(riid) ) {
26 *ppvInterface = static_cast<IDetVerSvc*> (this);
27 } else {
28 return Service::queryInterface(riid, ppvInterface) ;
29 }
30 return StatusCode::SUCCESS;
31}
32
34{
35 Service::initialize();
36
37 MsgStream log(messageService(), name());
38 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
39
40 //assert m_conf is a valid file
41 if ( access( m_conf.c_str(), F_OK ) < 0 ) {
42 log << MSG::FATAL << "Cann't find config file: " << m_conf << endreq;
43 return StatusCode::FAILURE;
44 }
45
46 return StatusCode::SUCCESS;
47}
48
49StatusCode DetVerSvc::finalize ( ) {
50 MsgStream log(messageService(), name());
51 log << MSG::INFO << name() << ": End of Run finalize" << endreq;
52
53 return StatusCode::SUCCESS;
54}
55
57{
58 if ( m_phase < 0) { //phase has not been retrieved
59 SmartIF<IJobOptionsSvc> iSvc(serviceLocator()->service("JobOptionsSvc"));
60 if ( iSvc.isValid() ) {
61 std::string dll; //sub so name
62 const std::vector<const Property*>* ps = 0;
63 if ( (ps = iSvc->getProperties("RawDataInputSvc")) != 0 ) {
64 dll = "libDetVerSvc_IRaw.so"; //case 0: Input RAW
65 }
66 else if ( (ps = iSvc->getProperties("EventCnvSvc")) != 0 ) {
67 dll = "libDetVerSvc_IRoot.so"; //case 1: Input root
68 }
69 else if ( (ps = iSvc->getProperties("RealizationSvc")) != 0 ) {
70 dll = "libDetVerSvc_Sim.so"; //case 2: simulation
71 }
72 //else // //Unknown job type !!!!!
73
74 void *dl_handler = dlopen(dll.c_str(), RTLD_LAZY|RTLD_GLOBAL);
75 if ( dl_handler != 0 ) {
76 m_phase = fromRun( (*DetVerSvcPack::pf_helper)(serviceLocator()) );
77 }
78 dlclose(dl_handler);
79 }
80 }
81 return m_phase;
82}
83
84int DetVerSvc::fromRun(unsigned int run)
85{
86 std::vector<int> runList;
87 //parse m_conf
88 int iTmp;
89 std::ifstream fs(m_conf.c_str());
90 fs >> iTmp;
91 while ( ! fs.eof() ) {
92 runList.push_back(iTmp);
93 fs >> iTmp;
94 }
95
96 //return phase from run
97 int iPhase = 1;
98 for ( std::vector<int>::iterator it = runList.begin(); it != runList.end(); ++it ) {
99 if ( run < (*it) ) {
100 break;
101 }
102 ++iPhase;
103 }
104 return iPhase;
105}
virtual ~DetVerSvc()
Definition: DetVerSvc.cxx:19
virtual StatusCode finalize()
Definition: DetVerSvc.cxx:49
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
Definition: DetVerSvc.cxx:23
int phase()
Definition: DetVerSvc.cxx:56
DetVerSvc(const std::string &name, ISvcLocator *svcloc)
Definition: DetVerSvc.cxx:12
virtual StatusCode initialize()
Definition: DetVerSvc.cxx:33
int(* pf_helper)(ISvcLocator *)
Definition: DetVerSvc.cxx:9