The Gaudi Framework  v30r3 (a5ef0a68)
DetDataSvc.cpp
Go to the documentation of this file.
1 #define DETECTORDATASVC_DETDATASVC_CPP
2 
3 // Include files
4 #include "DetDataSvc.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
25 
26 // Service initialization
27 StatusCode DetDataSvc::initialize()
28 {
29  // Call base class initialization
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 
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};
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
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 
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 
149 {
150 
152 
153  if ( m_usePersistency ) {
154  // Create root address
155  unsigned long iargs[] = {0, 0};
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 
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 
184 {
185  m_eventTime = time;
186  DEBMSG << "Event Time set to " << eventTime() << endmsg;
187 }
188 
190 bool DetDataSvc::validEventTime() const { return true; }
191 
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 
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 Status::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 == 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 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:411
#define UNLIKELY(x)
Definition: Kernel.h:122
constexpr static const auto FAILURE
Definition: StatusCode.h:88
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:288
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
void handle(const Incident &) override
Inform that a new incident has occured.
Definition: DetDataSvc.cpp:196
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.
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:47
bool validEventTime() const override
Check if the event time has been set.
Definition: DetDataSvc.cpp:190
bool isSuccess() const
Definition: StatusCode.h:287
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
Definition: TsDataSvc.cpp:842
StatusCode updateObject(DataObject *toUpdate) override
Update object.
Definition: DetDataSvc.cpp:208
Gaudi::Property< CLID > m_rootCLID
Definition: TsDataSvc.h:70
Gaudi::Property< std::string > m_detDbRootName
Definition: DetDataSvc.h:98
Gaudi::Property< std::string > m_detDbLocation
Definition: DetDataSvc.h:96
const Gaudi::Time & eventTime() const override
Get the event time.
Definition: DetDataSvc.cpp:193
StatusCode initialize() override
Service initialization.
Definition: TsDataSvc.cpp:1085
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:206
#define ON_DEBUG
Definition: DetDataSvc.cpp:16
bool isFailure() const
Definition: StatusCode.h:139
STL class.
#define DECLARE_COMPONENT(type)
Gaudi::Property< bool > m_usePersistency
Definition: DetDataSvc.h:99
StatusCode setupDetectorDescription()
Deal with Detector Description initialization.
Definition: DetDataSvc.cpp:56
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
StatusCode clearStore() override
Remove all data objects in the data store.
Definition: DetDataSvc.cpp:148
Based on seal::Time.
Definition: Time.h:237
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
SmartIF< IAddressCreator > m_addrCreator
Address Creator to be used.
Definition: DetDataSvc.h:111
DetDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: DetDataSvc.cpp:174
StatusCode reinitialize() override
Initialize the service.
Definition: DetDataSvc.cpp:110
StatusCode finalize() override
Finalize the service.
Definition: DetDataSvc.cpp:129
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
#define DEBMSG
Definition: DetDataSvc.cpp:19
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:433
StatusCode finalize() override
Service initialization.
Definition: TsDataSvc.cpp:1126
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Time m_eventTime
Current event time.
Definition: DetDataSvc.h:108
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:168
virtual bool isValid() const =0
Check if the object is valid (it can be always invalid).
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:165
Base class for all Incidents (computing events).
Definition: Incident.h:17
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:53
Gaudi::Property< int > m_detStorageType
Definition: DetDataSvc.h:94
void setEventTime(const Gaudi::Time &time) override
Set the new event time.
Definition: DetDataSvc.cpp:183
Interface for objects with a validity.
Definition: IValidity.h:12
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
Definition: TsDataSvc.cpp:116
Opaque address interface definition.
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:30
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
Gaudi::Property< std::string > m_rootName
Definition: TsDataSvc.h:71