Newer
Older
Tb / TbKernel / src / .svn / text-base / TbTimingSvc.cpp.svn-base
  1. // Gaudi
  2. #include "GaudiKernel/MsgStream.h"
  3.  
  4. // Local
  5. #include "TbTimingSvc.h"
  6.  
  7. DECLARE_SERVICE_FACTORY(TbTimingSvc)
  8.  
  9. //============================================================================
  10. // Constructor
  11. //============================================================================
  12. TbTimingSvc::TbTimingSvc(const std::string& name, ISvcLocator* svc)
  13. : base_class(name, svc),
  14. m_evtMinTime(0UL),
  15. m_evtMaxTime(0UL),
  16. m_msg(NULL) {}
  17.  
  18. //============================================================================
  19. // Destructor
  20. //============================================================================
  21. TbTimingSvc::~TbTimingSvc() {
  22.  
  23. // Delete the message service.
  24. if (m_msg) delete m_msg;
  25. }
  26.  
  27. //============================================================================
  28. // Initialisation
  29. //============================================================================
  30. StatusCode TbTimingSvc::initialize() {
  31.  
  32. // Initialise the base class.
  33. StatusCode sc = Service::initialize();
  34. if (!sc.isSuccess()) return sc;
  35. return StatusCode::SUCCESS;
  36. }
  37.  
  38. //============================================================================
  39. // Finalisation
  40. //============================================================================
  41. StatusCode TbTimingSvc::finalize() {
  42.  
  43. // Finalise the base class.
  44. return Service::finalize();
  45. }
  46.  
  47. //============================================================================
  48. // Convert local time (in ns) to global timestamp.
  49. //============================================================================
  50. uint64_t TbTimingSvc::localToGlobal(const double& htime) {
  51.  
  52. // Conversion factor (25 ns correspond to 4096 global time units).
  53. constexpr double f = 4096. / 25.;
  54. const double dt = floor(htime * f);
  55. return dt < 0. ? m_evtMinTime - static_cast<uint64_t>(fabs(dt))
  56. : m_evtMinTime + static_cast<uint64_t>(dt);
  57. }
  58.  
  59. //============================================================================
  60. // Convert global timestamp to local time (in ns).
  61. //============================================================================
  62. double TbTimingSvc::globalToLocal(const uint64_t& time) {
  63. // Conversion factor (4096 global time units correspond to 25 ns).
  64. constexpr double f = 25. / 4096.;
  65. return time < m_evtMinTime ? -f * (m_evtMinTime - time)
  66. : f * (time - m_evtMinTime);
  67. }