11 #include <framework/datastore/DataStore.h> 
   12 #include <framework/datastore/StoreAccessorBase.h> 
   13 #include <framework/utilities/ArrayIterator.h> 
   14 #include <framework/dataobjects/RelationElement.h> 
   15 #include <framework/dataobjects/RelationContainer.h> 
   16 #include <framework/logging/Logger.h> 
   23   template <
class T> 
class StoreArray;
 
  104     template < 
class MapType = std::map<index_type, consol
idation_type> > 
class ReplaceMap {
 
  113         typename MapType::const_iterator iter = 
m_replace.find(old);
 
  117         return std::make_pair(old, 
false);
 
  132     template < 
class VecType = std::vector<consol
idation_type> > 
class ReplaceVec {
 
  187         B2FATAL(
"Tried to create RelationArray '" << 
m_name << 
"' with a durability larger than the StoreArrays it relates");
 
  206         B2FATAL(
"Tried to create RelationArray '" << 
m_name << 
"' with a durability larger than the StoreArrays it relates");
 
  223         B2FATAL(
"Cannot guess relation name, please supply correct name");
 
  236     inline operator bool()
  const { 
return isValid(); }
 
  249         B2FATAL(
"trying to get accessor params from non-existing relation (this is likely a framework bug)");
 
  258         B2FATAL(
"trying to get accessor params from non-existing relation (this is likely a framework bug)");
 
  272       (*m_relations)->elements().Delete();
 
  296       std::vector<weight_type> weights(to.size(), weight);
 
  306     void add(
index_type from, 
const std::vector<index_type>& to, 
const std::vector<weight_type>& weights)
 
