Check.cpp 2.9 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
39
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * 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.
 */

#include "Check.h"

using namespace std;

namespace lstdpp128 {

Check::Check() :
	_maxNumberOfChannels(0),
	_numberOfGoodEvents(0),
	_numberOfBadEvents(0),
	_numberOfEventsNotInserted(0),
	_onZeroBlock(false),
	_zeroCounter(0),
	_maxTime(0),
	_ordered(true) {
}

void Check::init() {

	_maxNumberOfChannels = (1 << MAX_BITS);

	_numberOfGoodEvents = 0;
	_numberOfBadEvents = 0;
	_numberOfEventsNotInserted = 0;

	_onZeroBlock = false;
	_zeroCounter = 0;
}

Check::~Check() {
}

int32_t Check::numberOfGoodEvents() const {
	return _numberOfGoodEvents;
}

int32_t Check::numberOfBadEvents() const {
	return _numberOfBadEvents;
}

int32_t Check::numberOfEventsNotInserted() const {
	return _numberOfEventsNotInserted;
}

time_type Check::maxTime() const {
	return _maxTime;
}

bool Check::isOrdered() const {
	return _ordered;
}

bool Check::checkEvent(Event const & event) {

	if (event.crate >= listModeContext.crateBoard.nbCrates) {
		cout << "event " << event << " is bad, crate error" << endl;
		return false;
	}

	if (event.board >= listModeContext.crateBoard.crates[event.crate].nbBoards) {
		cout << "event " << event << " is bad, board error" << endl;
		return false;
	}

	if (event.channel >= listModeContext.crateBoard.crates[event.crate].boards[event.board].nbChannels) {
		cout << "event " << event << " is bad, channel error" << endl;
		return false;
	}

	return true;
}

void Check::processBadEvent(Event const & event) {
	_numberOfBadEvents++;
}

void Check::processEvent(Event const & event) {
	_numberOfGoodEvents++;

98
	if (event.crate == 0 && event.channel == 0 && event.data[0] == 0 && event.data[1] == 0) {
legoc's avatar
legoc committed
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
129
130
131
132
133
134
135
136
137
138
139
140
141
		if (_onZeroBlock) {
			_zeroCounter++;
		} else {
			_onZeroBlock = true;
			_zeroCounter = 1;
		}
	} else {
		if (_onZeroBlock) {

			if (_zeroCounter > 1) {
				cout << "Zero block with " << _zeroCounter << " elements" << endl;
			}

			_onZeroBlock = false;
			_zeroCounter = 0;
		}
	}

	if (event.time() < _lastEvent.time()) {
		_ordered = false;
		//cout << event << " < " << _lastEvent << endl;
	}

	_lastEvent = event;

	if (event.time() > _maxTime) {
		_maxTime = event.time();
	}
}

void Check::processEvent(EventBlockArrayIterator const & e) {
	_numberOfGoodEvents++;
}

void Check::processEventNotInserted(Event const & event) {
	_numberOfGoodEvents++;
	_numberOfEventsNotInserted++;
}

void Check::finish() {
}

}