CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes | Static Private Attributes
evf::ParameterSetRetriever Class Reference

#include <ParameterSetRetriever.h>

Public Member Functions

std::string getAsString () const
 
std::string getHostString (const std::string &in, std::string modifier="") const
 
std::string getModuleTableAsString () const
 
std::string getPathTableAsString () const
 
 ParameterSetRetriever (const std::string &in)
 

Private Attributes

std::string pathIndexTable
 
std::string pset
 

Static Private Attributes

static const std::string dbheading ="db:"
 
static const std::string fileheading ="file:"
 
static const std::string webheading ="http://"
 

Detailed Description

Definition at line 8 of file ParameterSetRetriever.h.

Constructor & Destructor Documentation

evf::ParameterSetRetriever::ParameterSetRetriever ( const std::string &  in)

Definition at line 23 of file ParameterSetRetriever.cc.

References evf::SquidNet::check(), HDQMDatabaseProducer::configFile, dbheading, error, fileheading, lut2db_cfg::filename, getHostString(), recoMuon::in, geometryCSVtoXML::line, lumiQueryAPI::msg, NULL, pathIndexTable, pset, summarizeEdmComparisonLogfiles::success, webheading, and evf::write_data().

24  {
25  using std::string;
26  using std::ostringstream;
27  using std::ifstream;
28 
29 
30 
31  if (fileheading==in.substr(0,fileheading.size()))
32  {
33  string filename=in.substr(fileheading.size());
34  edm::LogInfo("psetRetriever")<<"filename is --> "<<filename<<" <--";
35 
36  string line;
37  ifstream configFile(filename.c_str());
38  while(std::getline(configFile,line)) {
39  pset+=line;
40  pset+="\n";
41  }
42  }
43  else if (webheading==in.substr(0,webheading.size()))
44  {
45  string hostname = getHostString(in);
46  SquidNet sn(3128,"http://localhost:8000/RELEASE-NOTES.txt");
47  edm::LogInfo("psetRetriever")<<"Using cfg from " << in;
48  CURL* han = curl_easy_init();
49  if(han==0)
50  {
51  XCEPT_RAISE(evf::Exception,"could not create handle for web ParameterSet");
52  }
53 
54  struct curl_slist *headers=NULL; /* init to NULL is important */
55  headers = curl_slist_append(headers, "Pragma:");
56  curl_easy_setopt(han, CURLOPT_HTTPHEADER, headers);
57  char error[CURL_ERROR_SIZE];
58  if(sn.check())
59  curl_easy_setopt(han, CURLOPT_PROXY, "localhost:3128");
60 
61  curl_easy_setopt(han, CURLOPT_URL, hostname.c_str());
62  curl_easy_setopt(han, CURLOPT_VERBOSE,"");
63  curl_easy_setopt(han, CURLOPT_NOSIGNAL,"");
64  // curl_easy_setopt(han, CURLOPT_TIMEOUT, 60.0L);
65 
66  curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &write_data);
67  curl_easy_setopt(han, CURLOPT_WRITEDATA, &pset);
68  curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error);
69  int success = curl_easy_perform(han);
70  curl_slist_free_all(headers); /* free the header list */
71  curl_easy_cleanup(han);
72  han = 0;
73  if(success != 0)
74  {
75  ostringstream msg;
76  msg << "could not get config from url " << in << " error #"
77  << success << " " << error;
78  XCEPT_RAISE(evf::Exception,msg.str().c_str());
79  }
80 
81  //now get path-index table
82  han = curl_easy_init();
83  if(han==0)
84  {
85  XCEPT_RAISE(evf::Exception,"could not create handle for web ParameterSet");
86  }
87  headers = NULL;
88  headers = curl_slist_append(headers, "Pragma:");
89  curl_easy_setopt(han, CURLOPT_HTTPHEADER, headers);
90  if(sn.check())
91  curl_easy_setopt(han, CURLOPT_PROXY, "localhost:3128");
92  hostname = getHostString(in,"path");
93  curl_easy_setopt(han, CURLOPT_URL, hostname.c_str());
94  curl_easy_setopt(han, CURLOPT_VERBOSE,"");
95  curl_easy_setopt(han, CURLOPT_NOSIGNAL,"");
96  // curl_easy_setopt(han, CURLOPT_TIMEOUT, 60.0L);
97 
98  curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &write_data);
99  curl_easy_setopt(han, CURLOPT_WRITEDATA, &pathIndexTable);
100  curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error);
101  success = curl_easy_perform(han);
102  curl_slist_free_all(headers); /* free the header list */
103  curl_easy_cleanup(han);
104 
105  if(success != 0)
106  {
107  ostringstream msg;
108  msg << "could not get pathindex table from url " << in << " error #"
109  << success << " " << error;
110  XCEPT_RAISE(evf::Exception,msg.str().c_str());
111  }
112 
113 
114  }
115  else if (dbheading==in.substr(0,dbheading.size()))
116  {
117  XCEPT_RAISE(evf::Exception,"db access for ParameterSet not yet implemented");
118  }
119  else
120  {
121  edm::LogInfo("psetRetriever")<<"Using string cfg from RunControl or XML";
122  pset = in;
123  }
124  }
std::string getHostString(const std::string &in, std::string modifier="") const
#define NULL
Definition: scimark2.h:8
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *pointer)
Definition: CurlUtils.h:12
static const std::string dbheading
tuple filename
Definition: lut2db_cfg.py:20
static const std::string webheading
static const std::string fileheading

