FileReader.h 3.13 KB
Newer Older
Simon Spannagel's avatar
Simon Spannagel committed
1
2
3
4
5
6
7
8
9
10
11
12
/**
 * @file
 * @brief Definition of ROOT data file reader module
 * @copyright Copyright (c) 2017-2019 CERN and the Corryvreckan 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.
 */

#include <functional>
#include <map>
#include <string>
13

14
15
#include <TFile.h>
#include <TTree.h>
Simon Spannagel's avatar
Simon Spannagel committed
16

17
#include "core/module/Module.hpp"
18

19
namespace corryvreckan {
Simon Spannagel's avatar
Simon Spannagel committed
20
21
22
    /**
     * @ingroup Modules
     * @brief Module to read data stored in ROOT file back to the Corryvreckan clipboard
23
     * @remarks The implementation of this module is based on the ROOTObjectReader module of the Allpix Squared project
Simon Spannagel's avatar
Simon Spannagel committed
24
25
26
     *
     * Reads the tree of objects in the data format of the \ref FileWriter module. Copies all stored objects that are
     * supported back to the clipboard.
Simon Spannagel's avatar
Simon Spannagel committed
27
     */
28
    class FileReader : public Module {
Simon Spannagel's avatar
Simon Spannagel committed
29
    public:
Simon Spannagel's avatar
Simon Spannagel committed
30
        using ObjectCreatorMap =
31
32
            std::map<std::type_index,
                     std::function<void(std::vector<Object*>, std::string detector, std::shared_ptr<Clipboard> clipboard)>>;
Simon Spannagel's avatar
Simon Spannagel committed
33
34
35
36
37
38

        /**
         * @brief Constructor for this global module
         * @param config Configuration object for this module as retrieved from the steering file
         * @param detectors List of detectors to perform task on
         */
39
        FileReader(Configuration config, std::vector<std::shared_ptr<Detector>> detectors);
Simon Spannagel's avatar
Simon Spannagel committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
        /**
         * @brief Destructor deletes the internal objects read from ROOT Tree
         */
        ~FileReader() override;

        /**
         * @brief Open the ROOT file containing the stored output data
         */
        void initialise() override;

        /**
         * @brief Move the objects stored for the current event to the clipboard
         */
        StatusCode run(std::shared_ptr<Clipboard> clipboard) override;

        /**
         * @brief Output summary and close the ROOT file
         */
        void finalise() override;

    private:
        /**
         * @brief Internal object storing objects and information to construct a message from tree
         */
        struct object_info {
            std::vector<Object*>* objects;
            std::string detector;
        };

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

        // File containing the objects
        std::unique_ptr<TFile> input_file_;

        // Object trees in the file
        std::vector<TTree*> trees_;
78
        TTree* event_tree_{nullptr};
79
        Event* event_{};
Simon Spannagel's avatar
Simon Spannagel committed
80
81
82
83
84
85
86
87
88
89
90
91

        // List of objects and detector information converted from the trees
        std::list<object_info> object_info_array_;

        // Statistics for total amount of objects stored
        unsigned long read_cnt_{};

        // Counter for number of events read:
        int event_num_{};

        // Internal map to construct an object from it's type index
        ObjectCreatorMap object_creator_map_;
Simon Spannagel's avatar
Simon Spannagel committed
92
    };
Simon Spannagel's avatar
Simon Spannagel committed
93
} // namespace allpix