ATLAS Offline Software
Loading...
Searching...
No Matches
PunchThroughG4Tool.cxx File Reference
#include "PunchThroughPDFCreator.h"
#include "PunchThroughParticle.h"
#include "PunchThroughG4Tool.h"
#include "PathResolver/PathResolver.h"
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string_view>
#include <charconv>
#include <cmath>
#include "CLHEP/Random/RandFlat.h"
#include "TFile.h"
#include "TH2F.h"
#include "TH1.h"
#include "TMath.h"
#include "TKey.h"
#include "GeoPrimitives/GeoPrimitivesHelpers.h"

Go to the source code of this file.

Functions

template<typename T>
std::vector< T > str_to_list (const std::string_view str)

Function Documentation

◆ str_to_list()

template<typename T>
std::vector< T > str_to_list ( const std::string_view str)

Definition at line 877 of file PunchThroughG4Tool.cxx.

878{
879 constexpr char delimiters = ',';
880 std::vector<T> tokens;
881 // Skip delimiters at beginning.
882 std::string_view::size_type lastPos = str.find_first_not_of(delimiters, 0);
883 // Find first "non-delimiter".
884 std::string_view::size_type pos = str.find_first_of(delimiters, lastPos);
885
886 while (std::string_view::npos != pos || std::string_view::npos != lastPos) {
887 // Found a token, add it to the vector.
888 std::string_view numbStr = str.substr(lastPos, pos - lastPos);
889 T num = -9999;
890 std::from_chars(numbStr.data(), numbStr.data() + numbStr.size(), num);
891 tokens.push_back(num);
892 // Skip delimiters. Note the "not_of"
893 lastPos = str.find_first_not_of(delimiters, pos);
894 // Find next "non-delimiter"
895 pos = str.find_first_of(delimiters, lastPos);
896 }
897 return tokens;
898}