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

FWConfigurationManager::FWConfigurationManager ( )

Definition at line 43 of file FWConfigurationManager.cc.

43 : m_ignore(false) {}

◆ ~FWConfigurationManager()

FWConfigurationManager::~FWConfigurationManager ( )
virtual

Definition at line 50 of file FWConfigurationManager.cc.

50 {}

◆ FWConfigurationManager() [2/2]

FWConfigurationManager::FWConfigurationManager ( const FWConfigurationManager )
privatedelete

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.

67  {
68  assert(nullptr != iConf);
69  m_configurables[iName] = iConf;
70 }

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

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

◆ getIgnore()

bool FWConfigurationManager::getIgnore ( ) const
inline

Definition at line 51 of file FWConfigurationManager.h.

51 { return m_ignore; }

References m_ignore.

Referenced by CmsShowMain::setupDataHandling().

◆ guessAndReadFromFile()

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

Definition at line 171 of file FWConfigurationManager.cc.

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 }

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.

◆ operator=()

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

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

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 }

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

◆ readFromOldFile()

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

Definition at line 116 of file FWConfigurationManager.cc.

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 }

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

Referenced by readFromFile().

◆ setFrom()

void FWConfigurationManager::setFrom ( const FWConfiguration iConfig) const

Definition at line 75 of file FWConfigurationManager.cc.

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 }

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

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

◆ setIgnore()

void FWConfigurationManager::setIgnore ( )
inline

Definition at line 50 of file FWConfigurationManager.h.

50 { m_ignore = true; }

References m_ignore.

Referenced by CmsShowMain::CmsShowMain().

◆ to()

void FWConfigurationManager::to ( FWConfiguration oConfig) const

Definition at line 86 of file FWConfigurationManager.cc.

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 }

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

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

◆ writeToFile()

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

Definition at line 97 of file FWConfigurationManager.cc.

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 }

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

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

fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
FWConfiguration::streamTo
static void streamTo(std::ostream &oTo, const FWConfiguration &iConfig, const std::string &name)
Definition: FWConfiguration.cc:192
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
cms::cuda::assert
assert(be >=bs)
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
DDAxes::x
mps_check.command
list command
Definition: mps_check.py:25
relativeConstraints.error
error
Definition: relativeConstraints.py:53
FWConfiguration::KeyValues
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
Definition: FWConfiguration.h:40
config
Definition: config.py:1
FWXMLConfigParser
Definition: FWXMLConfigParser.h:32
FWConfigurationManager::m_ignore
bool m_ignore
Definition: FWConfigurationManager.h:61
FWConfigurationManager::to
void to(FWConfiguration &) const
Definition: FWConfigurationManager.cc:86
looper.config
config
Definition: looper.py:291
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
mps_setup.stdout
stdout
Definition: mps_setup.py:250
createfilelist.int
int
Definition: createfilelist.py:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
FWConfigurationManager::m_configurables
std::map< std::string, FWConfigurable * > m_configurables
Definition: FWConfigurationManager.h:60
fwlog::kWarning
Definition: fwLog.h:35
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
looper.cfg
cfg
Definition: looper.py:297
SimpleSAXParser
Definition: SimpleSAXParser.h:69
FWConfigurationManager::setFrom
void setFrom(const FWConfiguration &) const
Definition: FWConfigurationManager.cc:75
FWConfiguration::addKeyValue
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
Definition: FWConfiguration.cc:57
fwlog::kInfo
Definition: fwLog.h:35
type
type
Definition: HCALResponse.h:21
FWConfigurationManager::readFromOldFile
void readFromOldFile(const std::string &) const
Definition: FWConfigurationManager.cc:116
FWConfiguration::keyValues
const KeyValues * keyValues() const
Definition: FWConfiguration.h:51
FWJobMetadataManager::usableData
std::vector< Data > & usableData()
Definition: FWJobMetadataManager.h:31
fwlog::kError
Definition: fwLog.h:35
FWConfiguration
Definition: FWConfiguration.h:31
operator<
bool operator<(DTCELinkId const &lhs, DTCELinkId const &rhs)
Definition: DTCELinkId.h:70
g
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
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37