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