Project
Loading...
Searching...
No Matches
o2::eventgen::GeneratorFileOrCmd Struct Reference

#include <GeneratorFileOrCmd.h>

Inherited by o2::eventgen::GeneratorHepMC, and o2::eventgen::GeneratorTParticle.

Public Member Functions

void setup (const GeneratorFileOrCmdParam &param, const conf::SimConfig &config)
 
void setup (const FileOrCmdGenConfig &param, const conf::SimConfig &config)
 
void setCmd (const std::string &cmd)
 
void setCmdPid (const pid_t cmdPid)
 
void setNEvents (unsigned int nev)
 
void setSeed (unsigned long seed)
 
void setBmax (float bmax)
 
void setFileNames (const std::string &filenames)
 
void setOutputSwitch (const std::string &opt)
 
void setSeedSwitch (const std::string &opt)
 
void setNEventsSwitch (const std::string &opt)
 
void setBmaxSwitch (const std::string &opt)
 
void setBackgroundSwitch (const std::string &opt)
 
void setWait (int miliseconds=500)
 

Protected Member Functions

virtual std::string makeCmdLine () const
 
virtual bool executeCmdLine (const std::string &cmd)
 
virtual bool terminateCmd ()
 
virtual bool makeTemp (const bool &)
 
virtual bool removeTemp () const
 
virtual bool makeFifo () const
 
virtual bool ensureFiles ()
 
virtual void waitForData (const std::string &filename) const
 

Protected Attributes

std::string mCmd = ""
 
std::list< std::string > mFileNames
 
std::string mTemporary
 
unsigned int mNEvents = 0
 
unsigned long mSeed = 0
 
float mBmax = -1.f
 
std::string mOutputSwitch = ">"
 
std::string mSeedSwitch = "-s"
 
std::string mNEventsSwitch = "-n"
 
std::string mBmaxSwitch = "-b"
 
std::string mBackgroundSwitch = "&"
 
int mWait = 500
 
int mCmdPid = -1
 

Detailed Description

Service class for either reading from a file or executing a program writing to a specific file

Definition at line 31 of file GeneratorFileOrCmd.h.

Member Function Documentation

◆ ensureFiles()

bool o2::eventgen::GeneratorFileOrCmd::ensureFiles ( )
protectedvirtual

