Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  28 Aug 2019, Nick Hastings, Forum, History plot problems for frontend with multiple indicies fedummy.cxxMakefile
    Reply  28 Aug 2019, Stefan Ritt, Forum, History plot problems for frontend with multiple indicies 
       Reply  28 Aug 2019, Nick Hastings, Forum, History plot problems for frontend with multiple indicies 
          Reply  28 Aug 2019, lcp, Forum, History plot problems for frontend with multiple indicies 
             Reply  16 Sep 2019, Konstantin Olchanski, Forum, History plot problems for frontend with multiple indicies 
       Reply  16 Sep 2019, Konstantin Olchanski, Forum, History plot problems for frontend with multiple indicies 
    Reply  29 Aug 2019, Ben Smith, Forum, History plot problems for frontend with multiple indicies 
       Reply  01 Sep 2019, Nick Hastings, Forum, History plot problems for frontend with multiple indicies 
          Reply  16 Sep 2019, Konstantin Olchanski, Forum, History plot problems for frontend with multiple indicies 
             Reply  16 Sep 2019, Nick Hastings, Forum, History plot problems for frontend with multiple indicies 
                Reply  17 Sep 2019, Konstantin Olchanski, Forum, History plot problems for frontend with multiple indicies 
                   Reply  18 Sep 2019, Nick Hastings, Forum, History plot problems for frontend with multiple indicies 
                      Reply  27 Sep 2019, Konstantin Olchanski, Forum, History plot problems for frontend with multiple indicies 
                         Reply  24 Aug 2020, Konstantin Olchanski, Forum, History plot problems for frontend with multiple indicies 
Message ID: 1665     Entry time: 28 Aug 2019     Reply to this: 1666   1669
Author: Nick Hastings 
Topic: Forum 
Subject: History plot problems for frontend with multiple indicies 
Hello experts,

I have been writing a SC frontend for a powersupply. I have used the model 
where the frontend can be started with "-i n" option so that each fe can 
control a different supply. During the development/testing of the program I 
would normally only run a single instance with "-i 1". However when I started
a second instance with "-i 2" I found problems with the history plots that
were being made for the original "-i 1" instance. The variable being plotted
seemed to randomly jump between the value from the "-i 1" instance and 
the "-i 2" instance.  confirmed that the "correct" values exist for each 
frontend in the odb under /Equipment/Foo01/Variables and 
/Equipment/Foo02/Variables

This is also not just a plotting artifact since I was also
able to see the two different values by running mhist.

I saw this behaviour using midas-2019-03 and also the head of the development
branch (686e4de2b55023b0d1936c60bcf4767c5e6caac0 from just under 48 hours ago). 

I was able to reproduce this with a stripped down frontend that just 
sets a variable that is equal to its frontend_index. Please find the code 
and Makefile attached. Presumably I've done something wrong in my 
implementation that hopefully a more experienced person can spot quite 
quickly, but please let me know if any more information is needed.

I have seen this behaviour on both Debian 10 and on a CentOS 7 Singularity 
image running on top of Debian 10.

Thanks,

Nick.

P.S. I made the topic of this post "Forum" and not "Bug Report" since I
expect the root of this problem is somewhere between the keyboard and chair.
Attachment 1: fedummy.cxx  4 kB  Uploaded 28 Aug 2019  | Hide | Hide all
/*******************************************************************\

  Name:         fetest.cxx
  Created by:   

  Contents:     Front end for testing MIDAS. Just sets a variable to
                the value of the frontend index.

\********************************************************************/

#undef NDEBUG // midas required assert() to be always enabled

#include <cassert>
#include "mfe.h"

/*-- Globals -------------------------------------------------------*/

/* The frontend name (client name) as seen by other MIDAS clients   */
const char *frontend_name = "fedummy";

/* The frontend file name, don't change it */
const char *frontend_file_name = __FILE__;

/* frontend_loop is called periodically if this variable is TRUE    */
BOOL frontend_call_loop = FALSE;

/* a frontend status page is displayed with this frequency in ms */
INT display_period = 0;

/* maximum event size produced by this frontend */
INT max_event_size      = 4*1024*1024;
INT max_event_size_frag = 4*1024*1024;

/* buffer size to hold events */
INT event_buffer_size = 10*1024*1024;

/*-- Function declarations -----------------------------------------*/

INT frontend_init();
INT frontend_exit();
INT begin_of_run(INT run_number, char *error);
INT end_of_run(INT run_number, char *error);
INT pause_run(INT run_number, char *error);
INT resume_run(INT run_number, char *error);
INT frontend_loop();
INT poll_event(INT source, INT count, BOOL test);
INT interrupt_configure(INT cmd, INT source, PTYPE adr);

