Belle II Software development
RelationArray Class Reference

Low-level class to create/modify relations between StoreArrays. More...

#include <RelationArray.h>

Inheritance diagram for RelationArray:
StoreAccessorBase

Classes

struct  Identity
 Struct for identity transformation on indices. More...
 
class  ReplaceMap
 Struct to replace indices based on a map-like container. More...
 
class  ReplaceVec
 Struct to replace indices based on a sequential container. More...
 

Public Types

enum  EConsolidationAction {
  c_doNothing ,
  c_negativeWeight ,
  c_zeroWeight ,
  c_deleteElement
}
 Modification actions for the consolidate member. More...
 
typedef ObjArrayIterator< const TClonesArray, const RelationElementconst_iterator
 STL-like const_iterator over the T objects (not T* ).
 
typedef RelationElement::index_type index_type
 Typedef to simplify use of correct index_type.
 
typedef RelationElement::weight_type weight_type
 Typedef to simplify use of correct weight_type.
 
typedef std::pair< index_type, bool > consolidation_type
 Typedef declaring the return value of any consolidation mapping.
 

Public Member Functions

bool create (bool replace=false)
 Create an empty relation array in the data store.
 
template<class FROM , class TO >
 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.
 
 RelationArray (const AccessorParams &fromAccessor, const AccessorParams &toAccessor, DataStore::EDurability durability=DataStore::c_Event)
 Constructor with AccessorParams for from- and to-side.
 
 RelationArray (const std::string &name, DataStore::EDurability durability=DataStore::c_Event)
 Constructor which only accepts name and durability of the relation.
 
 ~RelationArray ()
 Empty destructor.
 
bool isValid () const
 Check whether the object was created.
 
 operator bool () const
 Check whether the object was created.
 
const RelationElementoperator[] (int i) const
 Imitate array functionality.
 
int getEntries () const
 Get the number of elements.
 
const AccessorParamsgetFromAccessorParams () const
 Return the AccessorParams the attached relation points from.
 
const AccessorParamsgetToAccessorParams () const
 Return the AccessorParams the attached relation points to.
 
bool getModified () const
 Get modified flag of underlying container.
 
void setModified (bool modified)
 Set modified flag of underlying container.
 
void clear () override
 Clear all elements from the relation.
 
void add (index_type from, index_type to, weight_type weight=1.0)
 Add a new element to the relation.
 
void add (index_type from, const std::vector< index_type > &to, weight_type weight=1.0)
 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.
 
template<class InputIterator >
void add (index_type from, const InputIterator &begin, const InputIterator &end)
 Add a new element to the relation.
 
void consolidate ()
 Consolidate Relation Elements.
 
template<class FunctionFrom , class FunctionTo >
void consolidate (const FunctionFrom &replaceFrom=FunctionFrom(), const FunctionTo &replaceTo=FunctionTo(), EConsolidationAction action=c_doNothing)
 Consolidate RelationElements.
 
const_iterator begin () const
 Return const_iterator to first entry.
 
const_iterator end () const
 Return const_iterator to last entry +1.
 
