Line data Source code
1 : // DUNE DAQ modification notice:
2 : // This file has been modified from the original ATLAS oks source for the DUNE DAQ project.
3 : // Fork baseline commit: oks-08-03-04 (2022-04-14).
4 : // Renamed since fork: yes (from src/oks_utils.h to src/oks_utils.hpp).
5 :
6 : #ifndef OKS_KERNEL_UTILS_H
7 : #define OKS_KERNEL_UTILS_H
8 :
9 : #include "oks/exceptions.hpp"
10 :
11 : #include <boost/date_time/gregorian/gregorian_types.hpp>
12 : #include <boost/date_time/posix_time/posix_time_types.hpp>
13 :
14 : #include <map>
15 : #include <string>
16 :
17 : namespace dunedaq {
18 : namespace oks {
19 :
20 : class OksClass;
21 : class OksObject;
22 : class OksXmlInputStream;
23 : class OksFile;
24 : struct OksAliasTable;
25 : class OksKernel;
26 :
27 : // read date and time strings from OKS files (oks::Date, oks::Time or Boost ISO strings)
28 :
29 : boost::posix_time::ptime
30 : str2time(const char* value, size_t len, const char* file_name = nullptr);
31 : boost::gregorian::date
32 : str2date(const char* value, size_t len);
33 :
34 : // the structure for efficient search of objects to be re-read or to be deleted during reload
35 :
36 : struct ReloadObjects
37 : {
38 :
39 : template<typename T>
40 : using map_str_t = std::map<std::string, T>;
41 :
42 : std::map<const OksClass*, map_str_t<OksObject*>*> data;
43 : std::vector<OksObject*> created;
44 :
45 : ~ReloadObjects();
46 : void put(OksObject* obj);
47 : OksObject* pop(const OksClass* c, const std::string& id);
48 : };
49 :
50 : // the structure to pass common parameters to various read() methods of OksData and OksObject class
51 :
52 : struct ReadFileParams
53 : {
54 : OksFile* f;
55 : OksXmlInputStream& s;
56 : OksAliasTable* alias_table;
57 : OksKernel* oks_kernel;
58 : char format;
59 : ReloadObjects* reload_objects;
60 : const char* object_tag;
61 : size_t object_tag_len;
62 : OksObject* owner;
63 : std::string tmp;
64 :
65 133 : ReadFileParams(OksFile* f_, OksXmlInputStream& s_, OksAliasTable* t_, OksKernel* k_, char m_, ReloadObjects* l_)
66 133 : : f(f_)
67 133 : , s(s_)
68 133 : , alias_table(t_)
69 133 : , oks_kernel(k_)
70 133 : , format(m_)
71 133 : , reload_objects(l_)
72 : {
73 133 : init();
74 133 : }
75 :
76 : void init();
77 : };
78 :
79 : // 17-SEP-2009: for compatibility with previous OKS versions
80 : // FIXME: remove later ...
81 :
82 : class Date
83 : {
84 :
85 : public:
86 0 : Date(const char* s) { set(s); } // dd/mm/[yy]yy
87 :
88 0 : virtual ~Date() { ; }
89 :
90 : void set(const char*);
91 :
92 0 : long year() const { return p_tm.tm_year; }
93 0 : unsigned short month() const { return p_tm.tm_mon; }
94 0 : unsigned short day() const { return p_tm.tm_mday; }
95 :
96 : virtual std::string str() const;
97 :
98 : protected:
99 : struct tm p_tm;
100 : };
101 :
102 : std::ostream&
103 : operator<<(std::ostream&, const Date&);
104 :
105 : class Time : public Date
106 : {
107 :
108 : public:
109 0 : Time(const char* s)
110 0 : : Date(s)
111 : { /*set(s);*/
112 0 : } // dd/mm/[yy]yy hh:mm[:ss]
113 :
114 0 : virtual ~Time() { ; }
115 :
116 0 : unsigned short hour() const { return p_tm.tm_hour; }
117 0 : unsigned short min() const { return p_tm.tm_min; }
118 0 : unsigned short sec() const { return p_tm.tm_sec; }
119 :
120 : virtual std::string str() const;
121 : };
122 :
123 : std::ostream&
124 : operator<<(std::ostream&, const Time&);
125 :
126 : } // namespace oks
127 : } // namespace dunedaq
128 :
129 : #endif
|