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 namespace edm::streamer {
11  // could just use the c99 names here from stdint.h
12  typedef unsigned char uint8;
13  typedef unsigned short uint16;
14  typedef unsigned int uint32;
15  typedef unsigned long long uint64;
16  typedef unsigned char char_uint64[sizeof(uint64)];
17  typedef unsigned char char_uint32[sizeof(uint32)];
18  typedef unsigned char char_uint16[sizeof(uint16)];
19  typedef std::vector<std::string> Strings;
20 
22  // first four bytes are code, LSB first
23  unsigned long long a = v[0], b = v[1], c = v[2], d = v[3];
24  unsigned long long e = v[4], f = v[5], g = v[6], h = v[7];
25  a |= (b << 8) | (c << 16) | (d << 24) | (e << 32) | (f << 40) | (g << 48) | (h << 56);
26  return a;
27  }
28 
30  // first four bytes are code, LSB first
31  unsigned int a = v[0], b = v[1], c = v[2], d = v[3];
32  a |= (b << 8) | (c << 16) | (d << 24);
33  return a;
34  }
35 
37  // first four bytes are code, LSB first
38  unsigned int a = v[0], b = v[1];
39  a |= (b << 8);
40  return a;
41  }
42 
43  inline void convert(uint32 i, char_uint32 v) {
44  v[0] = i & 0xff;
45  v[1] = (i >> 8) & 0xff;
46  v[2] = (i >> 16) & 0xff;
47  v[3] = (i >> 24) & 0xff;
48  }
49 
50  inline void convert(uint16 i, char_uint16 v) {
51  v[0] = i & 0xff;
52  v[1] = (i >> 8) & 0xff;
53  }
54 
55  inline void convert(uint64 li, char_uint64 v) {
56  v[0] = li & 0xff;
57  v[1] = (li >> 8) & 0xff;
58  v[2] = (li >> 16) & 0xff;
59  v[3] = (li >> 24) & 0xff;
60  v[4] = (li >> 32) & 0xff;
61  v[5] = (li >> 40) & 0xff;
62  v[6] = (li >> 48) & 0xff;
63  v[7] = (li >> 56) & 0xff;
64  }
65 
66  namespace MsgTools {
67 
68  inline uint8* fillNames(const Strings& names, uint8* pos) {
69  uint32 sz = names.size();
70  convert(sz, pos); // save number of strings
71  uint8* len_pos = pos + sizeof(char_uint32); // area for length
72  pos = len_pos + sizeof(char_uint32); // area for full string of names
73  bool first = true;
74 
75  for (Strings::const_iterator beg = names.begin(); beg != names.end(); ++beg) {
76  if (first)
77  first = false;
78  else
79  *pos++ = ' ';
80  pos = edm::copy_all(*beg, pos);
81  }
82  convert((uint32)(pos - len_pos - sizeof(char_uint32)), len_pos);
83  return pos;
84  }
85 
86  inline void getNames(uint8* from, uint32 from_len, Strings& to) {
87  // not the most efficient way to do this
88  std::istringstream ist(std::string(reinterpret_cast<char*>(from), from_len));
89  typedef std::istream_iterator<std::string> Iter;
90  std::copy(Iter(ist), Iter(), std::back_inserter(to));
91  }
92 
93  } // namespace MsgTools
94 } // namespace edm::streamer
95 #endif
uint16 convert16(char_uint16 v)
Definition: MsgTools.h:36
unsigned char char_uint16[sizeof(uint16)]
Definition: MsgTools.h:18
void convert(uint32 i, char_uint32 v)
Definition: MsgTools.h:43
uint64 convert64(char_uint64 v)
Definition: MsgTools.h:21
unsigned char char_uint64[sizeof(uint64)]
Definition: MsgTools.h:16
uint8 * fillNames(const Strings &names, uint8 *pos)
Definition: MsgTools.h:68
uint32 convert32(char_uint32 v)
Definition: MsgTools.h:29
const std::string names[nVars_]
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
unsigned char uint8
Definition: MsgTools.h:12
double f[11][100]
d
Definition: ztail.py:151
void getNames(uint8 *from, uint32 from_len, Strings &to)
Definition: MsgTools.h:86
double b
Definition: hdecay.h:120
unsigned long long uint64
Definition: MsgTools.h:15
unsigned char char_uint32[sizeof(uint32)]
Definition: MsgTools.h:17
std::vector< std::string > Strings
Definition: MsgTools.h:19
Func copy_all(ForwardSequence &s, Func f)
wrappers for copy
Definition: Algorithms.h:20
double a
Definition: hdecay.h:121
unsigned short uint16
Definition: MsgTools.h:13
unsigned int uint32
Definition: MsgTools.h:14
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T first(std::pair< T, U > const &p)