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