CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
FWConfigurationManager Class Reference

#include <Fireworks/Core/interface/FWConfigurationManager.h>

Public Member Functions

void add (const std::string &iName, FWConfigurable *)
 does not take ownership More...
 
 FWConfigurationManager ()
 
bool getIgnore () const
 
void guessAndReadFromFile (FWJobMetadataManager *) const
 
void readFromFile (const std::string &) const
 
void setFrom (const FWConfiguration &) const
 
void setIgnore ()
 
void to (FWConfiguration &) const
 
void writeToFile (const std::string &) const
 
virtual ~FWConfigurationManager ()
 

Private Member Functions

 FWConfigurationManager (const FWConfigurationManager &)
 
const FWConfigurationManageroperator= (const FWConfigurationManager &)
 
void readFromOldFile (const std::string &) const
 

Private Attributes

std::map< std::string,
FWConfigurable * > 
m_configurables
 
bool m_ignore
 

Detailed Description

Description: <one line="" class="" summary>="">

Usage: <usage>

Definition at line 32 of file FWConfigurationManager.h.

Constructor & Destructor Documentation

FWConfigurationManager::FWConfigurationManager ( )

Definition at line 43 of file FWConfigurationManager.cc.

43  :m_ignore(false)
44 {
45 }
FWConfigurationManager::~FWConfigurationManager ( )
virtual

Definition at line 52 of file FWConfigurationManager.cc.

53 {
54 }
FWConfigurationManager::FWConfigurationManager ( const FWConfigurationManager )
private

Member Function Documentation

void FWConfigurationManager::add ( const std::string &  iName,
FWConfigurable iConf 
)

does not take ownership

Definition at line 72 of file FWConfigurationManager.cc.

References assert(), and m_configurables.

Referenced by counter.Counter::register(), and CmsShowMainBase::setupViewManagers().

73 {
74  assert(0!=iConf);
75  m_configurables[iName]=iConf;
76 }
assert(m_qm.get())
std::map< std::string, FWConfigurable * > m_configurables
bool FWConfigurationManager::getIgnore ( ) const
inline

Definition at line 53 of file FWConfigurationManager.h.

References m_ignore.

Referenced by CmsShowMain::setupDataHandling().

void FWConfigurationManager::guessAndReadFromFile ( FWJobMetadataManager dataMng) const

Definition at line 377 of file FWConfigurationManager.cc.

References EnergyCorrector::c, looper::cfg, dbtoconf::conf, f, mergeVDriftHistosByStation::file, fwLog, g, FWConfiguration::keyValues(), fwlog::kInfo, fwlog::kWarning, operator<(), geometryXMLtoCSV::parser, setFrom(), python.multivaluedict::sort(), AlCaHLTBitMon_QueryRunRegistry::string, FWJobMetadataManager::usableData(), and x.

378 {
379  struct CMatch {
381  int cnt;
382  const FWConfiguration* cfg;
383 
384  CMatch(std::string f):file(f), cnt(0), cfg(0) {}
385  bool operator < (const CMatch& x) const { return cnt < x.cnt; }
386  };
387 
388  std::vector<CMatch> clist;
389  clist.push_back(CMatch("reco.fwc"));
390  clist.push_back(CMatch("miniaod.fwc"));
391  clist.push_back(CMatch("aod.fwc"));
392  std::vector<FWJobMetadataManager::Data> & sdata = dataMng->usableData();
393 
394  for (std::vector<CMatch>::iterator c = clist.begin(); c != clist.end(); ++c ) {
395  std::string iName = gSystem->Which(TROOT::GetMacroPath(), c->file.c_str(), kReadPermission);
396  std::ifstream f(iName.c_str());
397  if (f.peek() != (int) '<') {
398  fwLog(fwlog::kWarning) << "FWConfigurationManager::guessAndReadFromFile can't open "<< iName << std::endl ;
399  continue;
400  }
401 
402  // Read again, this time actually parse.
403  std::ifstream g(iName.c_str());
405  parser->parse();
406 
407  c->cfg = parser->config();
408  const FWConfiguration::KeyValues* keyValues = 0;
409  for(FWConfiguration::KeyValues::const_iterator it = c->cfg->keyValues()->begin(),
410  itEnd = c->cfg->keyValues()->end(); it != itEnd; ++it) {
411  if (it->first == "EventItems" ) {
412  keyValues = it->second.keyValues();
413  break;
414  }
415  }
416 
417  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin(); it != keyValues->end(); ++it)
418  {
419  const FWConfiguration& conf = it->second;
420  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
421  const std::string& type = (*keyValues)[0].second.value();
422  for(std::vector<FWJobMetadataManager::Data>::iterator di = sdata.begin(); di != sdata.end(); ++di)
423  {
424  if (di->type_ == type) {
425  c->cnt++;
426  break;
427  }
428  }
429  }
430  // printf("%s file %d matches\n", iName.c_str(), c->cnt);
431  }
432  std::sort(clist.begin(), clist.end());
433  fwLog(fwlog::kInfo) << "Loading configuration file " << clist.back().file << std::endl;
434  setFrom(*(clist.back().cfg));
435 }
type
Definition: HCALResponse.h:21
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
tuple cfg
Definition: looper.py:259
const KeyValues * keyValues() const
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 g
Definition: Activities.doc:4
bool operator<(const FedChannelConnection &, const FedChannelConnection &)
void setFrom(const FWConfiguration &) const
double f[11][100]
std::vector< Data > & usableData()
tuple conf
Definition: dbtoconf.py:185
#define fwLog(_level_)
Definition: fwLog.h:50
Definition: DDAxes.h:10
const FWConfigurationManager& FWConfigurationManager::operator= ( const FWConfigurationManager )
private
void FWConfigurationManager::readFromFile ( const std::string &  iName) const

