CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondFormats/HLTObjects/src/AlCaRecoTriggerBits.cc

Go to the documentation of this file.
00001 #include "CondFormats/HLTObjects/interface/AlCaRecoTriggerBits.h"
00002 
00003 
00004 AlCaRecoTriggerBits::AlCaRecoTriggerBits(){}
00005 AlCaRecoTriggerBits::~AlCaRecoTriggerBits(){}
00006 
00007 const std::string::value_type AlCaRecoTriggerBits::delimeter_ = ';'; // separator
00008 
00009 //_____________________________________________________________________
00010 std::string AlCaRecoTriggerBits::compose(const std::vector<std::string> &paths) const
00011 {
00012   std::string mergedPaths;
00013   for (std::vector<std::string>::const_iterator iPath = paths.begin();
00014        iPath != paths.end(); ++iPath) {
00015     if (iPath != paths.begin()) mergedPaths += delimeter_;
00016     if (iPath->find(delimeter_) != std::string::npos) {
00017       // What to do in CondFormats?
00018       // cms::Exception? std::cerr? edm::LogError?
00019     }
00020     mergedPaths += *iPath;
00021   }
00022   
00023   // Special case: DB cannot store empty strings, see e.g. 
00024   // https://hypernews.cern.ch/HyperNews/CMS/get/database/674.html ,
00025   // so choose delimeter_ for that - it cannot appear in a path anyway.
00026   if (mergedPaths.empty()) mergedPaths = delimeter_;
00027 
00028   return mergedPaths;
00029 }
00030 
00031 //_____________________________________________________________________
00032 std::vector<std::string> AlCaRecoTriggerBits::decompose(const std::string &s) const
00033 {
00034   // decompose 's' into its parts that are separated by 'delimeter_'
00035   // (similar as in 
00036   //  Alignment/CommonAlignmentAlgorithm/src/AlignmentParameterSelector.cc)
00037 
00038   std::vector<std::string> result;
00039   if (!(s.size() == 1 && s[0] == delimeter_)) {
00040     // delimeter_ only indicates an empty list as DB cannot store empty strings
00041     std::string::size_type previousPos = 0;
00042     while (true) {
00043       const std::string::size_type delimiterPos = s.find(delimeter_, previousPos);
00044       if (delimiterPos == std::string::npos) {
00045         result.push_back(s.substr(previousPos)); // until end
00046         break;
00047       }
00048       result.push_back(s.substr(previousPos, delimiterPos - previousPos));
00049       previousPos = delimiterPos + 1; // +1: skip delim
00050     }
00051   }
00052 
00053   return result;
00054 }