  363     template<
class FunctionFrom, 
class FunctionTo> 
void consolidate(
const 
  364         FunctionFrom& replaceFrom = FunctionFrom(), 
const FunctionTo &
 
  385       if (params.first.empty()) {
 
  386         B2FATAL(
"Cannot guess relation name, please supply correct name");
 
  394       int index = (*m_relations)->elements().GetLast() + 1;
 
  395       return static_cast<RelationElement*
>((*m_relations)->elements().AddrAt(index));
 
  401       if (array.second == 0 && array.first.empty())
 
  405         B2FATAL(
"Relation '" << 
m_name << 
"' exists but points " << direction << 
" wrong array:" 
  406                 << 
" requested " << array.first << 
"(" << array.second << 
")" 
  407                 << 
", got " << rel.first << 
"(" << rel.second << 
")" 
  436     void assertValid()
 const { 
if (!
isValid()) B2FATAL(
"RelationArray does not point to valid StoreObject"); }
 
  446           B2FATAL(
"Couldn't create relation " << 
m_name << 
"!");
 
  465   template<
class FunctionFrom, 
class FunctionTo>
 
  469       B2ERROR(
"Cannot consolidate an invalid relation (" << 
m_name << 
")");
 
  472     typedef std::map<index_type, weight_type> element_t;
 
  473     typedef std::map<index_type, element_t > buffer_t;
 
  479     buffer_t::iterator lastFromIter = buffer.end();
 
  480     unsigned int nElements = (*m_relations)->getEntries();
 
  481     TClonesArray& elements = (*m_relations)->elements();
 
  482     for (
unsigned int i = 0; i < nElements; ++i) {
 
  492       if (from.first != lastFromIndex || lastFromIter == buffer.end()) {
 
  493         lastFromIter = buffer.insert(make_pair(from.first, element_t())).first;
 
  494         lastFromIndex = from.first;
 
  497       size_t size = element.
getSize();
 
  498       for (
size_t j = 0; j < size; ++j) {
 
  509         if (from.second || to.second) {
 
  517         lastFromIter->second[to.first] += weight;
 
  523     for (buffer_t::iterator iter = buffer.begin(); iter != buffer.end(); ++iter) {
 
  524       add(iter->first, iter->second.begin(), iter->second.end());
 
In the store you can park objects that have to be accessed by various modules.
EDurability
Durability types.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
static DataStore & Instance()
Instance of singleton Store.
bool createObject(TObject *object, bool replace, const StoreAccessorBase &accessor)
Create a new object/array in the DataStore or add an existing one.
TObject ** getObject(const StoreAccessorBase &accessor)
Get a pointer to a pointer of an object in the DataStore.
Optimizes class to iterate over TObjArray and classes inheriting from it.
Struct to replace indices based on a map-like container.
ReplaceMap(MapType &replace)
Set reference to used replacement map.
consolidation_type operator()(index_type old) const
Take old index and return the new index.
MapType & m_replace
Reference of the used replacement map.
Struct to replace indices based on a sequential container.
VecType & m_replace
Reference of the used replacement vector.
consolidation_type operator()(index_type old) const
Take old index and return the new index.
ReplaceVec(VecType &replace)
Set reference to used replacement vector.
Low-level class to create/modify relations between StoreArrays.
bool getModified() const
Get modified flag of underlying container.
ObjArrayIterator< const TClonesArray, const RelationElement > const_iterator
STL-like const_iterator over the T objects (not T* ).
const_iterator begin() const
Return const_iterator to first entry.
AccessorParams m_accessorTo
Accessor params for to array.
RelationArray(const StoreArray< FROM > &from, const StoreArray< TO > &to, const std::string &name="", DataStore::EDurability durability=DataStore::c_Event)
Constructor which takes both store arrays and performs some sanity checks on the relation.
const AccessorParams & getFromAccessorParams() const
Return the AccessorParams the attached relation points from.
void checkRelation(const std::string &direction, const AccessorParams &array, const AccessorParams &rel) const
Check that the AccessorParams stored in the relation and the one given to the constructor are the sam...
RelationContainer ** m_relations
Pointer that actually holds the relations.
void ensureAttached() const
Attach to relation, if necessary.
const RelationElement & operator[](int i) const
Imitate array functionality.
void add(index_type from, const std::vector< index_type > &to, weight_type weight=1.0)
Add a new element to the relation.
bool isValid() const
Check whether the object was created.
std::pair< index_type, bool > consolidation_type
Typedef declaring the return value of any consolidation mapping.
const AccessorParams & getToAccessorParams() const
Return the AccessorParams the attached relation points to.
void consolidate()
Consolidate Relation Elements.
RelationElement::index_type index_type
Typedef to simplify use of correct index_type.
EConsolidationAction
Modification actions for the consolidate member.
@ c_negativeWeight
Flip the sign of the weight to become negative if the original element got re-attributed.
@ c_zeroWeight
Set the weight of the relation to 0 if the original element got re-attributed.
@ c_deleteElement
Delete the whole relation element if the original element got re-attributed.
@ c_doNothing
Do nothing, just treat it as reordering.
~RelationArray()
Empty destructor.
void setModified(bool modified)
Set modified flag of underlying container.
void add(index_type from, const InputIterator &begin, const InputIterator &end)
Add a new element to the relation.
void add(index_type from, const std::vector< index_type > &to, const std::vector< weight_type > &weights)
Add a new element to the relation.
int getEntries() const
Get the number of elements.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
RelationElement::weight_type weight_type
Typedef to simplify use of correct weight_type.
RelationArray(const AccessorParams &fromAccessor, const AccessorParams &toAccessor, DataStore::EDurability durability=DataStore::c_Event)
Constructor with AccessorParams for from- and to-side.
RelationArray(const AccessorParams ¶ms)
Constructor which accepts the AccessorParams of the relation.
RelationArray(const std::string &name, DataStore::EDurability durability=DataStore::c_Event)
Constructor which only accepts name and durability of the relation.
const_iterator end() const
Return const_iterator to last entry +1.
void assertCreated()
Create relation, if necessary.
bool create(bool replace=false)
Create an empty relation array in the data store.
AccessorParams m_accessorFrom
Accessor params for from array.
void clear() override
Clear all elements from the relation.
RelationElement * next()
Return address where the next RelationElement should be created.
void assertValid() const
check that pointer exits, otherwise bail out.
Class to store relations between StoreArrays in the DataStore.
bool isDefaultConstructed() const
Returns true if no information was set yet or Clear() was called.
void setFromName(const std::string &name)
Set name of the StoreArray we relate from.
Class to store a single element of a relation.
index_type getFromIndex() const
Get index we point from.
index_type getToIndex(size_t n=0) const
Get nth index we point to.
unsigned int index_type
type used for indices.
float weight_type
type used for weights.
size_t getSize() const
Get number of indices we points to.
weight_type getWeight(size_t n=0) const
Get nth weight we point to.
Class to store a bidirectional index between two StoreArrays.
Provides access to fast ( O(log n) ) bi-directional lookups on a specified relation.
Base class for StoreObjPtr and StoreArray for easier common treatment.
DataStore::EDurability m_durability
Store durability under which the object/array is saved.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
AccessorParams getAccessorParams() const
Return pair of name and durability under which stored object is saved.
std::string m_name
Store name under which this object/array is saved.
Accessor to arrays stored in the data store.
std::pair< std::string, DataStore::EDurability > AccessorParams
Pair of parameters needed to find an object in the DataStore.
Abstract base class for different kinds of events.
Struct for identity transformation on indices.
consolidation_type operator()(index_type old) const
Take old index and return the new index.