BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
JobOptionsMgr.cxx
Go to the documentation of this file.
2
3#include "GaudiKernel/IMessageSvc.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/Bootstrap.h"
6#include "GaudiKernel/Service.h"
7#include "GaudiKernel/StatusCode.h"
8#include "GaudiKernel/Property.h"
9#include "ParserUtils.h" //in "GaudiSvc/JobOptionsSvc"
10#include "JobOptionsSvc.h" //in "GaudiSvc/JobOptionsSvc"
11#include <fstream>
12
13#define CheckSTATUS(msg) \
14 if ( sc.isFailure() ) { \
15 std::cout << "[JobOptionsMgr] " << msg << std::endl; \
16 exit(1); \
17 }
18
19#define MyPARSE(var) \
20{ \
21 sc = Gaudi::Parsers::parse(var, pprop->toString()); \
22 if ( sc.isFailure() ) { \
23 std::cout << "[JobOptionsMgr] Failed to parse " << #var << std::endl; \
24 exit(1); \
25 } \
26}
27
28
29JobOptionsMgr::JobOptionsMgr(const std::string& optname)
30 : m_optName(optname),
31 m_iFileType(-1),
32 m_evtMax(10),
33 m_dstFile("digi.root"),
34 m_recFile("digi.root")
35{
36 IService* svc;
37 StatusCode sc = Gaudi::svcLocator()->service("JobOptionsSvc", svc);
38 CheckSTATUS("Failed to retrieve the JobOptionsSvc");
39 m_svc = dynamic_cast<JobOptionsSvc*>(svc);
40
41 sc = m_svc->setProperty( StringProperty("TYPE", "FILE") );
42 sc = m_svc->setProperty( StringProperty("PATH", optname) );
43 CheckSTATUS("Failed to set the property of DistBossServer");
44
45 sc = m_svc->initialize();
46 CheckSTATUS("Failed to initialize JobOptionsSvc");
47
48 const Property* pprop = getProperty("ApplicationMgr", "EvtMax");
49 if ( pprop != NULL ) {
50 MyPARSE( m_evtMax );
51 }
52
53 if ( (pprop = getProperty("RawDataInputSvc", "InputFiles")) != NULL ) {
54 m_iFileType = 0;
55 MyPARSE( m_inputFiles );
56 }
57 else if ( (pprop = getProperty("BesSim", "TDSFlag")) != NULL ) {
58 m_iFileType = 1;
59 // to be continued ...
60 }
61 else if ( (pprop = getProperty("EventCnvSvc", "digiRootInputFile")) != NULL ) {
62 m_iFileType = 2;
63 MyPARSE( m_inputFiles );
64 }
65 else {
66 std::cout << "[JobOptionsMgr] Unknown Job Type!" << std::endl;
67 exit(1);
68 }
69
70 if ( (pprop = getProperty("EventPreSelect","WriteDst")) != NULL ) {
71 bool status;
72 MyPARSE(status);
73 if ( status ) {
74 m_oFileTypes.push_back(3);
75 if ( (pprop = getProperty("WriteDst", "digiRootOutputFile")) != NULL ) {
76 MyPARSE( m_dstFile );
77 }
78 }
79 }
80
81 if ( (pprop = getProperty("EventPreSelect","WriteRec")) != NULL ) {
82 bool status;
83 MyPARSE(status);
84 if ( status ) {
85 m_oFileTypes.push_back(4);
86 if ( (pprop = getProperty("WriteRec", "digiRootOutputFile")) != NULL ) {
87 MyPARSE( m_recFile );
88 }
89 }
90 }
91
92 if ( (pprop = getProperty("NTupleSvc", "Output")) != NULL ) {
93 m_oFileTypes.push_back(5);
94 MyPARSE( m_tupleOpts );
95 }
96
97 if ( (pprop = getProperty("THistSvc", "Output")) != NULL ) {
98 m_oFileTypes.push_back(6);
99 MyPARSE( m_histOpts);
100 }
101}
102
104{
105 StatusCode sc = m_svc->finalize();
106 CheckSTATUS("Failed to finalize JobOptionsSvc!");
107}
108
109#define ignorePROPERTY(client, pname) \
110 if ( clients[i] == client && property->name() == pname ) continue
111
112void JobOptionsMgr::clientOptsTemplate(const std::string& svrName)
113{
114 Gaudi::Parsers::Catalogue* m_clientCatalogue = new Gaudi::Parsers::Catalogue;
115
116 StatusCode sc;
117
118 std::vector<std::string> clients = m_svc->getClients();
119 for ( unsigned int i = 0; i < clients.size(); ++i ) {
120 const std::vector<const Property*>* properties = m_svc->getProperties(clients[i]);
121 for ( unsigned int j = 0; j < properties->size(); ++j ) {
122 const Property* property = properties->at(j);
123
124 ignorePROPERTY("ApplicationMgr", "EvtMax");
125
126 ignorePROPERTY("RawDataInputSvc", "InputFiles");
127 //ignorePROPERTY("BesRndmGenSvc", "RndmSeed"); //placeholder for simulation
128 ignorePROPERTY("EventCnvSvc", "digiRootInputFile");
129
130 ignorePROPERTY("WriteDst", "digiRootOutputFile");
131 ignorePROPERTY("WriteRec", "digiRootOutputFile");
132 //ignorePROPERTY("NTupleSvc", "Output"); //placeholder for NTupleSvc
133 //ignorePROPERTY("THistSvc", "Output"); //placeholder for THistSvc
134
135 sc = m_clientCatalogue->addProperty(clients[i], property->name(), property->toString());
136 if ( sc.isFailure() ) {
137 m_clientCatalogue->addProperty(clients[i], property->name(), '"'+property->toString()+'"');
138 }
139 }
140 }
141
142 m_clientCatalogue->addProperty("DistBoss", "ServerName", '"'+svrName+'"');
143 if ( m_iFileType == 0 ) {
144 m_clientCatalogue->addProperty("RawDataInputSvc", "RunMode", "3");
145 }
146 //else if ( m_iFileType == 1 ) { //placeholder for simulation
147 // m_clientCatalogue->addProperty("BesRndmGenSvc", "RunMode", "3");
148 //}
149 //else if ( m_iFileType == 2 ) {
150 // m_clientCatalogue->addProperty("EventCnvSvc", "RunMode", "3");
151 //}
152 for ( unsigned int i = 0; i < m_oFileTypes.size(); ++i ) {
153 int type = m_oFileTypes[i];
154 if ( type == 3 ) {
155 m_clientCatalogue->addProperty("WriteDst", "RunMode", "3");
156 }
157 else if ( type == 4 ) {
158 m_clientCatalogue->addProperty("WriteRec", "RunMode", "3");
159 }
160 //else if ( type == 5 ) {
161 // m_clientCatalogue->addProperty("NTupleSvc", "RunMode", "3");
162 //}
163 //else if ( type == 6 ) {
164 // m_clientCatalogue->addProperty("THistSvc", "RunMode", "3");
165 //}
166 }
167
168 std::string client_opt_name = m_optName + ".distboss_client";
169 std::ofstream os(client_opt_name.c_str(), std::ios::out|std::ios::trunc);
170 if ( ! os ) {
171 std::cout << "[JobOptionsMgr] Failed to open client_template file!" << std::endl;
172 exit(1);
173 }
174
175 m_clientCatalogue->fillStream( os );
176
177 delete m_clientCatalogue;
178}
179
180const Property* JobOptionsMgr::getProperty(const std::string& client, const std::string& name)
181{
182 const Property* pprop = NULL;
183
184 const std::vector<const Property*>* properties = m_svc->getProperties(client);
185 if ( properties != NULL ) {
186 for ( unsigned int i = 0; i < properties->size(); ++i ) {
187 if ( properties->at(i)->name() == name) {
188 pprop = properties->at(i);
189 break;
190 }
191 }
192 }
193
194 return pprop;
195}
#define CheckSTATUS(msg)
#define MyPARSE(var)
#define ignorePROPERTY(client, pname)
void clientOptsTemplate(const std::string &svrName)
virtual ~JobOptionsMgr()
JobOptionsMgr(const std::string &optname)