Skip to content
Snippets Groups Projects
Commit 71669760 authored by Dominik Muller's avatar Dominik Muller
Browse files

HepMC3 repeating reader for simulation performance measurements

parent 9fe8b4d1
Branches refactor
No related tags found
No related merge requests found
This diff is collapsed.
// $Id: HepMCReaderAlg.cpp,v 1.33 2009-06-15 17:02:35 gcorti Exp $
// Include files
#include <map>
// from Event
#include "Event/GenFSR.h"
#include "Event/GenFSRMTManager.h"
// from LHCb
#include "Kernel/ParticleID.h"
// local
#include "HepMCReaderAlg.h"
// HepMC
#include "HepMC3/Attribute.h"
#include "HepMC3/GenParticle.h"
#include "HepMC3/GenVertex.h"
#include "NewRnd/RndGlobal.h"
#include "HepMC3/ReaderAscii.h"
#include "HepMC3/ReaderHEPEVT.h"
//#include "HepMC3/ReaderRoot.h"
//#include "HepMC3/ReaderRootTree.h"
//-----------------------------------------------------------------------------
// Implementation file for class : HepMCReaderAlg
//
// 2005-08-11 : Patrick Robbe
//-----------------------------------------------------------------------------
// Declaration of the Algorithm Factory
DECLARE_COMPONENT( HepMCReaderAlg )
//=============================================================================
// Initialisation. Check parameters
//=============================================================================
StatusCode HepMCReaderAlg::initialize() {
StatusCode sc = MultiTransformer::initialize();
HepMC3::Reader* m_reader = nullptr;
if ( sc.isFailure() ) return sc;
if ( m_FileName != "" ) {
// if ( m_reader_name == "ReaderRoot" ) {
// m_reader = new HepMC3::ReaderRoot( m_FileName );
//} else if ( m_reader_name == "ReaderRootTree" ) {
// m_reader = new HepMC3::ReaderRootTree( m_FileName );
if ( m_reader_name == "ReaderAscii" ) {
m_reader = new HepMC3::ReaderAscii( m_FileName );
} else if ( m_reader_name == "ReaderHEPEVT" ) {
m_reader = new HepMC3::ReaderHEPEVT( m_FileName );
} else {
error() << "No valid reader for HepMC specified. Will not write anything." << endmsg;
}
}
// Count the number of events in the file
HepMC3::GenEvent evt{};
while ( !m_reader->failed() ) {
m_reader->read_event( evt );
m_events_in_file++;
}
debug() << "==> Initialize" << endmsg;
return StatusCode::SUCCESS;
}
//=============================================================================
// Main execution
//=============================================================================
std::tuple<std::vector<HepMC3::GenEvent>, LHCb::GenCollisions, LHCb::GenHeader> HepMCReaderAlg::
operator()( const LHCb::GenHeader& old_gen_header ) const {
HepMC3::Reader* m_reader = nullptr;
// Copy the old event header
LHCb::GenHeader theGenHeader = old_gen_header;
// Create temporary containers for this event
std::vector<HepMC3::GenEvent> theEvents;
LHCb::GenCollisions theCollisions;
if ( m_FileName != "" ) {
// if ( m_reader_name == "ReaderRoot" ) {
// m_reader = new HepMC3::ReaderRoot( m_FileName );
//} else if ( m_reader_name == "ReaderRootTree" ) {
// m_reader = new HepMC3::ReaderRootTree( m_FileName );
if ( m_reader_name == "ReaderAscii" ) {
m_reader = new HepMC3::ReaderAscii( m_FileName );
} else if ( m_reader_name == "ReaderHEPEVT" ) {
m_reader = new HepMC3::ReaderHEPEVT( m_FileName );
} else {
error() << "No valid reader for HepMC specified. Will not write anything." << endmsg;
}
}
// Count the number of events in the file
theEvents.reserve( m_events_in_file );
while ( !m_reader->failed() ) {
m_reader->read_event( theEvents.emplace_back() );
if ( !m_reader->failed() ) theCollisions.insert( new LHCb::GenCollision{} );
}
theEvents.pop_back();
return std::make_tuple( std::move( theEvents ), std::move( theCollisions ), std::move( theGenHeader ) );
}
#pragma once
#include "GaudiAlg/Transformer.h"
#include <array>
#include <atomic>
#include <string>
#include <tuple>
#include "Event/GenFSR.h"
// Forward declarations
class ISampleHepMCReaderAlgTool;
class IPileUpTool;
class IDecayTool;
class IVertexSmearingTool;
class IFullGenEventCutTool;
class ICounterLogFile;
#include "Defaults/Locations.h"
#include "Event/GenCollision.h"
#include "Event/GenHeader.h"
#include "HepMC3/GenEvent.h"
#include "HepMC3/Reader.h"
#include "NewRnd/RndAlgSeeder.h"
namespace HepMC3
{
class GenParticle;
}
/** @class HepMCReaderAlg HepMCReaderAlg.h "HepMCReaderAlg.h"
*
* Replaces the main Generation and GenRndInit algorithm by reading HepMC3 events from
* a file and performing all necessary initialisation previously done by GenRndInit.
* Intended for performance tests of the detector simulation step
*
* @author Dominik Muller
* @date 2019-08-20
*/
class HepMCReaderAlg : public Gaudi::Functional::MultiTransformer<
std::tuple<std::vector<HepMC3::GenEvent>, LHCb::GenCollisions, LHCb::GenHeader>( const LHCb::GenHeader& )>{
private:
Gaudi::Property<std::string> m_FileName{this, "FileName", ""};
Gaudi::Property<std::string> m_reader_name{
this, "Reader", "ReaderRootTree", "Reader to use. Options: [ReaderRoot, ReaderRootTree, ReaderAscii, ReaderHEPEVT]"};
public:
/// Standard constructor
HepMCReaderAlg( const std::string& name, ISvcLocator* pSvcLocator )
: MultiTransformer( name, pSvcLocator,
{KeyValue{"GenHeaderInputLocation", Gaussino::GenHeaderLocation::PreGeneration}},
{{KeyValue{"HepMCEventLocation", Gaussino::HepMCEventLocation::Default},
KeyValue{"GenCollisionLocation", LHCb::GenCollisionLocation::Default},
KeyValue{"GenHeaderOutputLocation", Gaussino::GenHeaderLocation::Default}}} )
{
}
virtual ~HepMCReaderAlg() = default;
virtual StatusCode initialize() override;
virtual std::tuple<std::vector<HepMC3::GenEvent>, LHCb::GenCollisions, LHCb::GenHeader>
operator()( const LHCb::GenHeader& ) const override;
private:
std::atomic_size_t m_events_in_file{0};
mutable std::mutex m_writer_lock;
Gaudi::Property<std::string> m_FSRName{this, "GenFSRLocation", LHCb::GenFSRLocation::Default,
"Location where to store FSR counters"};
};
......@@ -97,6 +97,21 @@ def configure_generationMT(**kwargs):
return gen
def configure_benchmark_reader(**kwargs):
"""Simple utility function to create and configure a Generation instance
:**kwargs: Optional keyword arguments (not curently used)
:returns: Generation instance
"""
from Configurables import HepMCReaderAlg
gen = HepMCReaderAlg()
gen.Reader = 'ReaderAscii'
gen.FileName = '$GENERATORSROOT/data/default_ascii_event.txt'
return gen
def configure_rnd_init(**kwargs):
"""Simple utility function to create and configure an instance GenRndInit
......
......@@ -9,6 +9,7 @@ from Gaussino.GenUtils import configure_pgun, configure_generation
from Gaussino.GenUtils import configure_generationMT
from Gaussino.GenUtils import configure_rnd_init, configure_gen_monitor
from Gaussino.GenUtils import configure_hepmc_writer
from Gaussino.GenUtils import configure_benchmark_reader
class GenPhase(ConfigurableUser):
......@@ -21,6 +22,7 @@ class GenPhase(ConfigurableUser):
'PGUN': configure_pgun,
'P8MB': configure_generation,
'P8MBMT': configure_generationMT,
'SIMBM': configure_benchmark_reader,
}
__slots__ = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment