mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-14 08:41:17 +01:00
somewhere
This commit is contained in:
@@ -30,24 +30,29 @@ pthread_mutex_t DataProcessor::Mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
const GeneralData* DataProcessor::generalData(0);
|
||||
|
||||
bool DataProcessor::acquisitionStartedFlag(false);
|
||||
|
||||
bool DataProcessor::measurementStartedFlag(false);
|
||||
|
||||
|
||||
DataProcessor::DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m) :
|
||||
DataProcessor::DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m, fileFormat* ftype, bool* fwenable,
|
||||
int* cbaction,
|
||||
void (*dataReadycb)(int, char*, int, FILE*, char*, void*),
|
||||
void *pDataReadycb) :
|
||||
ThreadObject(NumberofDataProcessors),
|
||||
fifo(f),
|
||||
acquisitionStartedFlag(false),
|
||||
measurementStartedFlag(false),
|
||||
status(s),
|
||||
statusMutex(m),
|
||||
numTotalFramesCaught(0),
|
||||
numFramesCaught(0),
|
||||
firstAcquisitionIndex(0),
|
||||
firstMeasurementIndex(0),
|
||||
currentFrameIndex(0)
|
||||
currentFrameIndex(0),
|
||||
fileWriter(0),
|
||||
fileFormatType(ftype),
|
||||
fileWriteEnable(fwenable),
|
||||
callbackAction(cbaction),
|
||||
rawDataReadyCallBack(dataReadycb),
|
||||
pRawDataReady(pDataReadycb)
|
||||
{
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
|
||||
if(ThreadObject::CreateThread()){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
ErrorMask ^= (1<<index);
|
||||
@@ -59,40 +64,22 @@ DataProcessor::DataProcessor(Fifo*& f, runStatus* s, pthread_mutex_t* m) :
|
||||
|
||||
|
||||
DataProcessor::~DataProcessor() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
|
||||
for (vector<FileWriter*>::const_iterator it = fileWriter.begin(); it != fileWriter.end(); ++it)
|
||||
delete(*it);
|
||||
fileWriter.clear();
|
||||
|
||||
if (fileWriter) delete fileWriter;
|
||||
ThreadObject::DestroyThread();
|
||||
NumberofDataProcessors--;
|
||||
|
||||
}
|
||||
|
||||
/** static functions */
|
||||
|
||||
|
||||
uint64_t DataProcessor::GetErrorMask() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
return ErrorMask;
|
||||
}
|
||||
|
||||
|
||||
bool DataProcessor::GetAcquisitionStartedFlag(){
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
return acquisitionStartedFlag;
|
||||
uint64_t DataProcessor::GetRunningMask() {
|
||||
return RunningMask;
|
||||
}
|
||||
|
||||
|
||||
bool DataProcessor::GetMeasurementStartedFlag(){
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
return measurementStartedFlag;
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::SetGeneralData(GeneralData*& g) {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
generalData = g;
|
||||
#ifdef VERY_VERBOSE
|
||||
generalData->Print();
|
||||
@@ -101,37 +88,40 @@ void DataProcessor::SetGeneralData(GeneralData*& g) {
|
||||
|
||||
|
||||
/** non static functions */
|
||||
|
||||
/** getters */
|
||||
string DataProcessor::GetType(){
|
||||
return TypeName;
|
||||
}
|
||||
|
||||
bool DataProcessor::IsRunning() {
|
||||
return ((1 << index) & RunningMask);
|
||||
}
|
||||
|
||||
bool DataProcessor::GetAcquisitionStartedFlag(){
|
||||
return acquisitionStartedFlag;
|
||||
}
|
||||
|
||||
bool DataProcessor::GetMeasurementStartedFlag(){
|
||||
return measurementStartedFlag;
|
||||
}
|
||||
|
||||
uint64_t DataProcessor::GetNumTotalFramesCaught() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
return numTotalFramesCaught;
|
||||
}
|
||||
|
||||
|
||||
uint64_t DataProcessor::GetNumFramesCaught() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
return numFramesCaught;
|
||||
}
|
||||
|
||||
|
||||
uint64_t DataProcessor::GetProcessedAcquisitionIndex() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
return currentFrameIndex - firstAcquisitionIndex;
|
||||
}
|
||||
|
||||
|
||||
bool DataProcessor::IsRunning() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
return ((1 << index) & RunningMask);
|
||||
}
|
||||
|
||||
|
||||
/** setters */
|
||||
void DataProcessor::StartRunning() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask |= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
@@ -139,7 +129,6 @@ void DataProcessor::StartRunning() {
|
||||
|
||||
|
||||
void DataProcessor::StopRunning() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask ^= (1<<index);
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
@@ -147,32 +136,22 @@ void DataProcessor::StopRunning() {
|
||||
|
||||
|
||||
void DataProcessor::SetFifo(Fifo*& f) {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
|
||||
fifo = f;
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::ResetParametersforNewAcquisition() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
numTotalFramesCaught = 0;
|
||||
firstAcquisitionIndex = 0;
|
||||
currentFrameIndex = 0;
|
||||
if(acquisitionStartedFlag){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
acquisitionStartedFlag = false;
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
acquisitionStartedFlag = false;
|
||||
}
|
||||
|
||||
void DataProcessor::ResetParametersforNewMeasurement(){
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
numFramesCaught = 0;
|
||||
firstMeasurementIndex = 0;
|
||||
if(measurementStartedFlag){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
measurementStartedFlag = false;
|
||||
pthread_mutex_unlock(&Mutex);
|
||||
}
|
||||
measurementStartedFlag = false;
|
||||
if(RunningMask){
|
||||
pthread_mutex_lock(&Mutex);
|
||||
RunningMask = 0x0;
|
||||
@@ -181,57 +160,133 @@ void DataProcessor::ResetParametersforNewMeasurement(){
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::ThreadExecution() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
void DataProcessor::RecordFirstIndices(uint64_t fnum) {
|
||||
//listen to this fnum, later +1
|
||||
currentFrameIndex = fnum;
|
||||
|
||||
char* buffer=0;
|
||||
fifo->PopAddress(buffer);
|
||||
#ifdef FIFODEBUG
|
||||
if (!index) cprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
|
||||
#endif
|
||||
uint32_t numPackets = (uint32_t)(*((uint32_t*)buffer));
|
||||
if (numPackets == DUMMY_PACKET_VALUE) {
|
||||
StopProcessing(buffer);
|
||||
return;
|
||||
measurementStartedFlag = true;
|
||||
firstMeasurementIndex = fnum;
|
||||
|
||||
//start of entire acquisition
|
||||
if (!acquisitionStartedFlag) {
|
||||
acquisitionStartedFlag = true;
|
||||
firstAcquisitionIndex = fnum;
|
||||
}
|
||||
|
||||
uint64_t fnum; uint32_t pnum; uint32_t snum; uint64_t bcid;
|
||||
generalData->GetHeaderInfo(index,buffer+generalData->fifoBufferHeaderSize,16,fnum,pnum,snum,bcid);
|
||||
if (!index) cprintf(BLUE,"DataProcessing %d: fnum:%lld, pnum:%d\n", index, (long long int)fnum, pnum);
|
||||
#ifdef VERBOSE
|
||||
cprintf(BLUE,"%d First Acquisition Index:%lld\tFirst Measurement Index:%lld\n",
|
||||
index, (long long int)firstAcquisitionIndex, (long long int)firstMeasurementIndex);
|
||||
#endif
|
||||
}
|
||||
|
||||
fifo->FreeAddress(buffer);
|
||||
|
||||
void DataProcessor::SetMaxFramesPerFile() {
|
||||
if (fileWriter->GetType() == BINARY)
|
||||
fileWriter->SetMaxFramesPerFile(generalData->maxFramesPerFile);
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::SetFileFormat(const fileFormat f) {
|
||||
|
||||
if (*fileFormatType != f) {
|
||||
switch(f){
|
||||
#ifdef HDF5C
|
||||
case HDF5:
|
||||
*fileFormatType = f;
|
||||
#endif
|
||||
default:
|
||||
*fileFormatType = f;
|
||||
break;
|
||||
}
|
||||
|
||||
//remember the pointer values before they are destroyed
|
||||
char* fname=0; char* fpath=0; uint64_t* findex=0; bool* frindexenable=0;
|
||||
bool* fwenable=0; bool* owenable=0; int* dindex=0; int* nunits=0;
|
||||
fileWriter->GetMemberPointerValues(fname, fpath, findex, frindexenable, owenable, dindex, nunits);
|
||||
|
||||
SetupFileWriter(fname, fpath, findex, frindexenable, owenable, dindex, nunits);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataProcessor::StopProcessing(char* buf) {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
void DataProcessor::SetupFileWriter(char* fname, char* fpath, uint64_t* findex,
|
||||
bool* frindexenable, bool* owenable, int* dindex, int* nunits)
|
||||
{
|
||||
|
||||
cprintf(BLUE,"%d: End of Processing\n", index);
|
||||
if (fileWriter)
|
||||
delete fileWriter;
|
||||
|
||||
fifo->FreeAddress(buf);
|
||||
StopRunning();
|
||||
|
||||
if (!index) {
|
||||
while (RunningMask)
|
||||
usleep(5000);
|
||||
pthread_mutex_lock(statusMutex);
|
||||
*status = RUN_FINISHED;
|
||||
pthread_mutex_unlock((statusMutex));
|
||||
FILE_LOG(logINFO) << "Status: " << runStatusType(*status);
|
||||
switch(*fileFormatType){
|
||||
#ifdef HDF5C
|
||||
case HDF5:
|
||||
fileWriter = new HDF5FileWriter(index, fname, fpath, findex,
|
||||
frindexenable, owenable, dindex, nunits);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
fileWriter = new BinaryFileWriter(index, fname, fpath, findex,
|
||||
frindexenable, owenable, dindex, nunits, generalData->maxFramesPerFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int DataProcessor::CreateNewFile() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
//create file fileWriter.push_back(new BinaryFileWriter(fileName))
|
||||
if (!fileWriter)
|
||||
return FAIL;
|
||||
if (fileWriter->CreateFile(currentFrameIndex) == FAIL)
|
||||
return FAIL;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataProcessor::CloseFile() {
|
||||
FILE_LOG (logDEBUG) << __AT__ << " called";
|
||||
|
||||
if (fileWriter)
|
||||
fileWriter->CloseFile();
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::ThreadExecution() {
|
||||
char* buffer=0;
|
||||
fifo->PopAddress(buffer);
|
||||
#ifdef FIFODEBUG
|
||||
if (!index) cprintf(BLUE,"DataProcessor %d, pop 0x%p buffer:%s\n", index,(void*)(buffer),buffer);
|
||||
#endif
|
||||
|
||||
//check dummy
|
||||
uint32_t numBytes = (uint32_t)(*((uint32_t*)buffer));
|
||||
if (numBytes == DUMMY_PACKET_VALUE) {
|
||||
StopProcessing(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessAnImage(buffer + FIFO_HEADER_NUMBYTES);
|
||||
|
||||
//free
|
||||
fifo->FreeAddress(buffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataProcessor::StopProcessing(char* buf) {
|
||||
fifo->FreeAddress(buf);
|
||||
CloseFile();
|
||||
StopRunning();
|
||||
cprintf(BLUE,"%d: Processing Completed\n", index);
|
||||
}
|
||||
|
||||
|
||||
void DataProcessor::ProcessAnImage(char* buf) {
|
||||
numFramesCaught++;
|
||||
numTotalFramesCaught++;
|
||||
|
||||
uint64_t fnum = (*((uint64_t*)buf));
|
||||
//#ifdef VERBOSE
|
||||
if (!index) cprintf(BLUE,"DataProcessing %d: fnum:%lld\n", index, (long long int)fnum);
|
||||
//#endif
|
||||
if (!measurementStartedFlag)
|
||||
RecordFirstIndices(fnum);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user