|
ATLAS Offline Software
|
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <TFile.h>
#include <TList.h>
#include <TKey.h>
#include <TDirectory.h>
#include <TString.h>
#include <TObjString.h>
#include <TError.h>
#include "GaudiKernel/StatusCode.h"
#include "GaudiKernel/Bootstrap.h"
#include "GaudiKernel/IMessageSvc.h"
#include "GaudiKernel/ISvcLocator.h"
#include "AthenaKernel/errorcheck.h"
#include "CxxUtils/checker_macros.h"
#include "D3PDMakerUtils/ObjectMetadata.h"
#include "../Variable.h"
#include "../CodeGenerator_v2.h"
#include "../RootObjectMetadata.h"
Go to the source code of this file.
◆ ATLAS_NOT_THREAD_SAFE()
int main ATLAS_NOT_THREAD_SAFE |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
A convenience declaration to save myself some typeing.
Definition at line 93 of file d3pdReadersFromFile.cxx.
99 SmartIF<IMessageSvc> msvc{Gaudi::svcLocator()->service(
"MessageSvc")};
102 <<
"Couldn't set up the Gaudi message service";
110 po::options_description
desc( PROGRAM_DESC );
112 (
"help,h",
"Give some help with the program usage" )
113 (
"d3pd-files,f",
po::value< std::vector< std::string > >()->multitoken(),
114 "Input D3PD file(s)" )
115 (
"event-class-name,n", po::value< std::string >()->default_value(
"Event" ),
116 "Name for the D3PDReader event class" )
117 (
"output,o", po::value< std::string >()->default_value(
"." ),
118 "Output directory for the generated source files" )
119 (
"verbosity,v", po::value< int >()->default_value( 3 ),
120 "Verbosity level of the application. (1:VERBOSE, 2:DEBUG, 3:INFO, ...)" );
125 po::variables_map vm;
131 <<
"There was a problem with interpreting the command line options.";
133 <<
"Message: " << ex.what();
140 if( vm.count(
"help" ) ) {
141 std::cout <<
desc << std::endl;
148 msvc->setOutputLevel( vm[
"verbosity" ].as< int >() );
154 std::cout << PROGRAM_GREETING << std::endl;
157 if( ! vm.count(
"d3pd-files" ) ) {
159 <<
"You have to specify at least one D3PD file!";
162 const std::vector< std::string > file_names =
163 vm[
"d3pd-files" ].as< std::vector< std::string > >();
164 std::cout <<
" D3PD file(s): " << file_names << std::endl;
167 const std::string event_name = vm[
"event-class-name" ].as< std::string >();
168 std::cout <<
" Event class name: " << event_name << std::endl;
171 const std::string
output = vm[
"output" ].as< std::string >();
172 std::cout <<
" Output directory: " <<
output << std::endl;
177 std::set< D3PD::ObjectMetadata >
objects;
182 std::vector< std::string >::const_iterator file_itr = file_names.begin();
183 std::vector< std::string >::const_iterator file_end = file_names.end();
184 for( ; file_itr != file_end; ++file_itr ) {
188 <<
"Reading file: " << *file_itr;
189 TFile*
ifile = TFile::Open( file_itr->c_str(),
"READ" );
192 <<
"Failed to open D3PD file: " << *file_itr;
197 std::vector< std::string > metaDirectories;
198 const TList*
keys =
ifile->GetListOfKeys();
199 for( Int_t
i = 0;
i <
keys->GetSize(); ++
i ) {
200 const TKey*
key =
dynamic_cast< TKey*
>(
keys->At(
i ) );
202 std::string key_name =
key->GetName();
203 if( ( key_name.find(
"Meta" ) != key_name.npos ) &&
204 (
key->GetClassName() == std::string(
"TDirectoryFile" ) ) ) {
205 metaDirectories.push_back( key_name );
210 std::vector< std::string >::const_iterator dir_itr = metaDirectories.begin();
211 std::vector< std::string >::const_iterator dir_end = metaDirectories.end();
212 for( ; dir_itr != dir_end; ++dir_itr ) {
214 TDirectory*
dir =
ifile->GetDirectory( dir_itr->c_str() );
217 <<
"Failed to access directory: " << *dir_itr;
223 <<
"Failed to collect variable definitions from metadata directory: "
238 if( ! merged_objects.size() ) {
240 <<
"Didn't find any metadata about the D3PD variables in the "
241 <<
"specified file(s)!";
250 <<
"Couldn't create the D3PDObjectBase class source";
259 <<
"Couldn't create the VarHandle class source";
268 <<
"Couldn't create the VarProxy class source";
277 <<
"Couldn't create the UserD3PDObject class source";
286 <<
"Couldn't create the D3PDReadStats class source";
295 <<
"Couldn't create the D3PDPerfStats class source";
304 <<
"Couldn't create the Utils source";
311 std::vector< D3PD::ObjectMetadata >::const_iterator obj_itr = merged_objects.begin();
312 std::vector< D3PD::ObjectMetadata >::const_iterator obj_end = merged_objects.end();
313 for( ; obj_itr != obj_end; ++obj_itr ) {
319 *obj_itr ).isFailure() ) {
321 <<
"Couldn't generate the D3PDReader class header";
329 *obj_itr ).isFailure() ) {
331 <<
"Couldn't generate the D3PDReader class source";
342 <<
"Couldn't generate the D3PDReader event class header";
348 <<
"Couldn't generate the D3PDReader event class source";
◆ collectObjects()
Function collecting the objects from a specific directory in a file.
This function is used to collect the metadata about D3PDObjects from one particular directory in one D3PD file.
- Parameters
-
dir | The directory where metadata should be searched for |
objects | The global list of object metadata |
- Returns
StatusCode::SUCCESS
if the operation was successful, StatusCode::FAILURE
otherwise
Definition at line 364 of file d3pdReadersFromFile.cxx.
368 const TList*
keys =
dir->GetListOfKeys();
369 for( Int_t
i = 0;
i <
keys->GetSize(); ++
i ) {
372 const TKey*
key =
dynamic_cast< TKey*
>(
keys->At(
i ) );
374 if(
key->GetClassName() != std::string(
"TObjString" ) )
continue;
385 <<
"Reading object '" << objName <<
"'";
388 TObjString* ostring =
389 dynamic_cast< TObjString*
>(
dir->Get( TString(
key->GetName() ) +
";" +
393 <<
"Couldn't access object: " <<
key->GetName() <<
";"
395 return StatusCode::FAILURE;
401 if(
metadata.read( ostring->GetString().Data() ).isFailure() ) {
403 <<
"Couldn't collect variables from object: " <<
key->GetName();
404 return StatusCode::FAILURE;
408 if(
metadata.checkPrefixes().isFailure() ) {
410 <<
"Couldn't fix prefixes in metadata object with name: "
412 return StatusCode::FAILURE;
421 <<
"Merging objects with name '" << objName <<
"'";
428 <<
"Added object with name '" << objName <<
"'";
433 return StatusCode::SUCCESS;
◆ mergeObjects()
Function mergint the objects of the same type.
This function is used to merge the objects of the same type on its input.
This practically means that objects that have the same "object name" get merged, irrespective of their prefix.
- Parameters
-
objects | A set of independent D3PDObjects |
- Returns
- A merged list of D3PDObjects
Definition at line 445 of file d3pdReadersFromFile.cxx.
448 std::map< std::string, D3PD::ObjectMetadata > tmp_result;
451 std::set< D3PD::ObjectMetadata >::const_iterator set_itr =
objects.begin();
452 std::set< D3PD::ObjectMetadata >::const_iterator set_end =
objects.end();
453 for( ; set_itr != set_end; ++set_itr ) {
454 tmp_result[ set_itr->name() ].setName( set_itr->name() );
455 tmp_result[ set_itr->name() ].setPrefix( set_itr->prefix() );
456 tmp_result[ set_itr->name() ].setContainer( set_itr->container() );
457 tmp_result[ set_itr->name() ].merge( *set_itr );
461 std::vector< D3PD::ObjectMetadata >
result;
462 std::map< std::string, D3PD::ObjectMetadata >::const_iterator map_itr =
464 std::map< std::string, D3PD::ObjectMetadata >::const_iterator map_end =
466 for( ; map_itr != map_end; ++map_itr ) {
467 result.push_back( map_itr->second );
◆ operator<<()
template<typename T >
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const std::vector< T > & |
vec |
|
) |
| |
Formatted printing for vector objects.
The code has to print a vector in at least one place. To make it easily readable in the code, I like to use such an output operator. It can be used for any kind of vector as long as the template type can also be printed with the << operator.
- Parameters
-
out | An STL output stream |
vec | The vector that should be printed |
- Returns
- The same output stream that the operator received
Definition at line 68 of file d3pdReadersFromFile.cxx.
70 typename std::vector< T >::const_iterator itr =
vec.begin();
71 typename std::vector< T >::const_iterator
end =
vec.end();
72 for( ; itr !=
end; ++itr ) {
JetConstituentVector::iterator iterator
std::vector< D3PD::ObjectMetadata > mergeObjects(const std::set< D3PD::ObjectMetadata > &objects)
Function mergint the objects of the same type.
StatusCode writeD3PDPerfStats(const std::string &dir)
This function can be used to create the D3PDReader::D3PDPerfStats 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 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 writeD3PDObjectBase(const std::string &dir)
This function can be used to create the D3PDReader::D3PDObjectBase class's source files.
StatusCode writeVarHandle(const std::string &dir)
This function can be used to create the D3PDReader::VarHandle class's source files.
std::vector< size_t > vec
StatusCode writeUtils(const std::string &dir)
This function can be used to create source files containing some utility functions.
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 collectObjects(TDirectory *dir, std::set< D3PD::ObjectMetadata > &objects)
Function collecting the objects from a specific directory in a file.
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
StatusCode writeD3PDReadStats(const std::string &dir)
This function can be used to create the D3PDReader::D3PDReadStats 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 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 writeVarProxy(const std::string &dir)
This function can be used to create the D3PDReader::VarProxy class's source files.