Skip to content

Commit

Permalink
Merge branch 'master' into ddsim-set-run-event-track-step-stack-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusFrankATcernch authored Feb 11, 2024
2 parents c452e5a + 7e91000 commit 088ca64
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
8 changes: 8 additions & 0 deletions DDDigi/io/DigiEdm4hepInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

// podio/edm4hep include files
#include <podio/Frame.h>
#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
#include <podio/ROOTReader.h>
#else
#include <podio/ROOTFrameReader.h>
#endif

#include <edm4hep/SimTrackerHit.h>
#include <edm4hep/SimCalorimeterHit.h>
Expand Down Expand Up @@ -47,7 +51,11 @@ namespace dd4hep {
const podio::CollectionBase* get(const std::string& nam) const { return frame.get(nam); }
};

#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
using reader_t = podio::ROOTReader;
#else
using reader_t = podio::ROOTFrameReader;
#endif
using frame_t = edm4hep_read_frame_t;

/// EDM4HEP Digi input reader: Collection descriptor definition
Expand Down
21 changes: 16 additions & 5 deletions DDDigi/io/DigiEdm4hepOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@

/// edm4hep include files
#include <podio/CollectionBase.h>
#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
#include <podio/ROOTWriter.h>
#else
#include <podio/ROOTFrameWriter.h>
#endif
#include <podio/Frame.h>
#include <edm4hep/SimTrackerHit.h>
#include <edm4hep/MCParticleCollection.h>
#include <edm4hep/TrackerHitCollection.h>
#include <edm4hep/EventHeaderCollection.h>
#include <edm4hep/CalorimeterHitCollection.h>
#include <edm4hep/CaloHitContributionCollection.h>
Expand All @@ -50,13 +53,17 @@ namespace dd4hep {
using headercollection_t = std::pair<std::string,std::unique_ptr<edm4hep::EventHeaderCollection> >;
DigiEdm4hepOutput* m_parent { nullptr };
/// Reference to podio writer
#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
std::unique_ptr<podio::ROOTWriter> m_writer { };
#else
std::unique_ptr<podio::ROOTFrameWriter> m_writer { };
#endif
/// edm4hep event header collection
headercollection_t m_header { };
/// MC particle collection
particlecollection_t m_particles { };
/// Collection of all edm4hep tracker object collections
std::map<std::string, std::unique_ptr<edm4hep::TrackerHitCollection> > m_tracker_collections;
std::map<std::string, std::unique_ptr<edm4hep::TrackerHit3DCollection> > m_tracker_collections;
/// Collection of all edm4hep calorimeter object collections
std::map<std::string, std::unique_ptr<edm4hep::CalorimeterHitCollection> > m_calo_collections;
/// Output section name
Expand Down Expand Up @@ -114,7 +121,7 @@ namespace dd4hep {
m_particles = std::make_pair(nam, std::make_unique<edm4hep::MCParticleCollection>());
}
else if ( typ == "TrackerHits" ) {
m_tracker_collections.emplace(nam, std::make_unique<edm4hep::TrackerHitCollection>());
m_tracker_collections.emplace(nam, std::make_unique<edm4hep::TrackerHit3DCollection>());
}
else if ( typ == "CalorimeterHits" ) {
m_calo_collections.emplace(nam, std::make_unique<edm4hep::CalorimeterHitCollection>());
Expand Down Expand Up @@ -190,7 +197,11 @@ namespace dd4hep {
clear();
m_writer.reset();
std::string fname = m_parent->next_stream_name();
#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
m_writer = std::make_unique<podio::ROOTWriter>(fname);
#else
m_writer = std::make_unique<podio::ROOTFrameWriter>(fname);
#endif
m_parent->info("+++ Opened EDM4HEP output file %s", fname.c_str());
}

Expand Down Expand Up @@ -274,7 +285,7 @@ namespace dd4hep {
template <typename T> void
DigiEdm4hepOutputProcessor::convert_depos(const T& cont,
const predicate_t& predicate,
edm4hep::TrackerHitCollection* collection) const
edm4hep::TrackerHit3DCollection* collection) const
{
std::array<float,6> covMat = {0., 0., m_pointResoutionRPhi*m_pointResoutionRPhi,
0., 0., m_pointResoutionZ*m_pointResoutionZ
Expand Down Expand Up @@ -308,7 +319,7 @@ namespace dd4hep {
if ( !cont.empty() ) {
switch(cont.data_type) {
case SegmentEntry::TRACKER_HITS:
convert_depos(cont, predicate, static_cast<edm4hep::TrackerHitCollection*>(coll));
convert_depos(cont, predicate, static_cast<edm4hep::TrackerHit3DCollection*>(coll));
break;
case SegmentEntry::CALORIMETER_HITS:
convert_depos(cont, predicate, static_cast<edm4hep::CalorimeterHitCollection*>(coll));
Expand Down
13 changes: 10 additions & 3 deletions DDDigi/io/DigiEdm4hepOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
#include <DDDigi/DigiOutputAction.h>

/// C/C++ include files
#if __has_include("edm4hep/TrackerHitCollection.h")
#include <edm4hep/TrackerHitCollection.h>
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
}
#else
#include <edm4hep/TrackerHit3DCollection.h>
#endif

/// Forward declarations from edm4hep
namespace edm4hep {
class TrackerHitCollection;
class CalorimeterHitCollection;
}

Expand All @@ -35,7 +42,7 @@ namespace dd4hep {
* Supported output containers types are:
* - edm4hep::MCParticles aka "MCParticles"
* - edm4hep::CalorimeterHitCollection aka "CalorimeterHits"
* - edm4hep::TrackerHitCollection aka "TracketHits"
* - edm4hep::TrackerHit3DCollection aka "TracketHits"
*
* This entity actually is only the work dispatcher:
* It opens files and dumps data into
Expand Down Expand Up @@ -103,7 +110,7 @@ namespace dd4hep {

/// Convert tracker hits to edm4hep
template <typename T> void
convert_depos(const T& cont, const predicate_t& predicate, edm4hep::TrackerHitCollection* collection) const;
convert_depos(const T& cont, const predicate_t& predicate, edm4hep::TrackerHit3DCollection* collection) const;

/// Convert calorimeter hits to edm4hep
template <typename T> void
Expand Down
9 changes: 8 additions & 1 deletion DDDigi/io/DigiIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
#include <edm4hep/SimTrackerHit.h>
#include <edm4hep/MCParticle.h>
#include <edm4hep/MCParticleCollection.h>
#if __has_include("edm4hep/TrackerHitCollection.h")
#include <edm4hep/TrackerHitCollection.h>
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
}
#else
#include <edm4hep/TrackerHit3DCollection.h>
#endif
#include <edm4hep/SimTrackerHitCollection.h>
#include <edm4hep/CalorimeterHitCollection.h>
#include <edm4hep/SimCalorimeterHitCollection.h>
Expand Down Expand Up @@ -224,7 +231,7 @@ namespace dd4hep {
template <> template <>
void data_io<edm4hep_input>::_to_edm4hep(const std::pair<const CellID, EnergyDeposit>& dep,
const std::array<float, 6>& covMat,
edm4hep::TrackerHitCollection& collection,
edm4hep::TrackerHit3DCollection& collection,
int hit_type)

{
Expand Down
12 changes: 12 additions & 0 deletions DDG4/edm4hep/Geant4Output2EDM4hep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
#include <edm4hep/EDM4hepVersion.h>
/// podio include files
#include <podio/Frame.h>
#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
#include <podio/ROOTWriter.h>
#else
#include <podio/ROOTFrameWriter.h>
#endif
#include <podio/podioVersion.h>

/// Namespace for the AIDA detector description toolkit
Expand All @@ -48,7 +52,11 @@ namespace dd4hep {
*/
class Geant4Output2EDM4hep : public Geant4OutputAction {
protected:
#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
using writer_t = podio::ROOTWriter;
#else
using writer_t = podio::ROOTFrameWriter;
#endif
using stringmap_t = std::map< std::string, std::string >;
using trackermap_t = std::map< std::string, edm4hep::SimTrackerHitCollection >;
using calorimeterpair_t = std::pair< edm4hep::SimCalorimeterHitCollection, edm4hep::CaloHitContributionCollection >;
Expand Down Expand Up @@ -238,7 +246,11 @@ void Geant4Output2EDM4hep::beginRun(const G4Run* run) {
}
}
if ( !fname.empty() ) {
#if PODIO_VERSION_MAJOR > 0 || (PODIO_VERSION_MAJOR == 0 && PODIO_VERSION_MINOR >= 99)
m_file = std::make_unique<podio::ROOTWriter>(fname);
#else
m_file = std::make_unique<podio::ROOTFrameWriter>(fname);
#endif
if ( !m_file ) {
fatal("+++ Failed to open output file: %s", fname.c_str());
}
Expand Down

0 comments on commit 088ca64

Please sign in to comment.