ATLAS Offline Software
Loading...
Searching...
No Matches
python.ProphecyConfig.ProphecyConfig Class Reference

Base class for configurable objects in the jobOptions. More...

Inheritance diagram for python.ProphecyConfig.ProphecyConfig:
Collaboration diagram for python.ProphecyConfig.ProphecyConfig:

Public Types

typedef HLT::TypeInformation::for_each_type_c< typenameEDMLIST::map, my_functor, my_result<>, my_arg< HLT::TypeInformation::get_cont, CONTAINER > >::type result

Public Member Functions

 __init__ (self, runArgs=None, opts=None)
 generate (self, filter_name='', filter_args='')
 Run normal event generation.
 generateRunCard (self)
 Initialise runcard with generic options.
 generateEvents (self)
 Run normal event generation.
 add_parameter (self, configurable_name, value, desc='', parameter=None)
 Register configurable parameter.
 add_parameter_set (self, parameter_set, **kwargs)
 Alias to DecoratorFactory.decorate.
 emit_heartbeat (self, duration)
 Output a heartbeat message.
 fix_parameter (self, parameter, value=None, desc='')
 Register non-configurable parameter.
 runProphecy (configurator)
 run_directory (self)
 Get run directory.
 configurable_parameters (self)
 Get dictionary of configurable parameters.
 fixed_parameters (self)
 Get list of non-configurable parameters.
 logger (self)
 Get handle to logger.
 output_events_file_name (self)
 Get output file name.
 output_events_file_name (self, value)
 Set output file name.
 prophecy_directory (self)
 Get Prophecy directory.
 run_card_decorators (self)
 Get list of enabled run card decorators.
 run_card_path (self)
 Get full path to runcard.

Public Attributes

 nEvents = int( 1.1 * runArgs.maxEvents + 0.5 )
 Add universal functionality.
 random_seed = runArgs.randomSeed
int nEvents_weighted
 Print final preparation message.
 run_card_decorators
 Finalise registered decorators.
 run_card_path
 Write out final runcard.
 fixed_parameters
 Write out final runcard.
list running_process = []
 Remove any existing .lhe files to avoid repeated events.
 output_events_file_name
 Move output to correctly named file.
 run_directory

Static Protected Attributes

str _prophecy_executable = 'Prophecy4f'
 This must be defined by each derived class - don't change it in the jobOptions!

Private Attributes

str __output_events_file_name = 'ProphecyOTF._1.events'
 This needs to be set so that Generate_trf finds an appropriate file format for showering.
list __fixed_parameters = []
 Set up lists of parameters and decorators.
dict __configurable_parameters = {}
list __run_card_decorators = []
bool __enable_reweighting = True

Static Private Attributes

 __run_directory = os.environ['PWD']
 __logger = Logging.logging.getLogger('ProphecyControl')
 Setup athena-compatible logger.

Detailed Description

Base class for configurable objects in the jobOptions.

All subprocesses inherit from this class

Set up run directory and path to Prophecy

Definition at line 12 of file ProphecyConfig.py.

Member Typedef Documentation

◆ result

Definition at line 90 of file EDM_MasterSearch.h.

Constructor & Destructor Documentation

◆ __init__()

python.ProphecyConfig.ProphecyConfig.__init__ ( self,
runArgs = None,
opts = None )

Definition at line 22 of file ProphecyConfig.py.

22
23 def __init__( self, runArgs=None, opts=None ) :
24
25
26 self.__output_events_file_name = 'ProphecyOTF._1.events'
27
28
29 self.__fixed_parameters = []
30 self.__configurable_parameters = {}
31 self.__run_card_decorators = []
32
33
34 self.add_parameter_set( 'fromDefault' )
35
36
37 if runArgs is None :
38 self.logger.warning( 'No run arguments found! Using defaults.' )
39 else :
40 # Read values from runArgs
41 if hasattr(runArgs,'maxEvents') and runArgs.maxEvents > 0 :
42 self.nEvents = int( 1.1 * runArgs.maxEvents + 0.5 )
43 if hasattr(runArgs,'randomSeed') :
44 self.random_seed = runArgs.randomSeed
45
46 if 100 * self.nEvents > self.nEvents_weighted :
47 self.logger.warning( 'There are {0} events requested with {1} weighted ones.'.format( self.nEvents, self.nEvents_weighted ) )
48 self.nEvents_weighted = 100 * self.nEvents
49 self.logger.warning( 'Forcing weighted events to be {0}.'.format( self.nEvents_weighted ) )
50

Member Function Documentation

◆ add_parameter()

python.ProphecyConfig.ProphecyConfig.add_parameter ( self,
configurable_name,
value,
desc = '',
parameter = None )

