added SaveHit2NewFile() to fsuReader.h, this save the time sorted data to a simple format
This commit is contained in:
parent
5c6b5e7001
commit
55ee3931cc
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
121
Aux/fsuReader.h
121
Aux/fsuReader.h
|
@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user