92 {
93
95
96
97
98 SmartIF<IMessageSvc> msvc{Gaudi::svcLocator()->service("MessageSvc")};
99 if( !msvc ) {
101 << "Couldn't set up the Gaudi message service";
102 return 255;
103 }
104
105
106
107
108
111 ( "help,h", "Give some help with the program usage" )
112 ( "d3pd-files,f", po::value< std::vector< std::string > >()->multitoken(),
113 "Input D3PD file(s)" )
114 ( "event-class-name,n", po::value< std::string >()->default_value( "Event" ),
115 "Name for the D3PDReader event class" )
116 ( "output,o", po::value< std::string >()->default_value( "." ),
117 "Output directory for the generated source files" )
118 ( "verbosity,v", po::value< int >()->default_value( 3 ),
119 "Verbosity level of the application. (1:VERBOSE, 2:DEBUG, 3:INFO, ...)" );
120
121
122
123
124 po::variables_map vm;
125 try {
126 po::store( po::parse_command_line( argc, argv, desc ), vm );
127 po::notify( vm );
128 } catch( const std::exception& ex ) {
130 << "There was a problem with interpreting the command line options.";
132 << "Message: " << ex.what();
133 return 255;
134 }
135
136
137
138
139 if( vm.count( "help" ) ) {
140 std::cout <<
desc << std::endl;
141 return 0;
142 }
143
144
145
146
147 msvc->setOutputLevel( vm[ "verbosity" ].as< int >() );
148
149
150
151
152
154
155
156 if( ! vm.count( "d3pd-files" ) ) {
158 << "You have to specify at least one D3PD file!";
159 return 255;
160 }
161 const std::vector< std::string > file_names =
162 vm[ "d3pd-files" ].as< std::vector< std::string > >();
163 std::cout << " D3PD file(s): " << file_names << std::endl;
164
165
166 const std::string event_name = vm[ "event-class-name" ].as< std::string >();
167 std::cout << " Event class name: " << event_name << std::endl;
168
169
170 const std::string
output = vm[
"output" ].as< std::string >();
171 std::cout <<
" Output directory: " <<
output << std::endl;
172
173
174
175
176 std::set< D3PD::ObjectMetadata >
objects;
177
178
179
180
181 std::vector< std::string >::const_iterator file_itr = file_names.begin();
182 std::vector< std::string >::const_iterator file_end = file_names.end();
183 for( ; file_itr != file_end; ++file_itr ) {
184
185
187 << "Reading file: " << *file_itr;
188 TFile*
ifile = TFile::Open( file_itr->c_str(),
"READ" );
189 if( ( ! ifile ) ||
ifile->IsZombie() ) {
191 << "Failed to open D3PD file: " << *file_itr;
192 return 255;
193 }
194
195
196 std::vector< std::string > metaDirectories;
197 const TList*
keys =
ifile->GetListOfKeys();
198 for( Int_t i = 0;
i <
keys->GetSize(); ++
i ) {
199 const TKey*
key =
dynamic_cast< TKey*
>(
keys->At( i ) );
200 if (!key) continue;
201 std::string key_name =
key->GetName();
202 if( ( key_name.find( "Meta" ) != key_name.npos ) &&
203 (
key->GetClassName() == std::string(
"TDirectoryFile" ) ) ) {
204 metaDirectories.push_back( std::move(key_name) );
205 }
206 }
207
208
209 std::vector< std::string >::const_iterator dir_itr = metaDirectories.begin();
210 std::vector< std::string >::const_iterator dir_end = metaDirectories.end();
211 for( ; dir_itr != dir_end; ++dir_itr ) {
212
213 TDirectory*
dir =
ifile->GetDirectory( dir_itr->c_str() );
214 if( ! dir ) {
216 << "Failed to access directory: " << *dir_itr;
217 return 255;
218 }
219
222 << "Failed to collect variable definitions from metadata directory: "
223 << *dir_itr;
224 return 255;
225 }
226 }
227
228
231 }
232
233
234
235
236 std::vector< D3PD::ObjectMetadata > merged_objects =
mergeObjects( objects );
237 if( ! merged_objects.size() ) {
239 << "Didn't find any metadata about the D3PD variables in the "
240 << "specified file(s)!";
241 return 255;
242 }
243
244
245
246
249 << "Couldn't create the D3PDObjectBase class source";
250 return 255;
251 }
252
253
254
255
258 << "Couldn't create the VarHandle class source";
259 return 255;
260 }
261
262
263
264
267 << "Couldn't create the VarProxy class source";
268 return 255;
269 }
270
271
272
273
276 << "Couldn't create the UserD3PDObject class source";
277 return 255;
278 }
279
280
281
282
285 << "Couldn't create the D3PDReadStats class source";
286 return 255;
287 }
288
289
290
291
294 << "Couldn't create the D3PDPerfStats class source";
295 return 255;
296 }
297
298
299
300
303 << "Couldn't create the Utils source";
304 return 255;
305 }
306
307
308
309
310 std::vector< D3PD::ObjectMetadata >::const_iterator obj_itr = merged_objects.begin();
311 std::vector< D3PD::ObjectMetadata >::const_iterator obj_end = merged_objects.end();
312 for( ; obj_itr != obj_end; ++obj_itr ) {
313
314
315
316
318 *obj_itr ).isFailure() ) {
320 << "Couldn't generate the D3PDReader class header";
321 return 255;
322 }
323
324
325
326
328 *obj_itr ).isFailure() ) {
330 << "Couldn't generate the D3PDReader class source";
331 return 255;
332 }
333 }
334
335
336
337
339 objects ).isFailure() ) {
341 << "Couldn't generate the D3PDReader event class header";
342 return 255;
343 }
345 objects ).isFailure() ) {
347 << "Couldn't generate the D3PDReader event class source";
348 return 255;
349 }
350
351 return 0;
352}
#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.
static const char *const PROGRAM_DESC
The program description that's printed with the available parameters.
std::vector< D3PD::ObjectMetadata > mergeObjects(const std::set< D3PD::ObjectMetadata > &objects)
Function mergint the objects of the same type.
StatusCode collectObjects(TDirectory *dir, std::set< D3PD::ObjectMetadata > &objects)
Function collecting the objects from a specific directory in a file.
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 writeEventSource(const std::string &classname, const std::string &dir, const std::set< ObjectMetadata > &metadata)
Write the source of the main event class describing a D3PD tree.
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 writeEventHeader(const std::string &classname, const std::string &dir, const std::set< ObjectMetadata > &metadata)
Write the header of the main event class describing a D3PD tree.
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.