CMS 3D CMS Logo

ConfigurationRecord Class Reference

forward referece More...

#include <Utilities/General/interface/ConfigurationRecord.h>

List of all members.

Public Types

typedef std::vector< std::pair
< std::string, std::string > > 
Dict
typedef Dict::const_iterator DictCI
typedef
Dict::const_reverse_iterator 
DictCRI
typedef Dict::value_type DictEl
typedef Dict::iterator DictI

Public Member Functions

DictCI begin () const
 ConfigurationRecord (const std::string &isource, const Keys &ik=defKeys, bool evEnVar=true)
 ConfigurationRecord (std::istream &input, const Keys &ik=defKeys, bool evEnVar=true)
 ConfigurationRecord (const Keys &ik=defKeys, bool evEnVar=true)
void dump () const
DictCI end () const
DictCRI rbegin () const
DictCRI rend () const

Static Public Attributes

static const Keys defKeys

Protected Member Functions

void add (std::istream &input)
void add (const std::string &isource)
void parse ()

Protected Attributes

Dict dict_

Private Attributes

bool evalEnVar_
Keys keys
std::string source_

Classes

class  Keys


Detailed Description

forward referece

a Configuration Record parse a Record of the type KEY separator FIELD and store KEY&FIELD pairs in a vector

Definition at line 26 of file ConfigurationRecord.h.


Member Typedef Documentation

typedef std::vector<std::pair<std::string,std::string> > ConfigurationRecord::Dict

Definition at line 51 of file ConfigurationRecord.h.

typedef Dict::const_iterator ConfigurationRecord::DictCI

Definition at line 52 of file ConfigurationRecord.h.

typedef Dict::const_reverse_iterator ConfigurationRecord::DictCRI

Definition at line 53 of file ConfigurationRecord.h.

typedef Dict::value_type ConfigurationRecord::DictEl

Definition at line 55 of file ConfigurationRecord.h.

typedef Dict::iterator ConfigurationRecord::DictI

Definition at line 54 of file ConfigurationRecord.h.


Constructor & Destructor Documentation

ConfigurationRecord::ConfigurationRecord ( const Keys ik = defKeys,
bool  evEnVar = true 
) [explicit]

Definition at line 38 of file ConfigurationRecord.cc.

00038                                                                      : 
00039   keys(ik), evalEnVar_(evEnVar) {}

ConfigurationRecord::ConfigurationRecord ( std::istream &  input,
const Keys ik = defKeys,
bool  evEnVar = true 
)

Definition at line 41 of file ConfigurationRecord.cc.

References parse().

00041                                                                                           : 
00042   keys(ik), evalEnVar_(evEnVar)
00043 {
00044   add(input);
00045   parse();
00046 }

ConfigurationRecord::ConfigurationRecord ( const std::string &  isource,
const Keys ik = defKeys,
bool  evEnVar = true 
)

Definition at line 48 of file ConfigurationRecord.cc.

References parse().

00048                                                                                                  : 
00049   source_(isource), keys(ik), evalEnVar_(evEnVar)
00050 {parse();}


Member Function Documentation

void ConfigurationRecord::add ( std::istream &  input  )  [protected]

Definition at line 57 of file ConfigurationRecord.cc.

References edmNew::copy(), DBSPlugin::send(), and source_.

00057                                                 {
00058   input.unsetf( std::ios::skipws );
00059   std::istream_iterator<char > sbegin(input),send;
00060   std::copy(sbegin,send,inserter(source_,source_.end()));
00061   if (source_.empty()) return;
00062   source_ +="\n";
00063 }

void ConfigurationRecord::add ( const std::string &  isource  )  [protected]

Definition at line 52 of file ConfigurationRecord.cc.

References source_.

00052                                                        {
00053   if (isource.empty()) return;
00054   source_ += isource;
00055   source_ +="\n";
00056 }

DictCI ConfigurationRecord::begin ( void   )  const [inline]

Definition at line 65 of file ConfigurationRecord.h.

References dict_.

Referenced by ConfigurationDictionary::add().

00065 { return dict_.begin();}

void ConfigurationRecord::dump ( void   )  const

Definition at line 244 of file ConfigurationRecord.cc.

References GenUtil::cout, dict_, lat::endl(), and p.

