The Gaudi Framework  master (37c0b60a)
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"
15 #include <GaudiKernel/DataObject.h>
20 #include <GaudiKernel/IValidity.h>
21 #include <GaudiKernel/MsgStream.h>
22 #include <GaudiKernel/System.h>
23 using System::getEnv;
24 using System::isEnvSet;
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
37 StatusCode DetDataSvc::initialize() {
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;
46  return StatusCode::FAILURE;
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;
59  return StatusCode::FAILURE;
60  }
61 
62  return setupDetectorDescription();
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;
90  return StatusCode::FAILURE;
91  } else {
92  // Create address
93  unsigned long iargs[] = { 0, 0 };
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 };
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 
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 
187 bool DetDataSvc::validEventTime() const { return true; }
188 
191 
193 void 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 }
DetDataSvc::m_detDbRootName
Gaudi::Property< std::string > m_detDbRootName
Definition: DetDataSvc.h:105
Incident::source
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:54
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:197
std::string
STL class.
IValidity
Definition: IValidity.h:21
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
System.h
ON_DEBUG
#define ON_DEBUG
Definition: DetDataSvc.cpp:26
IOpaqueAddress
Definition: IOpaqueAddress.h:33
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:390
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::setProperty
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
Definition: IProperty.h:39
IAddressCreator.h
ISvcLocator
Definition: ISvcLocator.h:46
TsDataSvc::finalize
StatusCode finalize() override
Service initialization.
Definition: TsDataSvc.cpp:849
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:162
DetDataSvc::m_addrCreator
SmartIF< IAddressCreator > m_addrCreator
Address Creator to be used.
Definition: DetDataSvc.h:125
DetDataSvc::setEventTime
void setEventTime(const Gaudi::Time &time) override
Set the new event time.
Definition: DetDataSvc.cpp:181
TsDataSvc::initialize
StatusCode initialize() override
Service initialization.
Definition: TsDataSvc.cpp:816
DetDataSvc::updateObject
StatusCode updateObject(DataObject *toUpdate) override
Update object.
Definition: DetDataSvc.cpp:203
TsDataSvc::clearStore
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
Definition: TsDataSvc.cpp:117
Service::FSMState
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:62
Gaudi::Time
Definition: Time.h:241
DetDataSvc
Definition: DetDataSvc.h:39
StatusCode
Definition: StatusCode.h:65
DetDataSvc::m_usePersistency
Gaudi::Property< bool > m_usePersistency
Definition: DetDataSvc.h:113
IOpaqueAddress.h
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
DetDataSvc::validEventTime
bool validEventTime() const override
Check if the event time has been set.
Definition: DetDataSvc.cpp:187
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
System::isEnvSet
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:410
DetDataSvc::DetDataSvc
DetDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: DetDataSvc.cpp:176
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
Gaudi::StateMachine::RUNNING
@ RUNNING
Definition: StateMachine.h:26
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:180
DetDataSvc::finalize
StatusCode finalize() override
Finalize the service.
Definition: DetDataSvc.cpp:135
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
DetDataSvc::eventTime
const Gaudi::Time & eventTime() const override
Get the event time.
Definition: DetDataSvc.cpp:190
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
DetDataSvc::setupDetectorDescription
StatusCode setupDetectorDescription()
Deal with Detector Description initialization.
Definition: DetDataSvc.cpp:65
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DetDataSvc::m_detDbLocation
Gaudi::Property< std::string > m_detDbLocation
Definition: DetDataSvc.h:103
DataObject.h
IValidity::isValid
virtual bool isValid() const =0
Check if the object is valid (it can be always invalid).
gaudirun.args
args
Definition: gaudirun.py:336
IValidity.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
TsDataSvc::updateObject
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
Definition: TsDataSvc.cpp:662
DetDataSvc::reinitialize
StatusCode reinitialize() override
Initialize the service.
Definition: DetDataSvc.cpp:117
DataObject
Definition: DataObject.h:36
DetDataSvc::clearStore
StatusCode clearStore() override
Remove all data objects in the data store.
Definition: DetDataSvc.cpp:153
DetDataSvc::handle
void handle(const Incident &) override
Inform that a new incident has occured.
Definition: DetDataSvc.cpp:193
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:48
DetDataSvc::m_detStorageType
Gaudi::Property< int > m_detStorageType
Definition: DetDataSvc.h:101
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
IConversionSvc.h
ISvcLocator.h
DEBMSG
#define DEBMSG
Definition: DetDataSvc.cpp:29
Incident
Definition: Incident.h:27
DetDataSvc.h
DetDataSvc::m_eventTime
Gaudi::Time m_eventTime
Current event time.
Definition: DetDataSvc.h:122
MsgStream.h
IConversionSvc
Definition: IConversionSvc.h:47