CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParameterSetRetriever.cc
Go to the documentation of this file.
6 
7 #include "curl/curl.h"
8 #include <netdb.h>
9 #include <sys/socket.h> /* for AF_INET */
10 
11 #include <fstream>
12 
13 
14 
15 namespace evf{
16  //______________________________________________________________________________
17 
18 
22 
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  }
125 
126 
127  //______________________________________________________________________________
129  {
130  return pset;
131  }
132  //______________________________________________________________________________
134  {
135  return pathIndexTable;
136  }
137 
138 
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  }
162 } //end namespace evf
bool check()
Definition: SquidNet.cc:21
std::string getHostString(const std::string &in, std::string modifier="") const
#define NULL
Definition: scimark2.h:8
uint16_t size_type
std::string getPathTableAsString() const
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *pointer)
Definition: CurlUtils.h:12
string host
Definition: query.py:114
static const std::string dbheading
ParameterSetRetriever(const std::string &in)
tuple filename
Definition: lut2db_cfg.py:20
static const std::string webheading
static const std::string fileheading