Event.h 2.68 KB
Newer Older
legoc's avatar
legoc committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * Nomad Instrument Control Software
 *
 * Copyright 2011 Institut Laue-Langevin
 *
 * Licensed under the EUPL, Version 1.1 only (the "License");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
 * http://www.osor.eu/eupl
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 */

#ifndef LSTDPP_EVENT_H
#define LSTDPP_EVENT_H

#include <iostream>
#include <set>
#include "CrateBoard.h"

namespace lstdpp128 {

typedef int64_t time_type;

/**
 * Structure defining the event in lstdpp.
 */
struct Event {
	uint8_t crate;
	uint8_t board;
	uint16_t channel;
	uint16_t rollover;
	uint32_t timestamp;
39
	uint32_t data[2];
legoc's avatar
legoc committed
40
41
42
43
44
45
46
47
48
49

	enum CleanType {CLEAN, NOT_CLEAN, ANTI_COMPTON, UNDEFINED};
	CleanType status;

	Event() :
		crate(0),
		board(0),
		channel(0),
		rollover(0),
		timestamp(0),
50
51
52
53
		status(UNDEFINED) {
			data[0] = 0;
			data[1] = 0;
	}
legoc's avatar
legoc committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

	/**
	 * Returns the board type of the event in the current list mode context.
	 */
	inline BoardType boardType() const {
		return listModeContext.crateBoard.crates[crate].boards[board].boardType;
	}

	/**
	 * Returns the time resolution of the event in the current list mode context.
	 */
	inline uint32_t timeResolution() const {
		return BoardTimeResolution[listModeContext.crateBoard.crates[crate].boards[board].boardType];
	}

	/**
	 * Gets the absolute time.
	 */
	time_type time() const;

	/**
	 * Sets the absolute time. The value is converted into rollover and timestamp.
	 */
	void setTime(time_type value);
};

/**
 * Comparator to sort events with time.
 */
struct CompareEvents {

	inline bool operator()(Event const & a, Event const & b) {
		return a.time() < b.time();
	}
};

90
std::string eventColumnsToString(BoardType type);
legoc's avatar
legoc committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
std::ostream& operator<< (std::ostream& os, Event const & e);

std::string printBinary(int32_t * buffer);

bool readEvent(Event & event, int32_t * buffer);
void writeEvent(Event const & event, int32_t * buffer);

struct EventBlock {

	static int32_t maxId;
	int32_t id;

	std::multiset<Event, CompareEvents> events;

	EventBlock() {
		id = maxId;
		maxId++;
	}

	inline time_type minTime() const {
		return events.begin()->time();
	}

	inline time_type maxTime() const {
		std::multiset<Event, CompareEvents>::const_reverse_iterator e = events.rend();
		++e;
		return e->time();
	}

	EventBlock * split();
	EventBlock * split(time_type midTime);
};

std::ostream& operator<< (std::ostream& os, EventBlock const & b);

}

#endif