Member Function Documentation

std::string evf::ParameterSetRetriever::getAsString ( ) const
std::string evf::ParameterSetRetriever::getHostString ( const std::string &  in,
std::string  modifier = "" 
) const

Definition at line 139 of file ParameterSetRetriever.cc.

References query::host, scaleCards::path, pos, and webheading.

Referenced by ParameterSetRetriever().

140  {
141  using std::string;
142  string innohttp = in.substr(webheading.size());
143  string::size_type pos = innohttp.find(':',0);
144  string host = innohttp.substr(0,pos);
145  string path = innohttp.substr(pos);
146  if(modifier != "")
147  {
148  pos = path.find_last_of('.');
149  if(pos != string::npos)
150  {
151  string upath = path.substr(0,pos);
152  path = upath + '.' + modifier;
153  }
154  }
155  struct hostent *heb = gethostbyname(host.c_str());
156  struct hostent *he = gethostbyaddr(heb->h_addr_list[0], heb->h_length, heb->h_addrtype);
157  string completehost = "http://";
158  completehost += he->h_name;
159  completehost += path;
160  return completehost;
161  }
uint16_t size_type
list path
Definition: scaleCards.py:51
string host
Definition: query.py:114
static const std::string webheading
std::string evf::ParameterSetRetriever::getModuleTableAsString ( ) const
std::string evf::ParameterSetRetriever::getPathTableAsString ( ) const

Definition at line 133 of file ParameterSetRetriever.cc.

References pathIndexTable.

Referenced by evf::FWEPWrapper::init().

134  {
135  return pathIndexTable;
136  }

Member Data Documentation

const std::string evf::ParameterSetRetriever::dbheading ="db:"
staticprivate

Definition at line 20 of file ParameterSetRetriever.h.

Referenced by ParameterSetRetriever().

const std::string evf::ParameterSetRetriever::fileheading ="file:"
staticprivate

Definition at line 19 of file ParameterSetRetriever.h.

Referenced by ParameterSetRetriever().

std::string evf::ParameterSetRetriever::pathIndexTable
private

Definition at line 18 of file ParameterSetRetriever.h.

Referenced by getPathTableAsString(), and ParameterSetRetriever().

std::string evf::ParameterSetRetriever::pset
private

Definition at line 17 of file ParameterSetRetriever.h.

Referenced by getAsString(), and ParameterSetRetriever().

const std::string evf::ParameterSetRetriever::webheading ="http://"
staticprivate

Definition at line 21 of file ParameterSetRetriever.h.

Referenced by getHostString(), and ParameterSetRetriever().