ATLAS Offline Software
Functions
d3pdReaderRootCoreMaker Namespace Reference

Functions

def main ()
 C/C++ style main function. More...
 

Function Documentation

◆ main()

def d3pdReaderRootCoreMaker.main ( )

C/C++ style main function.

This function executes all the code stored in this script.

Returns
0 in case of success, something else in case of failure

Definition at line 24 of file d3pdReaderRootCoreMaker.py.

24 def main():
25 
26  # Create a logger object first of all:
27  from AthenaCommon.Logging import logging
28  logger = logging.getLogger( os.path.splitext( os.path.basename( sys.argv[ 0 ] ) )[ 0 ] )
29 
30  #
31  # Specify the command line options:
32  #
33  desc = "This script can be used to generate a RootCore package out of the D3PDReader " \
34  "sources generated by one of the D3PDReader code generators."
35  vers = "$Revision: 471380 $"
36  import optparse
37  parser = optparse.OptionParser( description = desc,
38  version = vers,
39  usage = "%prog [options] <source files>" )
40  parser.add_option( "-v", "--verbosity", dest = "verbosity",
41  action = "store", type = "int", default = 3,
42  help = "Message verbosity level" )
43  parser.add_option( "-p", "--package-name", dest = "packagename",
44  action = "store", type = "string", default = "D3PDReader",
45  help = "Name for the RootCore package" )
46  parser.add_option( "-o", "--output", dest = "output",
47  action = "store", type = "string", default = "./",
48  help = "Output directory for the RootCore package" )
49 
50  # Parse the command line options:
51  ( options, files ) = parser.parse_args()
52 
53  # Do a small sanity check:
54  if not len( files ):
55  logger.error( "You have to define at least one source file!" )
56  parser.print_help()
57  return 255
58 
59  # Set the default logging level:
60  logging.getLogger( "" ).setLevel( options.verbosity )
61 
62  # Print some welcome message:
63  logger.info( "***********************************************************" )
64  logger.info( "* D3PDReader RootCore Package Maker" )
65  logger.info( "* Version: $Revision: 471380 $" )
66  logger.info( "*" )
67  logger.info( "* Output level: " + str( options.verbosity ) )
68  logger.info( "* Package name: " + options.packagename )
69  logger.info( "* Output directory: " + options.output )
70  logger.info( "* Source files: " + ", ".join( files ) )
71  logger.info( "***********************************************************" )
72 
73  # Filter out the header and source files:
74  ( header_files, source_files ) = separateSources( files )
75  dictionary_header_files = dictionaryHeaders( files )
76 
77  # Create the package's skeleton:
78  if makeRootCorePackageSkeleton( options.output, options.packagename ):
79  logger.error( "Failed to create RootCore package skeleton" )
80  return 255
81 
82  # Copy the header files:
83  import shutil
84  for header in header_files:
85  shutil.copy( header, options.output + "/" + options.packagename + \
86  "/" + options.packagename )
87  pass
88 
89  # Copy the source files:
90  for source in source_files:
91  shutil.copy( source, options.output + "/" + options.packagename + "/Root/" )
92  pass
93 
94  # Transform the include paths in the source files:
95  rootcore_sources = [ ( options.output + "/" + options.packagename + "/Root/" + \
96  os.path.basename( source ) ) for source in source_files ]
97  for source in rootcore_sources:
98  # Read in the file's contents:
99  sfile = open( source, "r" )
100  cont = sfile.read()
101  sfile.close()
102 
103  # Modify the file's contents:
104  cont = re.sub( "#include \"(.*)\"",
105  "#include \"../%s/\g<1>\"" % options.packagename,
106  cont )
107 
108  # Overwrite the original file:
109  sfile = open( source, "w" )
110  sfile.write( cont )
111  sfile.close()
112  pass
113 
114  # Extract the class names to generate a dictionary for:
115  classnames = dictionaryClasses( dictionary_header_files )
116 
117  # Create the LinkDef file:
118  if writeLinkDefFile( options.output + "/" + options.packagename + "/Root/LinkDef.h",
119  classnames,
120  [ ( "../" + options.packagename + "/" + os.path.basename( header ) ) \
121  for header in dictionary_header_files ] ):
122  logger.error( "Failed writing RootCore LinkDef.h file" )
123  return 255
124 
125  # Write the ChangeLog, just for fun:
126  import datetime
127  clog = open( options.output + "/" + options.packagename + "/ChangeLog", "w" )
128  clog.write( "%s d3pdReaderRootCoreMaker.py <Attila.Krasznahorkay@cern.ch>\n" % datetime.date.today() )
129  clog.write( "\t* Created the package\n" )
130  clog.close()
131 
132  return 0
133 
134 # Execute the main function:
python.Helpers.makeRootCorePackageSkeleton
def makeRootCorePackageSkeleton(directory, name)
Create the directory structure for a RootCore package.
Definition: PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py:279
pool::DbPrintLvl::setLevel
void setLevel(MsgLevel l)
Definition: DbPrint.h:32
python.Helpers.separateSources
def separateSources(filenames)
Separate the source and header files based on their names.
Definition: PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py:17
python.Helpers.dictionaryClasses
def dictionaryClasses(filenames)
Function collecting the class names to create a dictionary for.
Definition: PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py:80
python.Helpers.writeLinkDefFile
def writeLinkDefFile(filename, classnames, headers=[])
Function writing a LinkDef file.
Definition: PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py:172
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
d3pdReaderRootCoreMaker.main
def main()
C/C++ style main function.
Definition: d3pdReaderRootCoreMaker.py:24
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
python.Helpers.dictionaryHeaders
def dictionaryHeaders(filenames)
Find the headers needed for dictionary generation.
Definition: PhysicsAnalysis/D3PDMaker/D3PDMakerReader/python/Helpers.py:48