ATLAS Offline Software
Public Member Functions | Public Attributes | Private Attributes | Static Private Attributes | List of all members
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 Member Functions

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

Public Attributes

 nEvents
 Add universal functionality. More...
 
 random_seed
 
 nEvents_weighted
 
 running_process
 Initialise timer. More...
 

Private Attributes

 __output_events_file_name
 This needs to be set so that Generate_trf finds an appropriate file format for showering. More...
 
 __fixed_parameters
 Set up lists of parameters and decorators. More...
 
 __configurable_parameters
 
 __run_card_decorators
 
 __enable_reweighting
 Finalise registered decorators. More...
 

Static Private Attributes

 __run_directory = os.environ['PWD']
 
 __logger = Logging.logging.getLogger('ProphecyControl')
 Setup athena-compatible logger. More...
 
string _prophecy_executable = 'Prophecy4f'
 This must be defined by each derived class - don't change it in the jobOptions! For rel 21.6, no longer need to set explicit path because prophecy4f is in $PATH. More...
 

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.

Constructor & Destructor Documentation

◆ __init__()

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

Reimplemented in python.ProphecyPowhegDefault.ProphecyPowhegDefault.

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()

def 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()

def 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()

def 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()

def 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()

def 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()

def 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()

def 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()

def 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 

◆ generateRunCard()

def 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()

def 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 

◆ output_events_file_name() [1/2]

def 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]

def 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()

def 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()

def 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()

def 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()

def 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()

def 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

python.ProphecyConfig.ProphecyConfig.__configurable_parameters
private

Definition at line 29 of file ProphecyConfig.py.

◆ __enable_reweighting

python.ProphecyConfig.ProphecyConfig.__enable_reweighting
private

Finalise registered decorators.

Print list of configurable parameters for users Add configurable parameters to fixed list Write out final runcard

Definition at line 80 of file ProphecyConfig.py.

◆ __fixed_parameters

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

python.ProphecyConfig.ProphecyConfig.__output_events_file_name
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

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

string python.ProphecyConfig.ProphecyConfig._prophecy_executable = 'Prophecy4f'
staticprivate

This must be defined by each derived class - don't change it in the jobOptions! For rel 21.6, no longer need to set explicit path because prophecy4f is in $PATH.

Definition at line 20 of file ProphecyConfig.py.

◆ nEvents

python.ProphecyConfig.ProphecyConfig.nEvents

Add universal functionality.

Initialise values from runArgs

Definition at line 41 of file ProphecyConfig.py.

◆ nEvents_weighted

python.ProphecyConfig.ProphecyConfig.nEvents_weighted

Definition at line 47 of file ProphecyConfig.py.

◆ random_seed

python.ProphecyConfig.ProphecyConfig.random_seed

Definition at line 43 of file ProphecyConfig.py.

◆ running_process

python.ProphecyConfig.ProphecyConfig.running_process

Initialise timer.

Setup heartbeat thread 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:
grepfile.info
info
Definition: grepfile.py:38
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
generateEvents
void generateEvents(int eventMax)
Definition: MDT_ResponseTest.cxx:46
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
python.DecoratorFactory.decorate
def decorate(hto4l_controller, decorator, **kwargs)
Definition: Hto4lControl/python/DecoratorFactory.py:5
python.processes.powheg.ZZ.logger
logger
Get handle to Athena logging.
Definition: ZZ.py:7
python.MadGraphUtils.generate
def generate(process_dir='PROC_mssm_0', grid_pack=False, gridpack_compile=False, extlhapath=None, required_accuracy=0.01, runArgs=None, bias_module=None, requirePMGSettings=False)
Definition: MadGraphUtils.py:391
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
ProphecyPowhegCommon.output_events_file_name
output_events_file_name
Definition: ProphecyPowhegCommon.py:18