All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/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 (UNLIKELY(outputLevel() <= MSG::DEBUG))
17 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= 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
28  // Call base class initialization
30  if( UNLIKELY(sc.isFailure()) ) return sc;
31 
32  // Set Data Loader
33  SmartIF<IConversionSvc> cnv_svc(serviceLocator()->service(m_persistencySvcName));
34  if( UNLIKELY(!cnv_svc.isValid()) ) {
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.isValid()) ) {
48  error() << "Unable to get AddressCreator." << endmsg;
49  return StatusCode::FAILURE;
50  }
51 
52  return setupDetectorDescription();
53 }
54 
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;
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  std::string dbrName = "/" + m_detDbRootName;
92  sc = i_setRoot( dbrName, rootAddr );
93  if( sc.isFailure() ) {
94  error() << "Unable to set detector data store root" << endmsg;
95  return sc;
96  }
97  }
98  else {
99  error() << "Unable to create address for /dd" << endmsg;
100  return sc;
101  }
102  }
103  // Writing the description file in the output log file [bugs #2854]
104  always() << "Detector description database: " << m_detDbLocation << endmsg;
105  }
106  else {
107  info() << "Detector description not requested to be loaded" << endmsg;
108  }
109 
110  return StatusCode::SUCCESS;
111 }
112 
113 // Service initialisation
115  // The DetectorDataSvc does not need to be re-initialized. If it is done
116  // all the Algorithms having references to DetectorElements will become
117  // invalid and crash the program. (Pere Mato)
118 
119  // Call base class reinitialization
120  //StatusCode sc = DataSvc::reinitialize();
121  //if( sc.isFailure() ) return sc;
122 
123  // Delete the associated event time
124  //if( 0 != m_eventTime ) delete m_eventTime;
125  //m_eventTimeDefined = false;
126 
127  //return setupDetectorDescription();
128  return StatusCode::SUCCESS;
129 }
130 
133 {
134  DEBMSG << "Finalizing" << endmsg;
135 
136  // clears the store
137  m_usePersistency = false; // avoid creation of an empty store when clearing
138  clearStore().ignore();
139 
140  // Releases the address creator
141  m_addrCreator = 0;
142 
143  // Releases the DataLoader
144  setDataLoader(0).ignore();
145 
146  // Finalize the base class
147  return DataSvc::finalize();
148 }
149 
152 
153  MsgStream log(msgSvc(), name());
154 
156 
157  if( m_usePersistency ) {
158  // Create root address
159  unsigned long iargs[] = {0,0};
160  const std::string args[] = {m_detDbLocation, m_detDbRootName};
161  IOpaqueAddress* rootAddr;
162  StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
163  CLID_Catalog,
164  args,
165  iargs,
166  rootAddr);
167  // Set detector data store root
168  if( sc.isSuccess() ) {
169  std::string dbrName = "/" + m_detDbRootName;
170  sc = i_setRoot( dbrName, rootAddr );
171  if( sc.isFailure() ) {
172  error() << "Unable to set detector data store root" << endmsg;
173  }
174  } else {
175  error() << "Unable to create address for /dd" << endmsg;
176  }
177  return sc;
178 
179  }
180  return StatusCode::SUCCESS;
181 
182 }
183 
185 DetDataSvc::DetDataSvc(const std::string& name,ISvcLocator* svc) :
186  base_class(name,svc), m_eventTime(0) {
187  declareProperty("DetStorageType", m_detStorageType = XML_StorageType );
188  declareProperty("DetDbLocation", m_detDbLocation = "empty" );
189  declareProperty("DetDbRootName", m_detDbRootName = "dd" );
190  declareProperty("UsePersistency", m_usePersistency = false );
191  declareProperty("PersistencySvc", m_persistencySvcName = "DetectorPersistencySvc" );
192  m_rootName = "/dd";
193  m_rootCLID = CLID_Catalog;
194  m_addrCreator = 0;
195 }
196 
199 }
200 
202 void DetDataSvc::setEventTime ( const Gaudi::Time& time ) {
203  m_eventTime = time;
204  DEBMSG << "Event Time set to " << eventTime() << endmsg;
205 }
206 
209  return true;
210 }
211 
214  return m_eventTime;
215 }
216 
218 void DetDataSvc::handle ( const Incident& inc ) {
219  ON_DEBUG {
220  debug() << "New incident received" << endmsg;
221  debug() << "Incident source: " << inc.source() << endmsg;
222  debug() << "Incident type: " << inc.type() << endmsg;
223  }
224  return;
225 }
226 
230 
231  DEBMSG << "Method updateObject starting" << endmsg;
232 
233  // Check that object to update exists
234  if ( 0 == toUpdate ) {
235  error() << "There is no DataObject to update" << endmsg;
236  return INVALID_OBJECT;
237  }
238 
239  // Retrieve IValidity interface of object to update
240  IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
241  if ( 0 == condition ) {
242  warning()
243  << "Cannot update DataObject: DataObject does not implement IValidity"
244  << endmsg;
245  return StatusCode::SUCCESS;
246  }
247 
248  // Check that the event time has been defined
249  if ( !validEventTime() ) {
250  warning()
251  << "Cannot update DataObject: event time undefined"
252  << endmsg;
253  return StatusCode::SUCCESS;
254  }
255 
256  // No need to update if condition is valid
257  if ( condition->isValid( eventTime() ) ) {
258  DEBMSG << "DataObject is valid: no need to update" << endmsg;
259  return StatusCode::SUCCESS;
260  } else {
261  DEBMSG << "DataObject is invalid: update it" << endmsg;
262  }
263 
264  // TODO: before loading updated object, update HERE its parent in data store
265 
266  // Now delegate update to the conversion service by calling the base class
267  DEBMSG << "Delegate update to relevant conversion service" << endmsg;
268  StatusCode status = DataSvc::updateObject(toUpdate);
269  if ( !status.isSuccess() ) {
270  error() << "Could not update DataObject" << endmsg;
271  if ( status == NO_DATA_LOADER )
272  error() << "There is no data loader" << endmsg;
273  return status;
274  }
275 
276  // Now cross-check that the new condition is valid
277  condition = dynamic_cast<IValidity*>(toUpdate);
278  if ( 0 == condition ) {
279  error() << "Updated DataObject does not implement IValidity" << endmsg;
280  return StatusCode::FAILURE;
281  }
283  !condition->isValid( eventTime() ) ) {
284  error() << "Updated DataObject is not valid" << endmsg;
285  error() << "Are you sure the conversion service has updated it?" << endmsg;
286  return StatusCode::FAILURE;
287  }
288 
289  // DataObject was successfully updated
290  DEBMSG << "Method updateObject exiting successfully" << endmsg;
291  return StatusCode::SUCCESS;
292 
293 }
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:608
virtual StatusCode setDataLoader(IConversionSvc *svc)
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service.
Definition: DataSvc.cpp:203
#define UNLIKELY(x)
Definition: Kernel.h:127
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
const std::string & type() const
Access to the incident type.
Definition: Incident.h:34
virtual void handle(const Incident &)
Inform that a new incident has occured.
Definition: DetDataSvc.cpp:218
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:40
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
No data loader available.
std::string m_rootName
Name of root event.
Definition: DataSvc.h:50
virtual StatusCode updateObject(IRegistry *pDirectory)
Update object identified by its directory entry.
Definition: DataSvc.cpp:915
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
virtual StatusCode i_setRoot(const std::string &root_name, DataObject *pRootObj)
Initialize data store for new event by giving new event path and root object.
Definition: DataSvc.cpp:165
std::string m_persistencySvcName
Name of the persistency service.
Definition: DetDataSvc.h:92
#define ON_DEBUG
Definition: DetDataSvc.cpp:16
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
virtual bool validEventTime() const
Check if the event time has been set.
Definition: DetDataSvc.cpp:208
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
StatusCode setupDetectorDescription()
Deal with Detector Description initialization.
Definition: DetDataSvc.cpp:55
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Based on seal::Time.
Definition: Time.h:214
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode finalize()
Finalize the service.
Definition: DetDataSvc.cpp:132
SmartIF< IAddressCreator > m_addrCreator
Address Creator to be used.
Definition: DetDataSvc.h:101
int m_detStorageType
Detector Data Persistency Storage type.
Definition: DetDataSvc.h:83
virtual const Gaudi::Time & eventTime() const
Get the event time.
Definition: DetDataSvc.cpp:213
DetDataSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: DetDataSvc.cpp:185
virtual bool isValid() const =0
Check if the object is valid (it can be always invalid).
#define DEBMSG
Definition: DetDataSvc.cpp:19
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: Service.h:56
virtual void setEventTime(const Gaudi::Time &time)
Set the new event time.
Definition: DetDataSvc.cpp:202
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
virtual StatusCode initialize()
Service initialization.
Definition: DataSvc.cpp:1201
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
Definition: System.cpp:628
const long XML_StorageType
Definition: ClassID.h:58
virtual StatusCode clearStore()
Remove all data objects in the data store.
Definition: DetDataSvc.cpp:151
virtual StatusCode updateObject(DataObject *toUpdate)
Update object.
Definition: DetDataSvc.cpp:229
std::string m_detDbRootName
Name of the root node of the detector.
Definition: DetDataSvc.h:89
list args
Definition: gaudirun.py:254
virtual StatusCode clearStore()
IDataManagerSvc: Remove all data objects in the data store.
Definition: DataSvc.cpp:115
Gaudi::Time m_eventTime
Current event time.
Definition: DetDataSvc.h:98
virtual StatusCode reinitialize()
Initialize the service.
Definition: DetDataSvc.cpp:114
std::string m_detDbLocation
Location of detector Db (filename,URL)
Definition: DetDataSvc.h:86
Base class for all Incidents (computing events).
Definition: Incident.h:16
Object pointer is invalid.
Templated class to add the standard messaging functionalities.
Interface for objects with a validity.
Definition: IValidity.h:9
CLID m_rootCLID
Integer Property corresponding to CLID of root entry.
Definition: DataSvc.h:48
Opaque address interface definition.
void ignore() const
Definition: StatusCode.h:107
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:211
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
virtual ~DetDataSvc()
Standard Destructor.
Definition: DetDataSvc.cpp:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual StatusCode finalize()
Service initialization.
Definition: DataSvc.cpp:1241
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool m_usePersistency
Flag to control if the persistency is required.
Definition: DetDataSvc.h:95