-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a working example of reading several collections at the same time
- Loading branch information
Showing
5 changed files
with
285 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
test/k4FWCoreTest/options/runExampleFunctionalConsumerSeveralColls.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from Gaudi.Configuration import INFO | ||
from Configurables import ExampleFunctionalConsumerSeveralColls | ||
from Configurables import ApplicationMgr | ||
from Configurables import k4DataSvc | ||
from Configurables import PodioInput | ||
|
||
podioevent = k4DataSvc("EventDataSvc") | ||
podioevent.input = "output_k4test_exampledata_producer_multiple.root" | ||
|
||
inp = PodioInput() | ||
# We pass a space-separated list of collections to PodioInput to make sure | ||
# they are pushed to the TES | ||
inp.collections = [ | ||
"MCParticles1 MCParticles2", | ||
] | ||
|
||
consumer = ExampleFunctionalConsumerSeveralColls("ExampleFunctionalConsumerSeveralColls", | ||
InputCollection="MCParticles1 MCParticles2", | ||
) | ||
|
||
ApplicationMgr(TopAlg=[inp, consumer], | ||
EvtSel="NONE", | ||
EvtMax=10, | ||
ExtSvc=[podioevent], | ||
OutputLevel=INFO, | ||
) |
48 changes: 48 additions & 0 deletions
48
test/k4FWCoreTest/src/components/ExampleFunctionalConsumerSeveralColls.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "Gaudi/Property.h" | ||
#include "GaudiAlg/Consumer.h" | ||
|
||
#include "edm4hep/MCParticleCollection.h" | ||
|
||
// Define BaseClass_t | ||
#include "k4FWCore/BaseClass.h" | ||
|
||
#include <string> | ||
|
||
// Which type of collection we are reading | ||
// When reading multiple collections | ||
using colltype = std::vector<edm4hep::MCParticleCollection*>; | ||
|
||
struct ExampleFunctionalConsumerSeveralColls 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 | ||
ExampleFunctionalConsumerSeveralColls(const std::string& name, ISvcLocator* svcLoc) | ||
: Consumer(name, svcLoc, | ||
KeyValue("InputCollection", "MCParticles1 MCParticles 2") | ||
) {} | ||
|
||
// 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 { | ||
int i = 0; | ||
for (auto ptr : input) { | ||
if (i == 0) { | ||
for (const auto& particle : *ptr) { | ||
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++; | ||
} | ||
} | ||
else { | ||
if (ptr->size() != 0) { | ||
fatal() << "Wrong data in MCParticle collection"; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
DECLARE_COMPONENT(ExampleFunctionalConsumerSeveralColls) |