src/modules/DatabaseWriter/DatabaseWriterModule.hpp

Definition of database writer module. More…

Namespaces

Name
allpix
Helper class to hold support layers for a detector model.

Classes

Name
class allpix::DatabaseWriterModule
Module to write object data to PostgreSQL databases.

Detailed Description

Definition of database writer module.

Copyright: Copyright (c) 2017-2024 CERN and the Allpix Squared authors. This software is distributed under the terms of the MIT License, copied verbatim in the file “LICENSE.md”. In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. SPDX-License-Identifier: MIT

Source code


#include <atomic>
#include <fstream>
#include <map>
#include <string>

#include "core/config/Configuration.hpp"
#include "core/geometry/GeometryManager.hpp"
#include "core/messenger/Messenger.hpp"
#include "core/module/Module.hpp"

#include <pqxx/pqxx>

namespace allpix {
    class DatabaseWriterModule : public SequentialModule {
    public:
        DatabaseWriterModule(Configuration& config, Messenger* messenger, GeometryManager* geo_mgr);

        bool filter(const std::shared_ptr<BaseMessage>& message, const std::string& name) const;

        void initializeThread() override;

        void run(Event* event) override;

        void finalizeThread() override;

        void finalize() override;

    private:
        Messenger* messenger_;

        static void prepare_statements(const std::shared_ptr<pqxx::connection>& connection);

        // Object names to include or exclude from writing
        std::set<std::string> include_;
        std::set<std::string> exclude_;

        // postgreSQL objects
        static thread_local std::shared_ptr<pqxx::connection> conn_;
        std::string host_;
        std::string port_;
        std::string database_name_;
        std::string user_;
        std::string password_;
        std::string run_id_;
        int run_nr_{0};
        bool timing_global_{};

        // Statistical information about number of objects
        std::atomic<unsigned long> write_cnt_{};
        std::atomic<unsigned long> msg_cnt_{};
    };
} // namespace allpix

Updated on 2024-12-13 at 08:31:37 +0000