BOSS 7.1.1
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 "GaudiKernel/Parsers.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 SvcCatalog* m_clientCatalogue = new SvcCatalog;
116
117 StatusCode sc;
118
119 std::vector<std::string> clients = m_svc->getClients();
120 for ( unsigned int i = 0; i < clients.size(); ++i ) {
121 const std::vector<const Property*>* properties = m_svc->getProperties(clients[i]);
122 for ( unsigned int j = 0; j < properties->size(); ++j ) {
123 const Property* property = properties->at(j);
124
125 ignorePROPERTY("ApplicationMgr", "EvtMax");
126
127 ignorePROPERTY("RawDataInputSvc", "InputFiles");
128 //ignorePROPERTY("BesRndmGenSvc", "RndmSeed"); //placeholder for simulation
129 ignorePROPERTY("EventCnvSvc", "digiRootInputFile");
130
131 ignorePROPERTY("WriteDst", "digiRootOutputFile");
132 ignorePROPERTY("WriteRec", "digiRootOutputFile");
133 //ignorePROPERTY("NTupleSvc", "Output"); //placeholder for NTupleSvc
134 //ignorePROPERTY("THistSvc", "Output"); //placeholder for THistSvc
135
136 StringProperty* tmp= new StringProperty(property->name(), property->toString());
137 sc = m_clientCatalogue->addProperty(clients[i], tmp);
138 if ( sc.isFailure() ) {
139 StringProperty* tmp2 = new StringProperty(property->name(), '"'+property->toString()+'"');
140 m_clientCatalogue->addProperty(clients[i], tmp2);
141 }
142 }
143 }
144
145 StringProperty* tmpservername = new StringProperty("ServerName", '"'+svrName+'"');
146 m_clientCatalogue->addProperty("DistBoss", tmpservername);
147 if ( m_iFileType == 0 ) {
148 StringProperty* tmprunmode = new StringProperty("RunMode", "3");
149 m_clientCatalogue->addProperty("RawDataInputSvc", tmprunmode);
150 }
151 //else if ( m_iFileType == 1 ) { //placeholder for simulation
152 // m_clientCatalogue->addProperty("BesRndmGenSvc", "RunMode", "3");
153 //}
154 //else if ( m_iFileType == 2 ) {
155 // m_clientCatalogue->addProperty("EventCnvSvc", "RunMode", "3");
156 //}
157 for ( unsigned int i = 0; i < m_oFileTypes.size(); ++i ) {
158 int type = m_oFileTypes[i];
159 if ( type == 3 ) {
160 m_clientCatalogue->addProperty("WriteDst", new StringProperty("RunMode", "3"));
161 }
162 else if ( type == 4 ) {
163 m_clientCatalogue->addProperty("WriteRec", new StringProperty("RunMode", "3"));
164 }
165 //else if ( type == 5 ) {
166 // m_clientCatalogue->addProperty("NTupleSvc", "RunMode", "3");
167 //}
168 //else if ( type == 6 ) {
169 // m_clientCatalogue->addProperty("THistSvc", "RunMode", "3");
170 //}
171 }
172
173 std::string client_opt_name = m_optName + ".distboss_client";
174 std::ofstream os(client_opt_name.c_str(), std::ios::out|std::ios::trunc);
175 if ( ! os ) {
176 std::cout << "[JobOptionsMgr] Failed to open client_template file!" << std::endl;
177 exit(1);
178 }
179
180 m_clientCatalogue->fillStream( os );
181
182 delete m_clientCatalogue;
183}
184
185const Property* JobOptionsMgr::getProperty(const std::string& client, const std::string& name)
186{
187 const Property* pprop = NULL;
188
189 const std::vector<const Property*>* properties = m_svc->getProperties(client);
190 if ( properties != NULL ) {
191 for ( unsigned int i = 0; i < properties->size(); ++i ) {
192 if ( properties->at(i)->name() == name) {
193 pprop = properties->at(i);
194 break;
195 }
196 }
197 }
198
199 return pprop;
200}
#define CheckSTATUS(msg)
#define MyPARSE(var)
#define ignorePROPERTY(client, pname)
#define NULL
void clientOptsTemplate(const std::string &svrName)
virtual ~JobOptionsMgr()
JobOptionsMgr(const std::string &optname)