Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filter_msg_buffer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file filter_msg_buffer.cc
1 
2 #include "filter_msg_buffer.h"
3 
4 // in the constructor we allocate the specified amount of bytes for
5 // the output array.
6 
8  : msg_buffer(msglen)
9 {
10  // in the constructor we replace COUT's streambuf with this one.
11  // we remember the old one because we may want to replace it.
12 
13 #ifdef RDBUF_ACCEPTS_STREAMBUF
14  original_streambuf = COUT.rdbuf ( (STREAMBUF *) this);
15 #else
16  original_streambuf = COUT.rdbuf ();
17  COUT = (STREAMBUF *) this;
18 #endif
19 
20  int i,j,k;
24 
25  // allocate new memory for the matrix
26  state = new int **[msg_type_max];
27  for (i=0; i< msg_type_max; i++)
28  {
29  state[i] = new int* [msg_source_max];
30  for ( j =0; j<msg_source_max; j++) state[i][j] = new int [msg_sev_max];
31  }
32 
33  for (i=0; i < msg_type_max; i++)
34  for (j=0; j < msg_source_max ; j++)
35  for (k=0; k < msg_sev_max ; k++)
36  state[i][j][k] = ON;
37 }
38 
39 filter_msg_buffer::filter_msg_buffer(const int type_max, const int source_max,
40  const int sev_max, const int msglen)
41  : msg_buffer(msglen)
42 {
43  // in the constructor we replace COUT's streambuf with this one.
44  // we remember the old one because we may want to replace it.
45 #ifdef RDBUF_ACCEPTS_STREAMBUF
46  original_streambuf = COUT.rdbuf ( (STREAMBUF *) this);
47 #else
48  original_streambuf = COUT.rdbuf ();
49  COUT = (STREAMBUF *) this;
50 #endif
51 
52  int i,j,k;
53  msg_type_max = type_max;
54  msg_source_max = source_max;
55  msg_sev_max = sev_max;
56 
57  // allocate new memory for the matrix
58  state = new int **[msg_type_max];
59  for (i=0; i< msg_type_max; i++)
60  {
61  state[i] = new int* [msg_source_max];
62  for ( j =0; j<msg_source_max; j++) state[i][j] = new int [msg_sev_max];
63  }
64 
65  for (i=0; i < msg_type_max; i++)
66  for (j=0; j < msg_source_max ; j++)
67  for (k=0; k < msg_sev_max ; k++)
68  state[i][j][k] = ON;
69 }
70 
71 
72 
73 // in the destructor, we restore the original streambuf for COUT.
75 {
76 #ifdef RDBUF_ACCEPTS_STREAMBUF
77  COUT.rdbuf ( original_streambuf);
78 #else
80 #endif
81 
82  // free memory from the matrix
83  int i,j;
84  for (i=0; i< msg_type_max; i++)
85  {
86  for ( j =0; j<msg_source_max; j++) delete [] state[i][j];
87  delete [] state[i] ;
88  }
89  delete [] state;
90 
91 }
92 
93 // this is the function which is called as a result of the << std::endl
94 // and flush() operations
96 {
97 
98  msgProfile mp;
99  int length, ix;
100 
101 
102  char *x = format(&length, &mp);
103  int ret = 0;
104 
105  if ( state[mp.type][mp.source][mp.severity] )
106  {
107 #if defined(LVL2_WINNT) || defined(STREAMBUF_NEW_IOSTREAM)
108  for (ix =0; ix < length; ix++)
109  original_streambuf->sputc( x[ix] );
110  ret = original_streambuf->pubsync();
111 #else
112  for (ix =0; ix < length; ix++)
113  original_streambuf->overflow( x[ix] );
114  ret = original_streambuf->sync();
115 #endif
116  }
117  delete [] x;
118 
119  pos = 0;
120 
121  return ret;
122 }
123 
124 int filter_msg_buffer::set (const int type,
125  const int source,
126  const int severity,
127  const int value)
128 {
129 
130  if ( type < 0 || type >= msg_type_max) return -1;
131  if ( source < 0 || source>= msg_source_max) return -2;
132  if ( severity < 0 || severity>= msg_sev_max) return -3;
133 
134 
135 
136  state[type][source][severity] = value;
137  return 0;
138 }
139 
141  const int value)
142 {
143  if ( threshold < 0 || threshold >= msg_sev_max) return -1;
144 
145  int i,j,k;
146 
147  // leave type = 0 (UNSPECIFIED) untouched
148  for (i=1; i < msg_type_max; i++)
149  for (j=0; j < msg_source_max ; j++)
150  for (k=0; k < threshold ; k++)
151  state[i][j][k] = value;
152  return 0;
153 }
154 
156  const int value)
157 {
158  if ( type < 0 || type >= msg_type_max) return -1;
159 
160  int j,k;
161  for (j=0; j < msg_source_max ; j++)
162  for (k=0; k < msg_sev_max ; k++)
163  state[type][j][k] = value;
164  return 0;
165 }
166 
168  const int value)
169 {
170  if ( source< 0 || source >= msg_type_max) return -1;
171 
172  int i,k;
173  for (i=0; i < msg_type_max; i++)
174  for (k=0; k < msg_sev_max ; k++)
175  state [i] [source] [k] = value;
176  return 0;
177 }
178 
179 
181 {
182  int i,j,k;
183  for (i=1; i < msg_type_max; i++)
184  for (j=0; j < msg_source_max ; j++)
185  for (k=0; k < msg_sev_max ; k++)
186  state[i][j][k] = OFF;
187  return 0;
188 }
189 
191 {
192  int i,j,k;
193  for (i=0; i < msg_type_max; i++)
194  for (j=0; j < msg_source_max ; j++)
195  for (k=0; k < msg_sev_max ; k++)
196  state[i][j][k] = ON;
197  return 0;
198 }