Functions
ArtServicePointer.h File Reference
#include <iostream>
#include "art/Framework/Services/Registry/ServiceHandle.h"

Go to the source code of this file.

Functions

template<class T >
T * ArtServicePointer ()
 
template<class T >
T * GenericArtServicePointer ()
 

Function Documentation

template<class T >
T * ArtServicePointer ( )

Definition at line 62 of file ArtServicePointer.h.

62  {
63  return GenericArtServicePointer<T>();
64 }
template<class T >
T* GenericArtServicePointer ( )

Definition at line 37 of file ArtServicePointer.h.

37  {
38  try {
39  if ( art::ServiceRegistry::isAvailable<T>() ) {
40  return art::ServiceHandle<T>().get();
41  }
42 /*
43  art::ServiceRegistry& reg = art::ServiceRegistry::instance();
44  if ( ! reg.isAvailable<T>() ) return nullptr;
45  return &reg.get<T>();
46 */
47  } catch(const art::Exception& exc) {
48  std::string msg = exc.explain_self();
49  if ( msg.find("no ServiceRegistry has been set") != std::string::npos ) {
50  std::cout << "WARNING: ArtServicePointer: ServiceRegistry not found. Instantiate with" << std::endl;
51  std::cout << " ArtServiceHelper::load(\"myfcl.fcl\")" << std::endl;
52  } else {
53  std::cout << "WARNING: Art exception: \n" << msg;
54  }
55  } catch(...) {
56  std::cout << "ERROR: ArtServicePointer: Unexpected exception." << std::endl;
57  }
58  return nullptr;
59 }
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
QTextStream & endl(QTextStream &s)