HeterogeneousCore
SonicCore
interface
SonicClientBase.h
Go to the documentation of this file.
1
#ifndef HeterogeneousCore_SonicCore_SonicClientBase
2
#define HeterogeneousCore_SonicCore_SonicClientBase
3
4
#include "
FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h
"
5
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
6
7
#include <string>
8
#include <chrono>
9
#include <exception>
10
11
class
SonicClientBase
{
12
public
:
13
//constructor
14
SonicClientBase
() :
tries_
(0) {}
15
16
//destructor
17
virtual
~SonicClientBase
() =
default
;
18
19
void
setDebugName
(
const
std::string
&
debugName
) {
debugName_
=
debugName
; }
20
const
std::string
&
debugName
()
const
{
return
debugName_
; }
21
22
//main operation
23
virtual
void
dispatch
(
edm::WaitingTaskWithArenaHolder
holder) = 0;
24
25
protected
:
26
virtual
void
evaluate
() = 0;
27
28
//this should be overridden by clients that allow retries
29
virtual
unsigned
allowedTries
()
const
{
return
0; }
30
31
void
setStartTime
() {
32
tries_
= 0;
33
if
(
debugName_
.empty())
34
return
;
35
t0_
=
std::chrono::high_resolution_clock::now
();
36
}
37
38
void
finish
(
bool
success
, std::exception_ptr eptr = std::exception_ptr{}) {
39
//retries are only allowed if no exception was raised
40
if
(!
success
and !eptr) {
41
++
tries_
;
42
//if max retries has not been exceeded, call evaluate again
43
if
(
tries_
<
allowedTries
()) {
44
evaluate
();
45
//avoid calling doneWaiting() twice
46
return
;
47
}
48
//prepare an exception if exceeded
49
else
{
50
cms::Exception
ex(
"SonicCallFailed"
);
51
ex <<
"call failed after max "
<<
tries_
<<
" tries"
;
52
eptr = make_exception_ptr(ex);
53
}
54
}
55
if
(!
debugName_
.empty()) {
56
auto
t1
=
std::chrono::high_resolution_clock::now
();
57
edm::LogInfo
(
debugName_
) <<
"Client time: "
58
<< std::chrono::duration_cast<std::chrono::microseconds>(
t1
-
t0_
).count();
59
}
60
holder_
.
doneWaiting
(eptr);
61
}
62
63
//members
64
unsigned
tries_
;
65
edm::WaitingTaskWithArenaHolder
holder_
;
66
67
//for logging/debugging
68
std::string
debugName_
;
69
std::chrono::time_point<std::chrono::high_resolution_clock>
t0_
;
70
};
71
72
#endif
MessageLogger.h
SonicClientBase::SonicClientBase
SonicClientBase()
Definition:
SonicClientBase.h:14
SonicClientBase::~SonicClientBase
virtual ~SonicClientBase()=default
edm::LogInfo
Definition:
MessageLogger.h:254
SonicClientBase::finish
void finish(bool success, std::exception_ptr eptr=std::exception_ptr{})
Definition:
SonicClientBase.h:38
SonicClientBase::debugName
const std::string & debugName() const
Definition:
SonicClientBase.h:20
SonicClientBase::tries_
unsigned tries_
Definition:
SonicClientBase.h:64
SonicClientBase
Definition:
SonicClientBase.h:11
fileCollector.now
now
Definition:
fileCollector.py:207
edm::WaitingTaskWithArenaHolder
Definition:
WaitingTaskWithArenaHolder.h:31
RandomServiceHelper.t1
t1
Definition:
RandomServiceHelper.py:256
SonicClientBase::allowedTries
virtual unsigned allowedTries() const
Definition:
SonicClientBase.h:29
SonicClientBase::holder_
edm::WaitingTaskWithArenaHolder holder_
Definition:
SonicClientBase.h:65
summarizeEdmComparisonLogfiles.success
success
Definition:
summarizeEdmComparisonLogfiles.py:115
SonicClientBase::evaluate
virtual void evaluate()=0
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
SonicClientBase::setDebugName
void setDebugName(const std::string &debugName)
Definition:
SonicClientBase.h:19
SonicClientBase::setStartTime
void setStartTime()
Definition:
SonicClientBase.h:31
WaitingTaskWithArenaHolder.h
SonicClientBase::debugName_
std::string debugName_
Definition:
SonicClientBase.h:68
SonicClientBase::dispatch
virtual void dispatch(edm::WaitingTaskWithArenaHolder holder)=0
SonicClientBase::t0_
std::chrono::time_point< std::chrono::high_resolution_clock > t0_
Definition:
SonicClientBase.h:69
cms::Exception
Definition:
Exception.h:70
edm::WaitingTaskWithArenaHolder::doneWaiting
void doneWaiting(std::exception_ptr iExcept)
Definition:
WaitingTaskWithArenaHolder.cc:62
Generated for CMSSW Reference Manual by
1.8.16