00244                                      {
00245   for (DictCI p=dict_.begin(); p!=dict_.end(); ++p)
00246     GenUtil::cout << (*p).first << " => " << (*p).second << std::endl;
00247 } 

DictCI ConfigurationRecord::end ( void   )  const [inline]

Definition at line 66 of file ConfigurationRecord.h.

References dict_.

Referenced by ConfigurationDictionary::add().

00066 { return dict_.end();}

void ConfigurationRecord::parse (  )  [protected]

Definition at line 68 of file ConfigurationRecord.cc.

References ConfigurationRecord::Keys::comments(), GenUtil::cout, dict_, e, lat::endl(), evalEnVar_, Exception, i, getDQMSummary::key, keys, ConfigurationRecord::Keys::modifiers(), p, replace(), replaceRange(), ConfigurationRecord::Keys::separator(), EnvVerbosity< Tag >::silent(), source_, and cmsScimarkStop::tokens.

Referenced by ConfigurationRecord().

00068                                {
00069   using std::string;
00070 
00071   if (source_.empty()) return;
00072   // cout << "\nSOURCE:" << endl;
00073   // cout << source_ << endl;
00074 
00075   std::vector<std::string> asisText;
00076   // strip asis text 
00077   {
00078     size_t i = source_.find("@{",0);
00079     while(i!=string::npos) {
00080       size_t e = source_.find("}@",i);
00081       if (e!=string::npos) {
00082         string asis  = source_.substr(i+2,e-i-2);
00083         string placeOlder("@"); placeOlder+=toa()(asisText.size());
00084         asisText.push_back(asis);
00085         source_.replace(i,e+2-i,placeOlder);
00086         i = source_.find("@{",i);
00087       } else throw cms::Exception("ConfigurationRecord: unmatched @{");
00088     }
00089   }
00090 
00091    // evaluate env var if required
00092   if (evalEnVar_) {
00093     size_t i = source_.find("${",0);
00094     while(i!=string::npos) {
00095       size_t e = source_.find("}",i);
00096       if (e!=string::npos) {
00097         string evarN  = source_.substr(i+2,e-i-2);
00098         string evarV;
00099         if (!evarN.empty()) evarV = envUtil(evarN.c_str()).getEnv();
00100         source_.replace(i,e+1-i,evarV);
00101         i = source_.find("${",i);
00102       } else throw cms::Exception("ConfigurationRecord: unmatched ${");
00103     }
00104   }  
00105 
00106   // cout << "special done" << endl;
00107 
00108   // clean source from comments
00109 
00110   // C stile comments (not yet implemented...)
00111 
00112   //inline comments
00113   for (Keys::iter p=keys.comments().begin();p!=keys.comments().end();p++) {
00114     /* int ic = */ replaceRange(source_,*p,"\n","\n");
00115   }
00116   
00117   //  cout << "comment done" << endl;
00118 
00119   // remove multiple "blanks"
00120   replace(source_,"  "," ",true);
00121   // replace tabs
00122   replace(source_,"\t"," ",false);
00123   // remove blank lines
00124   replace(source_," \n","\n",true);
00125   replace(source_,"\n  ","\n",true);
00126   replace(source_,"\n\n","\n",true);
00127   
00128   // cout << "blanks done" << endl;
00129 
00130 
00131   // find KEY separator ... and tokenize
00132 
00133   // get rid of blanks and cr before separator and modifier
00134   {
00135     string expr(" "); expr += keys.separator();
00136     replace(source_,expr,keys.separator(),false);
00137   }
00138   {
00139     string expr("\n"); expr += keys.separator();
00140     replace(source_,expr,keys.separator(),false);
00141   }
00142 
00143   for (Keys::iter p=keys.modifiers().begin();p!=keys.modifiers().end();p++) {
00144 
00145     {
00146       string expr(" "); expr += *p;
00147       replace(source_,expr,*p,false);
00148     }
00149     {
00150       string expr("\n"); expr += *p;
00151       replace(source_,expr,*p,false);
00152     }
00153 
00154   }
00155 
00156   // cout << "\nSOURCE:" << endl;
00157   // cout << source_ <<"-------"<< endl << endl;
00158 
00159   // get rid of leading and trailing blanks and comments
00160   {
00161     size_t i = source_.find_first_not_of(string(" \n/#"),0);
00162     if (i!=string::npos) source_.erase(0,i);
00163     i = source_.find_last_not_of(string(" \n/#"),string::npos);
00164     if (i!=string::npos) source_.resize(i+1);
00165   }
00166 
00167   //  cout << "\nSOURCE:" << endl;
00168   //cout << source_ <<"-------"<< endl << endl;
00169 
00170 
00171   // if nothing left return...
00172   if (source_.empty()) return;
00173 
00174 
00175   // add a special separator before KEY
00176   string sillySep("^^^");
00177   {
00178     size_t i = source_.find(keys.separator(),0); // skip first
00179     i = source_.find(keys.separator(),i+keys.separator().size());
00180     while(i!=string::npos) {
00181       size_t e = source_.find_last_of(string(" \n"),i);
00182       if (e==string::npos) 
00183         throw cms::Exception("ConfigurationRecord: wrong parsing of configuration");
00184       else e++;
00185       source_.insert(e,sillySep);
00186       i = source_.find(keys.separator(),i+3+keys.separator().size());
00187     } 
00188   }
00189   
00190   // get rid of blanks and cr after separator
00191   {
00192     string expr = keys.separator() + " ";
00193     replace(source_,expr,keys.separator(),true);
00194     expr = keys.separator() + "\n";
00195     replace(source_,expr,keys.separator(),true);
00196   }
00197   
00198   // cout << "\nSOURCE:" << endl;
00199   // cout << source_ << endl << endl;
00200   
00201   // if nothng left return...
00202   if (source_.empty()) return;
00203 
00204   // tokenize and insert in the dictionary
00205   Tokenizer tokens(sillySep, source_);
00206   // cout << "\nfound " << tokens.size() << " tokens " << endl;
00207   std::vector<string>::const_iterator e= tokens.end();
00208   for (std::vector<string>::const_iterator p= tokens.begin();p!=e; ++p) {
00209     // cout << (*p) << endl;
00210     string::size_type pos = (*p).find(keys.separator(),0);
00211     if (pos==string::npos) {
00212       if (!GenUtilVerbosity::silent())
00213         GenUtil::cout << "ConfigurationRecord: wrong parsing of token " << *p << std::endl;
00214       continue;
00215     }
00216     string key((*p),0,pos);
00217     // replace asis
00218     replace(key," @","@",true);
00219     if (key[0]=='@') {
00220       int i = ato<int>()(key.substr(1,string::npos).c_str());
00221       key = asisText[i];
00222     }
00223     string token((*p),pos+1,string::npos);
00224     if (!token.empty()) {
00225       // get rid of trailing blanks and \n
00226       replace(token,"  "," ",true);
00227       replace(token," \n","\n",false);
00228       replace(token,"\n ","\n",false);
00229       // replace(token,"\n","",false);
00230       if ((!token.empty())&&token[token.size()-1]=='\n') token.resize(token.size()-1);
00231       // replace asis
00232       replace(token," @","@",true);
00233       if (token[0]=='@') {
00234         int i = ato<int>()(token.substr(1,string::npos).c_str());
00235         token = asisText[i];
00236       }
00237     }
00238     // cout << key << " -> |" << token <<"|"<<endl;
00239     dict_.push_back(DictEl(key,token));
00240   }
00241   
00242 }

DictCRI ConfigurationRecord::rbegin ( void   )  const [inline]

Definition at line 68 of file ConfigurationRecord.h.

References dict_.

00068 { return dict_.rbegin();}

DictCRI ConfigurationRecord::rend ( void   )  const [inline]

Definition at line 69 of file ConfigurationRecord.h.

References dict_.

00069 { return dict_.rend();}


Member Data Documentation

const ConfigurationRecord::Keys ConfigurationRecord::defKeys [static]

Definition at line 48 of file ConfigurationRecord.h.

Dict ConfigurationRecord::dict_ [protected]

Definition at line 82 of file ConfigurationRecord.h.

Referenced by begin(), dump(), end(), parse(), rbegin(), and rend().

bool ConfigurationRecord::evalEnVar_ [private]

Definition at line 87 of file ConfigurationRecord.h.

Referenced by parse().

Keys ConfigurationRecord::keys [private]

Definition at line 86 of file ConfigurationRecord.h.

Referenced by parse().

std::string ConfigurationRecord::source_ [private]

Definition at line 85 of file ConfigurationRecord.h.

Referenced by add(), and parse().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:16:47 2009 for CMSSW by  doxygen 1.5.4