add timeOffset example file
This commit is contained in:
parent
0f487c354b
commit
84851051f7
40
Bin2Root.cpp
40
Bin2Root.cpp
|
@ -52,21 +52,31 @@ std::vector<std::pair<int, int64_t>> readFileAndExtractData(const std::string& f
|
|||
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
|
||||
// Function to extract the number between the n-th and (n+1)-th underscore
|
||||
int extractDigiSN(const std::string& str, int n = 1) {
|
||||
std::size_t pos = 0;
|
||||
|
||||
// Find the position of the n-th underscore
|
||||
for (int i = 0; i < n; ++i) {
|
||||
pos = str.find('_', pos);
|
||||
if (pos == std::string::npos) {
|
||||
std::cerr << "Less than " << n << " underscores in the string." << std::endl;
|
||||
return -1; // Return error if there are fewer underscores than expected
|
||||
}
|
||||
++pos; // Move to the next character after the underscore
|
||||
}
|
||||
|
||||
std::size_t secondUnderscore = str.find('_', firstUnderscore + 1);
|
||||
if (secondUnderscore == std::string::npos) {
|
||||
return -1; // No second underscore found, return an error value
|
||||
// Find the position of the (n+1)-th underscore
|
||||
std::size_t nextUnderscore = str.find('_', pos);
|
||||
if (nextUnderscore == std::string::npos) {
|
||||
std::cerr << "No (n+1)-th underscore found." << std::endl;
|
||||
return -1; // Return error if there's no (n+1)-th underscore
|
||||
}
|
||||
|
||||
// Extract the substring between the first and second underscores
|
||||
std::string extracted = str.substr(firstUnderscore + 1, secondUnderscore - firstUnderscore - 1);
|
||||
// Extract the substring between the n-th and (n+1)-th underscores
|
||||
std::string extracted = str.substr(pos, nextUnderscore - pos);
|
||||
|
||||
// Convert the extracted string to an integer using std::stoi
|
||||
// Convert the extracted substring to an integer using std::stoi
|
||||
try {
|
||||
return std::stoi(extracted);
|
||||
} catch (const std::invalid_argument& e) {
|
||||
|
@ -96,7 +106,8 @@ int main(int argc, char **argv) {
|
|||
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, sn appears between the n-th - (n+1)-th underscore of the fileName] 0\n");
|
||||
printf("[digi sn] [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");
|
||||
|
@ -138,6 +149,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
std::vector<std::pair<int, int64_t>> timeOffsetList ;
|
||||
timeOffsetList.clear();
|
||||
|
||||
printf("-------> Out file name : %s \n", outFileName.Data());
|
||||
printf("=========================================\n");
|
||||
|
@ -160,10 +172,12 @@ int main(int argc, char **argv) {
|
|||
for(int i = 0; i < nFile; i++ ){
|
||||
printf(">>>>>>>> %2d | %s \n", i, inFileName[i].Data());
|
||||
reader[i].OpenFile(inFileName[i]);
|
||||
for (size_t i = 0 ; timeOffsetList.size(); i++) {
|
||||
int sn = extractDigiSN(inFileName[i].Data());
|
||||
if( timeOffsetList.size() > 1 ){
|
||||
for (size_t i = 1 ; timeOffsetList.size(); i++) {
|
||||
int sn = extractDigiSN(inFileName[i].Data(), timeOffsetList[0].first);
|
||||
if( sn == timeOffsetList[i].first ) reader[i].SetTimeOffset(timeOffsetList[i].second);
|
||||
}
|
||||
}
|
||||
reader[i].ScanNumHit();
|
||||
totalHitCount += reader[i].GetNumHit();
|
||||
}
|
||||
|
|
4
timeOffset.txt
Normal file
4
timeOffset.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
1 0
|
||||
123 456
|
||||
86 49
|
||||
19267 0
|
Loading…
Reference in New Issue
Block a user