~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/input/InputCppRootData/InputCppRootData.hh

merging in changes in merge branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
2
 *
 
3
 * MAUS is free software: you can redistribute it and/or modify
 
4
 * it under the terms of the GNU General Public License as published by
 
5
 * the Free Software Foundation, either version 3 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * MAUS is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 */
 
17
 
 
18
#ifndef _MAUS_SRC_INPUT_INPUTCPPROOTDATA_INPUTCPPROOTDATA_HH__
 
19
#define _MAUS_SRC_INPUT_INPUTCPPROOTDATA_INPUTCPPROOTDATA_HH__
 
20
 
 
21
#include <string>
 
22
#include <set>
 
23
#include <map>
 
24
 
 
25
#include "Rtypes.h"  // ROOT
 
26
 
 
27
#include "json/json.h"
 
28
 
 
29
#include "Utils/Exception.hh"
 
30
#include "src/common_cpp/API/InputBase.hh"
 
31
 
 
32
class irstream;
 
33
 
 
34
namespace MAUS {
 
35
 
 
36
/** @class InputCppRootData
 
37
 *
 
38
 *  InputCppRootData enables us to read in ROOT files and emit them as strings
 
39
 *  containing json formatted data. InputCppRootData uses irstream from
 
40
 *  JsonCppStreamer to read ROOT files and JsonCppConverter to convert from
 
41
 *  ROOT to json.
 
42
 */
 
43
class InputCppRootData : public InputBase<MAUS::Data> {
 
44
  public:
 
45
    /** Constructor for InputCppRootData, initialises all members to NULL
 
46
     *
 
47
     *  @param filename if set forces the Inputter to use the filename rather than
 
48
     *         pulling a filename from the datacards at birth
 
49
     */
 
50
    explicit InputCppRootData(std::string filename = "");
 
51
 
 
52
    /** Destructor for InputCppRootData - calls death()
 
53
     */
 
54
    ~InputCppRootData();
 
55
 
 
56
    /** Birth function - loads datacards:
 
57
     *  - input_root_file_name: the input root file name
 
58
     *  - selected_spills: list of ints, that defines specific spills that will
 
59
     *    be loaded
 
60
     *  Initialises the ROOT file
 
61
     */
 
62
    void birth(const std::string& json_datacards) {
 
63
        InputBase<MAUS::Data>::birth(json_datacards);
 
64
    }
 
65
 
 
66
    /** Death function - deletes the root file*/
 
67
    void death() {
 
68
        InputBase<MAUS::Data>::death();
 
69
    }
 
70
 
 
71
    /** Return true if only loading spills specified in data cards
 
72
      */
 
73
    bool useSelectedSpills() const { return _select_spills; }
 
74
 
 
75
  private:
 
76
    /** Initialise the inputter
 
77
     */
 
78
    void _birth(const std::string& json_datacards);
 
79
 
 
80
    /** Deletes inputter member data
 
81
     */
 
82
    void _death();
 
83
 
 
84
    /** Gets the next event from the root file. If there are no more events,
 
85
     *  raises StopIteration.
 
86
     */
 
87
    MAUS::Data _emit_cpp();
 
88
 
 
89
    /** Gets an event from the root file; called by _emit_cpp()
 
90
     */
 
91
    template <class DataT>
 
92
    bool load_event(std::string branch_name, DataT&);
 
93
 
 
94
    /** Returns true if we are only loading selected spill numbers and
 
95
     *  the spill number is found in the data card, or if it is an invalid
 
96
     *  spill - there are already methods to handle those cases.
 
97
     *
 
98
     *  This is a help function to see if the set of loaded spill numbers
 
99
     *  contains the spill \"spillNum\".
 
100
     */
 
101
    bool is_selected_spill(int spillNum) const;
 
102
 
 
103
    /** _irstream holds root TFile.
 
104
     */
 
105
    irstream* _infile;
 
106
    std::string _infile_tree;
 
107
    std::string _filename;
 
108
    std::string _classname;
 
109
 
 
110
    event_type _event_type;
 
111
    bool _select_spills;
 
112
    std::set< int > _selected_spill_numbers;
 
113
    int _highest_spill_number;
 
114
};
 
115
}
 
116
 
 
117
#endif
 
118