CMS 3D CMS Logo

CacheParser.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PluginManager
4 // Class : CacheParser
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Apr 4 14:30:46 EDT 2007
11 //
12 
13 // system include files
14 #include <algorithm>
15 #include <limits>
16 #include "boost/version.hpp"
17 
18 // user include files
22 
23 namespace edmplugin {
24  //
25  // constants, enums and typedefs
26  //
27 
28  //
29  // static data member definitions
30  //
31 
32  //
33  // constructors and destructor
34  //
35  //CacheParser::CacheParser(std::istream&)
36  //{
37  //}
38 
39  // CacheParser::CacheParser(const CacheParser& rhs)
40  // {
41  // // do actual copying here;
42  // }
43 
44  //CacheParser::~CacheParser()
45  //{
46  //}
47 
48  //
49  // assignment operators
50  //
51  // const CacheParser& CacheParser::operator=(const CacheParser& rhs)
52  // {
53  // //An exception safe implementation is
54  // CacheParser temp(rhs);
55  // swap(rhs);
56  //
57  // return *this;
58  // }
59 
60  //
61  // member functions
62  //
63 
64  //
65  // const member functions
66  //
67 
68  //
69  // static member functions
70  //
71  static void checkForError(const std::istream& iIn, unsigned long iRecordNumber, const std::string& iContext) {
72  if (iIn.eof()) {
73  throw cms::Exception("PluginCacheParseFailed")
74  << "Unexpectedly reached end of file for line " << iRecordNumber << " just after '" << iContext << "'";
75  }
76  if (iIn.bad()) {
77  throw cms::Exception("PluginCacheParseFailed")
78  << "Reading failed on line " << iRecordNumber << " just after '" << iContext << "'";
79  }
80  }
81 
82  bool CacheParser::readline(std::istream& iIn,
83  const boost::filesystem::path& iDirectory,
84  unsigned long iRecordNumber,
85  PluginInfo& oInfo,
86  std::string& oPluginType) {
87  static const std::string kNewLine("start of new line");
89  std::string pluginName;
90  iIn >> fileName;
91  if (iIn.eof()) {
92  return false;
93  }
94  checkForError(iIn, iRecordNumber, kNewLine);
96  iIn >> pluginName;
97  checkForError(iIn, iRecordNumber, fileName);
98  CacheParser::restoreSpaces(pluginName);
99  iIn >> oPluginType;
100  checkForError(iIn, iRecordNumber, oPluginType);
101  CacheParser::restoreSpaces(oPluginType);
102 
103  oInfo.loadable_ = iDirectory / fileName;
104  oInfo.name_ = pluginName;
105 
106  //ignore everything to the end of line
107  iIn.ignore(std::numeric_limits<int>::max(), '\n');
108  while (iIn.peek() == '\n') {
109  iIn.get();
110  }
111  return true;
112  }
113 
114  namespace {
115  struct CompPluginInfos {
116  bool operator()(const PluginInfo& iLHS, const PluginInfo& iRHS) const { return iLHS.name_ < iRHS.name_; }
117  };
118  } // namespace
119 
120  void CacheParser::read(std::istream& iIn,
121  const boost::filesystem::path& iDirectory,
123  unsigned long recordNumber = 0;
124 
125  std::string pluginType;
126 
128 
129  while (iIn) {
130  ++recordNumber;
131  if (not readline(iIn, iDirectory, recordNumber, info, pluginType)) {
132  break;
133  }
134  iOut[pluginType].push_back(info);
135  }
136  //now do a sort which preserves any previous order for files
137  for (CacheParser::CategoryToInfos::iterator it = iOut.begin(), itEnd = iOut.end(); it != itEnd; ++it) {
138  std::stable_sort(it->second.begin(), it->second.end(), CompPluginInfos());
139  }
140  }
141 
142  void CacheParser::write(const CategoryToInfos& iInfos, std::ostream& oOut) {
143  //order the data more to our liking: library then object then type
144  LoadableToPlugins ordered;
145 
146  for (CategoryToInfos::const_iterator it = iInfos.begin(); it != iInfos.end(); ++it) {
147  std::string type(it->first);
148  for (std::vector<PluginInfo>::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
149  //remove any directory specification
150 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 47
151  std::string loadable(it2->loadable_.filename().string());
152 #else
153  std::string loadable(it2->loadable_.filename());
154 #endif
155  std::string name(it2->name_);
156  ordered[loadable].push_back(NameAndType(name, type));
157  }
158  }
159  write(ordered, oOut);
160  }
161 
162  void CacheParser::write(LoadableToPlugins& iIn, std::ostream& oOut) {
163  for (LoadableToPlugins::iterator it = iIn.begin(); it != iIn.end(); ++it) {
164  std::string loadable(it->first.string());
165  replaceSpaces(loadable);
166  edm::sort_all(it->second);
167 
168  for (std::vector<std::pair<std::string, std::string> >::iterator it2 = it->second.begin();
169  it2 != it->second.end();
170  ++it2) {
171  oOut << loadable << " " << replaceSpaces(it2->first) << " " << replaceSpaces(it2->second) << "\n";
172  }
173  }
174  }
175 
176  void CacheParser::read(std::istream& iIn, LoadableToPlugins& oOut) {
177  unsigned long recordNumber = 0;
178 
179  std::string pluginType;
180 
184 
185  while (iIn) {
186  ++recordNumber;
187  if (not readline(iIn, empty, recordNumber, info, pat.second)) {
188  break;
189  }
190  pat.first = info.name_;
191  oOut[info.loadable_].push_back(pat);
192  }
193  }
194 
197  while (std::string::npos != (index = io.find_first_of(" \t\n", index))) {
198  io[index] = '%';
199  }
200  return io;
201  }
202 
205  while (std::string::npos != (index = io.find_first_of("%", index))) {
206  io[index] = ' ';
207  }
208  return io;
209  }
210 } // namespace edmplugin
edmplugin
Definition: AlignmentAlgorithmPluginFactory.cc:9
edm::sort_all
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:92
edmplugin::CacheParser::read
static void read(std::istream &, const boost::filesystem::path &iDirectory, CategoryToInfos &oOut)
Definition: CacheParser.cc:120
edmplugin::CacheParser::readline
static bool readline(std::istream &iIn, const boost::filesystem::path &iDirectory, unsigned long iRecordNumber, PluginInfo &oInfo, std::string &oPluginType)
Definition: CacheParser.cc:82
edmplugin::CacheParser::NameAndType
std::pair< std::string, std::string > NameAndType
Definition: CacheParser.h:43
Algorithms.h
edmplugin::CacheParser::restoreSpaces
static std::string & restoreSpaces(std::string &io)
Definition: CacheParser.cc:203
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
edmplugin::CacheParser::CategoryToInfos
std::map< std::string, std::vector< PluginInfo > > CategoryToInfos
Definition: CacheParser.h:42
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edmplugin::PluginInfo::name_
std::string name_
Definition: PluginInfo.h:29
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edmplugin::PluginInfo::loadable_
boost::filesystem::path loadable_
Definition: PluginInfo.h:30
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edmplugin::CacheParser::replaceSpaces
static std::string & replaceSpaces(std::string &io)
Definition: CacheParser.cc:195
CacheParser.h
pat
Definition: HeavyIon.h:7
edmplugin::CacheParser::LoadableToPlugins
std::map< boost::filesystem::path, NameAndTypes > LoadableToPlugins
Definition: CacheParser.h:45
type
type
Definition: HCALResponse.h:21
edmplugin::CacheParser::write
static void write(const CategoryToInfos &, std::ostream &)
Definition: CacheParser.cc:142
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
Exception
Definition: hltDiff.cc:246
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
edmplugin::checkForError
static void checkForError(const std::istream &iIn, unsigned long iRecordNumber, const std::string &iContext)
Definition: CacheParser.cc:71
edmplugin::PluginInfo
Definition: PluginInfo.h:28