Register configurable parameter.

Definition at line 147 of file ProphecyConfig.py.

147
148 def add_parameter( self, configurable_name, value, desc='', parameter=None ) :
149 setattr( self, configurable_name, value ) # add new attribute
150 prophecy_parameter = parameter if parameter is not None else configurable_name
151 self.configurable_parameters[prophecy_parameter] = ( configurable_name, desc )
152

◆ add_parameter_set()

python.ProphecyConfig.ProphecyConfig.add_parameter_set ( self,
parameter_set,
** kwargs )

Alias to DecoratorFactory.decorate.

Definition at line 154 of file ProphecyConfig.py.

154
155 def add_parameter_set( self, parameter_set, **kwargs ) :
156 return decorate( self, parameter_set, **kwargs )
157

◆ configurable_parameters()

python.ProphecyConfig.ProphecyConfig.configurable_parameters ( self)

Get dictionary of configurable parameters.

Definition at line 207 of file ProphecyConfig.py.

207 @property
208 def configurable_parameters(self) :
209 return self.__configurable_parameters
210

◆ emit_heartbeat()

python.ProphecyConfig.ProphecyConfig.emit_heartbeat ( self,
duration )

Output a heartbeat message.

Definition at line 159 of file ProphecyConfig.py.

159
160 def emit_heartbeat(self, duration) :
161 message = 'Heartbeat: Prophecy generation has been running for {0} in total'.format( RepeatingTimer.human_readable_time_interval(duration) ) # noqa: F821
162 self.logger.info( message )
163 with open( '{0}/eventLoopHeartBeat.txt'.format( self.__run_directory ), 'w' ) as f : f.write( message )

◆ fix_parameter()

python.ProphecyConfig.ProphecyConfig.fix_parameter ( self,
parameter,
value = None,
desc = '' )

Register non-configurable parameter.

Definition at line 165 of file ProphecyConfig.py.

165
166 def fix_parameter( self, parameter, value=None, desc='' ) :
167 # Get previously set value if not overwriting
168 if value is None : value = getattr( self, parameter )
169 # Remove it from the configurable list if it was there
170 for prophecy_parameter, configurable_name_tuple in self.configurable_parameters.items() :
171 # Retrieve Prophecy parameter name and description if there is a match
172 if parameter == configurable_name_tuple[0] :
173 parameter, desc = prophecy_parameter, configurable_name_tuple[1]
174 self.configurable_parameters.pop(prophecy_parameter)
175 break
176 self.fixed_parameters.append( (parameter, value, desc) )

◆ fixed_parameters()

python.ProphecyConfig.ProphecyConfig.fixed_parameters ( self)

Get list of non-configurable parameters.

Definition at line 213 of file ProphecyConfig.py.

213 @property
214 def fixed_parameters(self) :
215 return self.__fixed_parameters
216

◆ generate()

python.ProphecyConfig.ProphecyConfig.generate ( self,
filter_name = '',
filter_args = '' )

Run normal event generation.

Definition at line 52 of file ProphecyConfig.py.

52
53 def generate( self, filter_name='', filter_args='' ) :
54 self.generateRunCard()
55 self.generateEvents()

◆ generateEvents()

python.ProphecyConfig.ProphecyConfig.generateEvents ( self)

Run normal event generation.

Definition at line 91 of file ProphecyConfig.py.

91
92 def generateEvents(self) :
93
94 time_start = time.time()
95 self.logger.info( 'Starting Prophecy LHEF event generation at {0}'.format( time.ctime( time_start ) ) )
96
97
98 heartbeat = HeartbeatTimer(600., "{}/eventLoopHeartBeat.txt".format(self.__run_directory))
99 heartbeat.setName("heartbeat thread")
100 heartbeat.daemon = True # Allow program to exit if this is the only live thread
101 heartbeat.start()
102
103
104 self.logger.info( 'Removing old Prophecy LHE files' )
105 try :
106 os.remove( 'plot*.lhe plot*.ev*ts' )
107 except OSError :
108 pass
109
110
112 if not os.path.exists('UNWEIGHTEDEVENTS'):
113 os.makedirs('UNWEIGHTEDEVENTS')
114 self.logger.info( 'Created directory UNWEIGHTEDEVENTS' )
115
116
117 self.running_process = []
118
119 self.runProphecy()
120
121
122 heartbeat.cancel()
123
124
125 generation_end = time.time()
126 elapsed_time = generation_end - time_start
127 self.logger.info( 'Running nominal Prophecy took {0} for {1} events => {2:6.3f} Hz'.format( HeartbeatTimer.readable_duration(elapsed_time), self.nEvents, self.nEvents / elapsed_time ) )
128
129 self.logger.info( 'Removing Prophecy born LHE file' )
130 try :
131 os.remove( 'plot_unweighted_born.lhe' )
132 except OSError :
133 pass
134
135
136 try :
137 os.rename( 'UNWEIGHTEDEVENTS/plot_unweighted.lhe', self.output_events_file_name )
138 self.logger.info( 'Moved plot_unweighted.lhe to {0}'.format(self.output_events_file_name) )
139 except OSError :
140 self.logger.warning( 'No output LHEF file found! Probably because the Prophecy process was killed before finishing.' )
141
142
143 self.logger.info( 'Finished at {0}'.format( time.asctime() ) )
144 return
145
void generateEvents(int eventMax)

