Commit ffe3af9b authored by legoc's avatar legoc

removed useless files

parent df010b6b
/*
* 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 <cstdlib>
#include <fstream>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <time.h>
#include <signal.h>
#include <boost/interprocess/managed_shared_memory.hpp>
#include "../../algorithms/nomad/Coincidence.h"
#include "../../Event.h"
#include "../../EventBlockArray.h"
#include "../../EventBlockArrayAlgorithm.h"
#include "../../LiveReader.h"
using namespace std;
using namespace boost::interprocess;
using namespace lstdpp128;
int32_t MAX_BLOCK_SIZE = 0;
int32_t BUFFER_SIZE = 1 << 12;
const char SHARED_MEMORY_NAME[] = "CoincidenceSharedMemory";
const char SHARED_MEMORY_DATA_NAME[] = "data";
const char SHARED_MEMORY_MATRIX_NAME[] = "matrix";
const char SHARED_MEMORY_ADCRATES_NAME[] = "adc_rates";
LiveReader reader;
int percentage(int a, int b) {
return 100.0f * (float)a / (float)b;
}
void shutdownHandler(int sig) {
reader.stop();
cout << "interrupting live process" << endl;
}
void printRate(double * rate, ostream& out) {
for (int i = 0; i < 7; ++i) {
out << setw(12) << rate[i] << " ";
}
out << endl;
}
void createFile(const std::string& fileName) {
std::ofstream outDataFile;
outDataFile.open(fileName.c_str());
outDataFile.close();
}
int main(int argc, char * argv[]) {
signal(SIGINT, shutdownHandler);
if (argc < 6) {
cerr << "usage : nomadcoincidence <file> <coincidence dT> <clean dT> <crateboard.txt> <detectoradc.txt> <coincidenceMatrixResolution> [maxBlocks] [blockSize]" << endl;
return EXIT_FAILURE;
}
string fileName = argv[1];
istringstream cit(argv[2]);
time_type coincidenceDT;
cit >> coincidenceDT;
istringstream clit(argv[2]);
time_type cleanDT;
clit >> cleanDT;
string crateBoardFileName = argv[4];
vector<int16_t> crateBoardList = BaseReader::loadList<int16_t>(crateBoardFileName);
string detectorADCFileName = argv[5];
vector<int16_t> detectorADCList = BaseReader::loadList<int16_t>(detectorADCFileName);
int16_t coincidenceMatrixResolution = 12;
if (argc >= 7) {
istringstream ir(argv[6]);
ir >> coincidenceMatrixResolution;
}
int32_t maxBlocks = -1;
if (argc >= 8) {
istringstream im(argv[7]);
im >> maxBlocks;
}
if (argc >= 9) {
istringstream is(argv[8]);
is >> BUFFER_SIZE;
}
MAX_BLOCK_SIZE = BUFFER_SIZE * 2;
string outFileName = fileName.substr(0, fileName.find_first_of('.')) + ".lsto";
string logFileName = outFileName + ".log";
ofstream log(logFileName.c_str());
log << "reading " << fileName << ", coincidence dT " << coincidenceDT << ", clean dT " << cleanDT << ", max blocks " << maxBlocks << ", block size " << BUFFER_SIZE << endl;
reader.init(BUFFER_SIZE);
bool success = reader.open(fileName);
if (!success) {
return EXIT_FAILURE;
}
log << "#adc = " << reader.numberOfADCs() << endl;
log << "#channels = " << reader.numberOfChannels() << endl;
// checking sizes
int16_t numberOfBoards = 0;
for (vector<int16_t>::const_iterator b = crateBoardList.begin(); b != crateBoardList.end(); ++b) {
numberOfBoards += (*b);
}
if (numberOfBoards != (reader.numberOfADCs() / 8)) {
log << "incoherent crate board list and number of ADCs" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
if (reader.numberOfADCs() != detectorADCList.size()) {
log << "incoherent detector ADC list and number of ADCs" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
// open managed shared memory to get pointer to histogram data
managed_shared_memory segment(open_only, SHARED_MEMORY_NAME);
pair<double *, unsigned long> dataResult;
dataResult = segment.find<double>(SHARED_MEMORY_DATA_NAME);
double * rates = dataResult.first;
log << "access to data shared memory with size " << dataResult.second << endl;
if (dataResult.second < 4 * 7) {
log << "problem in data shared memory size, exiting" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
pair<int32_t *, unsigned long> matrixResult = segment.find<int32_t>(SHARED_MEMORY_MATRIX_NAME);
int32_t * matrix = matrixResult.first;
log << "access to matrix shared memory with size " << matrixResult.second << endl;
int32_t matrixChannels = (1 << coincidenceMatrixResolution);
if (matrixResult.second < matrixChannels * matrixChannels) {
log << "problem in matrix shared memory size, exiting" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
pair<double *, unsigned long> ADCRatesResult = segment.find<double>(SHARED_MEMORY_ADCRATES_NAME);
double * ADCRates = ADCRatesResult.first;
log << "access to ADC rates shared memory with size " << ADCRatesResult.second << endl;
if (ADCRatesResult.second < reader.numberOfADCs()) {
log << "problem in ADC rates shared memory size, exiting" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
// algorithm
EventBlockArrayAlgorithm<Coincidence> algorithm(reader.numberOfADCs());
algorithm.processor().init(reader.listMode(), rates, coincidenceMatrixResolution, matrix, crateBoardList, detectorADCList, reader.numberOfADCs(), ADCRates, reader.numberOfChannels(), coincidenceDT, cleanDT, MAX_BLOCK_SIZE, outFileName);
// creating the events
EventBlockArray blocks(MAX_BLOCK_SIZE, maxBlocks);
int currentPercentage = 0;
time_t start = time(0);
time_t t1 = start;
int32_t numberOfEvents = reader.numberOfGoodEvents();
// reading list mode
while (true) {
// reading next block
int32_t blockSize = reader.readBlock();
// exiting if no data
if (blockSize == 0) {
break;
}
// processing block
algorithm.process(reader.buffer(), blockSize, blocks);
}
time_t t2 = time(0);
algorithm.finish(blocks);
log << "#events read = " << algorithm.processor().numberOfGoodEvents() << " (" << ((float)algorithm.processor().numberOfGoodEvents() / (float)(t2 - t1)) << " event/s)" << endl;
log << "#events bad = " << algorithm.processor().numberOfBadEvents() << " (" << percentage(algorithm.processor().numberOfBadEvents(), algorithm.processor().numberOfGoodEvents()) << "%)" << endl;
log << "#events not inserted = " << algorithm.processor().numberOfEventsNotInserted() << " (" << percentage(algorithm.processor().numberOfEventsNotInserted(), algorithm.processor().numberOfGoodEvents()) << "%)" << endl;
log << "max order = " << algorithm.processor().maxOrder() << endl;
log << endl;
log << "crystal rate = ";
printRate(rates + 0, log);
log << "crystal clean rate = ";
printRate(rates + 7, log);
log << "detector rate = ";
printRate(rates + 7 * 2, log);
log << "detector clean rate = ";
printRate(rates + 7 * 3, log);
log << "ADC rates" << endl;
for (int i = 0; i < reader.numberOfADCs(); ++i) {
log << "ADC " << setw(4) << i << " = "<< setw(20) << ADCRates[i] << endl;
}
return EXIT_SUCCESS;
}
/*
* 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 <cstdlib>
#include <fstream>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <time.h>
#include <signal.h>
#include <boost/interprocess/managed_shared_memory.hpp>
#include "../../algorithms/nomad/Coincidence.h"
#include "../../Event.h"
#include "../../EventArray.h"
#include "../../EventArrayAlgorithm.h"
#include "../../LiveReader.h"
using namespace std;
using namespace boost::interprocess;
using namespace lstdpp128;
int32_t BUFFER_SIZE = 1 << 12;
const char SHARED_MEMORY_NAME[] = "CoincidenceSharedMemory";
const char SHARED_MEMORY_DATA_NAME[] = "data";
const char SHARED_MEMORY_MATRIX_NAME[] = "matrix";
const char SHARED_MEMORY_ADCRATES_NAME[] = "adc_rates";
LiveReader reader;
int percentage(int a, int b) {
return 100.0f * (float)a / (float)b;
}
void shutdownHandler(int sig) {
reader.stop();
cout << "interrupting live process" << endl;
}
void printRate(double * rate, ostream& out) {
for (int i = 0; i < 7; ++i) {
out << setw(12) << rate[i] << " ";
}
out << endl;
}
void createFile(const std::string& fileName) {
std::ofstream outDataFile;
outDataFile.open(fileName.c_str());
outDataFile.close();
}
int main(int argc, char * argv[]) {
signal(SIGINT, shutdownHandler);
if (argc < 6) {
cerr << "usage : nomadcoincidencev <file> <coincidence dT> <clean dT> <crateboard.txt> <detectoradc.txt> <coincidenceMatrixResolution> [blockSize]" << endl;
return EXIT_FAILURE;
}
string fileName = argv[1];
istringstream cit(argv[2]);
time_type coincidenceDT;
cit >> coincidenceDT;
istringstream clit(argv[3]);
time_type cleanDT;
clit >> cleanDT;
string crateBoardFileName = argv[4];
vector<int16_t> crateBoardList = BaseReader::loadList<int16_t>(crateBoardFileName);
string detectorADCFileName = argv[5];
vector<int16_t> detectorADCList = BaseReader::loadList<int16_t>(detectorADCFileName);
int16_t coincidenceMatrixResolution = 12;
if (argc >= 7) {
istringstream ir(argv[6]);
ir >> coincidenceMatrixResolution;
}
int32_t blockSize = BUFFER_SIZE * 2;
if (argc >= 8) {
istringstream im(argv[7]);
im >> blockSize;
}
string outFileName = fileName.substr(0, fileName.find_first_of('.')) + ".lsto";
string logFileName = outFileName + ".log";
ofstream log(logFileName.c_str());
log << "reading " << fileName << ", coincidence dT " << coincidenceDT << ", clean dT " << cleanDT << ", process block size " << blockSize << endl;
//cout << "crate board = " << printList(crateBoardList) << endl;
//cout << "detector ADC = " << printList(detectorADCList) << endl;
reader.init(BUFFER_SIZE);
bool success = reader.open(fileName);
if (!success) {
return EXIT_FAILURE;
}
log << "#adc = " << reader.numberOfADCs() << endl;
log << "#channels = " << reader.numberOfChannels() << endl;
// checking sizes
int16_t numberOfBoards = 0;
for (vector<int16_t>::const_iterator b = crateBoardList.begin(); b != crateBoardList.end(); ++b) {
numberOfBoards += (*b);
}
if (numberOfBoards != (reader.numberOfADCs() / 8)) {
log << "incoherent crate board list and number of ADCs" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
if (reader.numberOfADCs() != detectorADCList.size()) {
log << "incoherent detector ADC list and number of ADCs" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
// open managed shared memory to get pointer to histogram data
managed_shared_memory segment(open_only, SHARED_MEMORY_NAME);
pair<double *, unsigned long> dataResult;
dataResult = segment.find<double>(SHARED_MEMORY_DATA_NAME);
double * rates = dataResult.first;
log << "access to data shared memory with size " << dataResult.second << endl;
if (dataResult.second < 4 * 7) {
log << "problem in data shared memory size, exiting" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
pair<int32_t *, unsigned long> matrixResult = segment.find<int32_t>(SHARED_MEMORY_MATRIX_NAME);
int32_t * matrix = matrixResult.first;
log << "access to matrix shared memory with size " << matrixResult.second << endl;
int32_t matrixChannels = (1 << coincidenceMatrixResolution);
if (matrixResult.second < matrixChannels * matrixChannels) {
log << "problem in matrix shared memory size, exiting" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
pair<double *, unsigned long> ADCRatesResult = segment.find<double>(SHARED_MEMORY_ADCRATES_NAME);
double * ADCRates = ADCRatesResult.first;
log << "access to ADC rates shared memory with size " << ADCRatesResult.second << endl;
if (ADCRatesResult.second < reader.numberOfADCs()) {
log << "problem in ADC rates shared memory size, exiting" << endl;
createFile(outFileName);
return EXIT_FAILURE;
}
// algorithm
EventArrayAlgorithm<Coincidence> algorithm(reader.numberOfADCs());
algorithm.processor().init(reader.listMode(), rates, coincidenceMatrixResolution, matrix, crateBoardList, detectorADCList, reader.numberOfADCs(), ADCRates, reader.numberOfChannels(), coincidenceDT, cleanDT, blockSize, outFileName);
// creating the events
EventArray events(blockSize);
int currentPercentage = 0;
time_t start = time(0);
time_t t1 = start;
int32_t numberOfEvents = reader.numberOfGoodEvents();
// reading list mode
while (true) {
// reading next block
int32_t blockSize = reader.readBlock();
// exiting if no data
if (blockSize == 0) {
break;
}
// processing block
algorithm.process(reader.buffer(), blockSize, events);
}
time_t t2 = time(0);
algorithm.finish(events);
log << "#events read = " << setw(20) << algorithm.processor().numberOfGoodEvents() << " (" << ((float)algorithm.processor().numberOfGoodEvents() / (float)(t2 - t1)) << " event/s)" << endl;
log << "#events bad = " << setw(20) << algorithm.processor().numberOfBadEvents() << " (" << percentage(algorithm.processor().numberOfBadEvents(), algorithm.processor().numberOfGoodEvents()) << "%)" << endl;
log << "#events not inserted = " << setw(20) << algorithm.processor().numberOfEventsNotInserted() << " (" << percentage(algorithm.processor().numberOfEventsNotInserted(), algorithm.processor().numberOfGoodEvents()) << "%)" << endl;
log << "max order = " << setw(20) << algorithm.processor().maxOrder() << endl;
log << endl;
log << "crystal rate = ";
printRate(rates + 0, log);
log << "crystal clean rate = ";
printRate(rates + 7, log);
log << "detector rate = ";
printRate(rates + 7 * 2, log);
log << "detector clean rate = ";
printRate(rates + 7 * 3, log);
log << "ADC rates" << endl;
for (int i = 0; i < reader.numberOfADCs(); ++i) {
log << "ADC " << setw(4) << i << " = "<< setw(20) << ADCRates[i] << endl;
}
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment