Skip to content

Commit

Permalink
Use new MetaDataHandles to be compliant with Frame based I/O (#41)
Browse files Browse the repository at this point in the history
* Use new MetaDataHandles to be compliant with Frame based I/O

* Remove no longer present fatherAlg from instantiation
  • Loading branch information
tmadlener committed Jun 28, 2023
1 parent f8d3ad8 commit 4704fb6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
14 changes: 4 additions & 10 deletions RecCalorimeter/src/components/CreateCaloCells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DECLARE_COMPONENT(CreateCaloCells)

CreateCaloCells::CreateCaloCells(const std::string& name, ISvcLocator* svcLoc) :
GaudiAlgorithm(name, svcLoc), m_geoSvc("GeoSvc", name), m_eventDataSvc("EventDataSvc", "CreateCaloCells") {
GaudiAlgorithm(name, svcLoc), m_geoSvc("GeoSvc", name) {
declareProperty("hits", m_hits, "Hits from which to create cells (input)");
declareProperty("cells", m_cells, "The created calorimeter cells (output)");

Expand Down Expand Up @@ -63,12 +63,9 @@ StatusCode CreateCaloCells::initialize() {
if (m_addPosition){
m_volman = m_geoSvc->lcdd()->volumeManager();
}
StatusCode sc_dataSvc = m_eventDataSvc.retrieve();
m_podioDataSvc = dynamic_cast<PodioDataSvc*>(m_eventDataSvc.get());
if (sc_dataSvc == StatusCode::FAILURE) {
error() << "Error retrieving Event Data Service" << endmsg;
return StatusCode::FAILURE;
}

// Copy over the CellIDEncoding string from the input collection to the output collection
m_cellsCellIDEncoding.put(m_hitsCellIDEncoding.get());

return StatusCode::SUCCESS;
}
Expand Down Expand Up @@ -131,9 +128,6 @@ StatusCode CreateCaloCells::execute() {

// push the CaloHitCollection to event store
m_cells.put(edmCellsCollection);
// Ship the metadata to the new collection
auto& coll_md = m_podioDataSvc->getProvider().getCollectionMetaData(m_cells.get()->getID());
coll_md.setValue("CellIDEncodingString", m_hits.getCollMetadataCellID(hits->getID()));

debug() << "Output Cell collection size: " << edmCellsCollection->size() << endmsg;

Expand Down
6 changes: 4 additions & 2 deletions RecCalorimeter/src/components/CreateCaloCells.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// FCCSW
#include "k4FWCore/DataHandle.h"
#include "k4FWCore/MetaDataHandle.h"
#include "k4Interface/ICalibrateCaloHitsTool.h"
#include "k4Interface/ICalorimeterTool.h"
#include "k4Interface/INoiseCaloCellsTool.h"
Expand Down Expand Up @@ -75,8 +76,11 @@ class CreateCaloCells : public GaudiAlgorithm {

/// Handle for calo hits (input collection)
DataHandle<edm4hep::SimCalorimeterHitCollection> m_hits{"hits", Gaudi::DataHandle::Reader, this};
/// Handle for the cellID encoding string of the input collection
MetaDataHandle<std::string> m_hitsCellIDEncoding{m_hits, "CellIDEncodingString", Gaudi::DataHandle::Reader};
/// Handle for calo cells (output collection)
DataHandle<edm4hep::CalorimeterHitCollection> m_cells{"cells", Gaudi::DataHandle::Writer, this};
MetaDataHandle<std::string> m_cellsCellIDEncoding{m_cells, "CellIDEncodingString", Gaudi::DataHandle::Writer};
/// Name of the detector readout
Gaudi::Property<std::string> m_readoutName{this, "readoutName", "ECalBarrelPhiEta", "Name of the detector readout"};
/// Name of active volumes
Expand Down Expand Up @@ -105,8 +109,6 @@ class CreateCaloCells : public GaudiAlgorithm {
/// Use only volume ID? If false, using PhiEtaSegmentation
bool m_useVolumeIdOnly;

PodioDataSvc* m_podioDataSvc;
ServiceHandle<IDataProviderSvc> m_eventDataSvc;
/// Pointer to the geometry service
ServiceHandle<IGeoSvc> m_geoSvc;
dd4hep::VolumeManager m_volman;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
DECLARE_COMPONENT(CreateCaloCellPositionsFCCee)

CreateCaloCellPositionsFCCee::CreateCaloCellPositionsFCCee(const std::string& name, ISvcLocator* svcLoc)
: GaudiAlgorithm(name, svcLoc), m_eventDataSvc("EventDataSvc", "CreateCaloCellPositionsFCCee") {
: GaudiAlgorithm(name, svcLoc) {
declareProperty("hits", m_hits, "Hit collection (input)");
declareProperty("positionsECalBarrelTool", m_cellPositionsECalBarrelTool,
"Handle for tool to retrieve cell positions in ECal Barrel");
Expand All @@ -31,12 +31,6 @@ CreateCaloCellPositionsFCCee::CreateCaloCellPositionsFCCee(const std::string& na
StatusCode CreateCaloCellPositionsFCCee::initialize() {
StatusCode sc = GaudiAlgorithm::initialize();
if (sc.isFailure()) return sc;
StatusCode sc_dataSvc = m_eventDataSvc.retrieve();
m_podioDataSvc = dynamic_cast<PodioDataSvc*>(m_eventDataSvc.get());
if (sc_dataSvc == StatusCode::FAILURE) {
error() << "Error retrieving Event Data Service" << endmsg;
return sc_dataSvc;
}

if (!m_cellPositionsECalBarrelTool) {
error() << "CellPositionsTool for ECal Barrel is missing!" << endmsg;
Expand Down Expand Up @@ -67,6 +61,9 @@ StatusCode CreateCaloCellPositionsFCCee::initialize() {
return StatusCode::FAILURE;
}

// Copy over the CellIDEncoding string from the input collection to the output collection
m_positionedHitsCellIDEncoding.put(m_hitsCellIDEncoding.get());

return StatusCode::SUCCESS;
}

Expand Down Expand Up @@ -126,9 +123,6 @@ StatusCode CreateCaloCellPositionsFCCee::execute() {
edmPositionedHitCollection->push_back(positionedHit);
}

auto& coll_md = m_podioDataSvc->getProvider().getCollectionMetaData(m_positionedHits.get()->getID());
coll_md.setValue("CellIDEncodingString", m_hits.getCollMetadataCellID(hits->getID()));

debug() << "Output positions collection size: " << edmPositionedHitCollection->size() << endmsg;
return StatusCode::SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// FCCSW
#include "k4FWCore/DataHandle.h"
#include "k4FWCore/MetaDataHandle.h"
#include "k4Interface/ICellPositionsTool.h"

// Gaudi
Expand Down Expand Up @@ -91,10 +92,10 @@ class CreateCaloCellPositionsFCCee : public GaudiAlgorithm {
dd4hep::DDSegmentation::BitFieldCoder* m_decoder = new dd4hep::DDSegmentation::BitFieldCoder("system:4");
/// Input collection
DataHandle<edm4hep::CalorimeterHitCollection> m_hits{"hits/hits", Gaudi::DataHandle::Reader, this};
MetaDataHandle<std::string> m_hitsCellIDEncoding{m_hits, "CellIDEncodingString", Gaudi::DataHandle::Reader};
/// Output collection
DataHandle<edm4hep::CalorimeterHitCollection> m_positionedHits{"hits/positionedHits", Gaudi::DataHandle::Writer, this};
PodioDataSvc* m_podioDataSvc;
ServiceHandle<IDataProviderSvc> m_eventDataSvc;
MetaDataHandle<std::string> m_positionedHitsCellIDEncoding{m_positionedHits, "CellIDEncodingString", Gaudi::DataHandle::Reader};

int m_system_id = m_decoder->index("system");
std::unordered_map<dd4hep::DDSegmentation::CellID, edm4hep::Vector3f> m_positions_cache{};
Expand Down

0 comments on commit 4704fb6

Please sign in to comment.