Module.cpp 1.92 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
/** @file
 *  @brief Implementation of the base module class
 *  @copyright Copyright (c) 2017 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 "Module.hpp"

using namespace corryvreckan;

13
14
Module::Module(Configuration config, Detector* detector) : Module(config, std::vector<Detector*>{detector}) {}

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Module::Module(Configuration config, std::vector<Detector*> detectors) {
    m_name = config.getName();
    m_config = config;
    m_detectors = detectors;
    IFLOG(TRACE) {
        std::stringstream det;
        for(auto& d : m_detectors) {
            det << d->name() << ", ";
        }
        LOG(TRACE) << "Module determined to run on detectors: " << det.str();
    }
}

Module::~Module() {}

Detector* Module::get_detector(std::string name) {
    auto it = find_if(m_detectors.begin(), m_detectors.end(), [&name](Detector* obj) { return obj->name() == name; });
    if(it == m_detectors.end()) {
        throw ModuleError("Device with detector ID " + name + " is not registered.");
    }

    return (*it);
}

39
Detector* Module::get_reference() {
40
    auto it = find_if(m_detectors.begin(), m_detectors.end(), [](Detector* obj) { return obj->isReference(); });
41
42
43
    return (*it);
}

44
45
Detector* Module::get_dut() {
    auto it = find_if(m_detectors.begin(), m_detectors.end(), [](Detector* obj) { return obj->isDUT(); });
46
47
48
49
    if(it == m_detectors.end()) {
        return nullptr;
    }

50
51
52
    return (*it);
}

53
54
55
56
57
58
59
bool Module::has_detector(std::string name) {
    auto it = find_if(m_detectors.begin(), m_detectors.end(), [&name](Detector* obj) { return obj->name() == name; });
    if(it == m_detectors.end()) {
        return false;
    }
    return true;
}