Defines header for Dhanya's Receiver instead of Aldo #2
162
sls_detector_calibration/jungfrauFileSLSReceiver.C
Normal file
162
sls_detector_calibration/jungfrauFileSLSReceiver.C
Normal file
@@ -0,0 +1,162 @@
|
||||
//#include "jungfrauCommonHeader.h"
|
||||
|
||||
#include <fstream> // std::ifstream
|
||||
#include <stdint.h> // uint16_t
|
||||
#include <ctime> // clock
|
||||
#include <iomanip> // std::setprecision
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
class oneframe {
|
||||
|
||||
public:
|
||||
uint64_t frameNumber;
|
||||
uint32_t expLength;
|
||||
uint32_t packetNumber;
|
||||
uint64_t bunchid;
|
||||
uint64_t timestamp;
|
||||
uint16_t modId;
|
||||
uint16_t row;
|
||||
uint16_t column;
|
||||
uint16_t detSpec2;
|
||||
uint32_t debug;
|
||||
uint16_t roundRNumber;
|
||||
uint8_t detType;
|
||||
uint8_t version;
|
||||
uint16_t detSpecx[32];
|
||||
uint16_t imagedata[NCH];
|
||||
|
||||
};
|
||||
|
||||
class jungfrauFileSLS {
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
ifstream filebin; // file descriptor
|
||||
oneframe thisframe;
|
||||
long long int filebinSize; // need 64 bit
|
||||
clock_t filebinStart;
|
||||
clock_t filebinStop;
|
||||
struct timeval tss,tsss; //for timing
|
||||
|
||||
jungfrauFileSLS() { // constructor
|
||||
|
||||
cout << "jungfrauFile constructed" << endl;
|
||||
//cout << "sizeof(thisframe) " << sizeof(thisframe) << endl;
|
||||
//cout << "address of data array " << &(thisframe.imagedata)<< endl;
|
||||
|
||||
}
|
||||
|
||||
uint16_t * getFrameDataHandle() {
|
||||
|
||||
return (uint16_t*)&(thisframe.imagedata);
|
||||
|
||||
}
|
||||
|
||||
bool readNextFrame() {
|
||||
|
||||
if (filebin.is_open()) {
|
||||
if (!filebin.eof()) {
|
||||
filebin.read(((char*)&thisframe),sizeof(thisframe));
|
||||
|
||||
std::cout << std::fixed << std::setprecision(2)
|
||||
<< "\r [" << std::string(int(filebin.tellg()*10 / float(filebinSize)), '#')
|
||||
<< std::string(10 + 1 - int(filebin.tellg()*10 / float(filebinSize)), ' ')
|
||||
<< "] " << 100 * filebin.tellg() / float(filebinSize) << "%";
|
||||
|
||||
if (filebin.good()) {return true;} // necessary to stop the frame 'after' the last frame returning true
|
||||
else {
|
||||
filebinStop = clock();
|
||||
double elapsed_secs = double(filebinStop - filebinStart) / CLOCKS_PER_SEC;
|
||||
cout << " end of file reached in " << elapsed_secs << "s" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
} else {
|
||||
filebinStop = clock();
|
||||
double elapsed_secs = double(filebinStop - filebinStart) / CLOCKS_PER_SEC;
|
||||
cout << " end of file reached in " << elapsed_secs << "s" << endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cout << "file not open" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int currentFrameNumber() {
|
||||
|
||||
return int(thisframe.frameNumber);
|
||||
|
||||
}
|
||||
|
||||
uint64_t currentBunchID() {
|
||||
|
||||
return uint64_t(thisframe.bunchid);
|
||||
|
||||
}
|
||||
|
||||
/*****************/
|
||||
/* VH 2022-05-05 */
|
||||
/*****************/
|
||||
uint64_t currentSCnumber() {
|
||||
|
||||
return ( ( thisframe.bunchid >> 8 )&0xf );
|
||||
|
||||
}
|
||||
/*****************/
|
||||
/* VH 2022-05-05 */
|
||||
/*****************/
|
||||
|
||||
void rewind() {
|
||||
if (filebin.is_open()) {
|
||||
cout << "rewinding file" << endl;
|
||||
filebin.clear();
|
||||
filebin.seekg(0);
|
||||
} else {
|
||||
cout << "file was not open" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void open(char *fformat, int fileindex) {
|
||||
|
||||
char fname[1000];
|
||||
sprintf(fname,fformat,fileindex);
|
||||
cout << "file name " << fname << endl;
|
||||
if (filebin.is_open()) {
|
||||
cout << "WARNING: a file is already open" << endl;
|
||||
cout << "WARNING: closing this file" << endl;
|
||||
filebin.close();
|
||||
}
|
||||
cout << "opening file" << endl;
|
||||
filebin.open((const char *)(fname), ios::in | ios::binary);
|
||||
filebin.seekg(0,filebin.end);
|
||||
filebinSize = filebin.tellg();
|
||||
filebin.seekg(0,filebin.beg);
|
||||
filebinStart = clock();
|
||||
}
|
||||
|
||||
void close() {
|
||||
|
||||
if (filebin.is_open()) {
|
||||
filebin.close();
|
||||
cout << "closed file" << endl;
|
||||
} else {
|
||||
cout << "file was not open" << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool isOpen() {
|
||||
if (filebin.is_open()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user