fsuReader.h improved, AggSeparator save file in local folder

This commit is contained in:
splitPoleDAQ 2024-01-17 18:19:50 -05:00
parent 12eec58287
commit ec5470a372
3 changed files with 57 additions and 47 deletions

View File

@ -14,9 +14,8 @@
#include <vector>
#include <sys/stat.h>
int main(int argc, char **argv) {
std::string inFileName = argv[1];
int AggSeperator(std::string inFileName, short verbose = false){
FILE * file = fopen(inFileName.c_str(), "r");
@ -25,16 +24,27 @@ int main(int argc, char **argv) {
return -1;
}
std::string folder = "";
size_t found = inFileName.find_last_of('/');
std::string fileName = inFileName;
if( found != std::string::npos ){
folder = inFileName.substr(0, found + 1);
fileName = inFileName.substr(found +1 );
}
// printf(" folder : %s \n", folder.c_str());
// printf("fileName : %s \n", fileName.c_str());
char * buffer = nullptr;
unsigned int word; // 4 bytes = 32 bits
bool newFileFlag[8] = {true};
while( !feof(file)){
do{
size_t dummy = fread(&word, 4, 1, file);
if( dummy != 1 ){
printf("read file error. abort.\n");
printf("End of File.\n");
break;
}
@ -54,19 +64,19 @@ int main(int argc, char **argv) {
dummy = fread(&word, 4, 1, file);
unsigned int bdAggCounter = word;
printf("Agg counter : %u\n", bdAggCounter);
if( verbose ) printf("Agg counter : %u\n", bdAggCounter);
dummy = fread(&word, 4, 1, file);
unsigned int aggTimeTag = word;
for( int chMask = 0; chMask < 8 ; chMask ++ ){ // the max numnber of Coupled/RegChannel is 8 for PHA, PSD, QDC
if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue;
printf("==================== Dual/Group Channel Block, ch Mask : 0x%X\n", chMask *2);
if( verbose ) printf("==================== Dual/Group Channel Block, ch Mask : 0x%X\n", chMask *2);
dummy = fread(&word, 4, 1, file);
unsigned int dualChannelBlockSize = ( word & 0x7FFFFFFF ) * 4 ;
printf("dual channel size : %d words\n", dualChannelBlockSize / 4);
if( verbose ) printf("dual channel size : %d words\n", dualChannelBlockSize / 4);
buffer = new char[dualChannelBlockSize];
fseek(file, -4, SEEK_CUR);
@ -75,10 +85,10 @@ int main(int argc, char **argv) {
FILE * haha = nullptr;
if( newFileFlag[chMask] ) {
haha = fopen( (inFileName + "." + std::to_string(chMask)).c_str(), "wb");
haha = fopen( (fileName + "." + std::to_string(chMask )).c_str(), "wb");
newFileFlag[chMask] = false;
}else{
haha = fopen( (inFileName + "." + std::to_string(chMask)).c_str(), "a+");
haha = fopen( (fileName + "." + std::to_string(chMask )).c_str(), "a+");
}
fwrite(buffer, dualChannelBlockSize, 1, haha);
@ -87,12 +97,14 @@ int main(int argc, char **argv) {
}
};
}while( !feof(file));
fclose(file);
printf("======================= Duel channel seperated \n");
return 0;
return 1;
}
#endif

View File

@ -9,7 +9,6 @@
#include "TTree.h"
#define MAX_MULTI 100
#define TIMEJUMP 1e8 // 0.1 sec or 10 Hz, any signal less than 10 Hz should increase the value.
#define ORDERSHIFT 100000

View File

@ -117,11 +117,12 @@ inline void FSUReader::OpenFile(std::string fileName, bool verbose){
}
std::string fileNameNoExt;
found = fileName.find_last_of(".fsu");
size_t found2 = fileName.find_last_of('/');
if( found == std::string::npos ){
fileNameNoExt = fileName.substr(0, found);
if( found2 == std::string::npos ){
fileNameNoExt = fileName.substr(0, found-4);
}else{
fileNameNoExt = fileName.substr(found2+1, found);
fileNameNoExt = fileName.substr(found2+1, found-4);
}
// Split the string by underscores
@ -186,6 +187,22 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose,bool saveData){
data->DecodeBuffer(buffer, aggSize, fast, verbose); // data will own the buffer
}else if( (header & 0xF ) == 0x8 ) { /// dual channel header
unsigned int dualSize = (word[0] & 0x7FFFFFFF) * 4; ///byte
buffer = new char[dualSize];
dummy = fread(buffer, dualSize, 1, inFile);
filePos = ftell(inFile);
data->buffer = buffer;
data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, false, verbose);
}else{
printf("incorrect header.\n trminate.");
return -20;
}
if( saveData ){
for( int ch = 0; ch < data->GetNChannel(); ch++){
@ -214,24 +231,6 @@ inline int FSUReader::ReadNextBlock(bool fast, int verbose,bool saveData){
data->ClearTriggerRate();
data->ClearBuffer(); // this will clear the buffer.
}else if( (header & 0xF ) == 0x8 ) { /// dual channel header
unsigned int dualSize = (word[0] & 0x7FFFFFFF) * 4; ///byte
buffer = new char[dualSize];
dummy = fread(buffer, dualSize, 1, inFile);
filePos = ftell(inFile);
data->buffer = buffer;
data->DecodeDualBlock(buffer, dualSize, DPPType, chMask, false, verbose);
data->ClearTriggerRate();
data->ClearBuffer();
}else{
printf("incorrect header.\n trminate.");
return -20;
}
return 0;
}