clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name MonitorDB.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="daq" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ daq/slc/database/src/MonitorDB.cc
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | #include "daq/slc/database/MonitorDB.h" |
| 9 | |
| 10 | #include <daq/slc/database/DBHandlerException.h> |
| 11 | #include <daq/slc/system/LogFile.h> |
| 12 | |
| 13 | using namespace Belle2; |
| 14 | |
| 15 | void MonitorDB::add(DBInterface& db, const std::string& table, |
| 16 | const std::string& vname, int val) |
| 17 | { |
| 18 | try { |
| 19 | createTable(db, table); |
| 20 | db.execute("insert into %s (name, value_i) values ('%s', %d);", |
| 21 | table.c_str(), vname.c_str(), val); |
| 22 | } catch (const DBHandlerException& e) { |
| 23 | LogFile::error(e.what()); |
| 24 | throw (e); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | void MonitorDB::add(DBInterface& db, const std::string& table, |
| 29 | const std::string& vname, float val) |
| 30 | { |
| 31 | try { |
| 32 | createTable(db, table); |
| 33 | db.execute("insert into %s (name, value_f) values ('%s', %f);", |
| 34 | table.c_str(), vname.c_str(), val); |
| 35 | } catch (const DBHandlerException& e) { |
| 36 | LogFile::error(e.what()); |
| 37 | throw (e); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | void MonitorDB::add(DBInterface& db, const std::string& table, |
| 42 | const std::string& vname, const std::string& val) |
| 43 | { |
| 44 | try { |
| 45 | createTable(db, table); |
| 46 | db.execute("insert into %s (name, value_t) values ('%s', '%s');", |
| 47 | table.c_str(), vname.c_str(), val.c_str()); |
| 48 | } catch (const DBHandlerException& e) { |
| 49 | LogFile::error(e.what()); |
| 50 | throw (e); |
| 51 | } |
| 52 | |
| 53 | } |
| 54 | |
| 55 | NSMVarList MonitorDB::get(DBInterface& db, const std::string& tablename, |
| 56 | const std::string& vname) |
| 57 | { |
| 58 | if (!db.isConnected()) db.connect(); |
| 59 | db.execute("select *, extract(epoch from record_time) rtime " |
| 60 | "from %s p where p.name = '%s' order by id;", |
| 61 | tablename.c_str(), vname.c_str()); |
| 62 | return readTable(db, vname); |
| 63 | } |
| 64 | |
| 65 | NSMVarList MonitorDB::get(DBInterface& db, const std::string& tablename, |
| 66 | const std::string& vname, int max) |
| 67 | { |
| 68 | if (!db.isConnected()) db.connect(); |
| 69 | db.execute("select *, extract(epoch from record_time) rtime " |
| 70 | "from %s p where p.name = '%s' limit %d order by id;", |
| 71 | tablename.c_str(), vname.c_str(), max); |
| 72 | return readTable(db, vname); |
| 73 | } |
| 74 | |
| 75 | NSMVarList MonitorDB::get(DBInterface& db, const std::string& tablename, |
| 76 | const std::string& vname, const Date& start, |
| 77 | const Date& end) |
| 78 | { |
| 79 | if (!db.isConnected()) db.connect(); |
| 80 | db.execute("select *, extract(epoch from record_time) rtime " |
| 81 | "from %s p where p.name = '%s' and record_time > '%s' and " |
| 82 | "record_time < '%s'order by id;", tablename.c_str(), |
| 83 | vname.c_str(), start.toString(), end.toString()); |
| 84 | return readTable(db, vname); |
| 85 | } |
| 86 | |
| 87 | NSMVarList MonitorDB::get(DBInterface& db, const std::string& tablename, |
| 88 | const std::string& vname, int max, |
| 89 | const Date& start, const Date& end) |
| 90 | { |
| 91 | if (!db.isConnected()) db.connect(); |
| 1 | Assuming the condition is false | |
|
| |
| 92 | db.execute("select *, extract(epoch from record_time) rtime " |
| 93 | "from %s p where p.name = '%s' and record_time > '%s' and " |
| 94 | "record_time < '%s' limit %d order by id;", |
| 95 | tablename.c_str(), vname.c_str(), |
| 96 | start.toString(), end.toString(), max); |
| 97 | return readTable(db, vname); |
| 3 | | Calling 'MonitorDB::readTable' | |
|
| 98 | } |
| 99 | |
| 100 | NSMVarList MonitorDB::readTable(DBInterface& db, const std::string& vname) |
| 101 | { |
| 102 | DBRecordList record_v(db.loadRecords()); |
| 103 | NSMVarList vars; |
| 104 | for (size_t i = 0; i < record_v.size(); i++) { |
| 4 | | Assuming the condition is true | |
|
| 5 | | Loop condition is true. Entering loop body | |
|
| 105 | DBRecord& record(record_v[i]); |
| 106 | NSMVar var(vname); |
| 6 | | Calling constructor for 'NSMVar' | |
|
| 8 | | Returning from constructor for 'NSMVar' | |
|
| 107 | if (record.hasField("value_b")) { |
| 9 | | Assuming the condition is true | |
|
| |
| 108 | var = (int)record.getBool("value_b"); |
| 11 | | Calling 'NSMVar::operator=' | |
|
| 109 | } else if (record.hasField("value_c")) { |
| 110 | var = (int)record.getInt("value_c"); |
| 111 | } else if (record.hasField("value_s")) { |
| 112 | var = (int)record.getInt("value_s"); |
| 113 | } else if (record.hasField("value_i")) { |
| 114 | var = record.getInt("value_i"); |
| 115 | } else if (record.hasField("value_f")) { |
| 116 | var = record.getFloat("value_f"); |
| 117 | } else if (record.hasField("value_d")) { |
| 118 | var = record.getFloat("value_d"); |
| 119 | } else if (record.hasField("value_t")) { |
| 120 | var = record.get("value_t"); |
| 121 | } |
| 122 | var.setId(record.getInt("id")); |
| 123 | var.setDate(record.getInt("rtime")); |
| 124 | LogFile::debug("%d=%s", record.getInt("rtime"), Date(var.getDate()).toString()); |
| 125 | vars.push_back(var); |
| 126 | } |
| 127 | return vars; |
| 128 | } |
| 129 | |
| 130 | void MonitorDB::createTable(DBInterface& db, const std::string& tablename) |
| 131 | { |
| 132 | if (!db.isConnected()) db.connect(); |
| 133 | if (!db.checkTable(tablename)) { |
| 134 | db.execute("create table %s \n" |
| 135 | "(name varchar(64), \n" |
| 136 | "id bigserial, \n" |
| 137 | "record_time timestamp with time zone default current_timestamp, \n" |
| 138 | "value_b boolean default NULL, \n" |
| 139 | "value_c char default NULL, \n" |
| 140 | "value_s smallint default NULL, \n" |
| 141 | "value_i int default NULL, \n" |
| 142 | "value_l bigint default NULL, \n" |
| 143 | "value_f float default NULL, \n" |
| 144 | "value_d double precision default NULL, \n" |
| 145 | "value_t text default NULL \n" |
| 146 | "); ", tablename.c_str()); |
| 147 | db.execute("create index %s_id_index on %s(id);", |
| 148 | tablename.c_str(), tablename.c_str()); |
| 149 | } |
| 150 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | #ifndef _Belle2_NSMVar_h |
| 9 | #define _Belle2_NSMVar_h |
| 10 | |
| 11 | #include <daq/slc/base/Serializable.h> |
| 12 | #include <daq/slc/base/Date.h> |
| 13 | |
| 14 | #include <vector> |
| 15 | #include <string> |
| 16 | |
| 17 | namespace Belle2 { |
| 18 | |
| 19 | class NSMVar : public Serializable { |
| 20 | |
| 21 | public: |
| 22 | enum Type { |
| 23 | NONE = 0, |
| 24 | INT, |
| 25 | FLOAT, |
| 26 | TEXT, |
| 27 | }; |
| 28 | |
| 29 | public: |
| 30 | static const NSMVar NOVALUE; |
| 31 | |
| 32 | public: |
| 33 | NSMVar() : m_value(NULL), m_name(), m_type(NONE), m_len(0) |
| 34 | { |
| 35 | setDate(Date()); |
| 36 | } |
| 37 | NSMVar(const std::string& name, Type type, int len, const void* value) |
| 38 | : m_value(NULL) |
| 39 | { |
| 40 | copy(name, type, len, value); |
| 41 | } |
| 42 | NSMVar(const std::string& name, const std::string& value) |
| 43 | : m_value(NULL) |
| 44 | { |
| 45 | copy(name, TEXT, value.size(), value.c_str()); |
| 46 | } |
| 47 | NSMVar(const std::string& name, int value) |
| 48 | : m_value(NULL) |
| 49 | { |
| 50 | copy(name, INT, 0, &value); |
| 51 | } |
| 52 | NSMVar(const std::string& name, float value) |
| 53 | : m_value(NULL) |
| 54 | { |
| 55 | copy(name, FLOAT, 0, &value); |
| 56 | } |
| 57 | NSMVar(const std::string& name, int len, int* value) |
| 58 | : m_value(NULL) |
| 59 | { |
| 60 | copy(name, INT, len, value); |
| 61 | } |
| 62 | NSMVar(const std::string& name, int len, float* value) |
| 63 | : m_value(NULL) |
| 64 | { |
| 65 | copy(name, FLOAT, len, value); |
| 66 | } |
| 67 | NSMVar(const std::string& name, const std::vector<int>& value); |
| 68 | NSMVar(const std::string& name, const std::vector<float>& value); |
| 69 | NSMVar(const std::string& name) : m_value(NULL), m_name(name), m_type(NONE), m_len(0) {} |
| 7 | | Returning without writing to 'this->m_id' | |
|
| 70 | NSMVar(const NSMVar& var) : m_value(NULL) { *this = var; } |
| 71 | ~NSMVar(); |
| 72 | |
| 73 | public: |
| 74 | const NSMVar& operator=(const NSMVar& var) |
| 75 | { |
| 76 | copy(var.m_name, var.m_type, var.m_len, var.m_value, var.m_id, var.m_date); |
| 77 | m_node = var.m_node; |
| 78 | m_date = var.m_date; |
| 79 | return *this; |
| 80 | } |
| 81 | const NSMVar& operator=(int val) |
| 82 | { |
| 83 | copy(m_name, INT, 0, &val, m_id); |
| 12 | | 5th function call argument is an uninitialized value |
|
| 84 | return *this; |
| 85 | } |
| 86 | const NSMVar& operator=(float val) |
| 87 | { |
| 88 | copy(m_name, FLOAT, 0, &val, m_id); |
| 89 | return *this; |
| 90 | } |
| 91 | const NSMVar& operator=(const std::string& val) |
| 92 | { |
| 93 | if (val.size() > 0) { |
| 94 | copy(m_name, TEXT, val.size(), val.c_str(), m_id); |
| 95 | } else { |
| 96 | copy(m_name, TEXT, 1, "", m_id); |
| 97 | } |
| 98 | return *this; |
| 99 | } |
| 100 | const NSMVar& operator=(const std::vector<int>& val); |
| 101 | const NSMVar& operator=(const std::vector<float>& val); |
| 102 | const NSMVar& operator>>(int& val) const { val = getInt(); return *this; } |
| 103 | const NSMVar& operator>>(float& val) const { val = getFloat(); return *this; } |
| 104 | const NSMVar& operator>>(std::string& val) const { val = getText(); return *this; } |
| 105 | const NSMVar& operator>>(std::vector<int>& val) const; |
| 106 | const NSMVar& operator>>(std::vector<float>& val) const; |
| 107 | |
| 108 | public: |
| 109 | void setNode(const std::string& node) { m_node = node; } |
| 110 | void setName(const std::string& name) { m_name = name; } |
| 111 | const void* get() const { return m_value; } |
| 112 | void* get() { return m_value; } |
| 113 | int size() const; |
| 114 | const std::string& getNode() const { return m_node; } |
| 115 | const std::string& getName() const { return m_name; } |
| 116 | Type getType() const { return m_type; } |
| 117 | const char* getTypeLabel() const; |
| 118 | int getLength() const { return m_len; } |
| 119 | int getInt() const; |
| 120 | float getFloat() const; |
| 121 | const char* getText() const; |
| 122 | int getInt(int i) const; |
| 123 | float getFloat(int i) const; |
| 124 | int getId() const { return m_id; } |
| 125 | void setId(int id) { m_id = id; } |
| 126 | void setDate(int date) { m_date = date; } |
| 127 | void setDate(const Date& date) { m_date = date.get(); } |
| 128 | int getDate() const { return m_date; } |
| 129 | |
| 130 | public: |
| 131 | void readObject(Reader&) override; |
| 132 | void writeObject(Writer&) const override; |
| 133 | |
| 134 | public: |
| 135 | void copy(const std::string& name, Type type, int len, |
| 136 | const void* value, int id = 0, int date = 0); |
| 137 | |
| 138 | private: |
| 139 | void* m_value; |
| 140 | std::string m_node; |
| 141 | std::string m_name; |
| 142 | Type m_type; |
| 143 | int m_len; |
| 144 | int m_id; |
| 145 | int m_date; |
| 146 | |
| 147 | }; |
| 148 | |
| 149 | typedef std::vector<NSMVar> NSMVarList; |
| 150 | |
| 151 | } |
| 152 | |
| 153 | #endif |