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 ()
 
void readFromFile (const std::string &) const
 
void setFrom (const FWConfiguration &) const
 
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
 

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 39 of file FWConfigurationManager.cc.

40 {
41 }
FWConfigurationManager::~FWConfigurationManager ( )
virtual

Definition at line 48 of file FWConfigurationManager.cc.

49 {
50 }
FWConfigurationManager::FWConfigurationManager ( const FWConfigurationManager )
private

Member Function Documentation

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

does not take ownership

Definition at line 68 of file FWConfigurationManager.cc.

References m_configurables.

Referenced by CmsShowMainBase::setupViewManagers().

69 {
70  assert(0!=iConf);
71  m_configurables[iName]=iConf;
72 }
std::map< std::string, FWConfigurable * > m_configurables
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 351 of file FWConfigurationManager.cc.

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

352 {
353  std::ifstream f(iName.c_str());
354  if (f.peek() != (int) '<')
355  return readFromOldFile(iName);
356 
357  // Check that the syntax is correct.
358  SimpleSAXParser syntaxTest(f);
359  syntaxTest.parse();
360  f.close();
361 
362  // Read again, this time actually parse.
363  std::ifstream g(iName.c_str());
364  // Actually parse the results.
366  parser.parse();
367  setFrom(*parser.config());
368 }
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 128 of file FWConfigurationManager.cc.

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

Referenced by readFromFile().

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

Definition at line 78 of file FWConfigurationManager.cc.

References FWConfiguration::keyValues(), and m_configurables.

Referenced by readFromFile(), and readFromOldFile().

79 {
80  assert(0!=iConfig.keyValues());
81  for(FWConfiguration::KeyValues::const_iterator it = iConfig.keyValues()->begin(),
82  itEnd = iConfig.keyValues()->end();
83  it != itEnd;
84  ++it) {
85  std::map<std::string,FWConfigurable*>::const_iterator itFound = m_configurables.find(it->first);
86  assert(itFound != m_configurables.end());
87  itFound->second->setFrom(it->second);
88  }
89 }
const KeyValues * keyValues() const
std::map< std::string, FWConfigurable * > m_configurables
void FWConfigurationManager::to ( FWConfiguration oConfig) const

Definition at line 92 of file FWConfigurationManager.cc.

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

Referenced by writeToFile().

93 {
95  for(std::map<std::string,FWConfigurable*>::const_iterator it = m_configurables.begin(),
96  itEnd = m_configurables.end();
97  it != itEnd;
98  ++it) {
99  it->second->addTo(config);
100  oConfig.addKeyValue(it->first, config, true);
101  }
102 }
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 106 of file FWConfigurationManager.cc.

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

107 {
108  try
109  {
110  ofstream file(iName.c_str());
111  if(not file) {
112  std::string message("unable to open file %s ", iName.c_str());
113  fflush(stdout);
114  message += iName;
115  throw std::runtime_error(message.c_str());
116  }
117  FWConfiguration top;
118  to(top);
119  fwLog(fwlog::kInfo) << "Writing to file "<< iName.c_str() << "...\n";
120  fflush(stdout);
121 
122  streamTo(file, top, "top");
123  }
124  catch (std::runtime_error &e) { std::cout << e.what() << std::endl; }
125 }
void to(FWConfiguration &) const
void streamTo(std::ostream &, const FWConfiguration &, const std::string &name)
#define fwLog(_level_)
Definition: fwLog.h:51
tuple cout
Definition: gather_cfg.py:121

Member Data Documentation

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

Definition at line 58 of file FWConfigurationManager.h.

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