CMS 3D CMS Logo

SonicClientBase.cc
Go to the documentation of this file.
4 
6  const std::string& debugName,
7  const std::string& clientName)
8  : allowedTries_(params.getUntrackedParameter<unsigned>("allowedTries", 0)),
9  debugName_(debugName),
10  clientName_(clientName),
11  fullDebugName_(debugName_) {
12  if (!clientName_.empty())
13  fullDebugName_ += ":" + clientName_;
14 
15  std::string modeName(params.getParameter<std::string>("mode"));
16  if (modeName == "Sync")
18  else if (modeName == "Async")
20  else if (modeName == "PseudoAsync")
22  else
23  throw cms::Exception("Configuration") << "Unknown mode for SonicClient: " << modeName;
24 }
25 
27  if (dispatcher_ and mode_ == mode)
28  return;
29  mode_ = mode;
30 
31  //get correct dispatcher for mode
33  dispatcher_ = std::make_unique<SonicDispatcher>(this);
34  else if (mode_ == SonicMode::PseudoAsync)
35  dispatcher_ = std::make_unique<SonicDispatcherPseudoAsync>(this);
36 }
37 
39  start();
40  holder_ = std::move(holder);
41 }
42 
44 
45 void SonicClientBase::finish(bool success, std::exception_ptr eptr) {
46  //retries are only allowed if no exception was raised
47  if (!success and !eptr) {
48  ++tries_;
49  //if max retries has not been exceeded, call evaluate again
50  if (tries_ < allowedTries_) {
51  evaluate();
52  //avoid calling doneWaiting() twice
53  return;
54  }
55  //prepare an exception if exceeded
56  else {
57  cms::Exception ex("SonicCallFailed");
58  ex << "call failed after max " << tries_ << " tries";
59  eptr = make_exception_ptr(ex);
60  }
61  }
62  if (holder_) {
63  holder_->doneWaiting(eptr);
64  holder_.reset();
65  } else if (eptr)
66  std::rethrow_exception(eptr);
67 
68  //reset client data now (usually done at end of produce())
69  if (eptr)
70  reset();
71 }
72 
74  //restrict allowed values
75  desc.ifValue(edm::ParameterDescription<std::string>("mode", "PseudoAsync", true),
76  edm::allowedValues<std::string>("Sync", "Async", "PseudoAsync"));
77  if (allowRetry)
78  desc.addUntracked<unsigned>("allowedTries", 0);
79  desc.addUntracked<bool>("verbose", false);
80 }
SonicClientBase(const edm::ParameterSet &params, const std::string &debugName, const std::string &clientName)
SonicMode
virtual void evaluate()=0
SonicMode mode() const
void setMode(SonicMode mode)
void finish(bool success, std::exception_ptr eptr=std::exception_ptr{})
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::optional< edm::WaitingTaskWithArenaHolder > holder_
static void fillBasePSetDescription(edm::ParameterSetDescription &desc, bool allowRetry=true)
std::string clientName_
std::unique_ptr< SonicDispatcher > dispatcher_
std::string fullDebugName_
unsigned allowedTries_
virtual void reset()
def move(src, dest)
Definition: eostools.py:511