| The Gaudi Framework v32r1 (f65d50dc)

DetDataSvc.cpp
Go to the documentation of this file.
1 #define DETECTORDATASVC_DETDATASVC_CPP
2
3 // Include files
4 #include "DetDataSvc.h"
5 #include "GaudiKernel/DataObject.h"
6 #include "GaudiKernel/IAddressCreator.h"
7 #include "GaudiKernel/IConversionSvc.h"
8 #include "GaudiKernel/IOpaqueAddress.h"
9 #include "GaudiKernel/ISvcLocator.h"
10 #include "GaudiKernel/IValidity.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "GaudiKernel/System.h"
13 using System::getEnv;
14 using System::isEnvSet;
15
16 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
17 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
18
19 #define DEBMSG ON_DEBUG debug()
20 #define VERMSG ON_VERBOSE verbose()
21
22 // Instantiation of a static factory class used by clients to create
23 // instances of this service
24 DECLARE_COMPONENT( DetDataSvc )
25
26 // Service initialization
27 StatusCode DetDataSvc::initialize() {
28 // Call base class initialization
29 StatusCode sc = TsDataSvc::initialize();
30 if ( UNLIKELY( sc.isFailure() ) ) return sc;
31
32 // Set Data Loader
33 auto cnv_svc = serviceLocator()->service<IConversionSvc>( m_persistencySvcName );
34 if ( UNLIKELY( !cnv_svc ) ) {
35 error() << "Unable to retrieve " << m_persistencySvcName << endmsg;
36 return StatusCode::FAILURE;
37 }
38
39 sc = setDataLoader( cnv_svc );
40 if ( UNLIKELY( sc.isFailure() ) ) {
41 error() << "Unable to set DataLoader" << endmsg;
42 return sc;
43 }
44
45 // Get address creator from the DetectorPersistencySvc
46 m_addrCreator = cnv_svc;
47 if ( UNLIKELY( !m_addrCreator ) ) {
48 error() << "Unable to get AddressCreator." << endmsg;
49 return StatusCode::FAILURE;
50 }
51
52 return setupDetectorDescription();
53 }
54
55 StatusCode DetDataSvc::setupDetectorDescription() {
56 // Initialize the detector data transient store
57 ON_DEBUG {
58 debug() << "Storage type used is: " << m_detStorageType << endmsg;
59 debug() << "Setting DetectorDataSvc root node... " << endmsg;
60 }
61
62 if ( m_usePersistency ) {
63
64 IOpaqueAddress* rootAddr = nullptr;
65 if ( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
66
67 // if the name of DBlocation is not given - construct it!
68 // by retrieving the value of XMLDDBROOT
69
71 if ( isEnvSet( "XMLDDDBROOT" ) ) {
72 const std::string loc = getEnv( "XMLDDDBROOT" );
73 m_detDbLocation = loc + "/DDDB/lhcb.xml";
74 }
75 }
76 if ( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
77 error() << "Detector data location name not set. Detector data will "
78 "not be found."
79 << endmsg;
80 return StatusCode::FAILURE;
81 } else {
82 // Create address
83 unsigned long iargs[] = {0, 0};
84 const std::string args[] = {m_detDbLocation, m_detDbRootName};
85 StatusCode sc = m_addrCreator->createAddress( m_detStorageType, CLID_Catalog, args, iargs, rootAddr );
86 if ( sc.isSuccess() ) {
87 sc = i_setRoot( rootAddr );
88 if ( sc.isFailure() ) {
89 error() << "Unable to set detector data store root" << endmsg;
90 return sc;
91 }
92 } else {
93 error() << "Unable to create address for /dd" << endmsg;
94 return sc;
95 }
96 }
97 // Writing the description file in the output log file [bugs #2854]
98 always() << "Detector description database: " << m_detDbLocation.value() << endmsg;
99 } else {
100 info() << "Detector description not requested to be loaded" << endmsg;
101 }
102
103 return StatusCode::SUCCESS;
104 }
105
106 // Service initialisation
107 StatusCode DetDataSvc::reinitialize() {
108 // The DetectorDataSvc does not need to be re-initialized. If it is done
109 // all the Algorithms having references to DetectorElements will become
110 // invalid and crash the program. (Pere Mato)
111
112 // Call base class reinitialization
113 // StatusCode sc = DataSvc::reinitialize();
114 // if( sc.isFailure() ) return sc;
115
116 // Delete the associated event time
117 // if( 0 != m_eventTime ) delete m_eventTime;
118 // m_eventTimeDefined = false;
119
120 // return setupDetectorDescription();
121 return StatusCode::SUCCESS;
122 }
123
125 StatusCode DetDataSvc::finalize() {
126 DEBMSG << "Finalizing" << endmsg;
127
128 // clears the store
129 m_usePersistency = false; // avoid creation of an empty store when clearing
130 clearStore().ignore();
131
132 // Releases the address creator
133 m_addrCreator = nullptr;
134
135 // Releases the DataLoader
136 setDataLoader( nullptr ).ignore();
137
138 // Finalize the base class
139 return TsDataSvc::finalize();
140 }
141
143 StatusCode DetDataSvc::clearStore() {
144
145 TsDataSvc::clearStore().ignore();
146
147 if ( m_usePersistency ) {
148 // Create root address
149 unsigned long iargs[] = {0, 0};
150 const std::string args[] = {m_detDbLocation, m_detDbRootName};
151 IOpaqueAddress* rootAddr;
152 StatusCode sc = m_addrCreator->createAddress( m_detStorageType, CLID_Catalog, args, iargs, rootAddr );
153 // Set detector data store root
154 if ( sc.isSuccess() ) {
155 sc = i_setRoot( rootAddr );
156 if ( sc.isFailure() ) { error() << "Unable to set detector data store root" << endmsg; }
157 } else {
158 error() << "Unable to create address for /dd" << endmsg;
159 }
160 return sc;
161 }
162 return StatusCode::SUCCESS;
163 }
164
166 DetDataSvc::DetDataSvc( const std::string& name, ISvcLocator* svc ) : extends( name, svc ) {
167 setProperty( "RootCLID", CLID_Catalog );
168 }
169
171 void DetDataSvc::setEventTime( const Gaudi::Time& time ) {
172 m_eventTime = time;
173 DEBMSG << "Event Time set to " << eventTime() << endmsg;
174 }
175
177 bool DetDataSvc::validEventTime() const { return true; }
178
180 const Gaudi::Time& DetDataSvc::eventTime() const { return m_eventTime; }
181
183 void DetDataSvc::handle( const Incident& inc ) {
184 ON_DEBUG {
185 debug() << "New incident received" << endmsg;
186 debug() << "Incident source: " << inc.source() << endmsg;
187 debug() << "Incident type: " << inc.type() << endmsg;
188 }
189 }
190
193 StatusCode DetDataSvc::updateObject( DataObject* toUpdate ) {
194
195 DEBMSG << "Method updateObject starting" << endmsg;
196
197 // Check that object to update exists
198 if ( !toUpdate ) {
199 error() << "There is no DataObject to update" << endmsg;
200 return Status::INVALID_OBJECT;
201 }
202
203 // Retrieve IValidity interface of object to update
204 IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
205 if ( !condition ) {
206 warning() << "Cannot update DataObject: DataObject does not implement IValidity" << endmsg;
207 return StatusCode::SUCCESS;
208 }
209
210 // Check that the event time has been defined
211 if ( !validEventTime() ) {
212 warning() << "Cannot update DataObject: event time undefined" << endmsg;
213 return StatusCode::SUCCESS;
214 }
215
216 // No need to update if condition is valid
217 if ( condition->isValid( eventTime() ) ) {
218 DEBMSG << "DataObject is valid: no need to update" << endmsg;
219 return StatusCode::SUCCESS;
220 }
221
222 DEBMSG << "DataObject is invalid: update it" << endmsg;
223 // TODO: before loading updated object, update HERE its parent in data store
224
225 // Now delegate update to the conversion service by calling the base class
226 DEBMSG << "Delegate update to relevant conversion service" << endmsg;
227 StatusCode status = TsDataSvc::updateObject( toUpdate );
228 if ( !status.isSuccess() ) {
229 error() << "Could not update DataObject" << endmsg;
230 if ( status == Status::NO_DATA_LOADER ) error() << "There is no data loader" << endmsg;
231 return status;
232 }
233
234 // Now cross-check that the new condition is valid
235 condition = dynamic_cast<IValidity*>( toUpdate );
236 if ( !condition ) {
237 error() << "Updated DataObject does not implement IValidity" << endmsg;
238 return StatusCode::FAILURE;
239 }
240 if ( FSMState() == Gaudi::StateMachine::RUNNING && !condition->isValid( eventTime() ) ) {
241 error() << "Updated DataObject is not valid" << endmsg;
242 error() << "Are you sure the conversion service has updated it?" << endmsg;
243 return StatusCode::FAILURE;
244 }
245
246 // DataObject was successfully updated
247 DEBMSG << "Method updateObject exiting successfully" << endmsg;
248 return StatusCode::SUCCESS;
249 }
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:152
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:369
System.h
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:96
DetDataSvc::validEventTime
bool validEventTime() const override
Check if the event time has been set.
Definition: DetDataSvc.cpp:177
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
IConversionSvc
Definition: IConversionSvc.h:37
Service::FSMState
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:52
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
Definition: PropertyHolder.h:145
MsgStream.h
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:101
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:38
DetDataSvc::eventTime
const Gaudi::Time & eventTime() const override
Get the event time.
Definition: DetDataSvc.cpp:180
DetDataSvc::handle
void handle(const Incident &) override
Inform that a new incident has occured.
Definition: DetDataSvc.cpp:183
IAddressCreator::createAddress
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ipar, IOpaqueAddress *&refpAddress)=0
Create a Generic address using explicit arguments to identify a single object.
TsDataSvc::updateObject
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
Definition: TsDataSvc.cpp:649
DetDataSvc::updateObject
StatusCode updateObject(DataObject *toUpdate) override
Update object.
Definition: DetDataSvc.cpp:193
DetDataSvc::m_detDbRootName
Gaudi::Property< std::string > m_detDbRootName
Definition: DetDataSvc.h:96
DetDataSvc::m_detDbLocation
Gaudi::Property< std::string > m_detDbLocation
Definition: DetDataSvc.h:94
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
TsDataSvc::initialize
StatusCode initialize() override
Service initialization.
Definition: TsDataSvc.cpp:803
DetDataSvc.h
CommonMessagingBase::always
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition: CommonMessaging.h:89
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:104
TsDataSvc::setDataLoader
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc=nullptr) override
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service and optionally a data pro...
Definition: TsDataSvc.cpp:184
ON_DEBUG
#define ON_DEBUG
Definition: DetDataSvc.cpp:16
Incident::source
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:44
std::string
STL class.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
DetDataSvc::m_usePersistency
Gaudi::Property< bool > m_usePersistency
Definition: DetDataSvc.h:104
DetDataSvc::setupDetectorDescription
StatusCode setupDetectorDescription()
Deal with Detector Description initialization.
Definition: DetDataSvc.cpp:55
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
DetDataSvc
A DataSvc specialized in detector data.
Definition: DetDataSvc.h:29
gaudirun.args
args
Definition: gaudirun.py:307
DetDataSvc::clearStore
StatusCode clearStore() override
Remove all data objects in the data store.
Definition: DetDataSvc.cpp:143
Gaudi::Time
Based on seal::Time.
Definition: Time.h:231
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
DetDataSvc::m_addrCreator
SmartIF< IAddressCreator > m_addrCreator
Address Creator to be used.
Definition: DetDataSvc.h:116
DetDataSvc::DetDataSvc
DetDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: DetDataSvc.cpp:166
DetDataSvc::reinitialize
StatusCode reinitialize() override
Initialize the service.
Definition: DetDataSvc.cpp:107
IValidity::isValid
virtual bool isValid() const =0
Check if the object is valid (it can be always invalid).
DetDataSvc::finalize
StatusCode finalize() override
Finalize the service.
Definition: DetDataSvc.cpp:125
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:107
DEBMSG
#define DEBMSG
Definition: DetDataSvc.cpp:19
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
IOpaqueAddress.h
System::isEnvSet
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:389
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
TsDataSvc::finalize
StatusCode finalize() override
Service initialization.
Definition: TsDataSvc.cpp:840
IAddressCreator.h
IConversionSvc.h
DetDataSvc::m_eventTime
Gaudi::Time m_eventTime
Current event time.
Definition: DetDataSvc.h:113
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
TsDataSvc::i_setRoot
virtual StatusCode i_setRoot(std::string root_name, DataObject *pRootObj)
Initialize data store for new event by giving new event path and root object.
Definition: TsDataSvc.cpp:149
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
DetDataSvc::m_detStorageType
Gaudi::Property< int > m_detStorageType
Definition: DetDataSvc.h:92
DetDataSvc::setEventTime
void setEventTime(const Gaudi::Time &time) override
Set the new event time.
Definition: DetDataSvc.cpp:171
IValidity
Interface for objects with a validity.
Definition: IValidity.h:11
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
TsDataSvc::clearStore
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
Definition: TsDataSvc.cpp:104
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
IValidity.h
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
DataObject.h