File indexing completed on 2025-08-05 08:15:32
0001 #ifndef CALOCDB_MYUTILS_H
0002 #define CALOCDB_MYUTILS_H
0003
0004
0005 #include <TFitResultPtr.h>
0006 #include <TH1.h>
0007
0008
0009 #include <concepts>
0010 #include <filesystem>
0011 #include <fstream>
0012 #include <functional>
0013 #include <iostream>
0014 #include <string>
0015 #include <vector>
0016
0017 template <typename Func>
0018 concept InvocableWithString = std::invocable<Func, const std::string&>;
0019
0020 class myUtils
0021 {
0022 public:
0023 static void setEMCalDim(TH1* hist);
0024
0025 static std::pair<int, int> getSectorIB(int iphi, int ieta);
0026 static std::pair<int, int> getSectorIB(int towerIndex);
0027 static std::vector<std::string> split(const std::string& s, char delimiter);
0028 static TFitResultPtr doGausFit(TH1* hist, Double_t start, Double_t end, const std::string& name = "fitFunc");
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 template <InvocableWithString Callable>
0042 static Bool_t readCSV(const std::filesystem::path& filePath, Callable lineHandler, Bool_t skipHeader = true)
0043 {
0044 std::ifstream file(filePath);
0045
0046 if (!file.is_open())
0047 {
0048 std::cout << "Error: [" << filePath.string() << "] Could not open file." << std::endl;
0049 return false;
0050 }
0051
0052 std::string line;
0053
0054 if (skipHeader && std::getline(file, line))
0055 {
0056
0057 }
0058
0059 while (std::getline(file, line))
0060 {
0061
0062
0063
0064
0065
0066
0067 lineHandler(line);
0068 }
0069
0070
0071 if (file.bad())
0072 {
0073 std::cout << "Error: [" << filePath.string() << "] I/O error while reading file." << std::endl;
0074 return false;
0075 }
0076
0077
0078
0079
0080 return true;
0081 }
0082 };
0083
0084 #endif