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 "XMLCoreParser/XMLCoreParser.h"
#include "XMLCoreParser/XMLCoreNode.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 880 of file PunchThroughG4Tool.cxx.

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