bool registerInDataStore (DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
 Register the object/array in the DataStore.
 
bool registerInDataStore (const std::string &name, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
 Register the object/array in the DataStore.
 
bool isRequired (const std::string &name="")
 Ensure this array/object has been registered previously.
 
bool isOptional (const std::string &name="")
 Tell the DataStore about an optional input.
 
bool assign (TObject *object, bool replace=false)
 Assign 'object' to this accessor.
 
const std::string & getName () const
 Return name under which the object is saved in the DataStore.
 
DataStore::EDurability getDurability () const
 Return durability with which the object is saved in the DataStore.
 
AccessorParams getAccessorParams () const
 Return pair of name and durability under which stored object is saved.
 
virtual bool operator== (const StoreAccessorBase &other) const
 Check if two store accessors point to the same object/array.
 
virtual bool operator!= (const StoreAccessorBase &other) const
 Check if two store accessors point to a different object/array.
 
TClass * getClass () const
 The underlying object's type.
 
bool isArray () const
 Is this an accessor for an array?
 
bool notWrittenOut () const
 Returns true if this object/array should not be saved by output modules.
 
std::string readableName () const
 Convert this acessor into a readable string (for messages).
 

Protected Attributes

std::string m_name
 Store name under which this object/array is saved.
 
DataStore::EDurability m_durability
 Store durability under which the object/array is saved.
 
TClass * m_class
 The underlying object's type.
 
bool m_isArray
 Is this an accessor for an array?
 

Private Member Functions

 RelationArray (const AccessorParams &params)
 Constructor which accepts the AccessorParams of the relation.
 
RelationElementnext ()
 Return address where the next RelationElement should be created.
 
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 same.
 
void ensureAttached () const
 Attach to relation, if necessary.
 
void assertValid () const
 check that pointer exits, otherwise bail out.
 
void assertCreated ()
 Create relation, if necessary.
 

Private Attributes

AccessorParams m_accessorFrom
 Accessor params for from array.
 
AccessorParams m_accessorTo
 Accessor params for to array.
 
RelationContainer ** m_relations
 Pointer that actually holds the relations.
 

Friends

template<class FROM , class TO >
class RelationIndex
 
template<class FROM , class TO >
class RelationIndexContainer
 

Detailed Description

Low-level class to create/modify relations between StoreArrays.

Relations connect objects stored in two StoreArrays with each other, with the possibility of n:n connections and individual weights.

Note
In almost all cases, you'll want to create/find relations using RelationsObject instead.

Creating new relations

Assuming you have two StoreArrays called 'particles' and 'cdcsimhits', you can use RelationArray to create relations between entries:

RelationArray particlesToCdchits(particles, cdcsimhits);
for(int iPart = 0; iPart < particles.getEntries(); iPart++) {
//... create new hit 'myhit'
cdcsimhits.appendNew(myhit);
int cdcsimhitIdx = cdcsimhits.getEntries()-1; //index of last object stored
//connect objects at indices iPart and cdcsimhitIdx
particlesToCdchits.add(iPart, cdcsimhitIdx);
}
Low-level class to create/modify relations between StoreArrays.
Definition: RelationArray.h:62

This example loops over the 'particles' array and might for example simulate the particles' interaction with the detector. New hits are added and also connected with the particles that created them.

As with other data store objects, you should register relations you want to store in your implementation of Module::initialize(), see StoreArray::registerRelationTo()

See also
RelationsObject for the main user interface to relations.
RelationIndex provides an low-levvel interface to quickly find objects related to a given FROM/TO side object.
The on-disk data structure is provided by RelationElement objects in a RelationContainer.

Definition at line 62 of file RelationArray.h.

Member Typedef Documentation

◆ consolidation_type

typedef std::pair<index_type, bool> consolidation_type

Typedef declaring the return value of any consolidation mapping.

It contains the new index of the element and a bool which is true if the old element has been re-attributed and false if there was just an reordering.

Definition at line 88 of file RelationArray.h.

◆ const_iterator

typedef ObjArrayIterator<const TClonesArray, const RelationElement> const_iterator

STL-like const_iterator over the T objects (not T* ).

Definition at line 65 of file RelationArray.h.

◆ index_type

Typedef to simplify use of correct index_type.

Definition at line 68 of file RelationArray.h.

◆ weight_type

Typedef to simplify use of correct weight_type.

Definition at line 71 of file RelationArray.h.

Member Enumeration Documentation

◆ EConsolidationAction

Modification actions for the consolidate member.

Determines what is to be done with elements where the original element was re-attributed and not just reordered

Enumerator
c_doNothing 

Do nothing, just treat it as reordering.

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.

Definition at line 77 of file RelationArray.h.

77 {
82 };
@ c_negativeWeight
Flip the sign of the weight to become negative if the original element got re-attributed.
Definition: RelationArray.h:79
@ c_zeroWeight
Set the weight of the relation to 0 if the original element got re-attributed.
Definition: RelationArray.h:80
@ c_deleteElement
Delete the whole relation element if the original element got re-attributed.
Definition: RelationArray.h:81
@ c_doNothing
Do nothing, just treat it as reordering.
Definition: RelationArray.h:78

Constructor & Destructor Documentation

◆ RelationArray() [1/4]

RelationArray ( const StoreArray< FROM > &  from,
const StoreArray< TO > &  to,
const std::string &  name = "",
DataStore::EDurability  durability = DataStore::c_Event 
)
inline

Constructor which takes both store arrays and performs some sanity checks on the relation.

If the relation already exists it will be checked that the relation really relates between the given StoreArrays

Parameters
fromStoreArray the relation points from
toStoreArray the relation points to
nameName of the relation. Default is to use the default name based on the StoreArrays
durabilityDurability of the relation. If the durability is larger than the durability of the related StoreArrays, an error is raised.

Definition at line 178 of file RelationArray.h.

179 :
180 StoreAccessorBase(name.empty() ? DataStore::relationName(from.getName(), to.getName()) : name, durability,
181 RelationContainer::Class(), false),
182 m_accessorFrom(from.getAccessorParams()),
183 m_accessorTo(to.getAccessorParams()),
184 m_relations(0)
185 {
186 if (m_accessorFrom.second > m_durability || m_accessorTo.second > m_durability) {
187 B2FATAL("Tried to create RelationArray '" << m_name << "' with a durability larger than the StoreArrays it relates");
188 }
189 }
static std::string relationName(const std::string &fromName, const std::string &toName, std::string const &namedRelation="")
Return storage name for a relation between two arrays of the given names.
Definition: DataStore.h:180
AccessorParams m_accessorTo
Accessor params for to array.
RelationContainer ** m_relations
Pointer that actually holds the relations.
AccessorParams m_accessorFrom
Accessor params for from array.
StoreAccessorBase(const std::string &name, DataStore::EDurability durability, TClass *objClass, bool isArray)
Constructor to access an object or array in the DataStore.
DataStore::EDurability m_durability
Store durability under which the object/array is saved.
std::string m_name
Store name under which this object/array is saved.

◆ RelationArray() [2/4]

RelationArray ( const AccessorParams fromAccessor,
const AccessorParams toAccessor,
DataStore::EDurability  durability = DataStore::c_Event 
)
inline

Constructor with AccessorParams for from- and to-side.

Parameters
fromAccessor(name, durability) of from side array
toAccessor(name, durability) of to side array
durabilityDurability of the relation. If the durability is larger than the durability of the related StoreArrays, an error is raised.

Definition at line 198 of file RelationArray.h.

199 :
200 StoreAccessorBase(DataStore::relationName(fromAccessor.first, toAccessor.first), durability, RelationContainer::Class(), false),
201 m_accessorFrom(fromAccessor),
202 m_accessorTo(toAccessor),
203 m_relations(nullptr)
204 {
205 if (m_accessorFrom.second > m_durability || m_accessorTo.second > m_durability) {
206 B2FATAL("Tried to create RelationArray '" << m_name << "' with a durability larger than the StoreArrays it relates");
207 }
208 }

◆ RelationArray() [3/4]

RelationArray ( const std::string &  name,
DataStore::EDurability  durability = DataStore::c_Event 
)
inlineexplicit

Constructor which only accepts name and durability of the relation.

This constructor will only assign existing relations and will not create new ones since it lacks the information on the StoreArrays to relate

Parameters
nameName of the (existing) Relation
durabilityDurability of the (existing) Relation

Definition at line 218 of file RelationArray.h.

218 :
219 StoreAccessorBase(name, durability, RelationContainer::Class(), false),
220 m_relations(0)
221 {
222 if (name.empty()) {
223 B2FATAL("Cannot guess relation name, please supply correct name");
224 }
225 }

◆ ~RelationArray()

~RelationArray ( )
inline

Empty destructor.

Definition at line 228 of file RelationArray.h.

228{}

◆ RelationArray() [4/4]

RelationArray ( const AccessorParams params)
inlineexplicitprivate

Constructor which accepts the AccessorParams of the relation.

This constructor will only assign existing relations and will not create new ones since it lacks the information on the StoreArrays to relate

Parameters
paramsAccessorParams for the (existing) Relation

Definition at line 381 of file RelationArray.h.

381 :
382 StoreAccessorBase(params.first, params.second, RelationContainer::Class(), false),
383 m_relations(0)
384 {
385 if (params.first.empty()) {
386 B2FATAL("Cannot guess relation name, please supply correct name");
387 }
388 }

Member Function Documentation

◆ add() [1/4]

void add ( index_type  from,
const InputIterator &  begin,
const InputIterator &  end 
)
inline

Add a new element to the relation.

Parameters
fromindex to point from
beginiterator pointing to the begin of a sequence of std::pair<index_type,weight_type> or compatible
enditerator pointing to the end of a sequence of std::pair<index_type,weight_type> or compatible

Definition at line 320 of file RelationArray.h.

321 {
322 setModified(true);
323 new (next()) RelationElement(from, begin, end);
324 }
const_iterator begin() const
Return const_iterator to first entry.
RelationElement * next()
Return address where the next RelationElement should be created.
void setModified(bool modified)
Set modified flag of underlying container.
const_iterator end() const
Return const_iterator to last entry +1.

◆ add() [2/4]

void add ( index_type  from,
const std::vector< index_type > &  to,
const std::vector< weight_type > &  weights 
)
inline

Add a new element to the relation.

Parameters
fromindex to point from
toindices to point to
weightsweights of the relations

Definition at line 306 of file RelationArray.h.

307 {
308 setModified(true);
309 new (next()) RelationElement(from, to, weights);
310 }

◆ add() [3/4]

void add ( index_type  from,
const std::vector< index_type > &  to,
weight_type  weight = 1.0 
)
inline

Add a new element to the relation.

Parameters
fromindex to point from
toindices to point to
weightweight for all relations

Definition at line 293 of file RelationArray.h.

294 {
295 setModified(true);
296 std::vector<weight_type> weights(to.size(), weight);
297 new (next()) RelationElement(from, to, weights);
298 }

◆ add() [4/4]

void add ( index_type  from,
index_type  to,
weight_type  weight = 1.0 
)
inline

Add a new element to the relation.

Parameters
fromindex to point from
toindex to point to
weightweight of the relation

Definition at line 281 of file RelationArray.h.

282 {
283 setModified(true);
284 new (next()) RelationElement(from, to, weight);
285 }

◆ assertCreated()

void assertCreated ( )
inlineprivate

Create relation, if necessary.

After this function returns, the relation is guaranteed to be writeable.

Definition at line 442 of file RelationArray.h.

443 {
444 if (!isValid()) {
445 if (!create()) {
446 B2FATAL("Couldn't create relation " << m_name << "!");
447 }
448 }
449 }
bool isValid() const
Check whether the object was created.
bool create(bool replace=false)
Create an empty relation array in the data store.

◆ assertValid()

void assertValid ( ) const
inlineprivate

check that pointer exits, otherwise bail out.

Definition at line 436 of file RelationArray.h.

436{ if (!isValid()) B2FATAL("RelationArray does not point to valid StoreObject"); }

◆ assign()

bool assign ( TObject *  object,
bool  replace = false 
)
inherited

Assign 'object' to this accessor.

(takes ownership).

Parameters
objectThe object that should be put in the DataStore, should be of same type as the one used by this accessor.
replaceShould an existing object be replaced? (if existing and supplied object are equal, this has no effect)
Returns
True if the assignment succeeded. If false, assign() will delete 'object', do not use it afterwards.

Definition at line 33 of file StoreAccessorBase.cc.

34{
35 if (not object)
36 return false;
37
38 bool success = false;
39 const bool objIsArray = (object->IsA() == TClonesArray::Class());
40 TClass* objClass = objIsArray ? (static_cast<TClonesArray*>(object))->GetClass() : object->IsA();
41 if (objIsArray != isArray()) {
42 B2ERROR("Cannot assign an object to an array (or vice versa); while assigning to " << readableName());
43 } else if (objClass != getClass()) {
44 B2ERROR("Cannot assign() an object of type '" << objClass->GetName() << "' to " << readableName() << " of type '" <<
45 getClass()->GetName() << "'!");
46 } else {
47 success = DataStore::Instance().createObject(object, replace, *this);
48 }
49 if (!success)
50 delete object;
51 return success;
52}
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
bool createObject(TObject *object, bool replace, const StoreAccessorBase &accessor)
Create a new object/array in the DataStore or add an existing one.
Definition: DataStore.cc:316
std::string readableName() const
Convert this acessor into a readable string (for messages).
TClass * getClass() const
The underlying object's type.
bool isArray() const
Is this an accessor for an array?

◆ begin()

const_iterator begin ( ) const
inline

Return const_iterator to first entry.

Definition at line 369 of file RelationArray.h.

369{ assertValid(); return const_iterator((*m_relations)->elements(), 0); }
ObjArrayIterator< const TClonesArray, const RelationElement > const_iterator
STL-like const_iterator over the T objects (not T* ).
Definition: RelationArray.h:65
void assertValid() const
check that pointer exits, otherwise bail out.

◆ checkRelation()

void checkRelation ( const std::string &  direction,
const AccessorParams array,
const AccessorParams rel 
) const
inlineprivate

Check that the AccessorParams stored in the relation and the one given to the constructor are the same.

Definition at line 399 of file RelationArray.h.

400 {
401 if (array.second == 0 && array.first.empty())
402 return; //no information to check against...
403
404 if (array != rel) {
405 B2FATAL("Relation '" << m_name << "' exists but points " << direction << " wrong array:"
406 << " requested " << array.first << "(" << array.second << ")"
407 << ", got " << rel.first << "(" << rel.second << ")"
408 );
409 }
410 }

◆ clear()

void clear ( )
inlineoverridevirtual

Clear all elements from the relation.

Reimplemented from StoreAccessorBase.

Definition at line 269 of file RelationArray.h.

270 {
271 setModified(true);
272 (*m_relations)->elements().Delete();
273 }

◆ consolidate()

void consolidate ( )
inline

Consolidate Relation Elements.

This function will loop over the relation and "compress" it by merging all elements with the same fromIndex.

Definition at line 331 of file RelationArray.h.

331{ consolidate<Identity, Identity>(); }

◆ create()

bool create ( bool  replace = false)
inline

Create an empty relation array in the data store.

Parameters
replaceShould an existing object be replaced?
Returns
True if the creation succeeded.

Definition at line 153 of file RelationArray.h.

154 {
155 bool result = DataStore::Instance().createObject(0, replace, *this);
156 m_relations = reinterpret_cast<RelationContainer**>(DataStore::Instance().getObject(*this));
157 if (result) {
158 (*m_relations)->setFromName(m_accessorFrom.first);
159 (*m_relations)->setFromDurability(m_accessorFrom.second);
160 (*m_relations)->setToName(m_accessorTo.first);
161 (*m_relations)->setToDurability(m_accessorTo.second);
162 }
163 return result;
164 }
TObject ** getObject(const StoreAccessorBase &accessor)
Get a pointer to a pointer of an object in the DataStore.
Definition: DataStore.cc:306
void setFromName(const std::string &name)
Set name of the StoreArray we relate from.

◆ end()

const_iterator end ( ) const
inline

Return const_iterator to last entry +1.

Definition at line 371 of file RelationArray.h.

371{ assertValid(); return const_iterator((*m_relations)->elements(), getEntries()); }
int getEntries() const
Get the number of elements.

◆ ensureAttached()

void ensureAttached ( ) const
inlineprivate

Attach to relation, if necessary.

Definition at line 413 of file RelationArray.h.

414 {
415 if (m_relations)
416 return;
417
418 const_cast<RelationArray*>(this)->m_relations = reinterpret_cast<RelationContainer**>(DataStore::Instance().getObject(*this));
419 if (m_relations && *m_relations && !(*m_relations)->isDefaultConstructed()) {
420 AccessorParams fromAccessorRel((*m_relations)->getFromName(), (DataStore::EDurability)(*m_relations)->getFromDurability());
421 AccessorParams toAccessorRel((*m_relations)->getToName(), (DataStore::EDurability)(*m_relations)->getToDurability());
422 //set if unset
423 if (m_accessorFrom.first.empty())
424 const_cast<RelationArray*>(this)->m_accessorFrom = fromAccessorRel;
425 if (m_accessorTo.first.empty())
426 const_cast<RelationArray*>(this)->m_accessorTo = toAccessorRel;
427 checkRelation("from", m_accessorFrom, fromAccessorRel);
428 checkRelation("to", m_accessorTo, toAccessorRel);
429 } else {
430 //no relation found, mark as invalid
431 const_cast<RelationArray*>(this)->m_relations = nullptr;
432 }
433 }
EDurability
Durability types.
Definition: DataStore.h:58
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.
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...
bool isDefaultConstructed() const
Returns true if no information was set yet or Clear() was called.
std::pair< std::string, DataStore::EDurability > AccessorParams
Pair of parameters needed to find an object in the DataStore.

◆ getAccessorParams()

AccessorParams getAccessorParams ( ) const
inlineinherited

Return pair of name and durability under which stored object is saved.


Definition at line 134 of file StoreAccessorBase.h.

134{ return make_pair(m_name, m_durability);}

◆ getClass()

TClass * getClass ( ) const
inlineinherited

The underlying object's type.

Definition at line 149 of file StoreAccessorBase.h.

149{ return m_class; }
TClass * m_class
The underlying object's type.

◆ getDurability()

DataStore::EDurability getDurability ( ) const
inlineinherited

Return durability with which the object is saved in the DataStore.

Definition at line 131 of file StoreAccessorBase.h.

131{ return m_durability; }

◆ getEntries()

int getEntries ( ) const
inline

Get the number of elements.

Definition at line 242 of file RelationArray.h.

242{ return isValid() ? ((*m_relations)->getEntries()) : 0; }

◆ getFromAccessorParams()

const AccessorParams & getFromAccessorParams ( ) const
inline

Return the AccessorParams the attached relation points from.

Definition at line 245 of file RelationArray.h.

246 {
248 if (m_accessorFrom.first.empty())
249 B2FATAL("trying to get accessor params from non-existing relation (this is likely a framework bug)");
250 return m_accessorFrom;
251 }
void ensureAttached() const
Attach to relation, if necessary.

◆ getModified()

bool getModified ( ) const
inline

Get modified flag of underlying container.

Definition at line 263 of file RelationArray.h.

263{ assertValid(); return (*m_relations)->getModified(); }

◆ getName()

const std::string & getName ( ) const
inlineinherited

Return name under which the object is saved in the DataStore.

Definition at line 128 of file StoreAccessorBase.h.

128{ return m_name; }

◆ getToAccessorParams()

const AccessorParams & getToAccessorParams ( ) const
inline

Return the AccessorParams the attached relation points to.

Definition at line 254 of file RelationArray.h.

255 {
257 if (m_accessorTo.first.empty())
258 B2FATAL("trying to get accessor params from non-existing relation (this is likely a framework bug)");
259 return m_accessorTo;
260 }

◆ isArray()

bool isArray ( ) const
inlineinherited

Is this an accessor for an array?

Definition at line 152 of file StoreAccessorBase.h.

152{ return m_isArray; }
bool m_isArray
Is this an accessor for an array?

◆ isOptional()

bool isOptional ( const std::string &  name = "")
inlineinherited

Tell the DataStore about an optional input.

Mainly useful for creating diagrams of module inputs and outputs.

Parameters
nameIf not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event().
Returns
True if the object/array exists.

Definition at line 93 of file StoreAccessorBase.h.

94 {
95 if (!name.empty())
96 m_name = name;
97 return DataStore::Instance().optionalInput(*this);
98 }
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
Definition: DataStore.cc:739

◆ isRequired()

bool isRequired ( const std::string &  name = "")
inlineinherited

Ensure this array/object has been registered previously.

Will cause an ERROR if it does not exist. This must be called in the initialization phase.

Parameters
nameIf not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event().
Returns
True if the object/array exists.

Definition at line 78 of file StoreAccessorBase.h.

79 {
80 if (!name.empty())
81 m_name = name;
82 return DataStore::Instance().requireInput(*this);
83 }
bool requireInput(const StoreAccessorBase &accessor)
Produce ERROR message if no entry of the given type is registered in the DataStore.
Definition: DataStore.cc:722

◆ isValid()

bool isValid ( ) const
inline

Check whether the object was created.

Returns
True if the object exists.

Definition at line 234 of file RelationArray.h.

234{ ensureAttached(); return m_relations && *m_relations;}

◆ next()

RelationElement * next ( )
inlineprivate

Return address where the next RelationElement should be created.

Definition at line 392 of file RelationArray.h.

393 {
394 int index = (*m_relations)->elements().GetLast() + 1;
395 return static_cast<RelationElement*>((*m_relations)->elements().AddrAt(index));
396 }

◆ notWrittenOut()

bool notWrittenOut ( ) const
inherited

Returns true if this object/array should not be saved by output modules.

See DataStore::c_DontWriteOut. Can be changed by re-registering it with/without the flag.

Definition at line 53 of file StoreAccessorBase.cc.

54{
56 if (!entry) {
57 B2ERROR("notWrittenOut(): " << readableName() << " doesn't seem to be registered");
58 return false;
59 }
60 return entry->dontWriteOut;
61}
StoreEntry * getEntry(const StoreAccessorBase &accessor)
Check whether an entry with the correct type is registered in the DataStore map and return it.
Definition: DataStore.cc:294
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: StoreEntry.h:22
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition: StoreEntry.h:40

◆ operator bool()

operator bool ( ) const
inline

Check whether the object was created.

Definition at line 236 of file RelationArray.h.

236{ return isValid(); }

◆ operator!=()

virtual bool operator!= ( const StoreAccessorBase other) const
inlinevirtualinherited

Check if two store accessors point to a different object/array.

Definition at line 143 of file StoreAccessorBase.h.

144 {
145 return !(*this == other);
146 }

◆ operator==()

virtual bool operator== ( const StoreAccessorBase other) const
inlinevirtualinherited

Check if two store accessors point to the same object/array.

Definition at line 137 of file StoreAccessorBase.h.

138 {
139 return getAccessorParams() == other.getAccessorParams();
140 }
AccessorParams getAccessorParams() const
Return pair of name and durability under which stored object is saved.

◆ operator[]()

const RelationElement & operator[] ( int  i) const
inline

Imitate array functionality.

Definition at line 239 of file RelationArray.h.

239{ assertValid(); return (*m_relations)->getElement(i);}

◆ readableName()

std::string readableName ( ) const
inherited

Convert this acessor into a readable string (for messages).

e.g. "object EventMetaData (durability: event)"

Definition at line 18 of file StoreAccessorBase.cc.

19{
20 std::string str(isArray() ? "array" : "object");
21 str += " '" + getName() + "' (durability: ";
22 switch (getDurability()) {
24 str += "event";
25 break;
27 str += "persistent";
28 break;
29 }
30 return str + ")";
31}
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
DataStore::EDurability getDurability() const
Return durability with which the object is saved in the DataStore.
const std::string & getName() const
Return name under which the object is saved in the DataStore.

◆ registerInDataStore() [1/2]

bool registerInDataStore ( const std::string &  name,
DataStore::EStoreFlags  storeFlags = DataStore::c_WriteOut 
)
inlineinherited

Register the object/array in the DataStore.

This must be called in the initialization phase.

Parameters
nameIf not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event().
storeFlagsORed combination of DataStore::EStoreFlags.
Returns
True if the registration succeeded.

Definition at line 64 of file StoreAccessorBase.h.

65 {
66 if (!name.empty())
67 m_name = name;
69 }
bool registerEntry(const std::string &name, EDurability durability, TClass *objClass, bool array, EStoreFlags storeFlags)
Register an entry in the DataStore map.
Definition: DataStore.cc:190

◆ registerInDataStore() [2/2]

bool registerInDataStore ( DataStore::EStoreFlags  storeFlags = DataStore::c_WriteOut)
inlineinherited

Register the object/array in the DataStore.

This must be called in the initialization phase.

Parameters
storeFlagsORed combination of DataStore::EStoreFlags.
Returns
True if the registration succeeded.

Definition at line 52 of file StoreAccessorBase.h.

53 {
55 }

◆ setModified()

void setModified ( bool  modified)
inline

Set modified flag of underlying container.

Definition at line 266 of file RelationArray.h.

266{ assertCreated(); (*m_relations)->setModified(modified); }
void assertCreated()
Create relation, if necessary.

Friends And Related Function Documentation

◆ RelationIndex

friend class RelationIndex
friend

Definition at line 460 of file RelationArray.h.

◆ RelationIndexContainer

friend class RelationIndexContainer
friend

Definition at line 461 of file RelationArray.h.

Member Data Documentation

◆ m_accessorFrom

AccessorParams m_accessorFrom
private

Accessor params for from array.

Definition at line 452 of file RelationArray.h.

◆ m_accessorTo

AccessorParams m_accessorTo
private

Accessor params for to array.

Definition at line 455 of file RelationArray.h.

◆ m_class

TClass* m_class
protectedinherited

The underlying object's type.

Definition at line 172 of file StoreAccessorBase.h.

◆ m_durability

DataStore::EDurability m_durability
protectedinherited

Store durability under which the object/array is saved.

Definition at line 169 of file StoreAccessorBase.h.

◆ m_isArray

bool m_isArray
protectedinherited

Is this an accessor for an array?

Definition at line 175 of file StoreAccessorBase.h.

◆ m_name

std::string m_name
protectedinherited

Store name under which this object/array is saved.

Definition at line 166 of file StoreAccessorBase.h.

◆ m_relations

RelationContainer** m_relations
private

Pointer that actually holds the relations.

Definition at line 458 of file RelationArray.h.


The documentation for this class was generated from the following file: