CMS 3D CMS Logo

MsgTools.h
Go to the documentation of this file.
1 #ifndef IOPool_Streamer_MsgTools_h
2 #define IOPool_Streamer_MsgTools_h
3 
4 #include <vector>
5 #include <string>
6 #include <sstream>
7 #include <iterator>
9 
10 // could just use the c99 names here from stdint.h
11 typedef unsigned char uint8;
12 typedef unsigned short uint16;
13 typedef unsigned int uint32;
14 typedef unsigned long long uint64;
15 typedef unsigned char char_uint64[sizeof(uint64)];
16 typedef unsigned char char_uint32[sizeof(uint32)];
17 typedef unsigned char char_uint16[sizeof(uint16)];
18 typedef std::vector<std::string> Strings;
19 
21  // first four bytes are code, LSB first
22  unsigned long long a = v[0], b = v[1], c = v[2], d = v[3];
23  unsigned long long e = v[4], f = v[5], g = v[6], h = v[7];
24  a |= (b << 8) | (c << 16) | (d << 24) | (e << 32) | (f << 40) | (g << 48) | (h << 56);
25  return a;
26 }
27 
29  // first four bytes are code, LSB first
30  unsigned int a = v[0], b = v[1], c = v[2], d = v[3];
31  a |= (b << 8) | (c << 16) | (d << 24);
32  return a;
33 }
34 
36  // first four bytes are code, LSB first
37  unsigned int a = v[0], b = v[1];
38  a |= (b << 8);
39  return a;
40 }
41 
42 inline void convert(uint32 i, char_uint32 v) {
43  v[0] = i & 0xff;
44  v[1] = (i >> 8) & 0xff;
45  v[2] = (i >> 16) & 0xff;
46  v[3] = (i >> 24) & 0xff;
47 }
48 
49 inline void convert(uint16 i, char_uint16 v) {
50  v[0] = i & 0xff;
51  v[1] = (i >> 8) & 0xff;
52 }
53 
54 inline void convert(uint64 li, char_uint64 v) {
55  v[0] = li & 0xff;
56  v[1] = (li >> 8) & 0xff;
57  v[2] = (li >> 16) & 0xff;
58  v[3] = (li >> 24) & 0xff;
59  v[4] = (li >> 32) & 0xff;
60  v[5] = (li >> 40) & 0xff;
61  v[6] = (li >> 48) & 0xff;
62  v[7] = (li >> 56) & 0xff;
63 }
64 
65 namespace MsgTools {
66 
67  inline uint8* fillNames(const Strings& names, uint8* pos) {
68  uint32 sz = names.size();
69  convert(sz, pos); // save number of strings
70  uint8* len_pos = pos + sizeof(char_uint32); // area for length
71  pos = len_pos + sizeof(char_uint32); // area for full string of names
72  bool first = true;
73 
74  for (Strings::const_iterator beg = names.begin(); beg != names.end(); ++beg) {
75  if (first)
76  first = false;
77  else
78  *pos++ = ' ';
79  pos = edm::copy_all(*beg, pos);
80  }
81  convert((uint32)(pos - len_pos - sizeof(char_uint32)), len_pos);
82  return pos;
83  }
84 
85  inline void getNames(uint8* from, uint32 from_len, Strings& to) {
86  // not the most efficient way to do this
87  std::istringstream ist(std::string(reinterpret_cast<char*>(from), from_len));
88  typedef std::istream_iterator<std::string> Iter;
89  std::copy(Iter(ist), Iter(), std::back_inserter(to));
90  }
91 
92 } // namespace MsgTools
93 
94 #endif
edm::copy_all
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
mps_fire.i
i
Definition: mps_fire.py:428
char_uint64
unsigned char char_uint64[sizeof(uint64)]
Definition: MsgTools.h:15
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
uint8
unsigned char uint8
Definition: MsgTools.h:11
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
pos
Definition: PixelAliasList.h:18
Algorithms.h
to
char_uint32
unsigned char char_uint32[sizeof(uint32)]
Definition: MsgTools.h:16
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Strings
std::vector< std::string > Strings
Definition: MsgTools.h:18
dqmdumpme.first
first
Definition: dqmdumpme.py:55
uint32
unsigned int uint32
Definition: MsgTools.h:13
MsgTools
Definition: MsgTools.h:65
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
uint16
unsigned short uint16
Definition: MsgTools.h:12
MsgTools::fillNames
uint8 * fillNames(const Strings &names, uint8 *pos)
Definition: MsgTools.h:67
convert32
uint32 convert32(char_uint32 v)
Definition: MsgTools.h:28
h
char_uint16
unsigned char char_uint16[sizeof(uint16)]
Definition: MsgTools.h:17
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
a
double a
Definition: hdecay.h:119
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
convert64
uint64 convert64(char_uint64 v)
Definition: MsgTools.h:20
uint64
unsigned long long uint64
Definition: MsgTools.h:14
ztail.d
d
Definition: ztail.py:151
convert16
uint16 convert16(char_uint16 v)
Definition: MsgTools.h:35
MsgTools::getNames
void getNames(uint8 *from, uint32 from_len, Strings &to)
Definition: MsgTools.h:85
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
convert
void convert(uint32 i, char_uint32 v)
Definition: MsgTools.h:42