Skip to content

Commit

Permalink
Allow to pass particle properties table in form of stringstream to co…
Browse files Browse the repository at this point in the history
…nstructor of EvtGen

Summary: In LHCb Gauss we are generating particle properties table on fly, which has to be written to the file in order to pass it to EvtGen constructor. This has the side effect that there is no good way of creating temporary file in safe way and current compilers do not like the function used to create temporary files as they are prone to race condition. In order to get rid of it, I added to EvtGen possibility to pass particle properties table in form of stringstream so we can eventually modify Gauss not to write temporary file at all or if needed write it in way which is not prone to race condition. Change here is fully transparent in a sense that existing code using EvtGen will work without any change.

Test Plan: I did run one of the tests with all changes and it works as expected.

Reviewers: tlatham, jback

Reviewed By: tlatham, jback

Tags: #evtgen

Differential Revision: https://phab.hepforge.org/D43
  • Loading branch information
Michal Kreps committed Jan 7, 2021
1 parent 5948de8 commit d0edfa8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
17 changes: 15 additions & 2 deletions EvtGen/EvtGen.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "EvtGenBase/EvtPDL.hh"

#include <list>
#include <iostream>

class EvtParticle;
class EvtRandomEngine;
Expand All @@ -36,14 +37,19 @@ class EvtHepMCEvent;

class EvtGen {
public:
EvtGen( const char* const decayName, const char* const pdtTableName,
EvtGen( const std::string& decayName, const std::string& pdtTableName,
EvtRandomEngine* randomEngine = 0, EvtAbsRadCorr* isrEngine = 0,
const std::list<EvtDecayBase*>* extraModels = 0, int mixingType = 1,
bool useXml = false );

EvtGen( const std::string& decayName, std::istream& pdtTableData,
EvtRandomEngine* randomEngine = 0, EvtAbsRadCorr* isrEngine = 0,
const std::list<EvtDecayBase*>* extraModels = 0, int mixingType = 1,
bool useXml = false );

~EvtGen();

void readUDecay( const char* const udecay_name, bool useXml = false );
void readUDecay( const std::string& udecay_name, bool useXml = false );

EvtHepMCEvent* generateDecay( int PDGid, EvtVector4R refFrameP4,
EvtVector4R translation,
Expand All @@ -52,6 +58,13 @@ class EvtGen {
void generateDecay( EvtParticle* p );

private:

void initialize( const std::string& decayName, std::istream& pdtTable,
EvtRandomEngine* randomEngine = 0,
EvtAbsRadCorr* isrEngine = 0,
const std::list<EvtDecayBase*>* extraModels = 0,
int mixingType = 1, bool useXml = false );

EvtPDL _pdl;
int _mixingType;
};
Expand Down
6 changes: 4 additions & 2 deletions EvtGenBase/EvtPDL.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@

#include <map>
#include <vector>
#include <string>
#include <iostream>

const int SPIN_NAME_LENGTH = 100;

class EvtPDL final {
public:
EvtPDL();

void read( const char* fname );
void readPDT( const std::string fname );
void read( const std::string& fname );
void readPDT( std::istream& data );

static double getMeanMass( EvtId i );
static double getMass( EvtId i );
Expand Down
35 changes: 29 additions & 6 deletions src/EvtGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,35 @@ EvtGen::~EvtGen()
}
}

EvtGen::EvtGen( const char* const decayName, const char* const pdtTableName,
EvtGen::EvtGen( const std::string& decayName, const std::string& pdtTableName,
EvtRandomEngine* randomEngine, EvtAbsRadCorr* isrEngine,
const std::list<EvtDecayBase*>* extraModels, int mixingType,
bool useXml )
{
std::ifstream pdtIn( pdtTableName );
if ( !pdtIn ) {
EvtGenReport( EVTGEN_ERROR, "EvtGen" )
<< "Could not open:" << pdtTableName << "EvtPDL" << endl;
return;
}
initialize( decayName, pdtIn, randomEngine, isrEngine, extraModels,
mixingType, useXml );
pdtIn.close();
}

EvtGen::EvtGen( const std::string& decayName, std::istream& pdtTableData,
EvtRandomEngine* randomEngine, EvtAbsRadCorr* isrEngine,
const std::list<EvtDecayBase*>* extraModels, int mixingType,
bool useXml )
{
initialize( decayName, pdtTableData, randomEngine, isrEngine, extraModels,
mixingType, useXml );
}

void EvtGen::initialize( const std::string& decayName, std::istream& pdtTable,
EvtRandomEngine* randomEngine, EvtAbsRadCorr* isrEngine,
const std::list<EvtDecayBase*>* extraModels,
int mixingType, bool useXml )
{
EvtGenReport( EVTGEN_INFO, "EvtGen" ) << "Initializing EvtGen" << endl;

Expand All @@ -82,10 +107,8 @@ EvtGen::EvtGen( const char* const decayName, const char* const pdtTableName,

EvtGenReport( EVTGEN_INFO, "EvtGen" )
<< "Main decay file name :" << decayName << endl;
EvtGenReport( EVTGEN_INFO, "EvtGen" )
<< "PDT table file name :" << pdtTableName << endl;

_pdl.readPDT( pdtTableName );
_pdl.readPDT( pdtTable );

if ( useXml ) {
EvtDecayTable::getInstance()->readXMLDecayFile( decayName, false );
Expand Down Expand Up @@ -113,11 +136,11 @@ EvtGen::EvtGen( const char* const decayName, const char* const pdtTableName,
EvtGenReport( EVTGEN_INFO, "EvtGen" ) << "Done initializing EvtGen" << endl;
}

void EvtGen::readUDecay( const char* const uDecayName, bool useXml )
void EvtGen::readUDecay( const std::string& uDecayName, bool useXml )
{
ifstream indec;

if ( uDecayName[0] == 0 ) {
if ( uDecayName.size() == 0 ) {
EvtGenReport( EVTGEN_INFO, "EvtGen" )
<< "Is not reading a user decay file!" << endl;
} else {
Expand Down
23 changes: 11 additions & 12 deletions src/EvtGenBase/EvtPDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ EvtPDL::EvtPDL()
}
}

void EvtPDL::read( const char* fname )
void EvtPDL::read( const std::string& fname )
{
readPDT( fname );
std::ifstream pdtIn( fname );
if ( !pdtIn ) {
EvtGenReport( EVTGEN_ERROR, "EvtGen" )
<< "Could not open:" << fname << "EvtPDL" << endl;
return;
}
readPDT( pdtIn );
pdtIn.close();
}

void EvtPDL::readPDT( const std::string fname )
void EvtPDL::readPDT( std::istream& indec )
{
ifstream indec;

indec.open( fname.c_str() );

char cmnd[100];
char xxxx[100];

Expand All @@ -76,11 +79,7 @@ void EvtPDL::readPDT( const std::string fname )
int lundkc;
EvtId i;

if ( !indec ) {
EvtGenReport( EVTGEN_ERROR, "EvtGen" )
<< "Could not open:" << fname.c_str() << "EvtPDL" << endl;
return;
}
indec.seekg( 0, std::ios::beg );

do {
char ch, ch1;
Expand Down

0 comments on commit d0edfa8

Please sign in to comment.