forked from key4hep/k4FWCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a filter algorithm (key4hep#210)
- Loading branch information
Showing
6 changed files
with
195 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Key4hep-Project. | ||
* | ||
* This file is part of Key4hep. | ||
* See https://key4hep.github.io/key4hep-doc/ for further info. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "Gaudi/Functional/FilterPredicate.h" | ||
#include "k4FWCore/FunctionalUtils.h" | ||
|
||
namespace k4FWCore { | ||
|
||
template <typename Signature> | ||
using FilterPredicate = Gaudi::Functional::FilterPredicate<Signature, details::BaseClass_t>; | ||
} |
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
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,52 @@ | ||
# | ||
# Copyright (c) 2014-2024 Key4hep-Project. | ||
# | ||
# This file is part of Key4hep. | ||
# See https://key4hep.github.io/key4hep-doc/ for further info. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# This is an creating some collections and filtering after | ||
# to check that the contents of the file are the expected ones | ||
|
||
from Gaudi.Configuration import INFO | ||
from Configurables import ( | ||
ExampleFunctionalTransformer, | ||
ExampleFunctionalProducer, | ||
ExampleFunctionalFilter, | ||
) | ||
from k4FWCore import ApplicationMgr, IOSvc | ||
from Configurables import EventDataSvc | ||
|
||
iosvc = IOSvc("IOSvc") | ||
iosvc.output = "functional_filter.root" | ||
|
||
transformer = ExampleFunctionalTransformer( | ||
"Transformer", InputCollection=["MCParticles"], OutputCollection=["NewMCParticles"] | ||
) | ||
|
||
producer = ExampleFunctionalProducer("Producer", OutputCollection=["MCParticles"]) | ||
|
||
filt = ExampleFunctionalFilter( | ||
"Filter", | ||
InputCollection="NewMCParticles", | ||
) | ||
|
||
ApplicationMgr( | ||
TopAlg=[producer, transformer, filt], | ||
EvtSel="NONE", | ||
EvtMax=10, | ||
ExtSvc=[EventDataSvc("EventDataSvc")], | ||
OutputLevel=INFO, | ||
) |
52 changes: 52 additions & 0 deletions
52
test/k4FWCoreTest/src/components/ExampleFunctionalFilter.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,52 @@ | ||
/* | ||
* Copyright (c) 2014-2024 Key4hep-Project. | ||
* | ||
* This file is part of Key4hep. | ||
* See https://key4hep.github.io/key4hep-doc/ for further info. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "Gaudi/Accumulators.h" | ||
#include "edm4hep/MCParticleCollection.h" | ||
|
||
#include "k4FWCore/FilterPredicate.h" | ||
|
||
#include <string> | ||
|
||
struct ExampleFunctionalFilter final : k4FWCore::FilterPredicate<bool(const edm4hep::MCParticleCollection& input)> { | ||
// The pair in KeyValue can be changed from python and it corresponds | ||
// to the name of the input collection | ||
ExampleFunctionalFilter(const std::string& name, ISvcLocator* svcLoc) | ||
: FilterPredicate(name, svcLoc, KeyValue("InputCollection", {"MCParticles"})) {} | ||
|
||
// This is the function that will be called to check if the event passes | ||
// Note that the function has to be const, as well as the collections | ||
// we get from the input | ||
bool operator()(const edm4hep::MCParticleCollection& input) const override { | ||
++m_counter; | ||
// Only pass for half of the events | ||
bool condition = m_counter.sum() % 2; | ||
if (condition) { | ||
info() << "Event passed" << endmsg; | ||
} else { | ||
info() << "Event did not pass" << endmsg; | ||
} | ||
return condition; | ||
} | ||
|
||
// Thread-safe counter | ||
mutable Gaudi::Accumulators::Counter<> m_counter{this, "Counter"}; | ||
}; | ||
|
||
DECLARE_COMPONENT(ExampleFunctionalFilter) |