Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:34

0001 
0002 #include "filter_msg_buffer.h"
0003 
0004 // in the constructor we allocate the specified amount of bytes for
0005 // the output array.
0006 
0007 filter_msg_buffer::filter_msg_buffer(const int msglen)
0008   : msg_buffer(msglen)
0009 {
0010   // in the constructor we replace COUT's streambuf with this one.
0011   // we remember the old one because we may want to replace it.
0012 
0013 #ifdef RDBUF_ACCEPTS_STREAMBUF
0014   original_streambuf = COUT.rdbuf ( (STREAMBUF *) this);
0015 #else
0016   original_streambuf = COUT.rdbuf ();
0017     COUT = (STREAMBUF *) this;
0018 #endif
0019 
0020   int i,j,k;
0021   msg_type_max = MSG_TYPE_MAX;
0022   msg_source_max = MSG_SOURCE_MAX;
0023   msg_sev_max = MSG_SEV_MAX;
0024 
0025   // allocate new memory for the matrix
0026   state = new int **[msg_type_max];
0027   for (i=0; i< msg_type_max; i++)
0028     {
0029       state[i] = new int* [msg_source_max];
0030       for ( j =0; j<msg_source_max; j++) state[i][j] = new int [msg_sev_max];
0031     }
0032 
0033   for (i=0; i < msg_type_max; i++)
0034     for (j=0; j < msg_source_max ; j++)
0035       for (k=0; k < msg_sev_max ; k++)
0036     state[i][j][k] = ON;
0037 }
0038 
0039 filter_msg_buffer::filter_msg_buffer(const int type_max, const int source_max, 
0040              const int sev_max, const int msglen)
0041   : msg_buffer(msglen)
0042 {
0043   // in the constructor we replace COUT's streambuf with this one.
0044   // we remember the old one because we may want to replace it.
0045 #ifdef RDBUF_ACCEPTS_STREAMBUF
0046   original_streambuf = COUT.rdbuf ( (STREAMBUF *) this);
0047 #else
0048   original_streambuf = COUT.rdbuf ();
0049     COUT = (STREAMBUF *) this;
0050 #endif
0051 
0052   int i,j,k;
0053   msg_type_max = type_max;
0054   msg_source_max = source_max;
0055   msg_sev_max = sev_max;
0056 
0057   // allocate new memory for the matrix
0058   state = new int **[msg_type_max];
0059   for (i=0; i< msg_type_max; i++)
0060     {
0061       state[i] = new int* [msg_source_max];
0062       for ( j =0; j<msg_source_max; j++) state[i][j] = new int [msg_sev_max];
0063     }
0064 
0065   for (i=0; i < msg_type_max; i++)
0066     for (j=0; j < msg_source_max ; j++)
0067       for (k=0; k < msg_sev_max ; k++)
0068     state[i][j][k] = ON;
0069 }
0070 
0071 
0072 
0073 // in the destructor, we restore the original streambuf for COUT.
0074 filter_msg_buffer::~filter_msg_buffer()
0075 {
0076 #ifdef RDBUF_ACCEPTS_STREAMBUF
0077   COUT.rdbuf ( original_streambuf);
0078 #else
0079   COUT= original_streambuf;
0080 #endif
0081 
0082   // free memory from the matrix
0083   int i,j;
0084   for (i=0; i< msg_type_max; i++)
0085     {
0086       for ( j =0; j<msg_source_max; j++) delete [] state[i][j];
0087       delete [] state[i] ;
0088     }
0089   delete [] state;
0090 
0091 }
0092 
0093 // this is the function which is called as a result of the << std::endl 
0094 // and flush() operations
0095 int filter_msg_buffer::sync ()
0096 { 
0097 
0098   msgProfile mp;
0099   int length, ix;
0100 
0101 
0102   char *x = format(&length, &mp);
0103   int ret = 0;
0104 
0105   if ( state[mp.type][mp.source][mp.severity] )
0106     {
0107 #if defined(LVL2_WINNT) || defined(STREAMBUF_NEW_IOSTREAM)
0108       for (ix =0; ix < length; ix++)
0109     original_streambuf->sputc( x[ix] );
0110       ret = original_streambuf->pubsync();
0111 #else
0112       for (ix =0; ix < length; ix++)
0113     original_streambuf->overflow( x[ix] );
0114       ret = original_streambuf->sync();
0115 #endif
0116     }
0117   delete [] x;
0118 
0119   pos = 0;
0120   
0121   return ret;
0122 }
0123 
0124 int filter_msg_buffer::set (const int type, 
0125       const int source,
0126       const int severity,
0127       const int value)
0128 {
0129 
0130   if ( type < 0 ||  type >= msg_type_max) return -1;  
0131   if ( source < 0 ||  source>= msg_source_max) return -2;
0132   if ( severity < 0 ||  severity>= msg_sev_max) return -3;
0133 
0134 
0135 
0136   state[type][source][severity] = value;
0137   return 0;
0138 }
0139 
0140 int filter_msg_buffer::set_severity_below_threshold(const int threshold,
0141                             const int value)
0142 {
0143   if ( threshold < 0 ||  threshold >= msg_sev_max) return -1;
0144 
0145   int i,j,k;
0146 
0147     // leave type = 0 (UNSPECIFIED) untouched
0148   for (i=1; i < msg_type_max; i++)
0149     for (j=0; j < msg_source_max ; j++)
0150       for (k=0; k < threshold ; k++)
0151                 state[i][j][k] = value;
0152   return 0;
0153 }
0154 
0155 int filter_msg_buffer::set_type (const int type,
0156                  const int value)
0157 {
0158   if ( type < 0 ||  type >= msg_type_max) return -1;
0159 
0160   int j,k;
0161     for (j=0; j < msg_source_max ; j++)
0162       for (k=0; k < msg_sev_max ; k++)
0163     state[type][j][k] = value;
0164   return 0;
0165 }
0166 
0167 int filter_msg_buffer::set_source (const int source,
0168                  const int value)
0169 {
0170   if ( source< 0 ||  source >= msg_type_max) return -1;
0171 
0172   int i,k;
0173   for (i=0; i < msg_type_max; i++)
0174       for (k=0; k < msg_sev_max ; k++)
0175     state [i] [source] [k] = value;
0176   return 0;
0177 }
0178 
0179 
0180 int filter_msg_buffer::all_off()
0181 {
0182   int i,j,k;
0183   for (i=1; i < msg_type_max; i++)
0184     for (j=0; j < msg_source_max ; j++)
0185       for (k=0; k < msg_sev_max ; k++)
0186                 state[i][j][k] = OFF;
0187   return 0;
0188 }
0189 
0190 int filter_msg_buffer::all_on()
0191 {
0192   int i,j,k;
0193   for (i=0; i < msg_type_max; i++)
0194     for (j=0; j < msg_source_max ; j++)
0195       for (k=0; k < msg_sev_max ; k++)
0196     state[i][j][k] = ON;
0197   return 0;
0198 }