◆ generateRunCard()

python.ProphecyConfig.ProphecyConfig.generateRunCard ( self)

Initialise runcard with generic options.

Definition at line 57 of file ProphecyConfig.py.

57
58 def generateRunCard(self) :
59
60
61 for run_card_decorator in self.run_card_decorators :
62 if hasattr( run_card_decorator, 'finalise' ) : run_card_decorator.finalise()
63
64
65 self.logger.info( '** User configurable parameters for this process **' )
66 self.logger.info( ': Configurable parameter : Current value : Description' )
67 for value_tuple in sorted( self.configurable_parameters.values(), key=lambda x: x[0].lower() ) :
68 self.logger.info( ': {0:<22} : {1:>17} : {2}'.format( value_tuple[0], getattr(self, value_tuple[0]), value_tuple[1] ) )
69
70
71 [ self.fix_parameter( parameter=value_tuple[0], desc=value_tuple[1] ) for value_tuple in self.configurable_parameters.values() ]
72
73
74 self.logger.info( 'Writing Prophecy runcard to {0}'.format( self.run_card_path ) )
75 with open( self.run_card_path, 'w' ) as f :
76 for parameter_tuple in sorted( self.fixed_parameters, key=lambda x: x[0].lower() ) :
77 name, value, desc = parameter_tuple
78 # Set starting value to first in list when multiple values are provided
79 if isinstance(value,list) :
80 value = value[0]
81 self.__enable_reweighting = True
82 output_line = '{0:<30}! {1}'.format( '{0}={1}'.format( name, value ), desc )
83 f.write( '{0}\n'.format(output_line) )
84 self.logger.info( 'Wrote {0}'.format( output_line ) )
85
86
87 self.logger.info( 'Using executable: {0}'.format( self._prophecy_executable ) )
88 self.logger.info( 'Number of events and weight events: {0} {1}.'.format( self.nEvents, self.nEvents_weighted ) )
89

◆ logger()

python.ProphecyConfig.ProphecyConfig.logger ( self)

Get handle to logger.

Definition at line 219 of file ProphecyConfig.py.

219 @property
220 def logger(self) :
221 return self.__logger
222
static Root::TMsgLogger logger("iLumiCalc")

◆ output_events_file_name() [1/2]

python.ProphecyConfig.ProphecyConfig.output_events_file_name ( self)

Get output file name.

Definition at line 225 of file ProphecyConfig.py.

225 @property
226 def output_events_file_name(self) :
227 return self.__output_events_file_name

◆ output_events_file_name() [2/2]

python.ProphecyConfig.ProphecyConfig.output_events_file_name ( self,
value )

Set output file name.

Definition at line 230 of file ProphecyConfig.py.

230 @output_events_file_name.setter
231 def output_events_file_name(self, value) :
232 self.__output_events_file_name = value
233

◆ prophecy_directory()

python.ProphecyConfig.ProphecyConfig.prophecy_directory ( self)

Get Prophecy directory.

Definition at line 236 of file ProphecyConfig.py.

236 @property
237 def prophecy_directory(self) :
238 return self.__prophecy_directory
239

◆ run_card_decorators()

python.ProphecyConfig.ProphecyConfig.run_card_decorators ( self)

Get list of enabled run card decorators.

Definition at line 242 of file ProphecyConfig.py.

242 @property
243 def run_card_decorators(self) :
244 return self.__run_card_decorators
245

◆ run_card_path()

python.ProphecyConfig.ProphecyConfig.run_card_path ( self)

Get full path to runcard.

Definition at line 248 of file ProphecyConfig.py.

248 @property
249 def run_card_path(self) :
250 return '{0}/prophecy.input'.format( self.run_directory )
251

◆ run_directory()

python.ProphecyConfig.ProphecyConfig.run_directory ( self)

Get run directory.

Definition at line 201 of file ProphecyConfig.py.

201 @property
202 def run_directory(self) :
203 return self.__run_directory
204

◆ runProphecy()

python.ProphecyConfig.ProphecyConfig.runProphecy ( configurator)

