Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 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/SvcFactory.h"
13 #include "GaudiKernel/System.h"
14 using System::isEnvSet;
15 using System::getEnv;
16 
17 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
18 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
19 
20 #define DEBMSG ON_DEBUG debug()
21 #define VERMSG ON_VERBOSE verbose()
22 
23 // Instantiation of a static factory class used by clients to create
24 // instances of this service
26 
27 // Service initialization
29  // Call base class initialization
31  if( UNLIKELY(sc.isFailure()) ) return sc;
32 
33  // Set Data Loader
34  SmartIF<IConversionSvc> cnv_svc(serviceLocator()->service(m_persistencySvcName));
35  if( UNLIKELY(!cnv_svc.isValid()) ) {
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.isValid()) ) {
49  error() << "Unable to get AddressCreator." << endmsg;
50  return StatusCode::FAILURE;
51  }
52 
53  return setupDetectorDescription();
54 }
55 
57  // Initialize the detector data transient store
58  ON_DEBUG {
59  debug() << "Storage type used is: " << m_detStorageType << endmsg;
60  debug() << "Setting DetectorDataSvc root node... " << endmsg;
61  }
62 
63  if( m_usePersistency ) {
64 
65  IOpaqueAddress* rootAddr;
66  if( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
67 
68  // if the name of DBlocation is not given - construct it!
69  // by retrieving the value of XMLDDBROOT
70 
72  if ( isEnvSet("XMLDDDBROOT") ) {
73  m_detDbLocation = getEnv("XMLDDDBROOT");
74  m_detDbLocation += "/DDDB/lhcb.xml";
75  }
76  }
77  if( m_detDbLocation.empty() || "empty" == m_detDbLocation ) {
78  error() << "Detector data location name not set. Detector data will "
79  "not be found." << endmsg;
80  return StatusCode::FAILURE;
81  }
82  else {
83  // Create address
84  unsigned long iargs[]={0,0};
86  StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
88  args,
89  iargs,
90  rootAddr);
91  if( sc.isSuccess() ) {
92  std::string dbrName = "/" + m_detDbRootName;
93  sc = i_setRoot( dbrName, rootAddr );
94  if( sc.isFailure() ) {
95  error() << "Unable to set detector data store root" << endmsg;
96  return sc;
97  }
98  }
99  else {
100  error() << "Unable to create address for /dd" << endmsg;
101  return sc;
102  }
103  }
104  // Writing the description file in the output log file [bugs #2854]
105  always() << "Detector description database: " << m_detDbLocation << endmsg;
106  }
107  else {
108  info() << "Detector description not requested to be loaded" << endmsg;
109  }
110 
111  return StatusCode::SUCCESS;
112 }
113 
114 // Service initialisation
116  // The DetectorDataSvc does not need to be re-initialized. If it is done
117  // all the Algorithms having references to DetectorElements will become
118  // invalid and crash the program. (Pere Mato)
119 
120  // Call base class reinitialization
121  //StatusCode sc = DataSvc::reinitialize();
122  //if( sc.isFailure() ) return sc;
123 
124  // Delete the associated event time
125  //if( 0 != m_eventTime ) delete m_eventTime;
126  //m_eventTimeDefined = false;
127 
128  //return setupDetectorDescription();
129  return StatusCode::SUCCESS;
130 }
131 
134 {
135  DEBMSG << "Finalizing" << endmsg;
136 
137  // clears the store
138  m_usePersistency = false; // avoid creation of an empty store when clearing
139  clearStore().ignore();
140 
141  // Releases the address creator
142  m_addrCreator = 0;
143 
144  // Releases the DataLoader
145  setDataLoader(0).ignore();
146 
147  // Finalize the base class
148  return DataSvc::finalize();
149 }
150 
153 
154  MsgStream log(msgSvc(), name());
155 
157 
158  if( m_usePersistency ) {
159  // Create root address
160  unsigned long iargs[] = {0,0};
162  IOpaqueAddress* rootAddr;
163  StatusCode sc = m_addrCreator->createAddress (m_detStorageType,
164  CLID_Catalog,
165  args,
166  iargs,
167  rootAddr);
168  // Set detector data store root
169  if( sc.isSuccess() ) {
170  std::string dbrName = "/" + m_detDbRootName;
171  sc = i_setRoot( dbrName, rootAddr );
172  if( sc.isFailure() ) {
173  error() << "Unable to set detector data store root" << endmsg;
174  }
175  } else {
176  error() << "Unable to create address for /dd" << endmsg;
177  }
178  return sc;
179 
180  }
181  return StatusCode::SUCCESS;
182 
183 }
184 
187  base_class(name,svc), m_eventTime(0) {
188  declareProperty("DetStorageType", m_detStorageType = XML_StorageType );
189  declareProperty("DetDbLocation", m_detDbLocation = "empty" );
190  declareProperty("DetDbRootName", m_detDbRootName = "dd" );
191  declareProperty("UsePersistency", m_usePersistency = false );
192  declareProperty("PersistencySvc", m_persistencySvcName = "DetectorPersistencySvc" );
193  m_rootName = "/dd";
195  m_addrCreator = 0;
196 }
197 
200 }
201 
203 void DetDataSvc::setEventTime ( const Gaudi::Time& time ) {
204  m_eventTime = time;
205  DEBMSG << "Event Time set to " << eventTime() << endmsg;
206 }
207 
210  return true;
211 }
212 
214 const Gaudi::Time& DetDataSvc::eventTime ( ) const {
215  return m_eventTime;
216 }
217 
219 void DetDataSvc::handle ( const Incident& inc ) {
220  ON_DEBUG {
221  debug() << "New incident received" << endmsg;
222  debug() << "Incident source: " << inc.source() << endmsg;
223  debug() << "Incident type: " << inc.type() << endmsg;
224  }
225  return;
226 }
227 
231 
232  DEBMSG << "Method updateObject starting" << endmsg;
233 
234  // Check that object to update exists
235  if ( 0 == toUpdate ) {
236  error() << "There is no DataObject to update" << endmsg;
237  return INVALID_OBJECT;
238  }
239 
240  // Retrieve IValidity interface of object to update
241  IValidity* condition = dynamic_cast<IValidity*>( toUpdate );
242  if ( 0 == condition ) {
243  warning()
244  << "Cannot update DataObject: DataObject does not implement IValidity"
245  << endmsg;
246  return StatusCode::SUCCESS;
247  }
248 
249  // Check that the event time has been defined
250  if ( !validEventTime() ) {
251  warning()
252  << "Cannot update DataObject: event time undefined"
253  << endmsg;
254  return StatusCode::SUCCESS;
255  }
256 
257  // No need to update if condition is valid
258  if ( condition->isValid( eventTime() ) ) {
259  DEBMSG << "DataObject is valid: no need to update" << endmsg;
260  return StatusCode::SUCCESS;
261  } else {
262  DEBMSG << "DataObject is invalid: update it" << endmsg;
263  }
264 
265  // TODO: before loading updated object, update HERE its parent in data store
266 
267  // Now delegate update to the conversion service by calling the base class
268  DEBMSG << "Delegate update to relevant conversion service" << endmsg;
269  StatusCode status = DataSvc::updateObject(toUpdate);
270  if ( !status.isSuccess() ) {
271  error() << "Could not update DataObject" << endmsg;
272  if ( status == NO_DATA_LOADER )
273  error() << "There is no data loader" << endmsg;
274  return status;
275  }
276 
277  // Now cross-check that the new condition is valid
278  condition = dynamic_cast<IValidity*>(toUpdate);
279  if ( 0 == condition ) {
280  error() << "Updated DataObject does not implement IValidity" << endmsg;
281  return StatusCode::FAILURE;
282  }
284  !condition->isValid( eventTime() ) ) {
285  error() << "Updated DataObject is not valid" << endmsg;
286  error() << "Are you sure the conversion service has updated it?" << endmsg;
287  return StatusCode::FAILURE;
288  }
289 
290  // DataObject was successfully updated
291  DEBMSG << "Method updateObject exiting successfully" << endmsg;
292  return StatusCode::SUCCESS;
293 
294 }

Generated at Wed Dec 4 2013 14:33:11 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004