3 #include <onlmon/RunDBodbc.h>
20 std::vector<std::string> split(
const char sep,
const std::string&
s)
23 std::vector<size_t> slashes_pos;
27 str.insert(str.begin(), sep);
30 if (str[str.size() - 1] != sep)
35 for (
size_t i = 0;
i < str.size();
i++)
39 slashes_pos.push_back(
i);
43 std::vector<std::string> parts;
45 if (slashes_pos.size() > 0)
47 for (
size_t i = 0;
i < slashes_pos.size() - 1;
i++)
49 parts.push_back(str.substr(slashes_pos[
i] + 1,
50 slashes_pos[
i + 1] - slashes_pos[
i] - 1));
61 for (
size_t i = 0;
i < parts.size(); ++
i)
64 if (
i + 1 < parts.size())
96 std::ostringstream menufile;
100 std::ifstream
in(menufile.str().c_str());
106 std::cout << __PRETTY_FUNCTION__ <<
"File " << menufile.str() <<
" does not exist."
107 <<
"I'm creating it now" << std::endl;
109 std::ofstream
out(menufile.str().c_str());
116 std::cout << __PRETTY_FUNCTION__ <<
"Reading file " << menufile.str() << std::endl;
121 std::vector<std::string>
lines;
123 while (
in.getline(str, 1024,
'\n'))
125 lines.emplace_back(str);
130 std::ostringstream sline;
131 sline << header <<
"/" << path <<
"/" << relfilename;
133 lines.push_back(sline.str());
136 sort(lines.begin(), lines.end());
139 std::set<std::string> olines;
140 copy(lines.begin(), lines.end(),
141 std::insert_iterator<std::set<std::string> >(olines, olines.begin()));
144 std::ofstream
out(menufile.str());
145 copy(olines.begin(), olines.end(), std::ostream_iterator<std::string>(
out,
"\n"));
160 std::ostringstream htmlmenufile;
169 std::set<std::string> dirlist;
170 std::set<std::string>::const_iterator
it;
171 for (it = olines.begin(); it != olines.end(); ++
it)
174 std::string::size_type
pos = line.find_last_of(
'/');
175 pos = line.substr(0, pos).find_last_of(
'/');
177 std::vector<std::string> parts = split(
'/', dir);
178 for (
size_t i = 0;
i <= parts.size(); ++
i)
181 dirlist.insert(dir2);
187 std::ofstream
out(htmlmenufile.str().c_str());
190 std::cout << __PRETTY_FUNCTION__ <<
" cannot open output file "
191 << htmlmenufile.str() << std::endl;
195 for (it = dirlist.begin(); it != dirlist.end(); ++
it)
199 int nslashes =
count(dir.begin(), dir.end(),
'/') + 1;
201 std::string::size_type
pos = dir.find_last_of(
'/');
202 if (pos < dir.size())
204 name = dir.substr(pos + 1);
210 out <<
"<H" << nslashes <<
">" << name
211 <<
"</H" << nslashes <<
"><BR>\n";
215 std::set<std::string>::const_iterator it2;
216 for (it2 = olines.begin(); it2 != olines.end(); ++it2)
219 std::string::size_type pos2 = line.find_last_of(
'/');
220 pos2 = line.substr(0, pos2).find_last_of(
'/');
226 pos2 = sline.find(
'/');
228 if (pos2 < sline.size())
231 << sline.substr(pos + 1) <<
"\">"
232 << sline.substr(0, pos) <<
"</A><BR>\n";
247 std::ostringstream sfilename;
249 sfilename << header <<
"_";
250 if (!basefilename.empty())
252 sfilename << basefilename <<
"_";
256 std::ostringstream sfullfilename;
258 sfullfilename <<
fHtmlRunDir <<
"/" << sfilename.str();
260 fullfilename = sfullfilename.str();
261 filename = sfilename.str();
265 std::cout << __PRETTY_FUNCTION__ <<
"namer: header=" << header
266 <<
" basefilename=" << basefilename <<
" ext=" << ext
268 <<
"fullfilename=" << fullfilename
269 <<
" filename=" << filename
284 namer(header, basefilename, ext, fullfilename, filename);
285 addMenu(header, path, filename);
297 if (runtmp ==
"JUNK")
299 runtype =
"junkdata";
301 else if (runtmp ==
"PHYSICS")
303 runtype =
"eventdata";
305 else if (runtmp ==
"CALIBRATION")
307 runtype =
"calibdata";
309 else if (runtmp ==
"PREJECTED")
311 runtype =
"prejecteddata";
313 else if (runtmp ==
"LOCALPOLARIMETER")
315 runtype =
"localpoldata";
317 else if (runtmp ==
"PEDESTAL")
319 runtype =
"pedestaldata";
321 else if (runtmp ==
"VERNIERSCAN")
323 runtype =
"vernierscandata";
325 else if (runtmp ==
"ZEROFIELD")
327 runtype =
"zerofielddata";
329 std::cout <<
"runtype is " << runtype << std::endl;
331 std::ostringstream fulldir;
333 fulldir <<
fHtmlDir <<
"/" << runtype <<
"/"
337 DIR* htdir = opendir(fulldir.str().c_str());
340 std::vector<std::string> mkdirlist;
341 mkdirlist.push_back(fulldir.str());
343 std::string::size_type pos1;
344 while ((pos1 = updir.rfind(
'/')) != std::string::npos)
346 updir.erase(pos1, updir.size());
347 htdir = opendir(updir.c_str());
350 mkdirlist.push_back(updir);
358 while (mkdirlist.rbegin() != mkdirlist.rend())
363 std::cout << __PRETTY_FUNCTION__ <<
"Trying to create dir " << md << std::endl;
365 if (mkdir(md.c_str(), S_IRWXU | S_IRWXG | S_IRWXO))
367 std::cout << __PRETTY_FUNCTION__ <<
"Error creating directory " << md << std::endl;
371 mkdirlist.pop_back();
376 fulldir <<
"/.htaccess";
377 std::ofstream htaccess;
378 htaccess.open(fulldir.str().c_str(), std::ios::trunc);
379 htaccess <<
"<Files *.html.gz>" << std::endl;
380 htaccess <<
" AddEncoding x-gzip .gz" << std::endl;
381 htaccess <<
" AddType text/html .gz" << std::endl;
382 htaccess <<
"</Files>" << std::endl;
383 htaccess <<
"<Files *.txt.gz>" << std::endl;
384 htaccess <<
" AddEncoding x-gzip .gz" << std::endl;
385 htaccess <<
" AddType text/html .gz" << std::endl;
386 htaccess <<
"</Files>" << std::endl;
396 std::cout << __PRETTY_FUNCTION__ <<
"OK. fHtmlRunDir=" <<
fHtmlRunDir << std::endl;
411 const int range = 1000;
414 std::ostringstream
s;
416 s <<
"run_" << std::setw(10) << std::setfill(
'0') << start * range
417 <<
"_" << std::setw(10) << std::setfill(
'0') << (start + 1) * range;