The Gaudi Framework  v30r4 (9b837755)
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( 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( 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  setProperty( "RootCLID", CLID_Catalog );
177 }
178 
181 {
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 {
195  ON_DEBUG
196  {
197  debug() << "New incident received" << endmsg;
198  debug() << "Incident source: " << inc.source() << endmsg;
199  debug() << "Incident type: " << inc.type() << endmsg;
200  }
201 }
202 
206 {
207 
208  DEBMSG << "Method updateObject starting" << endmsg;
209 
210  // Check that object to update exists
211  if ( !toUpdate ) {
212  error() << "There is no DataObject to update" << endmsg;
213  return Status::INVALID_OBJECT;
214  }
215 
216  // Retrieve IValidity interface of object to update
217  IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
218  if ( !condition ) {
219  warning() << "Cannot update DataObject: DataObject does not implement IValidity" << endmsg;
220  return StatusCode::SUCCESS;
221  }
222 
223  // Check that the event time has been defined
224  if ( !validEventTime() ) {
225  warning() << "Cannot update DataObject: event time undefined" << endmsg;
226  return StatusCode::SUCCESS;
227  }
228 
229  // No need to update if condition is valid
230  if ( condition->isValid( eventTime() ) ) {
231  DEBMSG << "DataObject is valid: no need to update" << endmsg;
232  return StatusCode::SUCCESS;
233  }
234 
235  DEBMSG << "DataObject is invalid: update it" << endmsg;
236  // TODO: before loading updated object, update HERE its parent in data store
237 
238  // Now delegate update to the conversion service by calling the base class
239  DEBMSG << "Delegate update to relevant conversion service" << endmsg;
240  StatusCode status = TsDataSvc::updateObject( toUpdate );
241  if ( !status.isSuccess() ) {
242  error() << "Could not update DataObject" << endmsg;
243  if ( status == Status::NO_DATA_LOADER ) error() << "There is no data loader" << endmsg;
244  return status;
245  }
246 
247  // Now cross-check that the new condition is valid
248  condition = dynamic_cast<IValidity*>( toUpdate );
249  if ( !condition ) {
250  error() << "Updated DataObject does not implement IValidity" << endmsg;
251  return StatusCode::FAILURE;
252  }
253  if ( FSMState() == Gaudi::StateMachine::RUNNING && !condition->isValid( eventTime() ) ) {
254  error() << "Updated DataObject is not valid" << endmsg;
255  error() << "Are you sure the conversion service has updated it?" << endmsg;
256  return StatusCode::FAILURE;
257  }
258 
259  // DataObject was successfully updated
260  DEBMSG << "Method updateObject exiting successfully" << endmsg;
261  return StatusCode::SUCCESS;
262 }
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:89
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
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
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:193
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:187
bool isSuccess() const
Definition: StatusCode.h:287
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
Definition: TsDataSvc.cpp:699
StatusCode updateObject(DataObject *toUpdate) override
Update object.
Definition: DetDataSvc.cpp:205
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:190
StatusCode initialize() override
Service initialization.
Definition: TsDataSvc.cpp:875
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
#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:104
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:116
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
#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:916
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Time m_eventTime
Current event time.
Definition: DetDataSvc.h:113
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
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:159
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:180
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:109
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