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