MIDAS
Loading...
Searching...
No Matches
history_image.cxx File Reference
#include <string>
#include <exception>
#include <sstream>
#include <iomanip>
#include <thread>
#include <algorithm>
#include "midas.h"
#include "msystem.h"
#include "odbxx.h"
Include dependency graph for history_image.cxx:

Go to the source code of this file.

Functions

std::string history_dir ()
 
void start_image_history ()
 
void stop_image_history ()
 
int get_number_image_history_threads ()
 
int hs_image_retrieve (std::string image_name, time_t start_time, time_t stop_time, std::vector< time_t > &vtime, std::vector< std::string > &vfilename)
 

Function Documentation

◆ get_number_image_history_threads()

int get_number_image_history_threads ( )

Definition at line 317 of file history_image.cxx.

317{ return 0; }
Here is the caller graph for this function:

◆ history_dir()

std::string history_dir ( )

Definition at line 28 of file history_image.cxx.

28 {
29 static std::string dir;
30
31 if (dir.empty()) {
32 midas::odb o = {
33 {"History dir", ""}
34 };
35 o.connect("/Logger/History/IMAGE");
36
37 if (o["History dir"] != std::string(""))
38 dir = o["History dir"];
39 else {
40 midas::odb l("/Logger");
41 if (l.is_subkey("History dir")) {
42 dir = l["History dir"];
43 if (dir == "")
44 dir = l["Data dir"];
45 } else
46 dir = l["Data dir"];
47 }
48
49 if (dir.empty())
50 dir = cm_get_path();
51
52 if (dir.back() != '/')
53 dir += "/";
54 }
55 return dir;
56}
void connect(const std::string &path, const std::string &name, bool write_defaults, bool delete_keys_not_in_defaults=false)
Definition odbxx.cxx:1291
std::string cm_get_path()
Definition midas.cxx:1537
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hs_image_retrieve()

int hs_image_retrieve ( std::string  image_name,
time_t  start_time,
time_t  stop_time,
std::vector< time_t > &  vtime,
std::vector< std::string > &  vfilename 
)

Definition at line 332 of file history_image.cxx.

334{
335 // auto start = usStart();
336 std::string path = history_dir() + image_name;
337
338 std::string mask;
339 if (start_time == stop_time) {
340 ss_tzset(); // required by localtime_r()
341 struct tm ltm;
342 localtime_r(&start_time, &ltm);
343 std::stringstream s;
344 s <<
345 std::setfill('0') << std::setw(2) << ltm.tm_year - 100 <<
346 std::setfill('0') << std::setw(2) << ltm.tm_mon + 1 <<
347 std::setfill('0') << std::setw(2) << ltm.tm_mday <<
348 "_" << "??????.*";
349 mask = s.str();
350 } else {
351 ss_tzset(); // required by localtime_r()
352 struct tm ltStart, ltStop;
353 localtime_r(&start_time, &ltStart);
355 std::stringstream sStart, sStop;
356 std::string mStart, mStop;
357 mask = "??????_??????.*";
358
359 sStart <<
360 std::setfill('0') << std::setw(2) << ltStart.tm_year - 100 <<
361 std::setfill('0') << std::setw(2) << ltStart.tm_mon + 1 <<
362 std::setfill('0') << std::setw(2) << ltStart.tm_mday <<
363 "_" <<
364 std::setfill('0') << std::setw(2) << ltStart.tm_hour <<
365 std::setfill('0') << std::setw(2) << ltStart.tm_min <<
366 std::setfill('0') << std::setw(2) << ltStart.tm_sec;
367 mStart = sStart.str();
368 sStop <<
369 std::setfill('0') << std::setw(2) << ltStop.tm_year - 100 <<
370 std::setfill('0') << std::setw(2) << ltStop.tm_mon + 1 <<
371 std::setfill('0') << std::setw(2) << ltStop.tm_mday <<
372 "_" <<
373 std::setfill('0') << std::setw(2) << ltStop.tm_hour <<
374 std::setfill('0') << std::setw(2) << ltStop.tm_min <<
375 std::setfill('0') << std::setw(2) << ltStop.tm_sec;
376 mStop = sStop.str();
377 for (int i=0 ; i<13 ; i++) {
378 if (mStart[i] == mStop[i])
379 mask[i] = mStart[i];
380 else
381 break;
382 }
383 }
384
386
387 ss_file_find(path.c_str(), mask.c_str(), &vfn);
388
389 if (vfn.size() == 0)
390 ss_file_find(path.c_str(), "??????_??????.*", &vfn);
391
392 std::sort(vfn.begin(), vfn.end());
393
394 time_t minDiff = 1E7;
395 time_t minTime{};
396 int minIndex{};
397
398 for (unsigned i=0 ; i<vfn.size() ; i++) {
399 struct tm ti{};
400 sscanf(vfn[i].c_str(), "%2d%2d%2d_%2d%2d%2d", &ti.tm_year, &ti.tm_mon,
401 &ti.tm_mday, &ti.tm_hour, &ti.tm_min, &ti.tm_sec);
402 ti.tm_year += 100;
403 ti.tm_mon -= 1;
404 ti.tm_isdst = -1;
405 time_t ft = ss_mktime(&ti);
406 time_t now;
407 time(&now);
408
409 if (abs(ft - start_time) < minDiff) {
410 minDiff = abs(ft - start_time);
411 minTime = ft;
412 minIndex = i;
413 }
414
415 if (start_time != stop_time && ft >= start_time && ft <= stop_time) {
416 vtime.push_back(ft);
417 vfilename.push_back(vfn[i]);
418 }
419 }
420
421 // start == stop means return single image closest to them
422 if (start_time == stop_time && vfn.size() > 0) {
423 vtime.push_back(minTime);
424 vfilename.push_back(vfn[minIndex]);
425 }
426
427 //std::cout << "mask = " << mask << ", n = " << n << ", t = " << usSince(start)/1000.0 << " ms" << std::endl;
428
429 return HS_SUCCESS;
430}
#define HS_SUCCESS
Definition midas.h:727
time_t ss_mktime(struct tm *tms)
Definition system.cxx:3365
void ss_tzset()
Definition system.cxx:3355
INT ss_file_find(const char *path, const char *pattern, char **plist)
Definition system.cxx:6713
std::string history_dir()
INT i
Definition mdump.cxx:32
DWORD stop_time
Definition mevb.cxx:55
std::vector< std::string > STRING_LIST
Definition midas.h:246
#define mask(slot)
Definition midas_macro.h:54
MUTEX_T * tm
Definition odbedit.cxx:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_image_history()

void start_image_history ( )

Definition at line 315 of file history_image.cxx.

315{}
Here is the caller graph for this function:

◆ stop_image_history()

void stop_image_history ( )

Definition at line 316 of file history_image.cxx.

316{}
Here is the caller graph for this function: