Belle II Software
release-05-01-25
StoreAccessorBase.cc
1
/**************************************************************************
2
* BASF2 (Belle Analysis Framework 2) *
3
* Copyright(C) 2010 - Belle II Collaboration *
4
* *
5
* Author: The Belle II Collaboration *
6
* Contributors: Martin Heck *
7
* *
8
* This software is provided "as is" without any warranty. *
9
**************************************************************************/
10
11
#include <framework/datastore/StoreAccessorBase.h>
12
#include <framework/logging/Logger.h>
13
14
#include <TClass.h>
15
#include <TClonesArray.h>
16
#include <TObject.h>
17
18
using namespace
Belle2
;
19
20
std::string
StoreAccessorBase::readableName
()
const
21
{
22
std::string str(
isArray
() ?
"array"
:
"object"
);
23
str +=
" '"
+
getName
() +
"' (durability: "
;
24
switch
(
getDurability
()) {
25
case
DataStore::c_Event
:
26
str +=
"event"
;
27
break
;
28
case
DataStore::c_Persistent
:
29
str +=
"persistent"
;
30
break
;
31
}
32
return
str +
")"
;
33
}
34
35
bool
StoreAccessorBase::assign
(TObject*
object
,
bool
replace)
36
{
37
if
(not
object
)
38
return
false
;
39
40
bool
success =
false
;
41
const
bool
objIsArray = (
object
->IsA() == TClonesArray::Class());
42
TClass* objClass = objIsArray ? (
static_cast<
TClonesArray*
>
(object))->GetClass() :
object
->IsA();
43
if
(objIsArray !=
isArray
()) {
44
B2ERROR(
"Cannot assign an object to an array (or vice versa); while assigning to "
<<
readableName
());
45
}
else
if
(objClass !=
getClass
()) {
46
B2ERROR(
"Cannot assign() an object of type '"
<< objClass->GetName() <<
"' to "
<<
readableName
() <<
" of type '"
<<
47
getClass
()->GetName() <<
"'!"
);
48
}
else
{
49
success =
DataStore::Instance
().
createObject
(
object
, replace, *
this
);
50
}
51
if
(!success)
52
delete
object;
53
return
success;
54
}
55
bool
StoreAccessorBase::notWrittenOut
()
const
56
{
57
const
DataStore::StoreEntry
* entry =
DataStore::Instance
().
getEntry
(*
this
);
58
if
(!entry) {
59
B2ERROR(
"notWrittenOut(): "
<<
readableName
() <<
" doesn't seem to be registered"
);
60
return
false
;
61
}
62
return
entry->
dontWriteOut
;
63
}
Belle2::StoreAccessorBase::getDurability
DataStore::EDurability getDurability() const
Return durability with which the object is saved in the DataStore.
Definition:
StoreAccessorBase.h:133
Belle2::StoreAccessorBase::getClass
TClass * getClass() const
The underlying object's type.
Definition:
StoreAccessorBase.h:151
Belle2::DataStore::Instance
static DataStore & Instance()
Instance of singleton Store.
Definition:
DataStore.cc:54
Belle2::StoreAccessorBase::readableName
std::string readableName() const
Convert this acessor into a readable string (for messages).
Definition:
StoreAccessorBase.cc:20
Belle2::StoreAccessorBase::assign
bool assign(TObject *object, bool replace=false)
Assign 'object' to this accessor.
Definition:
StoreAccessorBase.cc:35
Belle2::StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
Definition:
StoreEntry.h:15
Belle2::StoreAccessorBase::notWrittenOut
bool notWrittenOut() const
Returns true if this object/array should not be saved by output modules.
Definition:
StoreAccessorBase.cc:55
Belle2::StoreAccessorBase::getName
const std::string & getName() const
Return name under which the object is saved in the DataStore.
Definition:
StoreAccessorBase.h:130
Belle2
Abstract base class for different kinds of events.
Definition:
MillepedeAlgorithm.h:19
Belle2::StoreAccessorBase::isArray
bool isArray() const
Is this an accessor for an array?
Definition:
StoreAccessorBase.h:154
Belle2::DataStore::c_Persistent
@ c_Persistent
Object is available during entire execution time.
Definition:
DataStore.h:62
Belle2::DataStore::createObject
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
Belle2::StoreEntry::dontWriteOut
bool dontWriteOut
Flag that indicates whether the object should be written to the output by default.
Definition:
StoreEntry.h:33
Belle2::DataStore::getEntry
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
Belle2::DataStore::c_Event
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition:
DataStore.h:61
framework
datastore
src
StoreAccessorBase.cc
Generated on Fri Nov 5 2021 03:52:09 for Belle II Software by
1.8.17