Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
evgb::EvtTimeShiftFactory Class Reference

#include <EvtTimeShiftFactory.h>

Classes

struct  Cleaner
 

Public Member Functions

evgb::EvtTimeShiftIGetEvtTimeShift (const std::string &name, const std::string &config="") const
 
bool IsKnownEvtTimeShift (const std::string &)
 
const std::vector< std::string > & AvailableEvtTimeShift () const
 
void Print () const
 
bool RegisterCreator (std::string name, EvtTimeShiftICtorFuncPtr_t ctorptr, bool *ptr)
 

Static Public Member Functions

static EvtTimeShiftFactoryInstance ()
 

Private Member Functions

 EvtTimeShiftFactory ()
 
virtual ~EvtTimeShiftFactory ()
 
 EvtTimeShiftFactory (const EvtTimeShiftFactory &)
 
void operator= (const EvtTimeShiftFactory &)
 

Private Attributes

std::map< std::string, EvtTimeShiftICtorFuncPtr_tfFunctionMap
 
std::map< std::string, bool * > fBoolPtrMap
 
std::vector< std::stringlistnames
 

Static Private Attributes

static EvtTimeShiftFactoryfgTheInstance
 

Friends

struct Cleaner
 

Detailed Description

Definition at line 33 of file EvtTimeShiftFactory.h.

Constructor & Destructor Documentation

evgb::EvtTimeShiftFactory::EvtTimeShiftFactory ( )
private

Definition at line 25 of file EvtTimeShiftFactory.cxx.

26 {
27  fgTheInstance = this; // record created self in static pointer
28 }
static EvtTimeShiftFactory * fgTheInstance
evgb::EvtTimeShiftFactory::~EvtTimeShiftFactory ( )
privatevirtual

Definition at line 30 of file EvtTimeShiftFactory.cxx.

31 {
32  fgTheInstance = 0;
33 }
static EvtTimeShiftFactory * fgTheInstance
evgb::EvtTimeShiftFactory::EvtTimeShiftFactory ( const EvtTimeShiftFactory )
private

Member Function Documentation

const std::vector< std::string > & evgb::EvtTimeShiftFactory::AvailableEvtTimeShift ( ) const

Definition at line 109 of file EvtTimeShiftFactory.cxx.

110 {
111  // list of names might be out of date due to new registrations
112  // rescan the std::map on each call (which won't be frequent)
113  listnames.clear();
114 
115  // scan map for registered names
117  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
118  listnames.push_back(itr->first);
119 
120  return listnames;
121 }
intermediate_table::const_iterator const_iterator
std::map< std::string, EvtTimeShiftICtorFuncPtr_t > fFunctionMap
std::vector< std::string > listnames
evgb::EvtTimeShiftI * evgb::EvtTimeShiftFactory::GetEvtTimeShift ( const std::string name,
const std::string config = "" 
) const

Definition at line 50 of file EvtTimeShiftFactory.cxx.

52 {
54 
55  mf::LogDebug("EvtTime")
56  << "EvtTimeShiftFactory::GetEvtTimeShift rwh name --->"
57  << name << "<--- \n config -->" << config << "<---" << std::endl;
58 
59  // trim any leading whitespace
60  std::string nameLocal = name;
61  std::string configLocal = "";
62  if( nameLocal.find_first_not_of(" \t\n") != 0 )
63  nameLocal.erase( 0, nameLocal.find_first_not_of(" \t\n") );
64 
65  // in case "name" actually includes the config string
66  size_t iws = nameLocal.find_first_of(" \t\n");
67  if ( iws != std::string::npos ) {
68  configLocal = nameLocal.substr(iws,std::string::npos);
69  configLocal += " ";
70  nameLocal.erase(iws,std::string::npos);
71  }
72  configLocal += config; // append any addition config string
73 
74  mf::LogDebug("EvtTime")
75  << "EvtTimeShiftFactory::GetEvtTimeShift rwh name --->"
76  << nameLocal << "<--- \n config -->" << configLocal << "<---" << std::endl;
77 
78  // we don't want map creating an entry if it doesn't exist
79  // so use map::find() not map::operator[]
81  = fFunctionMap.find(nameLocal);
82  if ( fFunctionMap.end() != itr ) {
83  // found an appropriate entry in the list
84  EvtTimeShiftICtorFuncPtr_t foo = itr->second; // this is the function
85  p = (*foo)(configLocal); // use function to create the EvtTimeShiftI
86  }
87  if ( ! p ) {
88  mf::LogInfo("EvtTime")
89  << "### EvtTimeShiftFactory WARNING: "
90  << "EvtTimeShiftI class \"" << nameLocal << "\" is not known" << std::endl;
91  Print();
92  throw cet::exception("NoEvtTimeShiftClass")
93  << "EvtTimeShiftI class \"" << nameLocal << "\" is not known" << std::endl;
94  }
95  return p;
96 }
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
intermediate_table::const_iterator const_iterator
interface for event time distribution
Definition: EvtTimeShiftI.h:29
std::map< std::string, EvtTimeShiftICtorFuncPtr_t > fFunctionMap
static Config * config
Definition: config.cpp:1054
p
Definition: test.py:223
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
evgb::EvtTimeShiftI *(* EvtTimeShiftICtorFuncPtr_t)(const std::string &)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
EvtTimeShiftFactory & evgb::EvtTimeShiftFactory::Instance ( void  )
static