Definition at line 177 of file ProphecyConfig.py.

177
178 def runProphecy(configurator) :
179 configurator.running_process.append(subprocess.Popen( [configurator._prophecy_executable,''], stdout=subprocess.PIPE, stdin=open(configurator.run_card_path), stderr=subprocess.STDOUT ) )
180
181 while configurator.running_process :
182 # Write output buffer if any
183 for process in configurator.running_process :
184 while True :
185 output = process.stdout.readline().rstrip()
186 if len(output) == 0 : break
187 configurator.logger.info( '{0}'.format(output) )
188 if process.poll() is not None : # process has ended
189 # Flush buffer and print final output (if any) to screen
190 process.stdout.flush()
191 while True :
192 output = process.stdout.readline().rstrip()
193 if len(output) == 0 : break
194 configurator.logger.info( '{0}'.format(output) )
195 # Close output stream and remove process from list
196 process.stdout.close()
197 configurator.running_process.remove( process )
198 configurator.logger.info( 'Prophecy finished - all done.' )

Member Data Documentation

◆ __configurable_parameters

dict python.ProphecyConfig.ProphecyConfig.__configurable_parameters = {}
private

Definition at line 29 of file ProphecyConfig.py.

◆ __enable_reweighting

bool python.ProphecyConfig.ProphecyConfig.__enable_reweighting = True
private

Definition at line 80 of file ProphecyConfig.py.

◆ __fixed_parameters

list python.ProphecyConfig.ProphecyConfig.__fixed_parameters = []
private

Set up lists of parameters and decorators.

Definition at line 28 of file ProphecyConfig.py.

◆ __logger

python.ProphecyConfig.ProphecyConfig.__logger = Logging.logging.getLogger('ProphecyControl')
staticprivate

Setup athena-compatible logger.

Definition at line 16 of file ProphecyConfig.py.

◆ __output_events_file_name

str python.ProphecyConfig.ProphecyConfig.__output_events_file_name = 'ProphecyOTF._1.events'
private

This needs to be set so that Generate_trf finds an appropriate file format for showering.

Definition at line 25 of file ProphecyConfig.py.

◆ __run_card_decorators

list python.ProphecyConfig.ProphecyConfig.__run_card_decorators = []
private

Definition at line 30 of file ProphecyConfig.py.

◆ __run_directory

python.ProphecyConfig.ProphecyConfig.__run_directory = os.environ['PWD']
staticprivate

Definition at line 13 of file ProphecyConfig.py.

◆ _prophecy_executable

python.ProphecyConfig.ProphecyConfig._prophecy_executable = 'Prophecy4f'
staticprotected

This must be defined by each derived class - don't change it in the jobOptions!

Print final preparation message.

For rel 21.6, no longer need to set explicit path because prophecy4f is in $PATH

Definition at line 20 of file ProphecyConfig.py.

◆ fixed_parameters

python.ProphecyConfig.ProphecyConfig.fixed_parameters

Write out final runcard.

Definition at line 75 of file ProphecyConfig.py.

◆ nEvents

python.ProphecyConfig.ProphecyConfig.nEvents = int( 1.1 * runArgs.maxEvents + 0.5 )

Add universal functionality.

Print final preparation message.

Initialise values from runArgs

Definition at line 41 of file ProphecyConfig.py.

◆ nEvents_weighted

python.ProphecyConfig.ProphecyConfig.nEvents_weighted

Print final preparation message.

Definition at line 45 of file ProphecyConfig.py.

◆ output_events_file_name

python.ProphecyConfig.ProphecyConfig.output_events_file_name

Move output to correctly named file.

Definition at line 136 of file ProphecyConfig.py.

◆ random_seed

python.ProphecyConfig.ProphecyConfig.random_seed = runArgs.randomSeed

Definition at line 43 of file ProphecyConfig.py.

◆ run_card_decorators

python.ProphecyConfig.ProphecyConfig.run_card_decorators

Finalise registered decorators.

Definition at line 60 of file ProphecyConfig.py.

◆ run_card_path

python.ProphecyConfig.ProphecyConfig.run_card_path

Write out final runcard.

Definition at line 73 of file ProphecyConfig.py.

◆ run_directory

python.ProphecyConfig.ProphecyConfig.run_directory

Definition at line 249 of file ProphecyConfig.py.

◆ running_process

list python.ProphecyConfig.ProphecyConfig.running_process = []

Remove any existing .lhe files to avoid repeated events.

The following is only needed for newer installation of prophecy?? RDS 2019/07 Create dirs UNWEIGHTEDEVENTS and HISTUNWEIGHTED

Initialise generation process tracker

Definition at line 116 of file ProphecyConfig.py.


The documentation for this class was generated from the following file: