Metronome.cpp 1.69 KB
Newer Older
Simon Spannagel's avatar
Simon Spannagel committed
1
#include "Metronome.h"
2
#include "objects/Event.hpp"
Simon Spannagel's avatar
Simon Spannagel committed
3
4
5
6

using namespace corryvreckan;
using namespace std;

7
Metronome::Metronome(Configuration config, std::vector<std::shared_ptr<Detector>> detectors)
8
    : Module(std::move(config), std::move(detectors)), m_triggers(0) {
Simon Spannagel's avatar
Simon Spannagel committed
9

10
    m_eventLength = m_config.get<double>("event_length", Units::get<double>(10, "us"));
11
    m_triggersPerEvent = m_config.get<uint32_t>("triggers", 0);
Simon Spannagel's avatar
Simon Spannagel committed
12
13
14
15
16
}

void Metronome::initialise() {

    // Set initial values for the start and stop time of the first event:
17
18
    m_eventStart = m_config.get<double>("skip_time", 0.);
    m_eventEnd = m_eventStart + m_eventLength;
Simon Spannagel's avatar
Simon Spannagel committed
19
20
}

21
StatusCode Metronome::run(std::shared_ptr<Clipboard> clipboard) {
Simon Spannagel's avatar
Simon Spannagel committed
22

Simon Spannagel's avatar
Simon Spannagel committed
23
    // Set up the current event:
24
    auto event = std::make_shared<Event>(m_eventStart, m_eventEnd);
Simon Spannagel's avatar
Simon Spannagel committed
25
26
    LOG(DEBUG) << "Defining event, time frame " << Units::display(m_eventStart, {"us", "ms", "s"}) << " to "
               << Units::display(m_eventEnd, {"us", "ms", "s"});
27
28
29
30
31
32
33
34
35
36
37
38

    if(m_triggersPerEvent > 1) {
        LOG(DEBUG) << "Adding " << m_triggersPerEvent << " triggers to event, IDs " << m_triggers << "-"
                   << (m_triggers + m_triggersPerEvent - 1);
    } else if(m_triggersPerEvent > 0) {
        LOG(DEBUG) << "Adding " << m_triggersPerEvent << " trigger to event, ID " << m_triggers;
    }
    for(uint32_t i = 0; i < m_triggersPerEvent; i++) {
        event->addTrigger(m_triggers++, (m_eventStart + m_eventEnd) / 2);
    }

    clipboard->putEvent(event);
39

Simon Spannagel's avatar
Simon Spannagel committed
40
41
42
43
44
    // Increment the current event's start and end times by the configured event length
    m_eventStart = m_eventEnd;
    m_eventEnd += m_eventLength;

    // Return value telling analysis to keep running
45
    return StatusCode::Success;
Simon Spannagel's avatar
Simon Spannagel committed
46
}