Ensure that all files in the list of file names exists. If any of te file names point to a net resource (e.g., alien://or https://) then this member function should not be called

The file names registered are replaced with their canonical path equivalents.

Returns
true if all currently registered file names can be found.

Definition at line 251 of file GeneratorFileOrCmd.cxx.

◆ executeCmdLine()

bool o2::eventgen::GeneratorFileOrCmd::executeCmdLine ( const std::string &  cmd)
protectedvirtual

Execute a command line (presumably formatted by makeCmdLine). If the command failed to execute, then make it a fatal error.

Parameters
cmdCommand line to execute, presumabley formatted by makeCmdLine.
Returns
true if the background command line was executed, false otherwise.

Definition at line 120 of file GeneratorFileOrCmd.cxx.

◆ makeCmdLine()

std::string o2::eventgen::GeneratorFileOrCmd::makeCmdLine ( ) const
protectedvirtual

Format a command line using the set command line, option flags, and option values.

Returns
formatted command line.

Definition at line 100 of file GeneratorFileOrCmd.cxx.

◆ makeFifo()

bool o2::eventgen::GeneratorFileOrCmd::makeFifo ( ) const
protectedvirtual

Make a fifo at the location of the first element of the list of file names (presumably a temporary file as created by makeTemp).

Returns
true if the FIFo was made correctly

Definition at line 233 of file GeneratorFileOrCmd.cxx.

◆ makeTemp()

bool o2::eventgen::GeneratorFileOrCmd::makeTemp ( const bool &  fromName)
protectedvirtual

Create a temporary file (and close it immediately). On success, the list of file names is cleared and the name of the temporary file set as the sole element in that list.

Returns
true if the temporary file name was generated successfully.

Definition at line 169 of file GeneratorFileOrCmd.cxx.

◆ removeTemp()

bool o2::eventgen::GeneratorFileOrCmd::removeTemp ( ) const
protectedvirtual

Remove the temporary file if it was set and it exists.

Returns
true if the temporary file was removed.

Definition at line 206 of file GeneratorFileOrCmd.cxx.

◆ setBackgroundSwitch()

void o2::eventgen::GeneratorFileOrCmd::setBackgroundSwitch ( const std::string &  opt)
inline

Set the background switch.

Parameters
optCommand line switch (e.g., &) to detach and send the event generator program into the background.

Definition at line 119 of file GeneratorFileOrCmd.h.

◆ setBmax()

void o2::eventgen::GeneratorFileOrCmd::setBmax ( float  bmax)
inline

Set the maximum impact parameter to sample by a background command. This should come from SimConfig::getBMax()

Parameters
bmaxMaximum impact parameter, in fm, to sample. This is passed to the command line via the mBmaxSwitch.

Definition at line 78 of file GeneratorFileOrCmd.h.

◆ setBmaxSwitch()

void o2::eventgen::GeneratorFileOrCmd::setBmaxSwitch ( const std::string &  opt)
inline

Set the maximum impact parameter switch.

Parameters
optCommand line switch (e.g., -b) to specify the maximum impact parameter (in fm) to sample when generating events.

Definition at line 112 of file GeneratorFileOrCmd.h.

◆ setCmd()

void o2::eventgen::GeneratorFileOrCmd::setCmd ( const std::string &  cmd)
inline

Set command to execute in bacground rather than reading from existing file(s)

Parameters
cmdCommand line. Can include options for the program to execute, but should not include pipes.

Definition at line 48 of file GeneratorFileOrCmd.h.

◆ setCmdPid()

void o2::eventgen::GeneratorFileOrCmd::setCmdPid ( const pid_t  cmdPid)
inline

Set command child process PID

Parameters
cmdPidchild process PID.

Definition at line 54 of file GeneratorFileOrCmd.h.

◆ setFileNames()

void o2::eventgen::GeneratorFileOrCmd::setFileNames ( const std::string &  filenames)

Set the file names to read from.

Parameters
filenamesA comma seperated list of files to read from.

Definition at line 91 of file GeneratorFileOrCmd.cxx.

◆ setNEvents()

void o2::eventgen::GeneratorFileOrCmd::setNEvents ( unsigned int  nev)
inline

Set the number of events that a background command should generate. This should come from SimConfig::getNEents.

Parameters
nevNumber of events to generate. This is passed via mNEventsSwitch to the command line.

Definition at line 62 of file GeneratorFileOrCmd.h.

◆ setNEventsSwitch()

void o2::eventgen::GeneratorFileOrCmd::setNEventsSwitch ( const std::string &  opt)
inline

Set the nevents switch.

Parameters
optCommand line switch (e.g., -n) to specify the number of events to generate.

Definition at line 104 of file GeneratorFileOrCmd.h.

◆ setOutputSwitch()

void o2::eventgen::GeneratorFileOrCmd::setOutputSwitch ( const std::string &  opt)
inline

Set the output switch.

Parameters
optCommand line switch (e.g., -o) to specify output file name.

Definition at line 90 of file GeneratorFileOrCmd.h.

◆ setSeed()

void o2::eventgen::GeneratorFileOrCmd::setSeed ( unsigned long  seed)
inline

Set the random number seed that a background command should use. This should come from SimConfig::getStartSeed

Parameters
seedRandom number seed. Will be passed to the commandline using the mSeedSwitch.

Definition at line 70 of file GeneratorFileOrCmd.h.

◆ setSeedSwitch()

void o2::eventgen::GeneratorFileOrCmd::setSeedSwitch ( const std::string &  opt)
inline

Set the seed switch.

Parameters
optCommand line switch (e.g., -s) to specify the random number seed to use when generating events.

Definition at line 97 of file GeneratorFileOrCmd.h.

◆ setup() [1/2]

void o2::eventgen::GeneratorFileOrCmd::setup ( const FileOrCmdGenConfig param,
const conf::SimConfig config 
)

Definition at line 76 of file GeneratorFileOrCmd.cxx.

◆ setup() [2/2]

void o2::eventgen::GeneratorFileOrCmd::setup ( const GeneratorFileOrCmdParam param,
const conf::SimConfig config 
)

Configure the generator from parameters and the general simulation configuration. This is implemented as a member function so as to better facilitate changes.

Definition at line 60 of file GeneratorFileOrCmd.cxx.

◆ setWait()

void o2::eventgen::GeneratorFileOrCmd::setWait ( int  miliseconds = 500)
inline

Set the wait time, in miliseconds, when waiting for data

Definition at line 121 of file GeneratorFileOrCmd.h.

◆ terminateCmd()

bool o2::eventgen::GeneratorFileOrCmd::terminateCmd ( )
protectedvirtual

Terminates the background command using PID of the child process generated by fork.

Returns
true if the process was terminated successfully

Definition at line 145 of file GeneratorFileOrCmd.cxx.

◆ waitForData()

void o2::eventgen::GeneratorFileOrCmd::waitForData ( const std::string &  filename) const
protectedvirtual

Wait for data to be available in case we're executing a background command

Definition at line 265 of file GeneratorFileOrCmd.cxx.

Member Data Documentation

◆ mBackgroundSwitch

std::string o2::eventgen::GeneratorFileOrCmd::mBackgroundSwitch = "&"
protected

The "switch" to put the program being executed in the background.

Definition at line 247 of file GeneratorFileOrCmd.h.

◆ mBmax

float o2::eventgen::GeneratorFileOrCmd::mBmax = -1.f
protected

Maximum impact parameter to sample in case we're executing a command. IF negative, then it is not passed to the command. This is passed to the command via the switch mBmaxSwitch

Definition at line 221 of file GeneratorFileOrCmd.h.

◆ mBmaxSwitch

std::string o2::eventgen::GeneratorFileOrCmd::mBmaxSwitch = "-b"
protected

The switch to specify maximum impact parameter to sample by the program being executed.

Definition at line 242 of file GeneratorFileOrCmd.h.

◆ mCmd

std::string o2::eventgen::GeneratorFileOrCmd::mCmd = ""
protected

Possible command line to execute. The command executed must accept the switches defined below. Note if mOutputSwitch is set to ">", then the program must write data to standard output

Definition at line 194 of file GeneratorFileOrCmd.h.

◆ mCmdPid

int o2::eventgen::GeneratorFileOrCmd::mCmdPid = -1
protected

PID of the background command

Definition at line 255 of file GeneratorFileOrCmd.h.

◆ mFileNames

std::list<std::string> o2::eventgen::GeneratorFileOrCmd::mFileNames
protected

List of file names to read. In case we're executing a command, then there will only be one file name in the list

Definition at line 199 of file GeneratorFileOrCmd.h.

◆ mNEvents

unsigned int o2::eventgen::GeneratorFileOrCmd::mNEvents = 0
protected

Number of events to generate in case we're executing a command. This is passed to the program via the switch mNEventsSwitch

Definition at line 209 of file GeneratorFileOrCmd.h.

◆ mNEventsSwitch

std::string o2::eventgen::GeneratorFileOrCmd::mNEventsSwitch = "-n"
protected

The switch to specify the number of events to generate to the program being executed

Definition at line 237 of file GeneratorFileOrCmd.h.

◆ mOutputSwitch

std::string o2::eventgen::GeneratorFileOrCmd::mOutputSwitch = ">"
protected

Switch to direct output to specified file. In case of a fifo, this should often be ">" - i.e., the standard output of the program is redirected to the fifo.

Definition at line 227 of file GeneratorFileOrCmd.h.

◆ mSeed

unsigned long o2::eventgen::GeneratorFileOrCmd::mSeed = 0
protected

Random number seed to use in case we're executing a command. This is passed to the program via the switch mSeedSwitch

Definition at line 215 of file GeneratorFileOrCmd.h.

◆ mSeedSwitch

std::string o2::eventgen::GeneratorFileOrCmd::mSeedSwitch = "-s"
protected

The switch specify the random number seed to the program executed

Definition at line 232 of file GeneratorFileOrCmd.h.

◆ mTemporary

std::string o2::eventgen::GeneratorFileOrCmd::mTemporary
protected

Name of temporary file, if it was created.

Definition at line 203 of file GeneratorFileOrCmd.h.

◆ mWait

int o2::eventgen::GeneratorFileOrCmd::mWait = 500
protected

Time in miliseconds between each wait for data

Definition at line 251 of file GeneratorFileOrCmd.h.


The documentation for this struct was generated from the following files: