Compare commits

...

5 Commits

Author SHA1 Message Date
splitPoleDAQ 2e65bbf233 added fsutsReader.h, this is the class to read the time sorted data from fsuReader.h 2024-01-19 03:11:50 -05:00
splitPoleDAQ 55ee3931cc added SaveHit2NewFile() to fsuReader.h, this save the time sorted data to a simple format 2024-01-19 03:11:10 -05:00
splitPoleDAQ 5c6b5e7001 added getTime_ns() in macro.h 2024-01-19 03:07:55 -05:00
splitPoleDAQ 792d1c5545 Added traceLength in Hit Class 2024-01-19 03:07:16 -05:00
splitPoleDAQ 2ee71637cc bug fix for ClassData for numCh < MAXNCHANNEL 2024-01-19 03:06:36 -05:00
8 changed files with 320 additions and 50 deletions

View File

@ -33,7 +33,7 @@ int main(){
count ++; count ++;
data->DataIndex[ch] ++; data->DataIndex[ch] ++;
if( data->DataIndex[ch] > MaxNData ) { if( data->DataIndex[ch] > data->GetDataSize() ) {
data->LoopIndex[ch] ++; data->LoopIndex[ch] ++;
data->DataIndex[ch] = 0; data->DataIndex[ch] = 0;
} }

View File

@ -27,7 +27,7 @@ int main(int argc, char **argv) {
printf("Incorrect number of arguments:\n"); printf("Incorrect number of arguments:\n");
printf("%s [timeWindow] [Buffer] [traceOn/Off] [verbose] [inFile1] [inFile2] .... \n", argv[0]); printf("%s [timeWindow] [Buffer] [traceOn/Off] [verbose] [inFile1] [inFile2] .... \n", argv[0]);
printf(" timeWindow : in ns \n"); printf(" timeWindow : in ns \n");
printf(" Buffer : Fraction of %d, recommand 0.4 \n", MaxNData); printf(" Buffer : Fraction of %d, recommand 0.4 \n", DefaultDataSize);
printf(" traceOn/Off : is traces stored \n"); printf(" traceOn/Off : is traces stored \n");
printf(" verbose : > 0 for debug \n"); printf(" verbose : > 0 for debug \n");
printf(" Output file name is contructed from inFile1 \n"); printf(" Output file name is contructed from inFile1 \n");
@ -70,7 +70,7 @@ int main(int argc, char **argv) {
for( int i = 0; i < nFile; i++) printf("%2d | %s \n", i, inFileName[i].Data()); for( int i = 0; i < nFile; i++) printf("%2d | %s \n", i, inFileName[i].Data());
printf("=====================================\n"); printf("=====================================\n");
printf(" Time Window = %u ns = %.1f us\n", timeWindow, timeWindow/1000.); printf(" Time Window = %u ns = %.1f us\n", timeWindow, timeWindow/1000.);
printf(" Buffer size = %.0f event/channel\n", MaxNData * bufferSize); printf(" Buffer size = %.0f event/channel\n", DefaultDataSize * bufferSize);
printf("===================================== input files:\n"); printf("===================================== input files:\n");
printf("Scanning files.....\n"); printf("Scanning files.....\n");
@ -289,6 +289,8 @@ int main(int argc, char **argv) {
//data[i]->PrintStat(); //data[i]->PrintStat();
} }
uShort dataSize = data[i]->GetDataSize();
for( int ch = 0; ch < data[i]->GetNChannel(); ch ++){ for( int ch = 0; ch < data[i]->GetNChannel(); ch ++){
int iData = data[i]->DataIndex[ch]; int iData = data[i]->DataIndex[ch];
@ -296,8 +298,8 @@ int main(int argc, char **argv) {
if( iData < 0 ) continue; if( iData < 0 ) continue;
if( (iLoop*MaxNData + iData) - (lastLoopIndex[i][ch]*MaxNData + lastDataIndex[i][ch]) > MaxNData * bufferSize ) { if( (iLoop*dataSize + iData) - (lastLoopIndex[i][ch]*dataSize + lastDataIndex[i][ch]) > dataSize * bufferSize ) {
if( debug ) printf("############# BREAK!!!! Group: %d, ch : %d | last : %d(%d), Present : %d(%d) | BufferSize : %.0f \n", i, ch, lastDataIndex[i][ch], lastLoopIndex[i][ch], iData, iLoop, MaxNData * bufferSize); if( debug ) printf("############# BREAK!!!! Group: %d, ch : %d | last : %d(%d), Present : %d(%d) | BufferSize : %.0f \n", i, ch, lastDataIndex[i][ch], lastLoopIndex[i][ch], iData, iLoop, dataSize * bufferSize);
fillFlag = false; fillFlag = false;
} }

View File

@ -1,5 +1,4 @@
#include "fsuReader.h" #include "fsuReader.h"
#include <chrono>
#include "TROOT.h" #include "TROOT.h"
#include "TSystem.h" #include "TSystem.h"
@ -44,15 +43,6 @@ struct GroupInfo{
}; };
unsigned long long getTime_ns(){
std::chrono::high_resolution_clock::time_point currentTime = std::chrono::high_resolution_clock::now();
std::chrono::nanoseconds nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime.time_since_epoch());
return nanoseconds.count();
}
//^############################################################# //^#############################################################
//^############################################################# //^#############################################################
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -114,7 +104,7 @@ int main(int argc, char **argv) {
printf("Processing %s (%d/%d) ..... \n\033[A\r", inFileName[i].Data(), i+1, nFile); printf("Processing %s (%d/%d) ..... \n\033[A\r", inFileName[i].Data(), i+1, nFile);
reader[i] = new FSUReader(inFileName[i].Data(), false); reader[i] = new FSUReader(inFileName[i].Data(), 0, false);
reader[i]->ScanNumBlock(0, 1); reader[i]->ScanNumBlock(0, 1);
// reader[i]->FillHitList(); // reader[i]->FillHitList();

View File

@ -1,19 +1,20 @@
#include "../ClassData.h" #include "../ClassData.h"
#include "../Hit.h" #include "../Hit.h"
#include <algorithm> #include <algorithm>
#include <filesystem>
class FSUReader{ class FSUReader{
public: public:
FSUReader(); FSUReader();
FSUReader(std::string fileName, uShort dataSize = 100, bool verbose = true); FSUReader(std::string fileName, uShort dataSize = 100, int verbose = 1);
~FSUReader(); ~FSUReader();
void OpenFile(std::string fileName, uShort dataSize, bool verbose = true); void OpenFile(std::string fileName, uShort dataSize, int verbose = 1);
bool isOpen() const{return inFile == nullptr ? false : true;} bool isOpen() const{return inFile == nullptr ? false : true;}
void ScanNumBlock(bool verbose = true, uShort saveData = 0); void ScanNumBlock(int verbose = 1, uShort saveData = 0);
int ReadNextBlock(bool fast = false, int verbose = 0, uShort saveData = 0); // saveData = 0 (no save), 1 (no trace), 2 (with trace); int ReadNextBlock(bool skipTrace= false, int verbose = 0, uShort saveData = 0); // saveData = 0 (no save), 1 (no trace), 2 (with trace);
int ReadBlock(unsigned int ID, int verbose = 0); int ReadBlock(unsigned int ID, int verbose = 0);
unsigned long GetTotNumBlock() const{ return totNumBlock;} unsigned long GetTotNumBlock() const{ return totNumBlock;}
@ -37,7 +38,9 @@ class FSUReader{
void ClearHitCount() {numHit = 0;} void ClearHitCount() {numHit = 0;}
ulong GetHitCount() const{ return numHit;} ulong GetHitCount() const{ return numHit;}
std::vector<Hit> GetHitVector() const {return hit;} std::vector<Hit> GetHitVector() const {return hit;}
void SortHit(); void SortHit(int verbose = false);
std::string SaveHit2NewFile(std::string saveFolder = "./");
private: private:
@ -57,7 +60,7 @@ class FSUReader{
int tick2ns; int tick2ns;
int order; int order;
int chMask; int chMask;
int numCh; uShort numCh;
std::vector<unsigned int> blockPos; std::vector<unsigned int> blockPos;
std::vector<unsigned int > blockTimeStamp; std::vector<unsigned int > blockTimeStamp;
@ -89,11 +92,11 @@ inline FSUReader::FSUReader(){
} }
inline FSUReader::FSUReader(std::string fileName, uShort dataSize, bool verbose){ inline FSUReader::FSUReader(std::string fileName, uShort dataSize, int verbose){
OpenFile(fileName, dataSize, verbose); OpenFile(fileName, dataSize, verbose);
} }
inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, bool verbose){ inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, int verbose){
inFile = fopen(fileName.c_str(), "r"); inFile = fopen(fileName.c_str(), "r");
@ -157,7 +160,7 @@ inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, bool verb
if( fileName.find("PSD") != std::string::npos ) DPPType = DPPType::DPP_PSD_CODE; if( fileName.find("PSD") != std::string::npos ) DPPType = DPPType::DPP_PSD_CODE;
if( fileName.find("QDC") != std::string::npos ) DPPType = DPPType::DPP_QDC_CODE; if( fileName.find("QDC") != std::string::npos ) DPPType = DPPType::DPP_QDC_CODE;
numCh = DPPType == DPPType::DPP_QDC_CODE ? 64 : 16; numCh = (DPPType == DPPType::DPP_QDC_CODE ? 64 : 16);
data = new Data(numCh, dataSize); data = new Data(numCh, dataSize);
data->tick2ns = tick2ns; data->tick2ns = tick2ns;
@ -166,7 +169,7 @@ inline void FSUReader::OpenFile(std::string fileName, uShort dataSize, bool verb
} }
inline int FSUReader::ReadNextBlock(bool fast, int verbose, uShort saveData){ inline int FSUReader::ReadNextBlock(bool skipTrace, int verbose, uShort saveData){
if( inFile == NULL ) return -1; if( inFile == NULL ) return -1;
if( feof(inFile) ) return -1; if( feof(inFile) ) return -1;
if( filePos >= inFileSize) return -1; if( filePos >= inFileSize) return -1;
@ -193,8 +196,7 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose, uShort saveData){
return -30; return -30;
} }
data->DecodeBuffer(buffer, aggSize, skipTrace, verbose); // data will own the buffer
data->DecodeBuffer(buffer, aggSize, fast, verbose); // data will own the buffer
}else if( (header & 0xF ) == 0x8 ) { /// dual channel header }else if( (header & 0xF ) == 0x8 ) { /// dual channel header
@ -204,7 +206,7 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose, uShort saveData){
filePos = ftell(inFile); filePos = ftell(inFile);
data->buffer = buffer; data->buffer = buffer;
data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, false, verbose); data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, skipTrace, verbose);
}else{ }else{
printf("incorrect header.\n trminate."); printf("incorrect header.\n trminate.");
@ -229,7 +231,13 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose, uShort saveData){
temp.energy2 = data->Energy2[ch][i]; temp.energy2 = data->Energy2[ch][i];
temp.timestamp = data->Timestamp[ch][i]; temp.timestamp = data->Timestamp[ch][i];
temp.fineTime = data->fineTime[ch][i]; temp.fineTime = data->fineTime[ch][i];
if( saveData > 1 ) temp.trace = data->Waveform1[ch][i]; if( saveData > 1 ) {
temp.traceLength = data->Waveform1[ch][i].size();
temp.trace = data->Waveform1[ch][i];
}else{
temp.traceLength = 0;
if( temp.trace.size() > 0 ) temp.trace.clear();
}
hit.push_back(temp); hit.push_back(temp);
@ -261,13 +269,15 @@ inline int FSUReader::ReadBlock(unsigned int ID, int verbose){
} }
inline void FSUReader::SortHit(){ inline void FSUReader::SortHit(int verbose){
if( verbose) printf("\nQuick Sort hit array according to time...");
std::sort(hit.begin(), hit.end(), [](const Hit& a, const Hit& b) { std::sort(hit.begin(), hit.end(), [](const Hit& a, const Hit& b) {
return a.timestamp < b.timestamp; return a.timestamp < b.timestamp;
}); });
if( verbose) printf(".......done.\n");
} }
inline void FSUReader::ScanNumBlock(bool verbose, uShort saveData){ inline void FSUReader::ScanNumBlock(int verbose, uShort saveData){
if( feof(inFile) ) return; if( feof(inFile) ) return;
blockID = 0; blockID = 0;
@ -277,7 +287,7 @@ inline void FSUReader::ScanNumBlock(bool verbose, uShort saveData){
fseek(inFile, 0L, SEEK_SET); fseek(inFile, 0L, SEEK_SET);
filePos = 0; filePos = 0;
while( ReadNextBlock(true, false, saveData) == 0 ){ while( ReadNextBlock(saveData < 2 ? true : false, verbose - 1, saveData) == 0 ){
blockPos.push_back(filePos); blockPos.push_back(filePos);
blockTimeStamp.push_back(data->aggTime); blockTimeStamp.push_back(data->aggTime);
blockID ++; blockID ++;
@ -298,10 +308,77 @@ inline void FSUReader::ScanNumBlock(bool verbose, uShort saveData){
blockID = 0; blockID = 0;
filePos = 0; filePos = 0;
if(saveData) { SortHit(verbose);
if( verbose) printf("\nQuick Sort hit array according to time...");
SortHit(); }
if( verbose) printf(".......done.\n");
} inline std::string FSUReader::SaveHit2NewFile(std::string saveFolder){
printf("FSUReader::%s\n", __func__);
std::string folder = "";
size_t found = fileName.find_last_of('/');
std::string outFileName = fileName;
if( found != std::string::npos ){
folder = fileName.substr(0, found + 1);
outFileName = fileName.substr(found +1 );
}
if( saveFolder.empty() ) saveFolder = "./";
if( saveFolder.back() != '/') saveFolder += '/';
//checkif the saveFolder exist;
if( saveFolder != "./"){
if (!std::filesystem::exists(saveFolder)) {
if (std::filesystem::create_directory(saveFolder)) {
std::cout << "Directory created successfully." << std::endl;
} else {
std::cerr << "Failed to create directory." << std::endl;
}
}
}
outFileName = saveFolder + outFileName + ".ts";
FILE * outFile = fopen(outFileName.c_str(), "wb"); //overwrite binary
uint32_t header = 0xAA000000;
header += sn;
fwrite( &header, 4, 1, outFile );
for( ulong i = 0; i < numHit; i++){
printf("Saving %lu/%lu (%.2f%%)\n\033[A\r", i, numHit, i*100./numHit);
fwrite( &(hit[i].sn), 2, 1, outFile);
fwrite( &(hit[i].ch), 1, 1, outFile);
fwrite( &(hit[i].energy), 2, 1, outFile);
fwrite( &(hit[i].energy2), 2, 1, outFile);
fwrite( &(hit[i].timestamp), 8, 1, outFile);
fwrite( &(hit[i].fineTime), 2, 1, outFile);
fwrite( &(hit[i].traceLength), 2, 1, outFile);
for( uShort j = 0; j < hit[i].traceLength; j++){
fwrite( &(hit[i].trace[j]), 2, 1, outFile);
}
}
off_t outFileSize = ftello(outFile); // unsigned int = Max ~4GB
fclose(outFile);
printf("Saved to %s, size: ", outFileName.c_str());
if( outFileSize < 1024 ) {
printf(" %ld Byte", outFileSize);
}else if( outFileSize < 1024*1024 ) {
printf(" %.2f kB", outFileSize/1024.);
}else if( outFileSize < 1024*1024*1024){
printf(" %.2f MB", outFileSize/1024./1024.);
}else{
printf(" %.2f GB", outFileSize/1024./1024./1024.);
}
printf("\n");
return outFileName;
} }

179
Aux/fsutsReader.h Normal file
View File

@ -0,0 +1,179 @@
#include "../Hit.h"
#include "../macro.h"
#include <stdio.h>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring> ///memset
#include <iostream> ///cout
#include <sstream>
#include <algorithm>
#include <bitset>
#include <vector>
class FSUTSReader{
public:
FSUTSReader();
FSUTSReader(std::string fileName, int verbose = true);
~FSUTSReader();
void OpenFile(std::string fileName, int verbose = true);
bool isOpen() const{return inFile == nullptr ? false : true;}
void ScanFile(int verbose = true);
int ReadNext(int verbose = 0);
int ReadBlock(unsigned int ID, int verbose = 0);
unsigned long GetNumHit() const{ return numHit;}
std::string GetFileName() const{return fileName;}
unsigned long GetFileByteSize() const {return inFileSize;}
int GetSN() const{return sn;}
private:
FILE * inFile;
std::string fileName;
unsigned long inFileSize;
unsigned int filePos;
unsigned long numHit;
bool isDualBlock;
ushort sn;
unsigned int blockID;
std::vector<unsigned int> blockPos;
Hit hit;
uint32_t header;
size_t dummy;
};
inline FSUTSReader::~FSUTSReader(){
fclose(inFile);
}
inline FSUTSReader::FSUTSReader(){
inFile = nullptr;
blockPos.clear();
hit.Clear();
}
inline FSUTSReader::FSUTSReader(std::string fileName, int verbose){
OpenFile(fileName, verbose);
}
inline void FSUTSReader::OpenFile(std::string fileName, int verbose){
inFile = fopen(fileName.c_str(), "r");
if( inFile == NULL ){
printf("FSUTSReader::Cannot open file : %s \n", fileName.c_str());
this->fileName = "";
return;
}
this->fileName = fileName;
fseek(inFile, 0L, SEEK_END);
inFileSize = ftell(inFile);
if(verbose) printf("%s | file size : %ld Byte = %.2f MB\n", fileName.c_str() , inFileSize, inFileSize/1024./1024.);
fseek(inFile, 0L, SEEK_SET);
filePos = 0;
numHit = 0;
blockID = 0;
blockPos.clear();
hit.Clear();
//check is the file is .ts file by checking the 1st 4 byte
dummy = fread(&header, 4, 1, inFile);
printf(" header : 0x%8X \n", header);
if( (header >> 24) != 0xAA ){
printf(" This is not a time-sorted fsu (*.fsu.ts) file. Abort.");
return;
}
sn = (header & 0xFFFFFF);
hit.sn = sn;
printf(" S/N : %u \n", sn);
}
inline int FSUTSReader::ReadNext(int verbose){
if( inFile == NULL ) return -1;
if( feof(inFile) ) return -1;
if( filePos >= inFileSize) return -1;
dummy = fread(&(hit.sn), 2, 1, inFile);
dummy = fread(&(hit.ch), 1, 1, inFile);
dummy = fread(&(hit.energy), 2, 1, inFile);
dummy = fread(&(hit.energy2), 2, 1, inFile);
dummy = fread(&(hit.timestamp), 8, 1, inFile);
dummy = fread(&(hit.fineTime), 2, 1, inFile);
dummy = fread(&(hit.traceLength), 2, 1, inFile);
hit.trace.clear();
if( hit.traceLength > 0 ){
for(uShort j = 0; j < hit.traceLength; j++){
short temp;
fread( &temp, 2, 1, inFile);
hit.trace.push_back(temp);
}
}
filePos = ftell(inFile);
if(verbose >= 1) hit.Print();
if(verbose >= 2) hit.PrintTrace();
return 0;
}
inline int FSUTSReader::ReadBlock(unsigned int ID, int verbose){
if( numHit == 0 ) return -1;
if( ID >= numHit ) return -1;
fseek( inFile, 0L, SEEK_SET);
if( verbose ) printf("Block index: %u, File Pos: %u byte\n", ID, blockPos[ID]);
fseek(inFile, blockPos[ID], SEEK_CUR);
filePos = blockPos[ID];
blockID = ID;
return ReadNext(verbose);
}
inline void FSUTSReader::ScanFile(int verbose){
if( feof(inFile) ) return;
blockPos.clear();
fseek(inFile, 0L, SEEK_SET);
dummy = fread(&header, 4, 1, inFile);
filePos = ftell(inFile);
blockPos.push_back(filePos);
blockID = 0;
while( ReadNext(verbose) == 0 ){
blockPos.push_back(filePos);
blockID ++;
if(verbose) printf("%u, %.2f%% %u/%lu\n\033[A\r", blockID, filePos*100./inFileSize, filePos, inFileSize);
}
numHit = blockID;
if(verbose) printf("\nScan complete: number of hit : %lu\n", numHit);
rewind(inFile);
blockID = 0;
filePos = 0;
}

View File

@ -179,6 +179,10 @@ inline Data::~Data(){
inline void Data::AllocateDataSize(uShort dataSize){ inline void Data::AllocateDataSize(uShort dataSize){
if( dataSize < 1) {
printf("dataSize cannot < 1, set dataSize = 1.\n");
dataSize = 1;
}
printf("Data::%s, size: %u\n", __func__, dataSize); printf("Data::%s, size: %u\n", __func__, dataSize);
this->dataSize = dataSize; this->dataSize = dataSize;
@ -276,6 +280,15 @@ inline void Data::ClearData(){
for( int ch = 0 ; ch < MaxNChannels; ch++){ for( int ch = 0 ; ch < MaxNChannels; ch++){
LoopIndex[ch] = 0; LoopIndex[ch] = 0;
DataIndex[ch] = -1; DataIndex[ch] = -1;
NumEventsDecoded[ch] = 0;
NumNonPileUpDecoded[ch] = 0;
TotNumNonPileUpEvents[ch] = 0 ;
calIndexes[ch][0] = -1;
calIndexes[ch][1] = -1;
if( ch >= numInputCh) break;
for( int j = 0; j < dataSize; j++){ for( int j = 0; j < dataSize; j++){
Timestamp[ch][j] = 0; Timestamp[ch][j] = 0;
fineTime[ch][j] = 0; fineTime[ch][j] = 0;
@ -289,13 +302,6 @@ inline void Data::ClearData(){
DigiWaveform4[ch][j].clear(); DigiWaveform4[ch][j].clear();
} }
NumEventsDecoded[ch] = 0;
NumNonPileUpDecoded[ch] = 0;
TotNumNonPileUpEvents[ch] = 0 ;
calIndexes[ch][0] = -1;
calIndexes[ch][1] = -1;
} }
tempWaveform1.clear(); tempWaveform1.clear();
@ -304,6 +310,7 @@ inline void Data::ClearData(){
tempDigiWaveform2.clear(); tempDigiWaveform2.clear();
tempDigiWaveform3.clear(); tempDigiWaveform3.clear();
tempDigiWaveform4.clear(); tempDigiWaveform4.clear();
} }
inline void Data::ClearBuffer(){ inline void Data::ClearBuffer(){
@ -462,7 +469,7 @@ inline void Data::PrintChData(unsigned short ch, unsigned int maxRowDisplay) con
if( DataIndex[ch] < 0 ) printf("no data in ch-%d\n", ch); if( DataIndex[ch] < 0 ) printf("no data in ch-%d\n", ch);
printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]); printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]);
for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? dataSize : DataIndex[ch]) ; ev++){ for( int ev = 0; ev < (LoopIndex[ch] > 0 ? dataSize : DataIndex[ch]) ; ev++){
if( DPPType == DPPType::DPP_PHA_CODE || DPPType == DPPType::DPP_QDC_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); if( DPPType == DPPType::DPP_PHA_CODE || DPPType == DPPType::DPP_QDC_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
if( DPPType == DPPType::DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); if( DPPType == DPPType::DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]);
if( maxRowDisplay > 0 && (unsigned int) ev > maxRowDisplay ) break; if( maxRowDisplay > 0 && (unsigned int) ev > maxRowDisplay ) break;

14
Hit.h
View File

@ -3,14 +3,15 @@
class Hit{ class Hit{
public: public:
int sn; unsigned short sn;
unsigned short bd; uint8_t bd;
unsigned short ch; uint8_t ch;
unsigned short energy; unsigned short energy;
unsigned short energy2; unsigned short energy2;
unsigned long long timestamp; unsigned long long timestamp;
unsigned short fineTime; unsigned short fineTime;
unsigned short traceLength;
std::vector<short> trace; std::vector<short> trace;
Hit(){ Hit(){
@ -25,6 +26,7 @@ public:
energy2 = 0; energy2 = 0;
timestamp = 0; timestamp = 0;
fineTime = 0; fineTime = 0;
traceLength = 0;
trace.clear(); trace.clear();
} }
@ -32,6 +34,12 @@ public:
printf("(%5d, %2d) %6d %16llu, %6d, %5ld\n", sn, ch, energy, timestamp, fineTime, trace.size()); printf("(%5d, %2d) %6d %16llu, %6d, %5ld\n", sn, ch, energy, timestamp, fineTime, trace.size());
} }
void PrintTrace(){
for( unsigned short i = 0; i < traceLength; i++){
printf("%3u | %6d \n", i, trace[i]);
}
}
// Define operator< for sorting // Define operator< for sorting
bool operator<(const Hit& other) const { bool operator<(const Hit& other) const {
return timestamp < other.timestamp; return timestamp < other.timestamp;

View File

@ -22,7 +22,7 @@
#include <sys/time.h> /** struct timeval, select() */ #include <sys/time.h> /** struct timeval, select() */
inline unsigned int get_time(){ inline unsigned int get_time_us(){
unsigned int time_us; unsigned int time_us;
struct timeval t1; struct timeval t1;
struct timezone tz; struct timezone tz;
@ -31,6 +31,13 @@ inline unsigned int get_time(){
return time_us; return time_us;
} }
#include <chrono>
inline unsigned long long getTime_ns(){
std::chrono::high_resolution_clock::time_point currentTime = std::chrono::high_resolution_clock::now();
std::chrono::nanoseconds nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(currentTime.time_since_epoch());
return nanoseconds.count();
}
typedef unsigned short uShort; typedef unsigned short uShort;
typedef unsigned int uInt; typedef unsigned int uInt;
typedef unsigned long uLong; typedef unsigned long uLong;