Skip to content

Commit

Permalink
set a CellID and check for it
Browse files Browse the repository at this point in the history
  • Loading branch information
fdplacido authored and vvolkl committed Oct 20, 2021
1 parent 9022a4d commit 5c278e8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
DECLARE_COMPONENT(k4FWCoreTest_cellID_reader)

k4FWCoreTest_cellID_reader::k4FWCoreTest_cellID_reader(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {;
// declareProperty("simtrackhits_w", m_simTrackerHitWriterHandle, "Dummy Hit collection Writer");
declareProperty("simtrackhits_r", m_simTrackerHitReaderHandle, "Dummy Hit collection Reader");
}

Expand All @@ -24,7 +23,10 @@ StatusCode k4FWCoreTest_cellID_reader::execute() {
auto collID = simtrackerhits_coll->getID();
const auto cellIDstr = m_simTrackerHitReaderHandle.getCollMetadataCellID(collID);

std::cout << "cellID is: " << cellIDstr << std::endl;
if (cellIDstr != "M:3,S-1:3,I:9,J:9,K-1:6") {
std::cout << "ERROR cellID is: " << cellIDstr << std::endl;
return StatusCode::FAILURE;
}

return StatusCode::SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
#include "edm4hep/SimTrackerHitCollection.h"

/** @class k4FWCoreTest_cellID
* Lightweight producer for edm data for tests that do not depend on the actual
* data content and therefore do not need the simulation machinery.
* Fills data members with increasing integers, together with some offset so that different
* events can be easily distinguished.
*
* Lightweight producer for edm data to test cellID reading
*/
class k4FWCoreTest_cellID_reader : public GaudiAlgorithm {
public:
Expand All @@ -36,8 +32,6 @@ class k4FWCoreTest_cellID_reader : public GaudiAlgorithm {
virtual StatusCode finalize() final;

private:
/// Handle for the SimTrackerHits to be written
// DataHandle<edm4hep::SimTrackerHitCollection> m_simTrackerHitWriterHandle{"SimTrackerHits", Gaudi::DataHandle::Writer, this};
/// Handle for the SimTrackerHits to be read
DataHandle<edm4hep::SimTrackerHitCollection> m_simTrackerHitReaderHandle{"SimTrackerHits", Gaudi::DataHandle::Reader, this};
};
Expand Down
19 changes: 18 additions & 1 deletion test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

DECLARE_COMPONENT(k4FWCoreTest_cellID_writer)

k4FWCoreTest_cellID_writer::k4FWCoreTest_cellID_writer(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {;
k4FWCoreTest_cellID_writer::k4FWCoreTest_cellID_writer(const std::string& aName, ISvcLocator* aSvcLoc)
: GaudiAlgorithm(aName, aSvcLoc), m_eventDataSvc("EventDataSvc", "k4FWCoreTest_cellID_writer") {;
declareProperty("simtrackhits_w", m_simTrackerHitWriterHandle, "Dummy Hit collection Writer");
}

Expand All @@ -13,6 +14,15 @@ StatusCode k4FWCoreTest_cellID_writer::initialize() {
if (GaudiAlgorithm::initialize().isFailure()) {
return StatusCode::FAILURE;
}

StatusCode sc = m_eventDataSvc.retrieve();
m_podioDataSvc = dynamic_cast<PodioDataSvc*>( m_eventDataSvc.get());

if (sc == StatusCode::FAILURE) {
error() << "Error retrieving Event Data Service" << endmsg;
return StatusCode::FAILURE;
}

return StatusCode::SUCCESS;
}

Expand All @@ -22,6 +32,13 @@ StatusCode k4FWCoreTest_cellID_writer::execute() {
auto hit = simTrackerHits->create();
hit.setPosition({3, 4, 5});

auto* collids = m_podioDataSvc->getCollectionIDs();

for (auto& id : collids->ids()) {
auto& collmd = m_podioDataSvc->getProvider().getCollectionMetaData(id);
collmd.setValue("CellIDEncodingString", "M:3,S-1:3,I:9,J:9,K-1:6");
}

return StatusCode::SUCCESS;
}

Expand Down
3 changes: 3 additions & 0 deletions test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class k4FWCoreTest_cellID_writer : public GaudiAlgorithm {
virtual StatusCode finalize() final;

private:
PodioDataSvc* m_podioDataSvc;
ServiceHandle<IDataProviderSvc> m_eventDataSvc;

/// Handle for the SimTrackerHits to be written
DataHandle<edm4hep::SimTrackerHitCollection> m_simTrackerHitWriterHandle{"SimTrackerHits", Gaudi::DataHandle::Writer, this};

Expand Down

0 comments on commit 5c278e8

Please sign in to comment.