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

FWConfigurationManager::~FWConfigurationManager ( )
virtual

Definition at line 50 of file FWConfigurationManager.cc.

50 {}
FWConfigurationManager::FWConfigurationManager ( const FWConfigurationManager )
privatedelete

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 counter.Counter::register(), SequenceTypes.Task::remove(), SequenceTypes.Task::replace(), and CmsShowMainBase::setupViewManagers().

67  {
68  assert(nullptr != iConf);
69  m_configurables[iName] = iConf;
70 }
std::map< std::string, FWConfigurable * > m_configurables
bool FWConfigurationManager::getIgnore ( ) const
inline
std::string FWConfigurationManager::guessAndReadFromFile ( FWJobMetadataManager dataMng) const

Definition at line 171 of file FWConfigurationManager.cc.

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

171  {
172  struct CMatch {
174  int cnt;
175  const FWConfiguration* cfg;
176 
177  CMatch(std::string f) : file(f), cnt(0), cfg(nullptr) {}
178  bool operator<(const CMatch& x) const { return cnt < x.cnt; }
179  };
180 
181  std::vector<CMatch> clist;
182  clist.push_back(CMatch("reco.fwc"));
183  clist.push_back(CMatch("miniaod.fwc"));
184  clist.push_back(CMatch("aod.fwc"));
185  std::vector<FWJobMetadataManager::Data>& sdata = dataMng->usableData();
186 
187  for (std::vector<CMatch>::iterator c = clist.begin(); c != clist.end(); ++c) {
188  std::string iName = gSystem->Which(TROOT::GetMacroPath(), c->file.c_str(), kReadPermission);
189  std::ifstream f(iName.c_str());
190  if (f.peek() != (int)'<') {
191  fwLog(fwlog::kWarning) << "FWConfigurationManager::guessAndReadFromFile can't open " << iName << std::endl;
192  continue;
193  }
194 
195  // Read again, this time actually parse.
196  std::ifstream g(iName.c_str());
198  parser->parse();
199 
200  c->cfg = parser->config();
201  const FWConfiguration::KeyValues* keyValues = nullptr;
202  for (FWConfiguration::KeyValues::const_iterator it = c->cfg->keyValues()->begin(),
203  itEnd = c->cfg->keyValues()->end();
204  it != itEnd;
205  ++it) {
206  if (it->first == "EventItems") {
207  keyValues = it->second.keyValues();
208  break;
209  }
210  }
211 
212  for (FWConfiguration::KeyValues::const_iterator it = keyValues->begin(); it != keyValues->end(); ++it) {
213  const FWConfiguration& conf = it->second;
214  const FWConfiguration::KeyValues* keyValues = conf.keyValues();
215  const std::string& type = (*keyValues)[0].second.value();
216  for (std::vector<FWJobMetadataManager::Data>::iterator di = sdata.begin(); di != sdata.end(); ++di) {
217  if (di->type_ == type) {
218  c->cnt++;
219  break;
220  }
221  }
222  }
223  // printf("%s file %d matches\n", iName.c_str(), c->cnt);
224  }
225  std::sort(clist.begin(), clist.end());
226  fwLog(fwlog::kInfo) << "Loading configuration file " << clist.back().file << std::endl;
227  setFrom(*(clist.back().cfg));
228 
229  return clist.back().file;
230 }
type
Definition: HCALResponse.h:21
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
void setFrom(const FWConfiguration &) const
double f[11][100]
std::vector< Data > & usableData()
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
#define fwLog(_level_)
Definition: fwLog.h:45
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:69
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 153 of file FWConfigurationManager.cc.

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

153  {
154  std::ifstream f(iName.c_str());
155  if (f.peek() != (int)'<')
156  return readFromOldFile(iName);
157 
158  // Check that the syntax is correct.
159  SimpleSAXParser syntaxTest(f);
160  syntaxTest.parse();
161  f.close();
162 
163  // Read again, this time actually parse.
164  std::ifstream g(iName.c_str());
165  // Actually parse the results.
167  parser.parse();
168  setFrom(*parser.config());
169 }
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 116 of file FWConfigurationManager.cc.

