Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lem::LEMClient Class Reference

Fetch LEM PID result from remote server. More...

Inheritance diagram for lem::LEMClient:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using Parameters = art::EDProducer::Table< LEMClientParams >
 
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 LEMClient (const Parameters &params)
 
 ~LEMClient ()
 
virtual void beginJob ()
 
virtual void produce (art::Event &evt)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Protected Attributes

LEMClientParams fParams
 
std::string fClientID
 

Detailed Description

Fetch LEM PID result from remote server.

Definition at line 56 of file LEMClient_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

Definition at line 60 of file LEMClient_module.cc.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

lem::LEMClient::LEMClient ( const Parameters params)
explicit

Definition at line 75 of file LEMClient_module.cc.

References fClientID, genie::utils::style::Format(), cet::getenv(), drop_table::host, and drop_table::user.

76  : fParams(params())
77  {
78  produces<std::vector<lem::PIDDetails>>();
79  produces<art::Assns<lem::PIDDetails, rb::Cluster>>();
80 
81  // Generate a unique ID so that the server can identify us.
82  char host[1024];
83  gethostname(host, 1023);
84  host[1023] = 0;
85  const char* user = getenv("USER");
86  if(!user) user = "(unknown)";
87  fClientID = TString::Format("%s@%s.%d.%ld",
88  user, host, getpid(), time(0)).Data();
89 
90  curl_global_init(CURL_GLOBAL_ALL);
91  }
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
std::string getenv(std::string const &name)
std::string fClientID
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
LEMClientParams fParams
lem::LEMClient::~LEMClient ( )

Definition at line 94 of file LEMClient_module.cc.

95  {
96  curl_global_cleanup();
97  }

Member Function Documentation

void lem::LEMClient::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 100 of file LEMClient_module.cc.

101  {
102  // Randomize ports and so on properly
103  srand(getpid());
104  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDProducer::currentContext ( ) const
protectedinherited
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

Referenced by skim::NueSkimmer::CopyMichelSlice(), and skim::NueSkimmer::CopyMichelTrack().

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void lem::LEMClient::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 107 of file LEMClient_module.cc.

References make_syst_table_plots::args, ana::assert(), lem::LiteHit::cellIdx, om::cerr, util::CreateAssn(), DEFINE_ART_MODULE(), allTimeWatchdog::endl, fClientID, PandAna.Demos.pi0_spectra::fmt, genie::utils::style::Format(), fParams, lem::PIDDetails::FromString(), lem::get_release(), art::DataViewImpl::getByLabel(), lem::LEMInput::hits, lem::LEMWebSettings::host, dumpEventsToText::inputs, lem::LEMWebSettings::maxPort, lem::LEMWebSettings::minPort, lem::LiteHit::pecorr, lem::post_query(), art::Event::put(), lem::LEMWebSettings::queryTimeout, shutoffs::rel, lem::LEMWebSettings::retryTimeout, string, and lem::LEMInput::totalGeV.

108  {
109  std::unique_ptr<std::vector<lem::PIDDetails> > pidcol(new std::vector<lem::PIDDetails>);
110  std::unique_ptr<art::Assns<lem::PIDDetails, rb::Cluster>> assns(new art::Assns<lem::PIDDetails, rb::Cluster>);
111 
112  const std::string rel = fParams.releaseOverride().empty() ? get_release() : fParams.releaseOverride();
113 
114  const LEMWebSettings& web = fParams.web();
115 
116  const std::string args = TString::Format("rel=%s&id=%s&timeout=%d",
117  rel.c_str(),
118  fClientID.c_str(),
119  web.queryTimeout()).Data();
120 
122  evt.getByLabel(fParams.inputLabel(), inputs);
123  art::FindManyP<rb::Cluster> fmt(inputs, evt, fParams.inputLabel());
124 
125  const int inputMax = inputs->size();
126  for(int inputIdx = 0; inputIdx < inputMax; ++inputIdx){
127  const LEMInput& input = (*inputs)[inputIdx];
128 
129  // DBL_DIG of precision guarantee the number roundtrips safely
130  std::string postdata = TString::Format("E=%.*g\n",
131  DBL_DIG, input.totalGeV).Data();
132  for(const LiteHit& hit: input.hits){
133  postdata += TString::Format("%d %.*g\n",
134  hit.cellIdx, DBL_DIG, hit.pecorr).Data();
135  }
136 
137  bool ok;
138  const std::string response = post_query(web.host(),
139  "pid?"+args,
140  postdata,
141  web.minPort(),
142  web.maxPort(),
143  web.queryTimeout(),
144  web.retryTimeout(),
145  ok);
146  if(!ok){
147  std::cerr << "No response from server after many retries. Aborting"
148  << std::endl;
149  abort();
150  }
151 
152  pidcol->push_back(PIDDetails::FromString(response));
153 
154  // Get all the slices associated with this match list
155  const std::vector<art::Ptr<rb::Cluster> > slices = fmt.at(inputIdx);
156  assert(slices.size() == 1);
157  util::CreateAssn(*this, evt, *pidcol, slices[0], *assns);
158  }
159 
160  evt.put(std::move(pidcol));
161  evt.put(std::move(assns));
162  }
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
OStream cerr
Definition: OStream.cxx:7
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::string post_query(const std::string &host, const std::string &query, const std::string &postdata, int minPort, int maxPort, int queryTimeout, int retryTimeout, bool &ok)
Make an HTTP POST query.
Definition: WebUtils.cxx:162
std::string get_release()
Figure out the current release. TODO: does this belong somewhere else?
Definition: WebUtils.cxx:178
string rel
Definition: shutoffs.py:11
static PIDDetails FromString(const std::string &s)
Definition: PIDDetails.cxx:19
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::string fClientID
Definition: structs.h:12
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
LEMClientParams fParams
enum BeamMode string
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

std::string lem::LEMClient::fClientID
protected

Definition at line 71 of file LEMClient_module.cc.

Referenced by LEMClient(), and produce().

LEMClientParams lem::LEMClient::fParams
protected

Definition at line 69 of file LEMClient_module.cc.

Referenced by produce().


The documentation for this class was generated from the following file: