CMS 3D CMS Logo

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
 
std::string 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 &)=delete
 
const FWConfigurationManageroperator= (const FWConfigurationManager &)=delete
 
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.

Referenced by getIgnore().

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

Definition at line 52 of file FWConfigurationManager.cc.

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

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 m_configurables.

Referenced by counter.Counter::register(), SequenceTypes.Task::remove(), SequenceTypes.Task::replace(), and CmsShowMainBase::setupViewManagers().

73 {
74  assert(nullptr!=iConf);
75  m_configurables[iName]=iConf;
76 }
std::map< std::string, FWConfigurable * > m_configurables
bool FWConfigurationManager::getIgnore ( ) const
inline
std::string FWConfigurationManager::guessAndReadFromFile ( FWJobMetadataManager dataMng) const

Definition at line 195 of file FWConfigurationManager.cc.

References EnergyCorrector::c, looper::cfg, f, FrontierConditions_GlobalTag_cff::file, fwLog, g, createfilelist::int, FWConfiguration::keyValues(), fwlog::kInfo, fwlog::kWarning, operator<(), createfilelist::parser, setFrom(), AlCaHLTBitMon_QueryRunRegistry::string, FWJobMetadataManager::usableData(), and x.

196 {
197  struct CMatch {
199  int cnt;
200  const FWConfiguration* cfg;
201 
202  CMatch(std::string f):file(f), cnt(0), cfg(nullptr) {}
203  bool operator < (const CMatch& x) const { return cnt < x.cnt; }
204  };
205 
206  std::vector<CMatch> clist;
207  clist.push_back(CMatch("reco.fwc"));
208  clist.push_back(CMatch("miniaod.fwc"));
209  clist.push_back(CMatch("aod.fwc"));
210  std::vector<FWJobMetadataManager::Data> & sdata = dataMng->usableData();
211 
212  for (std::vector<CMatch>::iterator c = clist.begin(); c != clist.end(); ++c ) {
213  std::string iName = gSystem->Which(TROOT::GetMacroPath(), c->file.c_str(), kReadPermission);
214  std::ifstream f(iName.c_str());
215  if (f.peek() != (int) '<') {
216  fwLog(fwlog::kWarning) << "FWConfigurationManager::guessAndReadFromFile can't open "<< iName << std::endl ;
217  continue;
218  }
219 
220  // Read again, this time actually parse.
221  std::ifstream g(iName.c_str());
223  parser->parse();
224 
225  c->cfg = parser->config();
226  const FWConfiguration::KeyValues* keyValues = nullptr;
227  for(FWConfiguration::KeyValues::const_iterator it = c->cfg->keyValues()->begin(),
228  itEnd = c->cfg->keyValues()->end(); it != itEnd; ++it) {
229  if (it->first == "EventItems" ) {
230  keyValues = it->second.keyValues();
231  break;
232  }
233  }
234 
235  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin(); it != keyValues->end(); ++it)
236  {
237  const FWConfiguration& conf = it->second;
238  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
239  const std::string& type = (*keyValues)[0].second.value();
240  for(std::vector<FWJobMetadataManager::Data>::iterator di = sdata.begin(); di != sdata.end(); ++di)
241  {
242  if (di->type_ == type) {
243  c->cnt++;
244  break;
245  }
246  }
247  }
248  // printf("%s file %d matches\n", iName.c_str(), c->cnt);
249  }
250  std::sort(clist.begin(), clist.end());
251  fwLog(fwlog::kInfo) << "Loading configuration file " << clist.back().file << std::endl;
252  setFrom(*(clist.back().cfg));
253 
254  return clist.back().file;
255 }
type
Definition: HCALResponse.h:21
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
const KeyValues * keyValues() const
#define nullptr
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()
#define fwLog(_level_)
Definition: fwLog.h:50
const FWConfigurationManager& FWConfigurationManager::operator= ( const FWConfigurationManager )
privatedelete

Referenced by getIgnore().

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

References f, g, createfilelist::int, SimpleSAXParser::parse(), createfilelist::parser, readFromOldFile(), setFrom(), and AlCaHLTBitMon_QueryRunRegistry::string.

176 {
177  std::ifstream f(iName.c_str());
178  if (f.peek() != (int) '<')
179  return readFromOldFile(iName);
180 
181  // Check that the syntax is correct.
182  SimpleSAXParser syntaxTest(f);
183  syntaxTest.parse();
184  f.close();
185 
186  // Read again, this time actually parse.
187  std::ifstream g(iName.c_str());
188  // Actually parse the results.
190  parser.parse();
191  setFrom(*parser.config());
192 }
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 mps_alisetup::command, mps_alisetup::config, relativeConstraints::error, python.rootplot.argparse::message, setFrom(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getIgnore(), and 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 }
Definition: config.py:1
void setFrom(const FWConfiguration &) const
void FWConfigurationManager::setFrom ( const FWConfiguration iConfig) const

Definition at line 82 of file FWConfigurationManager.cc.

References FWConfiguration::keyValues(), and m_configurables.

Referenced by guessAndReadFromFile(), FWPartialConfigLoadGUI::Load(), readFromFile(), and readFromOldFile().

83 {
84  assert(nullptr!=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
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().

void FWConfigurationManager::to ( FWConfiguration oConfig) const

Definition at line 96 of file FWConfigurationManager.cc.

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

Referenced by FWPartialConfigGUI::FWPartialConfigGUI(), FWPartialConfigSaveGUI::WriteConfig(), and 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 MillePedeFileConverter_cfg::e, FrontierConditions_GlobalTag_cff::file, fwLog, fwlog::kError, fwlog::kInfo, python.rootplot.argparse::message, FWConfiguration::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  FWConfiguration::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
#define fwLog(_level_)
Definition: fwLog.h:50
static void streamTo(std::ostream &oTo, const FWConfiguration &iConfig, const std::string &name)

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