| The Gaudi Framework v27r1

- 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/IAddressCreator.h"
6 #include "GaudiKernel/IConversionSvc.h"
7 #include "GaudiKernel/IOpaqueAddress.h"
8 #include "GaudiKernel/ISvcLocator.h"
9 #include "GaudiKernel/IValidity.h"
10 #include "GaudiKernel/DataObject.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 // 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 m_detDbLocation = getEnv("XMLDDDBROOT");
73 m_detDbLocation += "/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." << endmsg;
79 return StatusCode::FAILURE;
80 }
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,
86 CLID_Catalog,
87 args,
88 iargs,
89 rootAddr);
90 if( sc.isSuccess() ) {
91 sc = i_setRoot( "/" + m_detDbRootName, rootAddr );
92 if( sc.isFailure() ) {
93 error() << "Unable to set detector data store root" << endmsg;
94 return sc;
95 }
96 }
97 else {
98 error() << "Unable to create address for /dd" << endmsg;
99 return sc;
100 }
101 }
102 // Writing the description file in the output log file [bugs #2854]
103 always() << "Detector description database: " << m_detDbLocation << endmsg;
104 }
105 else {
106 info() << "Detector description not requested to be loaded" << endmsg;
107 }
108
109 return StatusCode::SUCCESS;
110 }
111
112 // Service initialisation
113 StatusCode DetDataSvc::reinitialize() {
114 // The DetectorDataSvc does not need to be re-initialized. If it is done
115 // all the Algorithms having references to DetectorElements will become
116 // invalid and crash the program. (Pere Mato)
117
118 // Call base class reinitialization
119 //StatusCode sc = DataSvc::reinitialize();
120 //if( sc.isFailure() ) return sc;
121
122 // Delete the associated event time
123 //if( 0 != m_eventTime ) delete m_eventTime;
124 //m_eventTimeDefined = false;
125
126 //return setupDetectorDescription();
127 return StatusCode::SUCCESS;
128 }
129
131 StatusCode DetDataSvc::finalize()
132 {
133 DEBMSG << "Finalizing" << endmsg;
134
135 // clears the store
136 m_usePersistency = false; // avoid creation of an empty store when clearing
137 clearStore().ignore();
138
139 // Releases the address creator
140 m_addrCreator = nullptr;
141
142 // Releases the DataLoader
143 setDataLoader(nullptr).ignore();
144
145 // Finalize the base class
146 return TsDataSvc::finalize();
147 }
148
150 StatusCode DetDataSvc::clearStore() {
151
152 TsDataSvc::clearStore().ignore();
153
154 if( m_usePersistency ) {
155 // Create root address
156 unsigned long iargs[] = {0,0};
157 const std::string args[] = {m_detDbLocation, m_detDbRootName};
158 IOpaqueAddress* rootAddr;
159 StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
160 CLID_Catalog,
161 args,
162 iargs,
163 rootAddr);
164 // Set detector data store root
165 if( sc.isSuccess() ) {
166 sc = i_setRoot( "/" + m_detDbRootName, rootAddr );
167 if( sc.isFailure() ) {
168 error() << "Unable to set detector data store root" << endmsg;
169 }
170 } else {
171 error() << "Unable to create address for /dd" << endmsg;
172 }
173 return sc;
174
175 }
176 return StatusCode::SUCCESS;
177
178 }
179
181 DetDataSvc::DetDataSvc(const std::string& name,ISvcLocator* svc) :
182 base_class(name,svc) {
183 declareProperty("DetStorageType", m_detStorageType = XML_StorageType );
184 declareProperty("DetDbLocation", m_detDbLocation = "empty" );
185 declareProperty("DetDbRootName", m_detDbRootName = "dd" );
186 declareProperty("UsePersistency", m_usePersistency = false );
187 declareProperty("PersistencySvc", m_persistencySvcName = "DetectorPersistencySvc" );
188 m_rootName = "/dd";
189 m_rootCLID = CLID_Catalog;
190 }
191
193 void DetDataSvc::setEventTime ( const Gaudi::Time& time ) {
194 m_eventTime = time;
195 DEBMSG << "Event Time set to " << eventTime() << endmsg;
196 }
197
199 bool DetDataSvc::validEventTime ( ) const {
200 return true;
201 }
202
204 const Gaudi::Time& DetDataSvc::eventTime ( ) const {
205 return m_eventTime;
206 }
207
209 void DetDataSvc::handle ( const Incident& inc ) {
210 ON_DEBUG {
211 debug() << "New incident received" << endmsg;
212 debug() << "Incident source: " << inc.source() << endmsg;
213 debug() << "Incident type: " << inc.type() << endmsg;
214 }
215 }
216
219 StatusCode DetDataSvc::updateObject( DataObject* toUpdate ) {
220
221 DEBMSG << "Method updateObject starting" << endmsg;
222
223 // Check that object to update exists
224 if ( !toUpdate ) {
225 error() << "There is no DataObject to update" << endmsg;
226 return INVALID_OBJECT;
227 }
228
229 // Retrieve IValidity interface of object to update
230 IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
231 if ( !condition ) {
232 warning()
233 << "Cannot update DataObject: DataObject does not implement IValidity"
234 << endmsg;
235 return StatusCode::SUCCESS;
236 }
237
238 // Check that the event time has been defined
239 if ( !validEventTime() ) {
240 warning()
241 << "Cannot update DataObject: event time undefined"
242 << endmsg;
243 return StatusCode::SUCCESS;
244 }
245
246 // No need to update if condition is valid
247 if ( condition->isValid( eventTime() ) ) {
248 DEBMSG << "DataObject is valid: no need to update" << endmsg;
249 return StatusCode::SUCCESS;
250 }
251
252 DEBMSG << "DataObject is invalid: update it" << endmsg;
253 // TODO: before loading updated object, update HERE its parent in data store
254
255 // Now delegate update to the conversion service by calling the base class
256 DEBMSG << "Delegate update to relevant conversion service" << endmsg;
257 StatusCode status = TsDataSvc::updateObject(toUpdate);
258 if ( !status.isSuccess() ) {
259 error() << "Could not update DataObject" << endmsg;
260 if ( status == NO_DATA_LOADER )
261 error() << "There is no data loader" << endmsg;
262 return status;
263 }
264
265 // Now cross-check that the new condition is valid
266 condition = dynamic_cast<IValidity*>(toUpdate);
267 if ( !condition ) {
268 error() << "Updated DataObject does not implement IValidity" << endmsg;
269 return StatusCode::FAILURE;
270 }
271 if ( FSMState() == Gaudi::StateMachine::RUNNING &&
272 !condition->isValid( eventTime() ) ) {
273 error() << "Updated DataObject is not valid" << endmsg;
274 error() << "Are you sure the conversion service has updated it?" << endmsg;
275 return StatusCode::FAILURE;
276 }
277
278 // DataObject was successfully updated
279 DEBMSG << "Method updateObject exiting successfully" << endmsg;
280 return StatusCode::SUCCESS;
281
282 }
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:617
System.h
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
DetDataSvc::validEventTime
bool validEventTime() const override
Check if the event time has been set.
Definition: DetDataSvc.cpp:199
std::string::empty
T empty(T...args)
AnalysisTest.initialize
def initialize()
Definition: AnalysisTest.py:12
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
IConversionSvc
Definition: IConversionSvc.h:37
Service::FSMState
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:57
MsgStream.h
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
plotSpeedupsPyRoot.time
tuple time
Definition: plotSpeedupsPyRoot.py:146
DetDataSvc::eventTime
const Gaudi::Time & eventTime() const override
Get the event time.
Definition: DetDataSvc.cpp:204
DetDataSvc::handle
void handle(const Incident &) override
Inform that a new incident has occured.
Definition: DetDataSvc.cpp:209
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
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
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:219
TsDataSvc::m_rootName
std::string m_rootName
Name of root event.
Definition: TsDataSvc.h:77
TsDataSvc::initialize
StatusCode initialize() override
Service initialization.
Definition: TsDataSvc.cpp:1321
DetDataSvc.h
DetDataSvc::m_persistencySvcName
std::string m_persistencySvcName
Name of the persistency service.
Definition: DetDataSvc.h:98
ON_DEBUG
#define ON_DEBUG
Definition: DetDataSvc.cpp:16
merge_files.sc
int sc
Definition: merge_files.py:167
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string
STL class.
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:118
DetDataSvc
Definition: DetDataSvc.h:28
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
StatusCode::FAILURE
Definition: StatusCode.h:29
DetDataSvc::clearStore
StatusCode clearStore() override
Remove all data objects in the data store.
Definition: DetDataSvc.cpp:150
Gaudi::Time
Based on seal::Time.
Definition: Time.h:213
StatusCode::SUCCESS
Definition: StatusCode.h:30
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:107
DetDataSvc::m_detStorageType
int m_detStorageType
Detector Data Persistency Storage type.
Definition: DetDataSvc.h:89
DetDataSvc::DetDataSvc
DetDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: DetDataSvc.cpp:181
DetDataSvc::reinitialize
StatusCode reinitialize() override
Initialize the service.
Definition: DetDataSvc.cpp:113
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:131
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:637
XML_StorageType
const long XML_StorageType
Definition: ClassID.h:57
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:16
TsDataSvc::setDataLoader
StatusCode setDataLoader(IConversionSvc *svc, IDataProviderSvc *dpsvc=0) override
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service and optionally a data pro...
Definition: TsDataSvc.cpp:214
DetDataSvc::m_detDbRootName
std::string m_detDbRootName
Name of the root node of the detector.
Definition: DetDataSvc.h:95
TsDataSvc::finalize
StatusCode finalize() override
Service initialization.
Definition: TsDataSvc.cpp:1362
gaudirun.args
list args
Definition: gaudirun.py:290
IAddressCreator.h
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
IConversionSvc.h
DetDataSvc::m_eventTime
Gaudi::Time m_eventTime
Current event time.
Definition: DetDataSvc.h:104
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
DetDataSvc::m_detDbLocation
std::string m_detDbLocation
Location of detector Db (filename,URL)
Definition: DetDataSvc.h:92
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
CommonMessaging
Definition: CommonMessaging.h:58
DetDataSvc::setEventTime
void setEventTime(const Gaudi::Time &time) override
Set the new event time.
Definition: DetDataSvc.cpp:193
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:108
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
TsDataSvc::m_rootCLID
CLID m_rootCLID
Integer Property corresponding to CLID of root entry.
Definition: TsDataSvc.h:75
IValidity.h
CommonMessagingBase::always
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition: CommonMessaging.h:109
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
DetDataSvc::m_usePersistency
bool m_usePersistency
Flag to control if the persistency is required.
Definition: DetDataSvc.h:101
DataObject.h