| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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::isEnvSet;
14 using System::getEnv;
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 {
29 // Call base class initialization
30 StatusCode sc = TsDataSvc::initialize();
31 if ( UNLIKELY( sc.isFailure() ) ) return sc;
32
33 // Set Data Loader
34 auto cnv_svc = serviceLocator()->service<IConversionSvc>( m_persistencySvcName );
35 if ( UNLIKELY( !cnv_svc ) ) {
36 error() << "Unable to retrieve " << m_persistencySvcName << endmsg;
37 return StatusCode::FAILURE;
38 }
39
40 sc = setDataLoader( cnv_svc );
41 if ( UNLIKELY( sc.isFailure() ) ) {
42 error() << "Unable to set DataLoader" << endmsg;
43 return sc;
44 }
45
46 // Get address creator from the DetectorPersistencySvc
47 m_addrCreator = cnv_svc;
48 if ( UNLIKELY( !m_addrCreator ) ) {
49 error() << "Unable to get AddressCreator." << endmsg;
50 return StatusCode::FAILURE;
51 }
52
53 return setupDetectorDescription();
54 }
55
56 StatusCode DetDataSvc::setupDetectorDescription()
57 {
58 // Initialize the detector data transient store
59 ON_DEBUG
60 {
61 debug() << "Storage type used is: " << m_detStorageType << endmsg;
62 debug() << "Setting DetectorDataSvc root node... " << endmsg;
63 }
64
65 if ( m_usePersistency ) {
66
67 IOpaqueAddress* rootAddr = nullptr;
68 if ( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
69
70 // if the name of DBlocation is not given - construct it!
71 // by retrieving the value of XMLDDBROOT
72
74 if ( isEnvSet( "XMLDDDBROOT" ) ) {
75 const std::string loc = getEnv( "XMLDDDBROOT" );
76 m_detDbLocation = loc + "/DDDB/lhcb.xml";
77 }
78 }
79 if ( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
80 error() << "Detector data location name not set. Detector data will "
81 "not be found."
82 << endmsg;
83 return StatusCode::FAILURE;
84 } else {
85 // Create address
86 unsigned long iargs[] = {0, 0};
87 const std::string args[] = {m_detDbLocation, m_detDbRootName};
88 StatusCode sc = m_addrCreator->createAddress( m_detStorageType, CLID_Catalog, args, iargs, rootAddr );
89 if ( sc.isSuccess() ) {
90 sc = i_setRoot( m_rootName, rootAddr );
91 if ( sc.isFailure() ) {
92 error() << "Unable to set detector data store root" << endmsg;
93 return sc;
94 }
95 } else {
96 error() << "Unable to create address for /dd" << endmsg;
97 return sc;
98 }
99 }
100 // Writing the description file in the output log file [bugs #2854]
101 always() << "Detector description database: " << m_detDbLocation.value() << endmsg;
102 } else {
103 info() << "Detector description not requested to be loaded" << endmsg;
104 }
105
106 return StatusCode::SUCCESS;
107 }
108
109 // Service initialisation
110 StatusCode DetDataSvc::reinitialize()
111 {
112 // The DetectorDataSvc does not need to be re-initialized. If it is done
113 // all the Algorithms having references to DetectorElements will become
114 // invalid and crash the program. (Pere Mato)
115
116 // Call base class reinitialization
117 // StatusCode sc = DataSvc::reinitialize();
118 // if( sc.isFailure() ) return sc;
119
120 // Delete the associated event time
121 // if( 0 != m_eventTime ) delete m_eventTime;
122 // m_eventTimeDefined = false;
123
124 // return setupDetectorDescription();
125 return StatusCode::SUCCESS;
126 }
127
129 StatusCode DetDataSvc::finalize()
130 {
131 DEBMSG << "Finalizing" << endmsg;
132
133 // clears the store
134 m_usePersistency = false; // avoid creation of an empty store when clearing
135 clearStore().ignore();
136
137 // Releases the address creator
138 m_addrCreator = nullptr;
139
140 // Releases the DataLoader
141 setDataLoader( nullptr ).ignore();
142
143 // Finalize the base class
144 return TsDataSvc::finalize();
145 }
146
148 StatusCode DetDataSvc::clearStore()
149 {
150
151 TsDataSvc::clearStore().ignore();
152
153 if ( m_usePersistency ) {
154 // Create root address
155 unsigned long iargs[] = {0, 0};
156 const std::string args[] = {m_detDbLocation, m_detDbRootName};
157 IOpaqueAddress* rootAddr;
158 StatusCode sc = m_addrCreator->createAddress( m_detStorageType, CLID_Catalog, args, iargs, rootAddr );
159 // Set detector data store root
160 if ( sc.isSuccess() ) {
161 sc = i_setRoot( m_rootName, rootAddr );
162 if ( sc.isFailure() ) {
163 error() << "Unable to set detector data store root" << endmsg;
164 }
165 } else {
166 error() << "Unable to create address for /dd" << endmsg;
167 }
168 return sc;
169 }
170 return StatusCode::SUCCESS;
171 }
172
174 DetDataSvc::DetDataSvc( const std::string& name, ISvcLocator* svc ) : base_class( name, svc )
175 {
176 m_detDbRootName.declareUpdateHandler(
177 [this]( Gaudi::Details::PropertyBase& ) { m_rootName = "/" + m_detDbRootName; } );
178 m_rootName = "/" + m_detDbRootName;
179 m_rootCLID = CLID_Catalog;
180 }
181
183 void DetDataSvc::setEventTime( const Gaudi::Time& time )
184 {
185 m_eventTime = time;
186 DEBMSG << "Event Time set to " << eventTime() << endmsg;
187 }
188
190 bool DetDataSvc::validEventTime() const { return true; }
191
193 const Gaudi::Time& DetDataSvc::eventTime() const { return m_eventTime; }
194
196 void DetDataSvc::handle( const Incident& inc )
197 {
198 ON_DEBUG
199 {
200 debug() << "New incident received" << endmsg;
201 debug() << "Incident source: " << inc.source() << endmsg;
202 debug() << "Incident type: " << inc.type() << endmsg;
203 }
204 }
205
208 StatusCode DetDataSvc::updateObject( DataObject* toUpdate )
209 {
210
211 DEBMSG << "Method updateObject starting" << endmsg;
212
213 // Check that object to update exists
214 if ( !toUpdate ) {
215 error() << "There is no DataObject to update" << endmsg;
216 return INVALID_OBJECT;
217 }
218
219 // Retrieve IValidity interface of object to update
220 IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
221 if ( !condition ) {
222 warning() << "Cannot update DataObject: DataObject does not implement IValidity" << endmsg;
223 return StatusCode::SUCCESS;
224 }
225
226 // Check that the event time has been defined
227 if ( !validEventTime() ) {
228 warning() << "Cannot update DataObject: event time undefined" << endmsg;
229 return StatusCode::SUCCESS;
230 }
231
232 // No need to update if condition is valid
233 if ( condition->isValid( eventTime() ) ) {
234 DEBMSG << "DataObject is valid: no need to update" << endmsg;
235 return StatusCode::SUCCESS;
236 }
237
238 DEBMSG << "DataObject is invalid: update it" << endmsg;
239 // TODO: before loading updated object, update HERE its parent in data store
240
241 // Now delegate update to the conversion service by calling the base class
242 DEBMSG << "Delegate update to relevant conversion service" << endmsg;
243 StatusCode status = TsDataSvc::updateObject( toUpdate );
244 if ( !status.isSuccess() ) {
245 error() << "Could not update DataObject" << endmsg;
246 if ( status == NO_DATA_LOADER ) error() << "There is no data loader" << endmsg;
247 return status;
248 }
249
250 // Now cross-check that the new condition is valid
251 condition = dynamic_cast<IValidity*>( toUpdate );
252 if ( !condition ) {
253 error() << "Updated DataObject does not implement IValidity" << endmsg;
254 return StatusCode::FAILURE;
255 }
256 if ( FSMState() == Gaudi::StateMachine::RUNNING && !condition->isValid( eventTime() ) ) {
257 error() << "Updated DataObject is not valid" << endmsg;
258 error() << "Are you sure the conversion service has updated it?" << endmsg;
259 return StatusCode::FAILURE;
260 }
261
262 // DataObject was successfully updated
263 DEBMSG << "Method updateObject exiting successfully" << endmsg;
264 return StatusCode::SUCCESS;
265 }
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:550
System.h
StatusCode::SUCCESS
Definition: StatusCode.h:30
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
StatusCode::FAILURE
Definition: StatusCode.h:29
IConversionSvc
Definition: IConversionSvc.h:37
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
gaudirun.args
args
Definition: gaudirun.py:236
DetDataSvc::handle
void handle(const Incident &) override
Inform that a new incident has occured.
Definition: DetDataSvc.cpp:196
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.
Incident::source
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:47
DetDataSvc::validEventTime
bool validEventTime() const override
Check if the event time has been set.
Definition: DetDataSvc.cpp:190
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:74
TsDataSvc::updateObject
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
Definition: TsDataSvc.cpp:1017
DetDataSvc::updateObject
StatusCode updateObject(DataObject *toUpdate) override
Update object.
Definition: DetDataSvc.cpp:208
TsDataSvc::m_rootCLID
Gaudi::Property< CLID > m_rootCLID
Definition: TsDataSvc.h:70
DetDataSvc::m_detDbRootName
Gaudi::Property< std::string > m_detDbRootName
Definition: DetDataSvc.h:97
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:146
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
DetDataSvc::m_detDbLocation
Gaudi::Property< std::string > m_detDbLocation
Definition: DetDataSvc.h:95
DetDataSvc::eventTime
const Gaudi::Time & eventTime() const override
Get the event time.
Definition: DetDataSvc.cpp:193
TsDataSvc::initialize
StatusCode initialize() override
Service initialization.
Definition: TsDataSvc.cpp:1321
DetDataSvc.h
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:214
ON_DEBUG
#define ON_DEBUG
Definition: DetDataSvc.cpp:16
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string
STL class.
DetDataSvc::m_usePersistency
Gaudi::Property< bool > m_usePersistency
Definition: DetDataSvc.h:98
DetDataSvc::setupDetectorDescription
StatusCode setupDetectorDescription()
Deal with Detector Description initialization.
Definition: DetDataSvc.cpp:56
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:117
DetDataSvc
Definition: DetDataSvc.h:30
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:120
DetDataSvc::clearStore
StatusCode clearStore() override
Remove all data objects in the data store.
Definition: DetDataSvc.cpp:148
Gaudi::Time
Based on seal::Time.
Definition: Time.h:213
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
DetDataSvc::m_addrCreator
SmartIF< IAddressCreator > m_addrCreator
Address Creator to be used.
Definition: DetDataSvc.h:110
DetDataSvc::DetDataSvc
DetDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: DetDataSvc.cpp:174
DetDataSvc::reinitialize
StatusCode reinitialize() override
Initialize the service.
Definition: DetDataSvc.cpp:110
DetDataSvc::finalize
StatusCode finalize() override
Finalize the service.
Definition: DetDataSvc.cpp:129
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
DEBMSG
#define DEBMSG
Definition: DetDataSvc.cpp:19
IOpaqueAddress.h
System::isEnvSet
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:570
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
TsDataSvc::finalize
StatusCode finalize() override
Service initialization.
Definition: TsDataSvc.cpp:1362
IAddressCreator.h
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:126
IConversionSvc.h
DetDataSvc::m_eventTime
Gaudi::Time m_eventTime
Current event time.
Definition: DetDataSvc.h:107
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:176
IValidity::isValid
virtual bool isValid() const =0
Check if the object is valid (it can be always invalid).
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
Service::FSMState
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:54
CommonMessaging
Definition: CommonMessaging.h:55
DetDataSvc::m_detStorageType
Gaudi::Property< int > m_detStorageType
Definition: DetDataSvc.h:93
DetDataSvc::setEventTime
void setEventTime(const Gaudi::Time &time) override
Set the new event time.
Definition: DetDataSvc.cpp:183
IValidity
Interface for objects with a validity.
Definition: IValidity.h:9
TsDataSvc::clearStore
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
Definition: TsDataSvc.cpp:115
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106
IValidity.h
CommonMessagingBase::always
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition: CommonMessaging.h:108
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:244
DataObject.h
TsDataSvc::m_rootName
Gaudi::Property< std::string > m_rootName
Definition: TsDataSvc.h:71