int read_dummy_event(char *pevent, int off);

/*-- Equipment list ------------------------------------------------*/

#ifndef FE_NAME
#define FE_NAME "fedummy"
#endif

#ifndef EQ_NAME
#define EQ_NAME "Dummy"
#endif

#ifndef EQ_EVID
#define EQ_EVID 1
#endif

char eq_name[256];

EQUIPMENT equipment[] = {

  { EQ_NAME "%02d"   ,         /* equipment name */
    {
      EQ_EVID, (1<<EQ_EVID),/* event ID, trigger mask */
      "SYSTEM",             /* event buffer */
      EQ_PERIODIC,          /* equipment type */
      0,                    /* event source */
      "MIDAS",              /* format */
      TRUE,                 /* enabled */
      RO_ALWAYS,            /* Read when running */
      1000,                 /* poll every so milliseconds */
      0,                    /* stop run after this event limit */
      0,                    /* number of sub events */
      1,                    /* history period */
      "", "", ""
    },
    read_dummy_event,/* readout routine */
    NULL,
    NULL,
    NULL,       /* bank list */
  }
  ,
  {""}
};
int event_size = 10*1024;

/*-- Frontend Init -------------------------------------------------*/
#include "msystem.h"

INT frontend_init()
{
   sprintf(eq_name, "%s%02d", EQ_NAME, get_frontend_index());
   return SUCCESS;
}

INT frontend_exit()
{
   return SUCCESS;
}

INT begin_of_run(INT run_number, char *error)
{
   return SUCCESS;
}

INT end_of_run(INT run_number, char *error)
{
   return SUCCESS;
}

INT pause_run(INT run_number, char *error)
{
   return SUCCESS;
}

INT resume_run(INT run_number, char *error)
{
   return SUCCESS;
}

INT frontend_loop()
{
   return SUCCESS;
}

INT poll_event(INT source, INT count, BOOL test)
{
   return 0;
}

INT interrupt_configure(INT cmd, INT source, PTYPE adr)
{
  return 0;
}

INT read_dummy_event(char *pevent, INT off)
{
   static HNDLE hVar = 0;
   if ( hVar == 0 ) {
      char str[1024];
      sprintf(str, "/Equipment/%s/Variables", eq_name);
      
      int status = db_find_key(hDB, 0, str, &hVar);
      if ( status == DB_NO_KEY ) {
         status = db_create_key(hDB, 0, str, TID_KEY);
         if (status == DB_SUCCESS) {
            status = db_find_key(hDB, 0, str, &hVar);
         }
      }
      
      if (status != SUCCESS) {
         cm_msg(MERROR, frontend_name, "read_dummy_event: Can\'t find or create %s, status %d, exiting", str, status);
         exit(1);
      }
   }
   const float data = static_cast<float>(get_frontend_index());
   const int status = db_set_value( hDB, hVar, "Data", &data,
                          sizeof(float), 1, TID_FLOAT);
   assert(status == DB_SUCCESS);
   return 0;
}

/* emacs
 * Local Variables:
 * tab-width: 8
 * c-basic-offset: 3
 * indent-tabs-mode: nil
 * End:
 */
Attachment 2: Makefile  607 Bytes  Uploaded 28 Aug 2019  | Hide | Hide all
OSFLAGS  = -DOS_LINUX -Dextname
CFLAGS   = -g -O2 -fPIC -Wall -Wno-unused-function -I$(MIDASSYS)/include
CXXFLAGS = -std=c++11 $(CFLAGS)

LIBS = -lm -lz -lutil -lnsl -lpthread -lrt
MIDASLIBS = $(MIDASSYS)/lib/libmidas.a
MFE = $(MIDASSYS)/lib/mfe.o

all:: fedummy.exe

fedummy.exe: %.exe: fedummy.cxx $(MIDASLIBS) $(MFE)
	$(CXX) -o $@ $(CXXFLAGS) $(OSFLAGS) $^ $(MIDASLIBS) $(LIBS) -DFE_NAME=\"fedummy\" -DEQ_NAME=\"FeDummy\" -DEQ_EVID=1


%.o: %.cxx
	$(CXX) $(CXXFLAGS) $(OSFLAGS) -c $<

%.d: %.cxx
	$(CXX) -MM -MD $(CXXFLAGS) $(OSFLAGS) -c $<

depend:

-include *.d

clean::
	-rm -f *.o *.exe
	-rm -f *.d

ELOG V3.1.4-2e1708b5