ATLAS Offline Software
Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StringUtils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // StringUtils.h
6 // L1TopoCommon
7 // Created by Christian Ohm
8 
9 #ifndef L1TOPOCOMMON_STRINGUTILS_H
10 #define L1TOPOCOMMON_STRINGUTILS_H
11 
12 // this file contains the following helper functions
13 
14 /*
15  1) binary representation of data
16  * get_binrep
17  * get_binrep_vector
18  * get_binrep_boolvec
19 
20  2) join(vec<str>,char) similar to the python str.join function
21 
22 */
23 
24 #include <sstream>
25 #include <bitset>
26 #include <algorithm>
27 #include <vector>
28 #include <limits.h>
29 
30 namespace TCS {
31 
32  template <class T>
33  inline std::string to_string (const T& t, int precision = -999, int width = -999, bool scientific = false) {
34  std::stringstream ss;
35  if (precision != -999) {
36  ss.precision(precision);
37  }
38  if (width != -999) {
39  ss.width(width);
40  }
41  if (scientific) {
42  ss.setf(std::ios::scientific);
43  }
44  else if (precision != -999)
45  ss.setf(std::ios::fixed);
46  ss << t;
47  return ss.str();
48  }
49 
50  template<typename T>
51  inline std::string get_binrep(const T& a) {
52  std::stringstream ss;
53  const char* beg = reinterpret_cast<const char*>(&a);
54  const char* end = beg + sizeof(a);
55  while(beg != end)
56  ss << std::bitset<CHAR_BIT>(*beg++);
57  return ss.str();
58  }
59 
60  template<typename T>
61  inline std::string get_binrep_vector(const T& a) {
62  std::stringstream ss;
63  for (unsigned int i = 0; i < a.size(); ++i) {
64  ss << get_binrep(a.at(i));
65  }
66  return ss.str();
67  }
68 
69  // for vector<bool> specifically (don't want to convert to 1 char per bit)...
70  inline std::string get_binrep_boolvec(const std::vector<bool>& a) {
71  std::stringstream ss;
72  for (std::vector<bool>::const_iterator it = a.begin(); it != a.end(); ++it)
73  ss << ((*it) ? 1 : 0);
74  return ss.str();
75  }
76 
77  std::string join(const std::vector<std::string>& v, const char c=',');
78 
79 } // end of namespace TCS
80 
81 #endif // not L1TOPOCOMMON_STRINGUTILS_H
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TCS::to_string
std::string to_string(const T &t, int precision=-999, int width=-999, bool scientific=false)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StringUtils.h:33
skel.it
it
Definition: skel.GENtoEVGEN.py:423
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
lumiFormat.i
int i
Definition: lumiFormat.py:92
TCS::get_binrep_boolvec
std::string get_binrep_boolvec(const std::vector< bool > &a)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StringUtils.h:70
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
python.PyAthena.v
v
Definition: PyAthena.py:157
a
TList * a
Definition: liststreamerinfos.cxx:10
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
TCS::get_binrep
std::string get_binrep(const T &a)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StringUtils.h:51
TCS
Definition: Global/GlobalSimulation/src/IO/Decision.h:18
TCS::get_binrep_vector
std::string get_binrep_vector(const T &a)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StringUtils.h:61
python.compressB64.c
def c
Definition: compressB64.py:93