CMS 3D CMS Logo

Public Types | Static Public Member Functions | Private Member Functions | Static Private Member Functions

edmplugin::CacheParser Class Reference

#include <CacheParser.h>

List of all members.

Public Types

typedef std::map< std::string,
std::vector< PluginInfo > > 
CategoryToInfos
typedef std::map
< boost::filesystem::path,
NameAndTypes
LoadableToPlugins
typedef std::pair< std::string,
std::string > 
NameAndType
typedef std::vector< NameAndTypeNameAndTypes

Static Public Member Functions

static void read (std::istream &, const boost::filesystem::path &iDirectory, CategoryToInfos &oOut)
static void read (std::istream &, LoadableToPlugins &oOut)
static void write (LoadableToPlugins &iIn, std::ostream &)
static void write (const CategoryToInfos &, std::ostream &)

Private Member Functions

 CacheParser (const CacheParser &)
const CacheParseroperator= (const CacheParser &)

Static Private Member Functions

static bool readline (std::istream &iIn, const boost::filesystem::path &iDirectory, unsigned long iRecordNumber, PluginInfo &oInfo, std::string &oPluginType)
static std::string & replaceSpaces (std::string &io)
static std::string & restoreSpaces (std::string &io)

Detailed Description

Definition at line 39 of file CacheParser.h.


Member Typedef Documentation

typedef std::map<std::string, std::vector<PluginInfo> > edmplugin::CacheParser::CategoryToInfos

Definition at line 43 of file CacheParser.h.

typedef std::map<boost::filesystem::path, NameAndTypes > edmplugin::CacheParser::LoadableToPlugins

Definition at line 46 of file CacheParser.h.

typedef std::pair< std::string, std::string> edmplugin::CacheParser::NameAndType

Definition at line 44 of file CacheParser.h.

Definition at line 45 of file CacheParser.h.


Constructor & Destructor Documentation

edmplugin::CacheParser::CacheParser ( const CacheParser ) [private]

Member Function Documentation

const CacheParser& edmplugin::CacheParser::operator= ( const CacheParser ) [private]
void CacheParser::read ( std::istream &  iIn,
const boost::filesystem::path &  iDirectory,
CacheParser::CategoryToInfos iOut 
) [static]

The std::vector<PluginInfo>'s in CategoryToInfos are guaranteed to be ordered by PluginInfo.name_ where identical names are ordered by the order they are passed to read. In this way multiple calls to read for different directories will preserve the ordering

Definition at line 125 of file CacheParser.cc.

References info, and readline().

{
  unsigned long recordNumber=0;
  
  std::string pluginType;
  
  PluginInfo info;

  while(iIn) {
    ++recordNumber;
    if( not readline(iIn,iDirectory,recordNumber,info,pluginType) ) {
      break;
    }
    iOut[pluginType].push_back(info);
  }
  //now do a sort which preserves any previous order for files
  for(CacheParser::CategoryToInfos::iterator it = iOut.begin(), itEnd=iOut.end();
      it != itEnd;
      ++it) {
    std::stable_sort(it->second.begin(),it->second.end(), CompPluginInfos());
  }
}
void CacheParser::read ( std::istream &  iIn,
LoadableToPlugins oOut 
) [static]

Definition at line 191 of file CacheParser.cc.

References relativeConstraints::empty, info, edmplugin::PluginInfo::loadable_, edmplugin::PluginInfo::name_, path(), and readline().

{
  unsigned long recordNumber=0;
  
  std::string pluginType;
  
  PluginInfo info;
  NameAndType pat;
  boost::filesystem::path empty;
  
  while(iIn) {
    ++recordNumber;
    if( not readline(iIn,empty,recordNumber,info,pat.second) ) {
      break;
    }
    pat.first = info.name_;
    oOut[info.loadable_].push_back(pat);
  }
}
bool CacheParser::readline ( std::istream &  iIn,
const boost::filesystem::path &  iDirectory,
unsigned long  iRecordNumber,
PluginInfo oInfo,
std::string &  oPluginType 
) [static, private]

Definition at line 85 of file CacheParser.cc.

References edmplugin::checkForError(), convertXMLtoSQLite_cfg::fileName, edmplugin::PluginInfo::loadable_, max(), edmplugin::PluginInfo::name_, and restoreSpaces().

Referenced by read().

{    
  static const std::string kNewLine("start of new line");
  std::string fileName;
  std::string pluginName;
  iIn >> fileName;
  if(iIn.eof()) { return false;}
  checkForError(iIn,iRecordNumber,kNewLine);
  CacheParser::restoreSpaces(fileName);
  iIn >> pluginName;
  checkForError(iIn,iRecordNumber,fileName);
  CacheParser::restoreSpaces(pluginName);
  iIn >> oPluginType;
  checkForError(iIn,iRecordNumber,oPluginType);
  CacheParser::restoreSpaces(oPluginType);
  
  oInfo.loadable_ = iDirectory / fileName;
  oInfo.name_ = pluginName;
  
  //ignore everything to the end of line
  iIn.ignore(std::numeric_limits<int>::max(),
             '\n');
  while(iIn.peek() == '\n') {
    iIn.get();
  }  
  return true;
}
std::string & CacheParser::replaceSpaces ( std::string &  io) [static, private]

Definition at line 212 of file CacheParser.cc.

References getHLTprescales::index.

Referenced by write().

{
  std::string::size_type index=0;
  while(std::string::npos != (index = io.find_first_of(" \t\n",index))) {
    io[index]='%';
  }
  return io;
}
std::string & CacheParser::restoreSpaces ( std::string &  io) [static, private]

Definition at line 221 of file CacheParser.cc.

References getHLTprescales::index.

Referenced by readline().

{
  std::string::size_type index=0;
  while(std::string::npos != (index = io.find_first_of("%",index))) {
    io[index]=' ';
  }
  return io;
}
void CacheParser::write ( const CategoryToInfos iInfos,
std::ostream &  oOut 
) [static]

Definition at line 151 of file CacheParser.cc.

References AlCaRecoCosmics_cfg::name.

Referenced by main().

{
  //order the data more to our liking: library then object then type
  LoadableToPlugins ordered;
  
  for(CategoryToInfos::const_iterator it = iInfos.begin();
      it != iInfos.end();
      ++it) {
    std::string type(it->first);
    for(std::vector<PluginInfo>::const_iterator it2=it->second.begin();
        it2 != it->second.end();
        ++it2) {
      //remove any directory specification
      std::string loadable(it2->loadable_.leaf());
      std::string name(it2->name_);
      ordered[loadable].push_back(NameAndType(name,type));
    }
  }
  write(ordered,oOut);
}
void CacheParser::write ( LoadableToPlugins iIn,
std::ostream &  oOut 
) [static]

Definition at line 173 of file CacheParser.cc.

References replaceSpaces(), and edm::sort_all().

{
  for( LoadableToPlugins::iterator it = iIn.begin();
       it!=iIn.end();
       ++it) {
    std::string loadable(it->first.string());
    replaceSpaces(loadable);
    edm::sort_all(it->second);
    
    for(std::vector<std::pair<std::string,std::string> >::iterator it2 = it->second.begin();
        it2 != it->second.end();
        ++it2) {
      oOut << loadable <<" "<<replaceSpaces(it2->first)<<" "<<replaceSpaces(it2->second)<<"\n";
    }
  }
}