added time offset, assume the digiitizer serial number is between first and 2nd underscore
This commit is contained in:
parent
a52db652dd
commit
0f487c354b
98
Bin2Root.cpp
98
Bin2Root.cpp
|
@ -11,16 +11,73 @@ inline unsigned int getTime_us(){
|
||||||
return time_us;
|
return time_us;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#include "TFile.h"
|
#include "TFile.h"
|
||||||
#include "TTree.h"
|
#include "TTree.h"
|
||||||
#include "TMacro.h"
|
#include "TMacro.h"
|
||||||
|
|
||||||
#define MAX_TRACE_LENGTH 2000
|
#define MAX_TRACE_LENGTH 2000
|
||||||
#define MAX_MULTI 100
|
#define MAX_MULTI 100
|
||||||
#define NMINARG 4
|
#define NMINARG 5
|
||||||
#define debug 0 // for > 1 number of hit to debug
|
#define debug 0 // for > 1 number of hit to debug
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
std::vector<std::pair<int, int64_t>> readFileAndExtractData(const std::string& filename) {
|
||||||
|
std::vector<std::pair<int, int64_t>> data;
|
||||||
|
std::ifstream file(filename);
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
std::cerr << "Error opening file!" << std::endl;
|
||||||
|
return data; // Return empty vector on failure
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
std::istringstream iss(line);
|
||||||
|
int first;
|
||||||
|
int64_t second;
|
||||||
|
|
||||||
|
// Extract an int and an int64_t from the line
|
||||||
|
if (iss >> first >> second) {
|
||||||
|
data.emplace_back(first, second);
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error parsing line: " << line << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
int extractDigiSN(const std::string& str) {
|
||||||
|
std::size_t firstUnderscore = str.find('_');
|
||||||
|
if (firstUnderscore == std::string::npos) {
|
||||||
|
return -1; // No first underscore found, return an error value
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t secondUnderscore = str.find('_', firstUnderscore + 1);
|
||||||
|
if (secondUnderscore == std::string::npos) {
|
||||||
|
return -1; // No second underscore found, return an error value
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the substring between the first and second underscores
|
||||||
|
std::string extracted = str.substr(firstUnderscore + 1, secondUnderscore - firstUnderscore - 1);
|
||||||
|
|
||||||
|
// Convert the extracted string to an integer using std::stoi
|
||||||
|
try {
|
||||||
|
return std::stoi(extracted);
|
||||||
|
} catch (const std::invalid_argument& e) {
|
||||||
|
std::cerr << "Invalid number format: " << extracted << std::endl;
|
||||||
|
return -1; // Return an error value on conversion failure
|
||||||
|
} catch (const std::out_of_range& e) {
|
||||||
|
std::cerr << "Number out of range: " << extracted << std::endl;
|
||||||
|
return -1; // Return an error value if the number is too large
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//^#############################################################
|
//^#############################################################
|
||||||
//^#############################################################
|
//^#############################################################
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
@ -30,12 +87,19 @@ int main(int argc, char **argv) {
|
||||||
printf("=========================================\n");
|
printf("=========================================\n");
|
||||||
if (argc < NMINARG) {
|
if (argc < NMINARG) {
|
||||||
printf("Incorrect number of arguments:\n");
|
printf("Incorrect number of arguments:\n");
|
||||||
printf("%s [timeWindow] [withTrace] [inFile1] [inFile2] .... \n", argv[0]);
|
printf("%s [timeWindow] [withTrace] [time Offset File] [inFile1] [inFile2] .... \n", argv[0]);
|
||||||
printf(" timeWindow : in ns, -1 = no event building \n");
|
printf(" timeWindow : in ns, -1 = no event building \n");
|
||||||
printf(" withTrace : 0 for no trace, 1 for trace \n");
|
printf(" withTrace : 0 for no trace, 1 for trace \n");
|
||||||
|
printf(" time Offset File : 0 for nothing \n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf(" Example: %s -1 0 '\\ls -1 *001*.bin' (no event build, no trace, no verbose)\n", argv[0]);
|
printf(" Example: %s -1 0 '\\ls -1 *001*.bin' (no event build, no trace, no verbose)\n", argv[0]);
|
||||||
printf(" %s 100 0 '\\ls -1 *001*.bin' (event build with 100 ns, no trace, no verbose)\n", argv[0]);
|
printf(" %s 100 0 '\\ls -1 *001*.bin' (event build with 100 ns, no trace, no verbose)\n", argv[0]);
|
||||||
|
printf("\n");
|
||||||
|
printf(" Time offset file format :\n");
|
||||||
|
printf("[digi ID] [time offset(int64_t)]\n");
|
||||||
|
printf("\n");
|
||||||
|
printf(" file name should be this format CH0@V1725_324_Data_run_196.bin\n");
|
||||||
|
printf(" so that the serial number is between the 1st and 2nd underscore\n");
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -46,6 +110,7 @@ int main(int argc, char **argv) {
|
||||||
///============= read input
|
///============= read input
|
||||||
long timeWindow = atoi(argv[1]);
|
long timeWindow = atoi(argv[1]);
|
||||||
bool traceOn = atoi(argv[2]);
|
bool traceOn = atoi(argv[2]);
|
||||||
|
std::string timeOffsetFile = argv[3];
|
||||||
const int nFile = argc - NMINARG + 1;
|
const int nFile = argc - NMINARG + 1;
|
||||||
TString inFileName[nFile];
|
TString inFileName[nFile];
|
||||||
for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i + NMINARG -1];}
|
for( int i = 0 ; i < nFile ; i++){ inFileName[i] = argv[i + NMINARG -1];}
|
||||||
|
@ -72,20 +137,33 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::pair<int, int64_t>> timeOffsetList ;
|
||||||
|
|
||||||
printf("-------> Out file name : %s \n", outFileName.Data());
|
printf("-------> Out file name : %s \n", outFileName.Data());
|
||||||
printf("=========================================\n");
|
printf("=========================================\n");
|
||||||
printf(" Time Window = %ld ns = %.1f us\n", timeWindow, timeWindow/1000.);
|
printf(" Time Window = %ld ns = %.1f us\n", timeWindow, timeWindow/1000.);
|
||||||
printf(" Include Trace = %s\n", traceOn ? "Yes" : "No");
|
printf(" Include Trace = %s\n", traceOn ? "Yes" : "No");
|
||||||
printf(" Max multiplity = %d hits/event (hard coded)\n", MAX_MULTI);
|
printf(" Max multiplity = %d hits/event (hard coded)\n", MAX_MULTI);
|
||||||
if( traceOn ) printf(" Max Trace Length = %d (hard coded)\n", MAX_TRACE_LENGTH);
|
if( traceOn ) printf(" Max Trace Length = %d (hard coded)\n", MAX_TRACE_LENGTH);
|
||||||
|
if( timeOffsetFile != "0" ) {
|
||||||
|
printf(" Time Offset File = %s\n", timeOffsetFile.c_str());
|
||||||
|
timeOffsetList = readFileAndExtractData(timeOffsetFile);
|
||||||
|
for (size_t i = 0 ; timeOffsetList.size(); i++) {
|
||||||
|
printf("Digi-%4d %16llu ps\n", timeOffsetList[i].first, timeOffsetList[i].second);
|
||||||
|
}
|
||||||
|
}
|
||||||
printf("========================================= Number of Files : %d \n", nFile);
|
printf("========================================= Number of Files : %d \n", nFile);
|
||||||
|
|
||||||
unsigned long long int totalHitCount = 0;
|
unsigned long long int totalHitCount = 0;
|
||||||
|
|
||||||
BinReader reader[nFile];
|
BinReader reader[nFile];
|
||||||
for(int i = 0; i < nFile; i++ ){
|
for(int i = 0; i < nFile; i++ ){
|
||||||
printf(">>>>>>>> %2d | %s \n", i, inFileName[i].Data());
|
printf(">>>>>>>> %2d | %s \n", i, inFileName[i].Data());
|
||||||
reader[i].OpenFile(inFileName[i]);
|
reader[i].OpenFile(inFileName[i]);
|
||||||
|
for (size_t i = 0 ; timeOffsetList.size(); i++) {
|
||||||
|
int sn = extractDigiSN(inFileName[i].Data());
|
||||||
|
if( sn == timeOffsetList[i].first ) reader[i].SetTimeOffset(timeOffsetList[i].second);
|
||||||
|
}
|
||||||
reader[i].ScanNumHit();
|
reader[i].ScanNumHit();
|
||||||
totalHitCount += reader[i].GetNumHit();
|
totalHitCount += reader[i].GetNumHit();
|
||||||
}
|
}
|
||||||
|
|
13
BinReader.h
13
BinReader.h
|
@ -45,9 +45,9 @@ struct Data{
|
||||||
printf("header : 0x%X \n", Header);
|
printf("header : 0x%X \n", Header);
|
||||||
printf(" Board : %u , Channel : %u\n", BoardID, Channel);
|
printf(" Board : %u , Channel : %u\n", BoardID, Channel);
|
||||||
if( Header & 4 ) {
|
if( Header & 4 ) {
|
||||||
printf("Energy : %5u, Energy2 : %5u, TimeStamp : %16lu ps\n", Energy, Energy_short, TimeStamp);
|
printf("Energy : %5u, Energy2 : %5u, TimeStamp : %16llu ps\n", Energy, Energy_short, TimeStamp);
|
||||||
}else{
|
}else{
|
||||||
printf("Energy : %5u, TimeStamp : %16lu ps\n", Energy, TimeStamp);
|
printf("Energy : %5u, TimeStamp : %16llu ps\n", Energy, TimeStamp);
|
||||||
}
|
}
|
||||||
printf(" Flag : 0x%08X\n", Flags);
|
printf(" Flag : 0x%08X\n", Flags);
|
||||||
if( (Header & 0x8 ) >= 1 ){ /// is waevform exist
|
if( (Header & 0x8 ) >= 1 ){ /// is waevform exist
|
||||||
|
@ -74,6 +74,7 @@ class BinReader{
|
||||||
bool isOpened;
|
bool isOpened;
|
||||||
Long64_t hitID;
|
Long64_t hitID;
|
||||||
long int numHit;
|
long int numHit;
|
||||||
|
int64_t timeOffset;
|
||||||
|
|
||||||
TBenchmark gClock;
|
TBenchmark gClock;
|
||||||
|
|
||||||
|
@ -91,7 +92,7 @@ class BinReader{
|
||||||
BinReader(TString inFileName);
|
BinReader(TString inFileName);
|
||||||
~BinReader();
|
~BinReader();
|
||||||
|
|
||||||
void OpenFile(TString inFileName);
|
void OpenFile(TString inFileName, int64_t timeOffset = 0);
|
||||||
void CloseFile();
|
void CloseFile();
|
||||||
void UpdateFileSize();
|
void UpdateFileSize();
|
||||||
bool IsEndOfFile();
|
bool IsEndOfFile();
|
||||||
|
@ -107,6 +108,8 @@ class BinReader{
|
||||||
void ScanNumHit();
|
void ScanNumHit();
|
||||||
void JumptoPrecent(int precent); ///this is offset by 1 block
|
void JumptoPrecent(int precent); ///this is offset by 1 block
|
||||||
void PrintStatus(int mod);
|
void PrintStatus(int mod);
|
||||||
|
|
||||||
|
void SetTimeOffset(int64_t timeOffset) { this->timeOffset = timeOffset; }
|
||||||
|
|
||||||
};
|
};
|
||||||
//========================== implementation
|
//========================== implementation
|
||||||
|
@ -147,8 +150,9 @@ BinReader::BinReader(TString inFileName){
|
||||||
OpenFile(inFileName);
|
OpenFile(inFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BinReader::OpenFile(TString inFileName){
|
void BinReader::OpenFile(TString inFileName, int64_t timeOffset){
|
||||||
inFile = fopen(inFileName, "r");
|
inFile = fopen(inFileName, "r");
|
||||||
|
this->timeOffset = timeOffset;
|
||||||
if( inFile == NULL ){
|
if( inFile == NULL ){
|
||||||
printf("Cannot read file : %s \n", inFileName.Data());
|
printf("Cannot read file : %s \n", inFileName.Data());
|
||||||
}else{
|
}else{
|
||||||
|
@ -233,6 +237,7 @@ int BinReader::ReadBlock(int skipTrace){
|
||||||
FillData(&data.BoardID);
|
FillData(&data.BoardID);
|
||||||
FillData(&data.Channel);
|
FillData(&data.Channel);
|
||||||
FillData(&data.TimeStamp);
|
FillData(&data.TimeStamp);
|
||||||
|
if( timeOffset != 0 ) data.TimeStamp += timeOffset;
|
||||||
|
|
||||||
if( (data.Header & 0x3) != 0 ) FillData(&data.Energy);
|
if( (data.Header & 0x3) != 0 ) FillData(&data.Energy);
|
||||||
|
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -21,4 +21,4 @@ clean :
|
||||||
|
|
||||||
Bin2Root : Bin2Root.cpp BinReader.h
|
Bin2Root : Bin2Root.cpp BinReader.h
|
||||||
@echo "--------- making Bin2Root"
|
@echo "--------- making Bin2Root"
|
||||||
$(CC) $(COPTS) -o Bin2Root Bin2Root.cpp BinReader.h $(ROOTLIBS)
|
$(CC) $(COPTS) -o Bin2Root Bin2Root.cpp $(ROOTLIBS)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user