Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test getting cellID #65

Merged
merged 4 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ add_test(NAME CreateExampleEventData
COMMAND ${K4RUN} options/createExampleEventData.py)
set_test_env(CreateExampleEventData)

add_test(NAME CreateExampleEventData_cellID
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} options/createExampleEventData_cellID.py)
set_test_env(CreateExampleEventData_cellID)

add_test(NAME TwoProducers
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
COMMAND ${K4RUN} options/TwoProducers.py --filename output_k4fwcore_test_twoproducer2.root --magicNumberOffset.Producer2 12345 --Producer1.magicNumberOffset 54321 )
Expand Down
24 changes: 24 additions & 0 deletions test/k4FWCoreTest/options/createExampleEventData_cellID.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from Gaudi.Configuration import *

from Configurables import k4DataSvc
podioevent = k4DataSvc("EventDataSvc")

from Configurables import k4FWCoreTest_cellID_writer, k4FWCoreTest_cellID_reader
producer = k4FWCoreTest_cellID_writer()
consumer = k4FWCoreTest_cellID_reader()

from Configurables import PodioOutput
out = PodioOutput("out")
out.filename = "output_k4test_exampledata_cellid.root"
out.outputCommands = ["keep *"]

from Configurables import ApplicationMgr
ApplicationMgr( TopAlg=[producer, consumer, out],
EvtSel="NONE",
EvtMax=10,
ExtSvc=[podioevent],
OutputLevel=INFO,
StopOnSignal=True,
)


35 changes: 35 additions & 0 deletions test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "k4FWCoreTest_cellID_reader.h"
#include "k4FWCoreTest_cellID_writer.h"


DECLARE_COMPONENT(k4FWCoreTest_cellID_reader)

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

k4FWCoreTest_cellID_reader::~k4FWCoreTest_cellID_reader() {}

StatusCode k4FWCoreTest_cellID_reader::initialize() {
if (GaudiAlgorithm::initialize().isFailure()) {
return StatusCode::FAILURE;
}
return StatusCode::SUCCESS;
}

StatusCode k4FWCoreTest_cellID_reader::execute() {

const auto simtrackerhits_coll = m_simTrackerHitReaderHandle.get();

auto collID = simtrackerhits_coll->getID();
const auto cellIDstr = m_simTrackerHitReaderHandle.getCollMetadataCellID(collID);

if (cellIDstr != cellIDtest) {
std::cout << "ERROR cellID is: " << cellIDstr << std::endl;
return StatusCode::FAILURE;
}

return StatusCode::SUCCESS;
}

StatusCode k4FWCoreTest_cellID_reader::finalize() { return GaudiAlgorithm::finalize(); }
38 changes: 38 additions & 0 deletions test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_reader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef K4FWCORE_K4FWCORETEST_CELLID_READER
#define K4FWCORE_K4FWCORETEST_CELLID_READER

// GAUDI
#include "GaudiAlg/GaudiAlgorithm.h"

// edm4hep
#include "k4FWCore/DataHandle.h"
#include "TTree.h"

// datamodel
#include "edm4hep/SimTrackerHitCollection.h"

/** @class k4FWCoreTest_cellID
* Lightweight producer for edm data to test cellID reading
*/
class k4FWCoreTest_cellID_reader : public GaudiAlgorithm {
public:
explicit k4FWCoreTest_cellID_reader(const std::string&, ISvcLocator*);
virtual ~k4FWCoreTest_cellID_reader();
/** Initialize.
* @return status code
*/
virtual StatusCode initialize() final;
/** Execute.
* @return status code
*/
virtual StatusCode execute() final;
/** Finalize.
* @return status code
*/
virtual StatusCode finalize() final;

private:
/// Handle for the SimTrackerHits to be read
DataHandle<edm4hep::SimTrackerHitCollection> m_simTrackerHitReaderHandle{"SimTrackerHits", Gaudi::DataHandle::Reader, this};
};
#endif /* K4FWCORE_K4FWCORETEST_CELLID */
41 changes: 41 additions & 0 deletions test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_writer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "k4FWCoreTest_cellID_writer.h"


DECLARE_COMPONENT(k4FWCoreTest_cellID_writer)

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");
}

k4FWCoreTest_cellID_writer::~k4FWCoreTest_cellID_writer() {}

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;
}

StatusCode k4FWCoreTest_cellID_writer::execute() {

edm4hep::SimTrackerHitCollection* simTrackerHits = m_simTrackerHitWriterHandle.createAndPut();
auto hit = simTrackerHits->create();
hit.setPosition({3, 4, 5});

auto& collmd = m_podioDataSvc->getProvider().getCollectionMetaData(simTrackerHits->getID());
collmd.setValue("CellIDEncodingString", cellIDtest);

return StatusCode::SUCCESS;
}

StatusCode k4FWCoreTest_cellID_writer::finalize() { return GaudiAlgorithm::finalize(); }
44 changes: 44 additions & 0 deletions test/k4FWCoreTest/src/components/k4FWCoreTest_cellID_writer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef K4FWCORE_K4FWCORETEST_CELLID_WRITER
#define K4FWCORE_K4FWCORETEST_CELLID_WRITER

// GAUDI
#include "GaudiAlg/GaudiAlgorithm.h"

// edm4hep
#include "k4FWCore/DataHandle.h"
#include "TTree.h"

// datamodel
#include "edm4hep/SimTrackerHitCollection.h"

const std::string cellIDtest = "M:3,S-1:3,I:9,J:9,K-1:6";

/** @class k4FWCoreTest_cellID
* Lightweight producer for edm data to test cellID
*/
class k4FWCoreTest_cellID_writer : public GaudiAlgorithm {
public:
explicit k4FWCoreTest_cellID_writer(const std::string&, ISvcLocator*);
virtual ~k4FWCoreTest_cellID_writer();
/** Initialize.
* @return status code
*/
virtual StatusCode initialize() final;
/** Execute.
* @return status code
*/
virtual StatusCode execute() final;
/** Finalize.
* @return status code
*/
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};

};
#endif /* K4FWCORE_K4FWCORETEST_CELLID_WRITER */