Definition at line 35 of file EvtTimeShiftFactory.cxx.

36 {
37  // Cleaner dtor calls EvtTimeShiftFactory dtor at job end
38  static Cleaner cleaner;
39 
40  if ( ! fgTheInstance ) {
41  // need to create one
42  cleaner.UseMe(); // dummy call to quiet compiler warnings
44  }
45 
46  return *fgTheInstance;
47 }
static EvtTimeShiftFactory * fgTheInstance
bool evgb::EvtTimeShiftFactory::IsKnownEvtTimeShift ( const std::string name)

Definition at line 98 of file EvtTimeShiftFactory.cxx.

99 {
100  // check if we know the name
101  bool res = false;
103  = fFunctionMap.find(name);
104  if ( fFunctionMap.end() != itr ) res = true;
105  return res;
106 }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
std::map< std::string, EvtTimeShiftICtorFuncPtr_t > fFunctionMap
void evgb::EvtTimeShiftFactory::operator= ( const EvtTimeShiftFactory )
private
void evgb::EvtTimeShiftFactory::Print ( ) const

Definition at line 123 of file EvtTimeShiftFactory.cxx.

124 {
125  std::ostringstream msg;
126  msg << "EvtTimeShiftFactory list of known EvtTimeShiftI classes: \n";
127 
128  const std::vector<std::string>& known = AvailableEvtTimeShift();
129  for (size_t i=0; i < known.size(); ++i) {
130  msg << " [" << std::setw(2) << i << "] " << known[i] << std::endl;
131  }
132  mf::LogInfo("EvtTime") << msg.str();
133 }
void msg(const char *fmt,...)
Definition: message.cpp:107
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const std::vector< std::string > & AvailableEvtTimeShift() const
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
QTextStream & endl(QTextStream &s)
bool evgb::EvtTimeShiftFactory::RegisterCreator ( std::string  name,
EvtTimeShiftICtorFuncPtr_t  ctorptr,
bool ptr 
)

Definition at line 135 of file EvtTimeShiftFactory.cxx.

138 {
139  // record new functions for creating processes
140  fFunctionMap[name] = foo;
141  fBoolPtrMap[name] = boolptr;
142  return true;
143 }
static QCString name
Definition: declinfo.cpp:673
std::map< std::string, EvtTimeShiftICtorFuncPtr_t > fFunctionMap
std::map< std::string, bool * > fBoolPtrMap

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 91 of file EvtTimeShiftFactory.h.

Member Data Documentation

std::map<std::string, bool*> evgb::EvtTimeShiftFactory::fBoolPtrMap
private

Definition at line 63 of file EvtTimeShiftFactory.h.

std::map<std::string, EvtTimeShiftICtorFuncPtr_t> evgb::EvtTimeShiftFactory::fFunctionMap
private

Definition at line 60 of file EvtTimeShiftFactory.h.

EvtTimeShiftFactory * evgb::EvtTimeShiftFactory::fgTheInstance
staticprivate

Definition at line 57 of file EvtTimeShiftFactory.h.

std::vector<std::string> evgb::EvtTimeShiftFactory::listnames
mutableprivate

Definition at line 65 of file EvtTimeShiftFactory.h.


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