diff --git a/Trigger/TrigTools/TrigTimeAlgs/TrigTimeAlgs/TrigTimeStamp.h b/Trigger/TrigTools/TrigTimeAlgs/TrigTimeAlgs/TrigTimeStamp.h new file mode 100644 index 0000000000000000000000000000000000000000..feba28a989e5bee96ea060a045fa705416ea64d0 --- /dev/null +++ b/Trigger/TrigTools/TrigTimeAlgs/TrigTimeAlgs/TrigTimeStamp.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef TrigTimeAlgs_TrigTimeStamp_h +#define TrigTimeAlgs_TrigTimeStamp_h + + +#include <chrono> +#include "SGTools/CLASS_DEF.h" +/** + * utility class to measure time duration in AthenaMT + * The pattern when it is useful: + * AlgA tags the beginning of the time period + *AlgA::execute() { + * timeStampHandle.record( std::move( std::make_unique<TrigTimeStamp>() ) ); } + * + * AlgB obtains the duration since the start tagged in AlgA: + * AlgB::execute() { + * double duration = timeStampHandle.cptr().milisecondsSince(); } + **/ +class TrigTimeStamp { +public: + typedef std::chrono::high_resolution_clock::time_point stamp_type; + + TrigTimeStamp() + : m_stamp( std::chrono::high_resolution_clock::now() ) {} + + /** + * time duration between now and when the time stamp was created + **/ + double millisecondsSince() const; + + /** + * Obtain the stamp value. + **/ + stamp_type get() const { return m_stamp; } +private: + stamp_type m_stamp; +}; + + + +CLASS_DEF( TrigTimeStamp , 262409323 , 1 ) + +#endif // TrigTimeAlgs_TrigTimeStamp_h + diff --git a/Trigger/TrigTools/TrigTimeAlgs/src/TrigTimeStamp.cxx b/Trigger/TrigTools/TrigTimeAlgs/src/TrigTimeStamp.cxx new file mode 100644 index 0000000000000000000000000000000000000000..0b571dcbf885fda389ee298700a0cf844b62db4a --- /dev/null +++ b/Trigger/TrigTools/TrigTimeAlgs/src/TrigTimeStamp.cxx @@ -0,0 +1,9 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#include "TrigTimeAlgs/TrigTimeStamp.h" + +double TrigTimeStamp::millisecondsSince() const { + return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now() - m_stamp ).count(); +}