Example #1
0
MEP::~MEP() {
	if (this->getNumberOfEvents() > 0) {
		/*
		 * TODO: Just for testing. Should be deleted later to boost performance!
		 */
		throw NA62Error("Deleting non-empty MEP!!!");
	}
	delete[] events;
	delete[] etherFrame_; // Here we free the most important buffer used for polling in Receiver.cpp
}
Example #2
0
void AExecutable::SetThreadAffinity(boost::thread* daThread, int threadPriority, std::vector<short> CPUsToBind, int scheduler) {
#ifndef __APPLE__
	int policy;
	pthread_t threadID = (pthread_t) (daThread->native_handle());
	if (scheduler > 0) {

		sched_param param;
		if (pthread_getschedparam(threadID, &policy, &param) != 0) {
			perror("pthread_getschedparam");
			exit(EXIT_FAILURE);
		}
		//LOG_ERROR("Policy " << policy << ", priority " << param.sched_priority);
		/**
		 * Set scheduling algorithm
		 * Possible values: SCHED_FIFO(1), SCHED_RR(2), SCHED_OTHER(0)
		 */
		policy = scheduler;
		param.__sched_priority = threadPriority;
		if (pthread_setschedparam(threadID, policy, &param) != 0) {
			perror("pthread_setschedparam");
			exit(EXIT_FAILURE);
		}
	}

	if (CPUsToBind.size() > 0) {
		/**
		 * Bind the thread to CPUs from CPUsToBind
		 */
		cpu_set_t mask;
		CPU_ZERO(&mask);

		for (unsigned int i = 0; i < CPUsToBind.size(); i++) {
			if (CPUsToBind[i] == -1) {
				CPU_ZERO(&mask);
				break;
			}
			CPU_SET(CPUsToBind[i], &mask);
		}

		if (pthread_setaffinity_np(threadID, sizeof(mask), &mask) < 0) {
			throw NA62Error("Unable to bind threads to specific CPUs!");
		}
	}
#endif
}
void SourceIDManager::Initialize(const uint16_t timeStampSourceID,
		std::vector<std::pair<int, int> > sourceIDs,
		std::vector<std::pair<int, int> > creamCrates) {
	TS_SOURCEID = timeStampSourceID;

	/*
	 * OPTION_DATA_SOURCE_IDS
	 *
	 */
	NUMBER_OF_L0_DATA_SOURCES = sourceIDs.size();

	L0_DATA_SOURCE_IDS = new uint8_t[NUMBER_OF_L0_DATA_SOURCES];
	L0_DATA_SOURCE_NUM_TO_PACKNUM = new uint16_t[NUMBER_OF_L0_DATA_SOURCES];

	bool LKrActive = false;

	int pos = -1;
	for (auto pair : sourceIDs) {
		if (pair.first == SOURCE_ID_LKr) {
			NUMBER_OF_L0_DATA_SOURCES--;
			LKrActive = true;
			continue;
		}

		L0_DATA_SOURCE_IDS[++pos] = pair.first;
		L0_DATA_SOURCE_NUM_TO_PACKNUM[pos] = pair.second;
		NUMBER_OF_EXPECTED_L0_PACKETS_PER_EVENT += pair.second;
	}

	/*
	 * OPTION_CREAM_CRATES
	 *
	 */
	if (LKrActive) {

		if (creamCrates.size() == 0) {
			throw NA62Error("Option defining CREAM IDsmust not be empty!'");
		}

		NUMBER_OF_EXPECTED_CREAM_PACKETS_PER_EVENT = creamCrates.size();
		LOCAL_ID_TO_CRATE_AND_CREAM_IDS =
				new std::pair<uint16_t, uint16_t>[NUMBER_OF_EXPECTED_CREAM_PACKETS_PER_EVENT];

		int creamNum = -1;
		for (auto pair : creamCrates) {
			uint8_t crateID = pair.first;
			uint8_t CREAMID = pair.second;
			CRATE_AND_CREAM_IDS_TO_LOCAL_ID[(crateID << 8) | CREAMID] =
					++creamNum;
			LOCAL_ID_TO_CRATE_AND_CREAM_IDS[creamNum] = std::make_pair(crateID,
					CREAMID);
		}
	} else {
		LOG(INFO)<<"There is no LKr SourceID in the sourceID option! Will ignore CREAM ID option";
		NUMBER_OF_EXPECTED_CREAM_PACKETS_PER_EVENT = 0;
	}

	LARGEST_L0_DATA_SOURCE_ID = 0;
	for (int i = 0; i < NUMBER_OF_L0_DATA_SOURCES; i++) {
		if (LARGEST_L0_DATA_SOURCE_ID < L0_DATA_SOURCE_IDS[i]) {
			LARGEST_L0_DATA_SOURCE_ID = L0_DATA_SOURCE_IDS[i];
		}
	}

	L0_DATA_SOURCE_ID_TO_NUM = new uint8_t[LARGEST_L0_DATA_SOURCE_ID + 1];
	L0_DATA_SOURCE_ID_TO_PACKNUM = new uint16_t[LARGEST_L0_DATA_SOURCE_ID + 1];

	for (uint8_t i = 0; i < NUMBER_OF_L0_DATA_SOURCES; i++) {
		L0_DATA_SOURCE_ID_TO_NUM[L0_DATA_SOURCE_IDS[i]] = i;
		L0_DATA_SOURCE_ID_TO_PACKNUM[L0_DATA_SOURCE_IDS[i]] =
				L0_DATA_SOURCE_NUM_TO_PACKNUM[i];
	}

}