89 {
90
92
93
94
95 SmartIF<IMessageSvc> msvc{Gaudi::svcLocator()->service("MessageSvc")};
96 if( !msvc ) {
98 << "Couldn't set up the Gaudi message service";
99 return 255;
100 }
101
102
103
104
105
108 ( "help,h", "Give some help with the program usage" )
109 ( "classname,n", po::value< std::string >()->default_value( "D3PDReader" ),
110 "Generated class name" )
111 ( "d3pd-files,f", po::value< std::vector< std::string > >()->multitoken(),
112 "Input D3PD file(s)" )
113 ( "tree,t", po::value< std::string >()->default_value( "" ), "Name of the D3PD tree" )
114 ( "variables,v", po::value< std::vector< std::string > >()->multitoken(),
115 "Variable names to consider (regular expression(s))" )
116 ( "prefixes,p", po::value< std::vector< std::string > >()->multitoken(),
117 "Variable name prefix(es)" )
118 ( "container,c", "Option specifying that a proxy class should be created" )
119 ( "output,o", po::value< std::string >()->default_value( "." ),
120 "Output directory for the generated source files" );
121
122
123
124
125 po::variables_map vm;
126 try {
127 po::store( po::parse_command_line( argc, argv, desc ), vm );
128 po::notify( vm );
129 } catch( const std::exception& ex ) {
131 << "There was a problem with interpreting the command line options.";
133 << "Message: " << ex.what();
134 return 255;
135 }
136
137
138
139
140 if( vm.count( "help" ) ) {
141 std::cout <<
desc << std::endl;
142 return 0;
143 }
144
145
146
147
148
150 std::cout << "Program will be executed with the options:" << std::endl;
151
152
153 std::string
class_name = vm[
"classname" ].as< std::string >();
154 std::cout <<
" Generating class with name: \"D3PDReader::" <<
class_name <<
"\""
155 << std::endl;
156
157
158 if( ! vm.count( "d3pd-files" ) ) {
160 << "You have to specify at least one D3PD file!";
161 return 255;
162 }
163 const std::vector< std::string > file_names =
164 vm[ "d3pd-files" ].as< std::vector< std::string > >();
165 std::cout << " D3PD file(s): " << file_names << std::endl;
166
167
168 const std::string d3pd_tree_name = vm[ "tree" ].as< std::string >();
169 if( d3pd_tree_name != "" ) {
170 std::cout << " Using D3PD tree: " << d3pd_tree_name << std::endl;
171 } else {
172 std::cout << " Trying to find D3PD tree automatically" << std::endl;
173 }
174
175
176 std::vector< std::string > var_names;
177 if( vm.count( "variables" ) ) {
178 var_names = vm[ "variables" ].as< std::vector< std::string > >();
179 std::cout << " Only considering variables with names: " << var_names << std::endl;
180 } else {
181 std::cout << " Considering all variables from the input file" << std::endl;
182 }
183
184
185 if( ( ( vm.count( "prefixes" ) != vm.count( "variables" ) ) &&
186 ( vm.count( "prefixes" ) != 1 ) ) ||
187 ( vm.count( "prefixes" ) == 0 ) ) {
189 << "You have to either specify just one prefix, or the same number as "
190 << "how many variable regular expressions you gave";
191 return 255;
192 }
193 const std::vector< std::string > prefixes =
194 vm[ "prefixes" ].as< std::vector< std::string > >();
195 std::cout << " Common variable prefix(es): " << prefixes << std::endl;
196
197
198 const bool is_container = vm.count( "container" );
199 std::cout << " Proxy class will " << ( is_container ? "" : "NOT " ) << "be created"
200 << std::endl;
201
202
203 const std::string
output = vm[
"output" ].as< std::string >();
204 std::cout <<
" Output directory: " <<
output << std::endl;
205
206
207
208
209 std::map< std::string, D3PD::RootObjectMetadata >
metadata;
210 std::vector< std::string >::const_iterator prefix_itr = prefixes.begin();
211 std::vector< std::string >::const_iterator prefix_end = prefixes.end();
212 for( ; prefix_itr != prefix_end; ++prefix_itr ) {
213 metadata[ *prefix_itr ].setName( class_name );
214 metadata[ *prefix_itr ].setPrefix( *prefix_itr );
215 metadata[ *prefix_itr ].setContainer( is_container );
216 }
217
218
219
220
221 std::vector< std::string >::const_iterator file_itr = file_names.begin();
222 std::vector< std::string >::const_iterator file_end = file_names.end();
223 for( ; file_itr != file_end; ++file_itr ) {
224
225 if( prefixes.size() > 1 ) {
226
227 for(
size_t i = 0;
i < prefixes.size(); ++
i ) {
229 metadata[ prefixes[ i ] ] ).isFailure() ) {
231 << "Couldn't extract the variable descriptions from file: "
232 << *file_itr;
233 return 255;
234 }
235 }
236
237 } else {
238
240 metadata[ prefixes[ 0 ] ] ).isFailure() ) {
242 << "Couldn't extract the variable descriptions from file: "
243 << *file_itr;
244 return 255;
245 }
246
247 }
248
249 }
250
251
252
253
255 summed_meta.
setName( class_name );
258 prefix_itr = prefixes.begin();
259 prefix_end = prefixes.end();
260 for( ; prefix_itr != prefix_end; ++prefix_itr ) {
261 summed_meta +=
metadata[ *prefix_itr ];
262 }
263
264
265
266
269 << "Couldn't create the D3PDObjectBase class source";
270 return 255;
271 }
272
273
274
275
278 << "Couldn't create the VarHandle class source";
279 return 255;
280 }
281
282
283
284
285 if( is_container ) {
288 << "Couldn't create the VarProxy class source";
289 return 255;
290 }
291 }
292
293
294
295
298 << "Couldn't create the UserD3PDObject class source";
299 return 255;
300 }
301
302
303
304
307 << "Couldn't create the D3PDReadStats class source";
308 return 255;
309 }
310
311
312
313
316 << "Couldn't create the D3PDPerfStats class source";
317 return 255;
318 }
319
320
321
322
325 << "Couldn't create the Utils source";
326 return 255;
327 }
328
329
330
331
334 << "Couldn't generate the D3PDReader class header";
335 return 255;
336 }
337
338
339
340
343 << "Couldn't generate the D3PDReader class source";
344 return 255;
345 }
346
347 return 0;
348}
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
static const char *const PROGRAM_GREETING
A greeting text that's printed when the application starts up.
StatusCode extractVariables(const std::string &file_name, const std::string &tree_name, const std::vector< std::string > &patterns, D3PD::RootObjectMetadata &metadata)
This function is used to extract the variable descriptions from the D3PD file.
static const char *const PROGRAM_DESC
The program description that's printed with the available parameters.
StatusCode writeUtils(const std::string &dir)
This function can be used to create source files containing some utility functions.
StatusCode writeHeader(const std::string &classname, const std::string &dir, const ObjectMetadata &metadata)
This function is used to create the header of the class describing a set of D3PD variables.
StatusCode writeD3PDReadStats(const std::string &dir)
This function can be used to create the D3PDReader::D3PDReadStats class's source files.
StatusCode writeSource(const std::string &classname, const std::string &dir, const ObjectMetadata &metadata)
This function is used to generate the source file of a D3PDReader class.
StatusCode writeVarHandle(const std::string &dir)
This function can be used to create the D3PDReader::VarHandle class's source files.
StatusCode writeVarProxy(const std::string &dir)
This function can be used to create the D3PDReader::VarProxy class's source files.
StatusCode writeD3PDObjectBase(const std::string &dir)
This function can be used to create the D3PDReader::D3PDObjectBase class's source files.
StatusCode writeUserD3PDObject(const std::string &dir)
This function can be used to create the D3PDReader::UserD3PDObject class's source files.
StatusCode writeD3PDPerfStats(const std::string &dir)
This function can be used to create the D3PDReader::D3PDPerfStats class's source files.