Reads the configuration specified in iName and creates the internal representation in terms of FWConfigutation objects.

Notice that if the file does not start with '<' the old CINT macro based system is used.

Definition at line 357 of file FWConfigurationManager.cc.

References f, g, SimpleSAXParser::parse(), geometryXMLtoCSV::parser, readFromOldFile(), and setFrom().

358 {
359  std::ifstream f(iName.c_str());
360  if (f.peek() != (int) '<')
361  return readFromOldFile(iName);
362 
363  // Check that the syntax is correct.
364  SimpleSAXParser syntaxTest(f);
365  syntaxTest.parse();
366  f.close();
367 
368  // Read again, this time actually parse.
369  std::ifstream g(iName.c_str());
370  // Actually parse the results.
372  parser.parse();
373  setFrom(*parser.config());
374 }
void readFromOldFile(const std::string &) const
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 g
Definition: Activities.doc:4
void setFrom(const FWConfiguration &) const
double f[11][100]
void FWConfigurationManager::readFromOldFile ( const std::string &  iName) const
private

Definition at line 134 of file FWConfigurationManager.cc.

References edmPickEvents::command, HDQMDatabaseProducer::config, relativeConstraints::error, python.rootplot.argparse::message, setFrom(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by readFromFile().

135 {
136  Int_t error=0;
137  // Int_t value =
138  gROOT->LoadMacro( iName.c_str(), &error );
139  if(0 != error) {
140  std::string message("unable to load macro file ");
141  message += iName;
142  throw std::runtime_error(message.c_str());
143  }
144 
145  const std::string command("(Long_t)(fwConfig() )");
146 
147  error = 0;
148  Long_t lConfig = gROOT->ProcessLineFast(command.c_str(),
149  &error);
150 
151  {
152  //need to unload this macro so that we can load a new configuration
153  // which uses the same function name in the macro
154  Int_t error = 0;
155  gROOT->ProcessLineSync((std::string(".U ")+iName).c_str(), &error);
156  }
157  if(0 != error) {
158  std::string message("unable to properly parse configuration file ");
159  message += iName;
160  throw std::runtime_error(message.c_str());
161  }
162  std::auto_ptr<FWConfiguration> config( reinterpret_cast<FWConfiguration*>(lConfig) );
163 
164  setFrom( *config);
165 }
void setFrom(const FWConfiguration &) const
void FWConfigurationManager::setFrom ( const FWConfiguration iConfig) const

Definition at line 82 of file FWConfigurationManager.cc.

References assert(), FWConfiguration::keyValues(), and m_configurables.

Referenced by guessAndReadFromFile(), readFromFile(), and readFromOldFile().

83 {
84  assert(0!=iConfig.keyValues());
85  for(FWConfiguration::KeyValues::const_iterator it = iConfig.keyValues()->begin(),
86  itEnd = iConfig.keyValues()->end();
87  it != itEnd;
88  ++it) {
89  std::map<std::string,FWConfigurable*>::const_iterator itFound = m_configurables.find(it->first);
90  assert(itFound != m_configurables.end());
91  itFound->second->setFrom(it->second);
92  }
93 }
const KeyValues * keyValues() const
assert(m_qm.get())
std::map< std::string, FWConfigurable * > m_configurables
void FWConfigurationManager::setIgnore ( )
inline

Definition at line 52 of file FWConfigurationManager.h.

References m_ignore.

Referenced by CmsShowMain::CmsShowMain().

52 { m_ignore = false; }
void FWConfigurationManager::to ( FWConfiguration oConfig) const

Definition at line 96 of file FWConfigurationManager.cc.

References FWConfiguration::addKeyValue(), HDQMDatabaseProducer::config, and m_configurables.

Referenced by writeToFile().

97 {
99  for(std::map<std::string,FWConfigurable*>::const_iterator it = m_configurables.begin(),
100  itEnd = m_configurables.end();
101  it != itEnd;
102  ++it) {
103  it->second->addTo(config);
104  oConfig.addKeyValue(it->first, config, true);
105  }
106 }
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
std::map< std::string, FWConfigurable * > m_configurables
void FWConfigurationManager::writeToFile ( const std::string &  iName) const

Definition at line 110 of file FWConfigurationManager.cc.

References alignCSCRings::e, mergeVDriftHistosByStation::file, fwLog, fwlog::kError, fwlog::kInfo, python.rootplot.argparse::message, streamTo(), AlCaHLTBitMon_QueryRunRegistry::string, and to().

111 {
112  try
113  {
114  std::ofstream file(iName.c_str());
115  if(not file) {
116  std::string message = "unable to open file " + iName;
117  message += iName;
118  throw std::runtime_error(message.c_str());
119  }
120  FWConfiguration top;
121  to(top);
122  fwLog(fwlog::kInfo) << "Writing to file "<< iName.c_str() << "...\n";
123  fflush(stdout);
124 
125  streamTo(file, top, "top");
126  }
127  catch (std::runtime_error &e)
128  {
129  fwLog(fwlog::kError) << "FWConfigurationManager::writeToFile() " << e.what() << std::endl;
130  }
131 }
void to(FWConfiguration &) const
void streamTo(std::ostream &, const FWConfiguration &, const std::string &name)
#define fwLog(_level_)
Definition: fwLog.h:50

Member Data Documentation

std::map<std::string, FWConfigurable*> FWConfigurationManager::m_configurables
private

Definition at line 62 of file FWConfigurationManager.h.

Referenced by add(), setFrom(), and to().

bool FWConfigurationManager::m_ignore
private

Definition at line 63 of file FWConfigurationManager.h.

Referenced by getIgnore(), and setIgnore().