CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/CondCore/ORA/src/Selection.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Selection.h"
00002 #include "CondCore/ORA/interface/Exception.h"
00003 //
00004 #include <sstream>
00005 
00006 std::vector<std::string>& ora::Selection::selectionTypes(){
00007   static std::vector<std::string> types;
00008   types.push_back("=");
00009   types.push_back("!=");
00010   types.push_back(">");
00011   types.push_back(">=");
00012   types.push_back("<");
00013   types.push_back("<=");
00014   return types;
00015 }
00016 
00017 std::string  ora::Selection::variableNameFromUniqueString(const std::string& uniqueString)
00018 {
00019   size_t ind = uniqueString.rfind("_");
00020   return uniqueString.substr(0,ind);
00021 }
00022 
00023 std::string ora::Selection::indexVariable(){
00024   static std::string s_var("ora::ContainerIndex");
00025   return s_var;
00026 }
00027 
00028 ora::Selection::Selection():m_items(),m_data(){
00029 }
00030 
00031 ora::Selection::~Selection(){
00032 }
00033 
00034 std::string
00035 ora::Selection::uniqueVariableName(const std::string& varName) const {
00036   std::stringstream uniqueVarName;
00037   unsigned int i = 0;
00038   bool notUnique = true;
00039   while(notUnique){
00040     bool found = false;
00041     uniqueVarName.str("");
00042     uniqueVarName << varName;
00043     uniqueVarName << "_" << i;
00044     for(coral::AttributeList::const_iterator iAttr = m_data.begin();
00045         iAttr!=m_data.end() && !found; ++iAttr){
00046       if( iAttr->specification().name() == uniqueVarName.str() ) found = true;
00047     }
00048     notUnique = found;
00049     i++;
00050   }
00051   return uniqueVarName.str();
00052 }
00053 
00054 void ora::Selection::addIndexItem( int startIndex, int endIndex ){
00055   if(endIndex<startIndex && endIndex>=0) {
00056     throwException("Cannot select with endIndex<startIndex.",
00057                    "Selection::addIndexItem");
00058   } else if( startIndex==endIndex && endIndex>=0){
00059     std::string varName = uniqueVariableName( indexVariable() );
00060     SelectionItemType selType = ora::EQ;
00061     m_items.push_back(std::make_pair(varName,selectionTypes()[selType]));
00062     m_data.extend<int>(varName);
00063     m_data[varName].data<int>() = startIndex;    
00064   } else {
00065     if(startIndex>0){
00066       std::string varName0 = uniqueVariableName( indexVariable() );
00067       SelectionItemType firstType = ora::GE;
00068       m_items.push_back(std::make_pair(varName0,selectionTypes()[firstType]));
00069       m_data.extend<int>(varName0);
00070       m_data[varName0].data<int>() = startIndex;
00071     }
00072     if(endIndex>0){
00073       std::string varName1 = uniqueVariableName( indexVariable() );
00074       SelectionItemType secondType = ora::LE;
00075       m_items.push_back(std::make_pair(varName1,selectionTypes()[secondType]));
00076       m_data.extend<int>(varName1);
00077       m_data[varName1].data<int>() = endIndex;
00078     }
00079   }
00080 }
00081 
00082 bool
00083 ora::Selection::isEmpty() const {
00084   return m_items.empty();
00085 }
00086 
00087 const std::vector<std::pair<std::string,std::string> >&
00088 ora::Selection::items() const {
00089   return m_items;
00090 }
00091 
00092 const coral::AttributeList&
00093 ora::Selection::data() const {
00094   return m_data;
00095 }