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

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

Definition at line 47 of file FWConfigurationManager.cc.

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

Member Function Documentation

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

does not take ownership

Definition at line 67 of file FWConfigurationManager.cc.

References m_configurables.

Referenced by CmsShowMainBase::setupViewManagers().

68 {
69  assert(0!=iConf);
70  m_configurables[iName]=iConf;
71 }
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 352 of file FWConfigurationManager.cc.

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

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

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

Referenced by readFromFile().

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

Definition at line 77 of file FWConfigurationManager.cc.

References FWConfiguration::keyValues(), and m_configurables.

Referenced by readFromFile(), and readFromOldFile().

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

Definition at line 91 of file FWConfigurationManager.cc.

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

Referenced by writeToFile().

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

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

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

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().