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 ()
 
 FWConfigurationManager (const FWConfigurationManager &)=delete
 
bool getIgnore () const
 
std::string guessAndReadFromFile (FWJobMetadataManager *) const
 
const FWConfigurationManageroperator= (const FWConfigurationManager &)=delete
 
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

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() [1/2]

FWConfigurationManager::FWConfigurationManager ( )

Definition at line 43 of file FWConfigurationManager.cc.

◆ ~FWConfigurationManager()

FWConfigurationManager::~FWConfigurationManager ( )
virtual

Definition at line 50 of file FWConfigurationManager.cc.

50 {}

◆ FWConfigurationManager() [2/2]

FWConfigurationManager::FWConfigurationManager ( const FWConfigurationManager )
delete

Member Function Documentation

◆ add()

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

does not take ownership

Definition at line 67 of file FWConfigurationManager.cc.

References cms::cuda::assert(), and m_configurables.

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

67  {
68  assert(nullptr != iConf);
69  m_configurables[iName] = iConf;
70 }
assert(be >=bs)
std::map< std::string, FWConfigurable * > m_configurables

◆ getIgnore()

bool FWConfigurationManager::getIgnore ( ) const
inline

Definition at line 51 of file FWConfigurationManager.h.

References m_ignore.

Referenced by CmsShowMain::setupDataHandling().

◆ guessAndReadFromFile()

std::string FWConfigurationManager::guessAndReadFromFile ( FWJobMetadataManager dataMng) const

Definition at line 171 of file FWConfigurationManager.cc.

References HltBtagPostValidation_cff::c, looper::cfg, f, geometryDiff::file, fwLog, g, createfilelist::int, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, FWConfiguration::keyValues(), fwlog::kInfo, fwlog::kWarning, cond::hdf5::operator<(), writedatasetfile::parser, setFrom(), jetUpdater_cfi::sort, 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 }
bool operator<(IOVSyncValue const &iLHS, IOVSyncValue const &iRHS)
Definition: IOVSyncValue.h:34
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
double f[11][100]
std::vector< Data > & usableData()
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
#define fwLog(_level_)
Definition: fwLog.h:45
const KeyValues * keyValues() const
void setFrom(const FWConfiguration &) const

◆ operator=()

const FWConfigurationManager& FWConfigurationManager::operator= ( const FWConfigurationManager )
delete

◆ readFromFile()

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 }
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 readFromOldFile(const std::string &) const
double f[11][100]
void setFrom(const FWConfiguration &) const

◆ readFromOldFile()

void FWConfigurationManager::readFromOldFile ( const std::string &  iName) const
private

Definition at line 116 of file FWConfigurationManager.cc.

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

Referenced by 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
list command
Definition: mps_check.py:25
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:29
void setFrom(const FWConfiguration &) const

◆ setFrom()

void FWConfigurationManager::setFrom ( const FWConfiguration iConfig) const

Definition at line 75 of file FWConfigurationManager.cc.

References cms::cuda::assert(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, 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 }
assert(be >=bs)
const KeyValues * keyValues() const
std::map< std::string, FWConfigurable * > m_configurables

◆ setIgnore()

void FWConfigurationManager::setIgnore ( )
inline

Definition at line 50 of file FWConfigurationManager.h.

References m_ignore.

Referenced by CmsShowMain::CmsShowMain().

◆ to()

void FWConfigurationManager::to ( FWConfiguration oConfig) const

Definition at line 86 of file FWConfigurationManager.cc.

References FWConfiguration::addKeyValue(), DiMuonV_cfg::config, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, 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 }
Definition: config.py:1
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:29
std::map< std::string, FWConfigurable * > m_configurables

◆ writeToFile()

void FWConfigurationManager::writeToFile ( const std::string &  iName) const

Definition at line 97 of file FWConfigurationManager.cc.

References MillePedeFileConverter_cfg::e, geometryDiff::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

◆ m_configurables

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

Definition at line 60 of file FWConfigurationManager.h.

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

◆ m_ignore

bool FWConfigurationManager::m_ignore
private

Definition at line 61 of file FWConfigurationManager.h.

Referenced by getIgnore(), and setIgnore().