From b44e63377a144b19196eaae40e3503c6e9e62bf3 Mon Sep 17 00:00:00 2001 From: "Ryan@MBA2024" Date: Fri, 24 May 2024 15:23:36 -0400 Subject: [PATCH] in progress to bypass the *.to file and directly build event --- .gitignore | 2 + .vscode/c_cpp_properties.json | 20 ++++++++++ .vscode/settings.json | 69 +++++++++++++++++++++++++++++++++ armory/EventBuilder2.cpp | 68 ++++++++++++++++++++++++++++++++ armory/evtReader.h | 23 +++++++++++ armory/text.cpp | 73 +++++++++++++++++++++++++++++++++++ 6 files changed, 255 insertions(+) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 armory/EventBuilder2.cpp create mode 100644 armory/text.cpp diff --git a/.gitignore b/.gitignore index 460482c..6f91b52 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ fsu_run_2021 data Data obsolete +raw_data +root_data test.cpp test diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..0417a1e --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "${workspaceFolder}/**", + "/Applications/root_v6.30.06/**" + ], + "defines": [], + "macFrameworkPath": [ + "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks" + ], + "compilerPath": "/usr/bin/clang", + "cStandard": "c17", + "cppStandard": "c++17", + "intelliSenseMode": "macos-clang-arm64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..98b7879 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,69 @@ +{ + "files.associations": { + "algorithm": "cpp", + "allocator": "cpp", + "array": "cpp", + "limits": "cpp", + "__bit_reference": "cpp", + "__config": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__verbose_abort": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "execution": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "ratio": "cpp", + "set": "cpp", + "shared_mutex": "cpp", + "span": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "valarray": "cpp", + "variant": "cpp", + "vector": "cpp" + } +} \ No newline at end of file diff --git a/armory/EventBuilder2.cpp b/armory/EventBuilder2.cpp new file mode 100644 index 0000000..7c9238f --- /dev/null +++ b/armory/EventBuilder2.cpp @@ -0,0 +1,68 @@ +/*================== + +Thie event builder both sort and build event. skip the *.to file. + +===================*/ + +#include +#include +#include +#include +#include + +#include "TFile.h" +#include "TTree.h" +#include "TMath.h" +#include "TBenchmark.h" +#include "TStopwatch.h" +#include "TTreeIndex.h" + +#include "../mapping.h" + +#include "evtReader.h" + +#define MAXMULTI 100 +#define MAXBUFFER 100 // number of hit in memory buffer + +int main(int argn, char **argv){ + printf("=====================================\n"); + printf("=== Event Builder from *.evt ===\n"); + printf("=====================================\n"); + + if (argn < 5 ) { + printf("Usage :\n"); + printf("%s [timeWindows] [Reject Flag] [SaveFileName] [*.evt File1 [*.evt File2] ...\n", argv[0]); + printf(" timeWindows [int]: 1 unit = 10 ns \n"); + printf(" Reject Flag [int]: 0 = no rejection, 1 = reject no gamma, 2 = reject no GAGG. see mapping.h\n"); + printf(" SaveFileName [str]: custom save file name \n"); + return 1; + } + + unsigned short timeWindow = atoi(argv[1]); + unsigned short rejectFlag = atoi(argv[2]); + TString outFileName = argv[3]; + + std::vector inFileList; + for( int i = 4; i < argn; i++) inFileList.push_back(argv[i]); + + //========== put data into RAM buffer. + std::vector hitListA, hitListB; + evtReader * reader = nullptr; + + for( size_t i = 0 ; i < inFileList.size(); i++){ + + reader = new evtReader(inFileList[i]); + reader->ScanNumberOfBlock(); + + reader->ReadBatchDataAndSort(MAXBUFFER); + hitListA = reader->GetDataList(); + + reader->ReadBatchDataAndSort(MAXBUFFER); + hitListB = reader->GetDataList(); + + delete reader; + } + + + return 0; +} \ No newline at end of file diff --git a/armory/evtReader.h b/armory/evtReader.h index e7e4542..dc5f45d 100644 --- a/armory/evtReader.h +++ b/armory/evtReader.h @@ -40,6 +40,8 @@ class evtReader{ long int inFilePosPrecent[10]; Long64_t blockIDPrecent[10]; + std::vector dataList; + ///============================================ Methods public: @@ -66,6 +68,8 @@ class evtReader{ void ScanNumberOfBlock(); void JumptoPrecent(int precent); ///this is offset by 1 block void PrintStatus(int mod); + + std::vector ReadBatchDataAndSort(long numData); }; @@ -306,4 +310,23 @@ void evtReader::PrintStatus(int mod){ } +std::vector evtReader::ReadBatchDataAndSort(long numData){ + + std::vector dataList_A; + if( endOfFile ){ + return dataList_A; + } + + dataList.clear(); + + for( long long k = 0; k < std::min(numData, nBlock); k++){ + ReadBlock(); + dataList.push_back(*data); + } + + //sort the dataList + std::sort(dataList.begin(), dataList.end(), [](const DataBlock & a, const DataBlock & b) { return a.time < b.time; }); + +} + #endif diff --git a/armory/text.cpp b/armory/text.cpp new file mode 100644 index 0000000..4066ff6 --- /dev/null +++ b/armory/text.cpp @@ -0,0 +1,73 @@ +/*================== + +Thie event builder both sort and build event. skip the *.to file. + +===================*/ + +#include +#include +#include +#include +#include + +#include "TFile.h" +#include "TTree.h" +#include "TMath.h" +#include "TBenchmark.h" +#include "TStopwatch.h" +#include "TTreeIndex.h" + +#include "../mapping.h" + +#include "evtReader.h" + +#define MAXMULTI 100 +#define MAXBUFFER 100 // number of hit in memory buffer + +int main(int argn, char **argv){ + printf("=====================================\n"); + printf("=== Event Builder from *.evt ===\n"); + printf("=====================================\n"); + + if (argn < 5 ) { + printf("Usage :\n"); + printf("%s [timeWindows] [Reject Flag] [SaveFileName] [*.evt File1 [*.evt File2] ...\n", argv[0]); + printf(" timeWindows [int]: 1 unit = 10 ns \n"); + printf(" Reject Flag [int]: 0 = no rejection, 1 = reject no gamma, 2 = reject no GAGG. see mapping.h\n"); + printf(" SaveFileName [str]: custom save file name \n"); + return 1; + } + + unsigned short timeWindow = atoi(argv[1]); + unsigned short rejectFlag = atoi(argv[2]); + TString outFileName = argv[3]; + + std::vector inFileList; + for( int i = 4; i < argn; i++) inFileList.push_back(argv[i]); + + //========== put data into RAM buffer. + std::vector hitListA, hitListB; + evtReader * reader = nullptr; + + for( size_t i = 0 ; i < inFileList.size(); i++){ + + reader = new evtReader(inFileList[i]); + reader->ScanNumberOfBlock(); + + // reader->ReadBatchDataAndSort(MAXBUFFER); + // hitListA = reader->GetDataList(); + + // reader->ReadBatchDataAndSort(MAXBUFFER); + // hitListB = reader->GetDataList(); + + + + + + + delete reader; + } + + + return 0; +} \ No newline at end of file