Insert.cpp 3.77 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 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 129 130 131 132 133 134 135 136 137 138 139 140 141
/*
 * 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 "Insert.h"

#include <iomanip>

using namespace std;

namespace lstdpp128 {

Insert::Insert() :
	_maxNumberOfChannels(0),
	_numberOfGoodEvents(0),
	_numberOfBadEvents(0),
	_numberOfEventsNotInserted(0) {

}

void Insert::init() {

	_maxNumberOfChannels = (1 << MAX_BITS);
	_numberOfGoodEvents = 0;
	_numberOfBadEvents = 0;
	_numberOfEventsNotInserted = 0;

	// initialise the maps
	for (int c = 0; c < listModeContext.crateBoard.nbCrates; c++) {
		for (int b = 0; b < listModeContext.crateBoard.crates[c].nbBoards; b++) {
			for (int ch = 0; ch < listModeContext.crateBoard.crates[c].boards[b].nbChannels; ch++) {
				_channelCounterInserted[c][b][ch] = 0;
				_channelCounterNotInserted[c][b][ch] = 0;
			}
		}
	}
}

Insert::~Insert() {
}

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

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

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

const std::map<int32_t, std::map<int32_t, std::map<int32_t, int32_t> > >& Insert::channelCounterInserted() const {
	return _channelCounterInserted;
}

const std::map<int32_t, std::map<int32_t, std::map<int32_t, int32_t> > >& Insert::channelCounterNotInserted() const {
	return _channelCounterNotInserted;
}


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

	if (event.crate >= listModeContext.crateBoard.nbCrates) {
		return false;
	}

	if (event.board >= listModeContext.crateBoard.crates[event.crate].nbBoards) {
		return false;
	}

	if (event.channel >= listModeContext.crateBoard.crates[event.crate].boards[event.board].nbChannels) {
		return false;
	}

	return true;
}

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

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

	_channelCounterInserted[event.crate][event.board][event.channel]++;
}

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

	_channelCounterInserted[(*e).crate][(*e).board][(*e).channel]++;
}

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

	_channelCounterNotInserted[event.crate][event.board][event.channel]++;
}

void Insert::finish() {

	cout << "number of events inserted, not inserted" << endl;

	for (map<int32_t, map<int32_t, map<int32_t, int32_t> > >::const_iterator c = _channelCounterInserted.begin(); c != _channelCounterInserted.end(); ++c) {
		cout << "crate " << c->first << endl;
		map<int32_t, map<int32_t, int32_t> > boardInserted = c->second;
		map<int32_t, map<int32_t, int32_t> > boardNotInserted = _channelCounterNotInserted[c->first];

		for (map<int32_t, map<int32_t, int32_t> >::const_iterator b = boardInserted.begin(); b != boardInserted.end(); ++b) {
			cout << "\tboard " << b->first << endl;

			map<int32_t, int32_t> channelInserted = b->second;
			map<int32_t, int32_t> channelNotInserted = boardNotInserted[b->first];

			for (map<int32_t, int32_t>::const_iterator ch = channelInserted.begin(); ch != channelInserted.end(); ++ch) {
				cout << "\t\t" << setw(5) << ch->first << " = " << setw(10) << ch->second << setw(10) << channelNotInserted[ch->first] << endl;
			}
		}
	}
}



}