Newer
Older
TB_Chris / TbKernel / src / .svn / text-base / TbTimingSvc.h.svn-base
  1. #ifndef TBTIMINGSVC_H
  2. #define TBTIMINGSVC_H 1
  3.  
  4. // Gaudi
  5. #include "GaudiKernel/Service.h"
  6. #include "GaudiKernel/Bootstrap.h"
  7.  
  8. // Local
  9. #include "TbKernel/ITbTimingSvc.h"
  10. #include "TbKernel/ITbGeometrySvc.h"
  11.  
  12. template <class TYPE>
  13. class SvcFactory;
  14.  
  15. /** @class TbTimingSvc TbTimingSvc.h
  16. *
  17. * Implementation of the testbeam timing service.
  18. *
  19. */
  20.  
  21. class TbTimingSvc : public extends1<Service, ITbTimingSvc> {
  22.  
  23. public:
  24. /// Constructor
  25. TbTimingSvc(const std::string& name, ISvcLocator* svc);
  26. /// Destructor
  27. virtual ~TbTimingSvc();
  28.  
  29. virtual StatusCode initialize();
  30. virtual StatusCode finalize();
  31.  
  32. virtual uint64_t localToGlobal(const double& htime);
  33. virtual double globalToLocal(const uint64_t& time);
  34.  
  35. virtual void setEventDefinition(const uint64_t& evtMinTime,
  36. const uint64_t& evtMaxTime) {
  37. m_evtMinTime = evtMinTime;
  38. m_evtMaxTime = evtMaxTime;
  39. }
  40. virtual void eventDefinition(uint64_t& evtMinTime,
  41. uint64_t& evtMaxTime) const {
  42. evtMinTime = m_evtMinTime;
  43. evtMaxTime = m_evtMaxTime;
  44. }
  45.  
  46. virtual void setOverlap(const uint64_t& overlap) { m_overlap = overlap; }
  47. virtual bool inEvent(const uint64_t& time) const {
  48. return time > m_evtMinTime && time < m_evtMaxTime;
  49. }
  50. virtual bool inOverlap(const uint64_t& time) const {
  51. return time > m_evtMaxTime - m_overlap && time < m_evtMaxTime;
  52. }
  53. virtual bool beforeOverlap(const uint64_t& time) const {
  54. return time < m_evtMaxTime - m_overlap;
  55. }
  56.  
  57. private:
  58. /// Allow SvcFactory to instantiate the service.
  59. friend class SvcFactory<TbTimingSvc>;
  60.  
  61. /// Lower limit of the current event (in global time units)
  62. uint64_t m_evtMinTime;
  63. /// Upper limit of the current event (in global time units)
  64. uint64_t m_evtMaxTime;
  65. /// Overlap with the next event (in global time units)
  66. uint64_t m_overlap;
  67.  
  68. /// Pointer to message stream
  69. mutable MsgStream* m_msg;
  70. /// On-demand access to message stream
  71. MsgStream& msg() const {
  72. if (!m_msg) m_msg = new MsgStream(msgSvc(), name());
  73. return *m_msg;
  74. }
  75. };
  76.  
  77. #endif