12#include <framework/datastore/StoreArray.h>
13#include <framework/datastore/RelationVector.h>
14#include <framework/datastore/RelationsObject.h>
15#include <framework/logging/Logger.h>
29 class SelectSubsetBase {
50 SelectSubsetBase() { }
192 template <
typename StoredClass >
194 static_assert(std::is_base_of<RelationsObject, StoredClass>::value,
195 "SelectSubset<T> only works with classes T inheriting from RelationsObject.");
239 B2FATAL(
"SelectSubset::registerSubset() can only be called once!");
245 m_subset->registerInDataStore(storeFlags);
255 template<
class T,
class ... MoreArguments >
258 if (array.getName() ==
m_set->getName()) {
265 if (
m_subset->notWrittenOut() or array.notWrittenOut())
269 if (array.getName() !=
m_subset->getName())
280 template<
class T,
class ... MoreArguments >
283 if (array.getName() ==
m_set->getName()) {
290 if (
m_subset->notWrittenOut() or array.notWrittenOut())
294 if (array.getName() !=
m_subset->getName())
311 for (
const std::string& arrayName : arrays) {
316 if (array.optionalRelationTo(*
m_set,
m_set->getDurability()))
318 if (
m_set->optionalRelationTo(array,
m_set->getDurability()))
328 void select(
const std::function<
bool (
const StoredClass*)>& f);
355 template <
class StoredClass>
359 std::map<int, int> oldToNew;
360 for (
const StoredClass& setObject : *
m_set) {
364 oldToNew[setObject.getArrayIndex()] =
m_subset->getEntries();
365 const StoredClass* subsetObject =
m_subset->appendNew(setObject);
367 setObject.addRelationTo(subsetObject);
372 for (
const auto& oldToNewPair : oldToNew) {
373 const StoredClass* setObject = (*m_set)[oldToNewPair.first];
374 const StoredClass* subsetObject = (*m_subset)[oldToNewPair.second];
378 for (
unsigned int iRel = 0; iRel < relations.size(); iRel++) {
379 relations.object(iRel)->addRelationTo(subsetObject, relations.weight(iRel));
384 for (
unsigned int iRel = 0; iRel < relations.size(); iRel++) {
385 subsetObject->addRelationTo(relations.object(iRel), relations.weight(iRel));
394 template <
class StoredClass>
398 for (
const StoredClass& subsetObject1 : *
m_subset) {
400 const StoredClass* setObject1 = subsetObject1.template getRelatedFrom<StoredClass>(
m_set->getName());
402 if (setObject1 !=
nullptr) {
405 for (
unsigned int iRel = 0; iRel < relations.size(); iRel++) {
406 const StoredClass* setObject2 = relations.object(iRel);
407 const double weight = relations.weight(iRel);
409 const StoredClass* subsetObject2 = setObject2->template getRelatedTo<StoredClass>(
m_subset->getName());
411 subsetObject1.addRelationTo(subsetObject2, weight);
418 template <
class StoredClass>
std::vector< std::string > getListOfRelatedArrays(const StoreAccessorBase &array) const
Returns a list of names of arrays which have registered relations that point to or from 'array'.
EStoreFlags
Flags describing behaviours of objects etc.
@ c_WriteOut
Object/array should be saved by output modules.
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
@ c_ErrorIfAlreadyRegistered
If the object/array was already registered, produce an error (aborting initialisation).
static DataStore & Instance()
Instance of singleton Store.
Class for type safe access to objects that are referred to in relations.
Type-independent implementation details of SelectSubset.
std::vector< std::string > m_inheritFromArrays
array names we inherit relations from.
virtual StoreAccessorBase * getSubSet()=0
Get accessor for reduced set.
bool m_inheritToSelf
If true, relations from set objects to set objects are copied.
bool m_reduceExistingSet
If true, non-selected candidates are removed from m_set, m_subset only exists temporarily.
std::vector< std::string > getInheritToArrays() const
Get list of arrays we inherit relations to.
bool getInheritToSelf() const
Do we inherit relations from original set to itself?
void swapSetsAndDestroyOriginal()
Swap set and subset (+relations), and keep only the reduced set.
virtual StoreAccessorBase * getSet()=0
Get accessor for original set.
std::vector< std::string > getInheritFromArrays() const
Get list of arrays we inherit relations from.
std::vector< std::string > m_inheritToArrays
array names we inherit relations to.
void inheritRelationsTo(const StoreArray< T > &array, MoreArguments... moreArgs)
Inherit relations pointing from objects selected into this subset to Other.
StoreArray< StoredClass > * m_set
The array we use as input.
~SelectSubset() override
Destructor.
static void inheritRelationsTo()
Empty method to stop the recursion of the variadic template.
SelectSubset & operator=(const SelectSubset &)=delete
no assignment operator
static void inheritRelationsFrom()
Empty method to stop the recursion of the variadic template.
StoreArray< StoredClass > * m_subset
The array we create.
DataStore::EStoreFlags m_subsetFlags
Flags used for m_subset.
void inheritRelationsFrom(const StoreArray< T > &array, MoreArguments... moreArgs)
Inherit relations pointing from Other to objects selected into this subset.
void inheritAllRelations()
Automatically inherit all relations to or from the original set (if registered when calling this func...
StoreAccessorBase * getSet() override
Get accessor for original set.
void registerSubset(const StoreArray< StoredClass > &set, const std::string &subsetName, DataStore::EStoreFlags storeFlags=DataStore::c_ErrorIfAlreadyRegistered)
Register the StoreArray<StoredClass> that will contain the subset of selected elements.
SelectSubset()
Constructor.
StoreAccessorBase * getSubSet() override
Get accessor for reduced set.
void registerSubset(const StoreArray< StoredClass > &set, DataStore::EStoreFlags storeFlags=DataStore::c_ErrorIfAlreadyRegistered)
Remove all non-selected objects from set.
SelectSubset(const SelectSubset &)=delete
no copy constructor
Base class for StoreObjPtr and StoreArray for easier common treatment.
void select(const std::function< bool(const StoredClass *)> &f)
This method is the actual worker.
std::map< int, int > copySetWithRelations(std::function< bool(const StoredClass *)> f)
Selects the elements, fill the subset and copies all the relations in which the set is involved.
void copyRelationsToSelf()
Copy any set -> set relations between selected objects.
Abstract base class for different kinds of events.