Skip to content

Commit

Permalink
Run clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Aug 2, 2023
1 parent 691dbc3 commit abfc800
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 146 deletions.
1 change: 0 additions & 1 deletion k4FWCore/components/PodioInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ PodioInput::PodioInput(const std::string& name, ISvcLocator* svcLoc) : Consumer(
}

void PodioInput::operator()() const {

for (auto& collName : m_collectionNames) {
debug() << "Registering collection to read " << collName << endmsg;
if (m_podioDataSvc->readCollection(collName).isFailure()) {
Expand Down
23 changes: 9 additions & 14 deletions test/k4FWCoreTest/src/components/ExampleFunctionalConsumer.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "Gaudi/Property.h"
#include "Gaudi/Algorithm.h"
#include "Gaudi/Property.h"
#include "GaudiAlg/Consumer.h"
#include "k4FWCore/DataWrapper.h"

#include "podio/CollectionBase.h"
#include "edm4hep/MCParticleCollection.h"
#include "podio/CollectionBase.h"

#include <string>

Expand All @@ -17,31 +17,26 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>;
using colltype = DataWrapper<podio::CollectionBase>;

struct ExampleFunctionalConsumer final : Gaudi::Functional::Consumer<void(const colltype& input), BaseClass_t> {

// The pair in KeyValue can be changed from python and it corresponds
// to the name of the input collection
ExampleFunctionalConsumer( const std::string& name, ISvcLocator* svcLoc )
: Consumer( name, svcLoc, KeyValue("InputCollection", "MCParticles")) {}
ExampleFunctionalConsumer(const std::string& name, ISvcLocator* svcLoc)
: Consumer(name, svcLoc, KeyValue("InputCollection", "MCParticles")) {}

// This is the function that will be called to transform the data
// Note that the function has to be const, as well as the collections
// we get from the input
void operator()(const colltype& input) const override {
auto* coll = dynamic_cast<const edm4hep::MCParticleCollection*>(input.getData());
int i = 0;
int i = 0;
for (const auto& particle : *coll) {
if ((particle.getPDG() != 1 + i) ||
(particle.getGeneratorStatus() != 2 + i) ||
(particle.getSimulatorStatus() != 3 + i) ||
(particle.getCharge() != 4 + i) ||
(particle.getTime() != 5 + i) ||
(particle.getMass() != 6 + i)) {
if ((particle.getPDG() != 1 + i) || (particle.getGeneratorStatus() != 2 + i) ||
(particle.getSimulatorStatus() != 3 + i) || (particle.getCharge() != 4 + i) ||
(particle.getTime() != 5 + i) || (particle.getMass() != 6 + i)) {
fatal() << "Wrong data in MCParticle collection";
}
i++;
}
}

};

DECLARE_COMPONENT(ExampleFunctionalConsumer)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "Gaudi/Property.h"
#include "Gaudi/Algorithm.h"
#include "Gaudi/Property.h"
#include "GaudiAlg/Consumer.h"
#include "k4FWCore/DataWrapper.h"

#include "podio/UserDataCollection.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/TrackCollection.h"
#include "edm4hep/TrackerHitCollection.h"
#include "podio/UserDataCollection.h"

#include <string>

Expand All @@ -19,82 +19,65 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>;
// Has to be wrapped in DataWrapper
using colltype = DataWrapper<podio::CollectionBase>;

struct ExampleFunctionalConsumerMultiple final : Gaudi::Functional::Consumer<void(const colltype&,
const colltype&,
const colltype&,
const colltype&,
const colltype&), BaseClass_t> {

struct ExampleFunctionalConsumerMultiple final
: Gaudi::Functional::Consumer<
void(const colltype&, const colltype&, const colltype&, const colltype&, const colltype&), BaseClass_t> {
// The pairs in KeyValue can be changed from python and they correspond
// to the names of the input collection
ExampleFunctionalConsumerMultiple( const std::string& name, ISvcLocator* svcLoc )
: Consumer( name, svcLoc,
{
KeyValue("InputCollectionFloat", "VectorFloat"),
KeyValue("InputCollectionParticles", "MCParticles"),
KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"),
KeyValue("InputCollectionTrackerHits", "TrackerHits"),
KeyValue("InputCollectionTracks", "Tracks"),
}
) {}
ExampleFunctionalConsumerMultiple(const std::string& name, ISvcLocator* svcLoc)
: Consumer(name, svcLoc,
{
KeyValue("InputCollectionFloat", "VectorFloat"),
KeyValue("InputCollectionParticles", "MCParticles"),
KeyValue("InputCollectionSimTrackerHits", "SimTrackerHits"),
KeyValue("InputCollectionTrackerHits", "TrackerHits"),
KeyValue("InputCollectionTracks", "Tracks"),
}) {}

// This is the function that will be called to transform the data
// Note that the function has to be const, as well as the collections
// we get from the input
void operator()(const colltype& floatVector,
const colltype& particles,
const colltype& simTrackerHits,
const colltype& trackerHits,
const colltype& tracks) const override {
void operator()(const colltype& floatVector, const colltype& particles, const colltype& simTrackerHits,
const colltype& trackerHits, const colltype& tracks) const override {
auto* floatVectorColl = dynamic_cast<const podio::UserDataCollection<float>*>(floatVector.getData());
if (((*floatVectorColl)[0] != 125) ||
((*floatVectorColl)[1] != 25) ||
((*floatVectorColl)[2] != m_event)) {
if (((*floatVectorColl)[0] != 125) || ((*floatVectorColl)[1] != 25) || ((*floatVectorColl)[2] != m_event)) {
fatal() << "Wrong data in floatVector collection";
}

auto* particlesColl = dynamic_cast<const edm4hep::MCParticleCollection*>(particles.getData());
auto p4 = (*particlesColl).momentum()[0];
if ((p4.x != m_magicNumberOffset + m_event + 5) ||
(p4.y != m_magicNumberOffset + 6) ||
(p4.z != m_magicNumberOffset + 7) ||
((*particlesColl)[0].getMass() != m_magicNumberOffset + m_event + 8)) {
auto p4 = (*particlesColl).momentum()[0];
if ((p4.x != m_magicNumberOffset + m_event + 5) || (p4.y != m_magicNumberOffset + 6) ||
(p4.z != m_magicNumberOffset + 7) || ((*particlesColl)[0].getMass() != m_magicNumberOffset + m_event + 8)) {
fatal() << "Wrong data in particles collection";
}

auto* simTrackerHitsColl = dynamic_cast<const edm4hep::SimTrackerHitCollection*>(simTrackerHits.getData());
if (((*simTrackerHitsColl)[0].getPosition()[0] != 3) ||
((*simTrackerHitsColl)[0].getPosition()[1] != 4) ||
if (((*simTrackerHitsColl)[0].getPosition()[0] != 3) || ((*simTrackerHitsColl)[0].getPosition()[1] != 4) ||
((*simTrackerHitsColl)[0].getPosition()[2] != 5)) {
fatal() << "Wrong data in simTrackerHits collection";
}

auto trackerHitsColl = dynamic_cast<const edm4hep::TrackerHitCollection*>(trackerHits.getData());
if (((*trackerHitsColl)[0].getPosition()[0] != 3) ||
((*trackerHitsColl)[0].getPosition()[1] != 4) ||
if (((*trackerHitsColl)[0].getPosition()[0] != 3) || ((*trackerHitsColl)[0].getPosition()[1] != 4) ||
((*trackerHitsColl)[0].getPosition()[2] != 5)) {
fatal() << "Wrong data in trackerHits collection";
}

auto tracksColl = dynamic_cast<const edm4hep::TrackCollection*>(tracks.getData());
if (((*tracksColl)[0].getType() != 1) ||
((*tracksColl)[0].getChi2() != 2.1) ||
((*tracksColl)[0].getNdf() != 3) ||
((*tracksColl)[0].getDEdx() != 4.1) ||
((*tracksColl)[0].getDEdxError() != 5.1) ||
((*tracksColl)[0].getRadiusOfInnermostHit() != 6.1)
if (((*tracksColl)[0].getType() != 1) || ((*tracksColl)[0].getChi2() != 2.1) || ((*tracksColl)[0].getNdf() != 3) ||
((*tracksColl)[0].getDEdx() != 4.1) || ((*tracksColl)[0].getDEdxError() != 5.1) ||
((*tracksColl)[0].getRadiusOfInnermostHit() != 6.1)
// ((*tracksColl)[0].getSubdetectorHitNumbers() != {1, 4})
) {
) {
fatal() << "Wrong data in tracks collection";
}

}

private:
// integer to add to the dummy values written to the edm
Gaudi::Property<int> m_magicNumberOffset{this, "magicNumberOffset", 0,
"Integer to add to the dummy values written to the edm"};
int m_event{0};

int m_event{0};
};

DECLARE_COMPONENT(ExampleFunctionalConsumerMultiple)
12 changes: 5 additions & 7 deletions test/k4FWCoreTest/src/components/ExampleFunctionalProducer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Gaudi/Property.h"
#include "Gaudi/Algorithm.h"
#include "Gaudi/Property.h"
#include "GaudiAlg/Producer.h"
#include "k4FWCore/DataWrapper.h"

Expand All @@ -15,11 +15,10 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>;
using colltype = DataWrapper<edm4hep::MCParticleCollection>;

struct ExampleFunctionalProducer final : Gaudi::Functional::Producer<colltype(), BaseClass_t> {

// The pair in KeyValue can be changed from python and it corresponds
// to the name of the output collection
ExampleFunctionalProducer( const std::string& name, ISvcLocator* svcLoc )
: Producer( name, svcLoc, KeyValue( "OutputCollection", "MCParticles" ) ) {}
ExampleFunctionalProducer(const std::string& name, ISvcLocator* svcLoc)
: Producer(name, svcLoc, KeyValue("OutputCollection", "MCParticles")) {}

// This is the function that will be called to produce the data
colltype operator()() const override {
Expand All @@ -33,8 +32,7 @@ struct ExampleFunctionalProducer final : Gaudi::Functional::Producer<colltype(),
private:
// We can define any property we want that can be set from python
// and use it inside operator()
Gaudi::Property<int> m_exampleInt{this, "ExampleInt", 3,
"Example int that can be used in the algorithm"};
Gaudi::Property<int> m_exampleInt{this, "ExampleInt", 3, "Example int that can be used in the algorithm"};
};

DECLARE_COMPONENT(ExampleFunctionalProducer)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "Gaudi/Property.h"
#include "Gaudi/Algorithm.h"
#include "Gaudi/Property.h"
#include "GaudiAlg/Producer.h"
#include "k4FWCore/DataWrapper.h"

#include "podio/UserDataCollection.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/TrackCollection.h"
#include "edm4hep/TrackerHitCollection.h"
#include "podio/UserDataCollection.h"

#include <string>

Expand All @@ -16,26 +16,23 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>;

// Which type of collections we are producing
// They have to be wrapped in DataWrapper
using Float_t = DataWrapper<podio::UserDataCollection<float>>;
using Particle_t = DataWrapper<edm4hep::MCParticleCollection>;
using Float_t = DataWrapper<podio::UserDataCollection<float>>;
using Particle_t = DataWrapper<edm4hep::MCParticleCollection>;
using SimTrackerHit_t = DataWrapper<edm4hep::SimTrackerHitCollection>;
using TrackerHit_t = DataWrapper<edm4hep::TrackerHitCollection>;
using Track_t = DataWrapper<edm4hep::TrackCollection>;

struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer<std::tuple<Float_t, Particle_t, SimTrackerHit_t, TrackerHit_t, Track_t>(), BaseClass_t> {
using TrackerHit_t = DataWrapper<edm4hep::TrackerHitCollection>;
using Track_t = DataWrapper<edm4hep::TrackCollection>;

struct ExampleFunctionalProducerMultiple final
: Gaudi::Functional::Producer<std::tuple<Float_t, Particle_t, SimTrackerHit_t, TrackerHit_t, Track_t>(),
BaseClass_t> {
// The pairs in KeyValue can be changed from python and they correspond
// to the names of the output collections
ExampleFunctionalProducerMultiple( const std::string& name, ISvcLocator* svcLoc )
: Producer( name, svcLoc,
{
KeyValue( "OutputCollectionFloat", "VectorFloat" ),
KeyValue( "OutputCollectionParticles", "MCParticles" ),
KeyValue( "OutputCollectionSimTrackerHits", "SimTrackerHits" ),
KeyValue( "OutputCollectionTrackerHits", "TrackerHits" ),
KeyValue( "OutputCollectionTracks", "Tracks" )
}
) {}
ExampleFunctionalProducerMultiple(const std::string& name, ISvcLocator* svcLoc)
: Producer(
name, svcLoc,
{KeyValue("OutputCollectionFloat", "VectorFloat"), KeyValue("OutputCollectionParticles", "MCParticles"),
KeyValue("OutputCollectionSimTrackerHits", "SimTrackerHits"),
KeyValue("OutputCollectionTrackerHits", "TrackerHits"), KeyValue("OutputCollectionTracks", "Tracks")}) {}

// This is the function that will be called to produce the data
std::tuple<Float_t, Particle_t, SimTrackerHit_t, TrackerHit_t, Track_t> operator()() const override {
Expand All @@ -48,22 +45,22 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer<std
floatVector->push_back(m_event);
Float_t floatVectorDW = DataWrapper<podio::UserDataCollection<float>>(std::move(floatVector));

auto particles = std::make_unique<edm4hep::MCParticleCollection>();
auto particle = particles->create();
auto& p4 = particle.momentum();
p4.x = m_magicNumberOffset + m_event + 5;
p4.y = m_magicNumberOffset + 6;
p4.z = m_magicNumberOffset + 7;
auto particles = std::make_unique<edm4hep::MCParticleCollection>();
auto particle = particles->create();
auto& p4 = particle.momentum();
p4.x = m_magicNumberOffset + m_event + 5;
p4.y = m_magicNumberOffset + 6;
p4.z = m_magicNumberOffset + 7;
particle.setMass(m_magicNumberOffset + m_event + 8);
Particle_t particleDW = DataWrapper<edm4hep::MCParticleCollection>(std::move(particles));

auto simTrackerHits = std::make_unique<edm4hep::SimTrackerHitCollection>();
auto hit = simTrackerHits->create();
auto hit = simTrackerHits->create();
hit.setPosition({3, 4, 5});
SimTrackerHit_t simTrackerHitDW = DataWrapper<edm4hep::SimTrackerHitCollection>(std::move(simTrackerHits));
SimTrackerHit_t simTrackerHitDW = DataWrapper<edm4hep::SimTrackerHitCollection>(std::move(simTrackerHits));

auto trackerHits = std::make_unique<edm4hep::TrackerHitCollection>();
auto trackerHit = trackerHits->create();
auto trackerHit = trackerHits->create();
trackerHit.setPosition({3, 4, 5});
TrackerHit_t trackerHitDW = DataWrapper<edm4hep::TrackerHitCollection>(std::move(trackerHits));

Expand Down Expand Up @@ -91,13 +88,11 @@ struct ExampleFunctionalProducerMultiple final : Gaudi::Functional::Producer<std
private:
// We can define any property we want that can be set from python
// and use it inside operator()
Gaudi::Property<int> m_exampleInt{this, "ExampleInt", 3,
"Example int that can be used in the algorithm"};
Gaudi::Property<int> m_exampleInt{this, "ExampleInt", 3, "Example int that can be used in the algorithm"};
// integer to add to the dummy values written to the edm
Gaudi::Property<int> m_magicNumberOffset{this, "magicNumberOffset", 0,
"Integer to add to the dummy values written to the edm"};
int m_event{0};

int m_event{0};
};

DECLARE_COMPONENT(ExampleFunctionalProducerMultiple)
24 changes: 11 additions & 13 deletions test/k4FWCoreTest/src/components/ExampleFunctionalTransformer.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "Gaudi/Property.h"
#include "Gaudi/Algorithm.h"
#include "Gaudi/Property.h"
#include "GaudiAlg/Transformer.h"
#include "k4FWCore/DataWrapper.h"

#include "podio/CollectionBase.h"
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/MutableMCParticle.h"
#include "podio/CollectionBase.h"

#include <string>

Expand All @@ -15,22 +15,21 @@ using BaseClass_t = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>;
// Which type of collection we are reading and writing
// Both have to be wrapped in DataWrapper
// For reading, the collection type is always podio::CollectionBase
using colltype_in = DataWrapper<podio::CollectionBase>;
using colltype_in = DataWrapper<podio::CollectionBase>;
using colltype_out = DataWrapper<edm4hep::MCParticleCollection>;

struct ExampleFunctionalTransformer final :
Gaudi::Functional::Transformer<colltype_out(const colltype_in&), BaseClass_t> {

ExampleFunctionalTransformer( const std::string& name, ISvcLocator* svcLoc )
: Transformer( name, svcLoc, KeyValue("InputCollection", "MCParticles"),
KeyValue( "OutputCollection", "NewMCParticles" ) ) {}
struct ExampleFunctionalTransformer final
: Gaudi::Functional::Transformer<colltype_out(const colltype_in&), BaseClass_t> {
ExampleFunctionalTransformer(const std::string& name, ISvcLocator* svcLoc)
: Transformer(name, svcLoc, KeyValue("InputCollection", "MCParticles"),
KeyValue("OutputCollection", "NewMCParticles")) {}

// This is the function that will be called to transform the data
// Note that the function has to be const, as well as all pointers to collections
// we get from the input
colltype_out operator()(const colltype_in& input) const override {
auto* coll = dynamic_cast<const edm4hep::MCParticleCollection*>(input.getData());
auto coll_out = std::make_unique<edm4hep::MCParticleCollection>();
auto* coll = dynamic_cast<const edm4hep::MCParticleCollection*>(input.getData());
auto coll_out = std::make_unique<edm4hep::MCParticleCollection>();
for (const auto& particle : *coll) {
auto new_particle = edm4hep::MutableMCParticle();
new_particle.setPDG(particle.getPDG() + 10);
Expand All @@ -45,7 +44,6 @@ struct ExampleFunctionalTransformer final :
colltype_out dw = DataWrapper<edm4hep::MCParticleCollection>(std::move(coll_out));
return dw;
}

};

DECLARE_COMPONENT(ExampleFunctionalTransformer)
Loading

0 comments on commit abfc800

Please sign in to comment.