References mps_check::command, looper::config, relativeConstraints::error, setFrom(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by getIgnore(), and readFromFile().

116  {
117  Int_t error = 0;
118  // Int_t value =
119  gROOT->LoadMacro(iName.c_str(), &error);
120  if (0 != error) {
121  std::string message("unable to load macro file ");
122  message += iName;
123  throw std::runtime_error(message.c_str());
124  }
125 
126  const std::string command("(Long_t)(fwConfig() )");
127 
128  error = 0;
129  Long_t lConfig = gROOT->ProcessLineFast(command.c_str(), &error);
130 
131  {
132  //need to unload this macro so that we can load a new configuration
133  // which uses the same function name in the macro
134  Int_t error = 0;
135  gROOT->ProcessLineSync((std::string(".U ") + iName).c_str(), &error);
136  }
137  if (0 != error) {
138  std::string message("unable to properly parse configuration file ");
139  message += iName;
140  throw std::runtime_error(message.c_str());
141  }
142  std::unique_ptr<FWConfiguration> config(reinterpret_cast<FWConfiguration*>(lConfig));
143 
144  setFrom(*config);
145 }
Definition: config.py:1
config
Definition: looper.py:291
void setFrom(const FWConfiguration &) const
list command
Definition: mps_check.py:25
void FWConfigurationManager::setFrom ( const FWConfiguration iConfig) const

Definition at line 75 of file FWConfigurationManager.cc.

References FWConfiguration::keyValues(), and m_configurables.

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

75  {
76  assert(nullptr != iConfig.keyValues());
77  for (FWConfiguration::KeyValues::const_iterator it = iConfig.keyValues()->begin(), itEnd = iConfig.keyValues()->end();
78  it != itEnd;
79  ++it) {
80  std::map<std::string, FWConfigurable*>::const_iterator itFound = m_configurables.find(it->first);
81  assert(itFound != m_configurables.end());
82  itFound->second->setFrom(it->second);
83  }
84 }
const KeyValues * keyValues() const
std::map< std::string, FWConfigurable * > m_configurables
void FWConfigurationManager::setIgnore ( )
inline

Definition at line 50 of file FWConfigurationManager.h.

References m_ignore.

Referenced by CmsShowMain::CmsShowMain().

void FWConfigurationManager::to ( FWConfiguration oConfig) const

Definition at line 86 of file FWConfigurationManager.cc.

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

Referenced by FWPartialConfigGUI::FWPartialConfigGUI(), FWPartialConfigSaveGUI::WriteConfig(), and writeToFile().

86  {
88  for (std::map<std::string, FWConfigurable*>::const_iterator it = m_configurables.begin(),
89  itEnd = m_configurables.end();
90  it != itEnd;
91  ++it) {
92  it->second->addTo(config);
93  oConfig.addKeyValue(it->first, config, true);
94  }
95 }
config
Definition: looper.py:291
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 97 of file FWConfigurationManager.cc.

References MillePedeFileConverter_cfg::e, FrontierConditions_GlobalTag_cff::file, fwLog, fwlog::kError, fwlog::kInfo, mps_setup::stdout, FWConfiguration::streamTo(), AlCaHLTBitMon_QueryRunRegistry::string, and to().

97  {
98  try {
99  std::ofstream file(iName.c_str());
100  if (not file) {
101  std::string message = "unable to open file " + iName;
102  message += iName;
103  throw std::runtime_error(message.c_str());
104  }
105  FWConfiguration top;
106  to(top);
107  fwLog(fwlog::kInfo) << "Writing to file " << iName.c_str() << "...\n";
108  fflush(stdout);
109 
110  FWConfiguration::streamTo(file, top, "top");
111  } catch (std::runtime_error& e) {
112  fwLog(fwlog::kError) << "FWConfigurationManager::writeToFile() " << e.what() << std::endl;
113  }
114 }
void to(FWConfiguration &) const
#define fwLog(_level_)
Definition: fwLog.h:45
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 60 of file FWConfigurationManager.h.

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

bool FWConfigurationManager::m_ignore
private

Definition at line 61 of file FWConfigurationManager.h.

Referenced by getIgnore(), and setIgnore().