Back Midas Rome Roody Rootana
  Midas DAQ System, Page 39 of 145  Not logged in ELOG logo
ID Date Author Topic Subject
  2157   29 Apr 2021 Pierre-Andre AmaudruzSuggestionTime zone selection for web page
> > The new history as well as the clock in the web page header show the local time 
> > of the user's computer running the browser.
> > Would it be possible to make it either always use the time zone of the Midas 
> > server, or make it selectable from the config page?
> > It's not ideal trying to relate error messages from the midas.log to history 
> > plots if the time stamps don't match.
> 
> I implemented a new row in the config page to select the time zone. 
> 
> "Local": Time zone where the browser runs
> "Server": Time zone where the midas server runs (you have to update mhttpd for that)
> "UTC+X": Any other time zone
> 
> The setting affects both the status header and the history display.
> 
> I spent quite some time with "named" time zones like "PST" "EST" "CEST", but the 
> support for that is not that great in JavaScript, so I decided to go with simple 
> UTC+X. Hope that's ok.
> 
> Please give it a try and let me know if it's working for you.
> 
> Best,
> Stefan

Hi Stefan,

This is great, the UTC+x is perfect, thank you.
PAA
  2156   26 Apr 2021 Zaher SalmanSuggestionembed modbvalue in SVG
I found a way to embed modbvalue into a SVG:

<text x="100" y="100" font-size="30rem">
Run=<tspan class="modbvalue" data-odb-path="/Runinfo/Run number"></tspan>
</text>

This seems to behave better that the suggestion below.

> You can't really embed it, but you can overlay it. You tag the SVG with a 
> "relative" position and then move the modbvalue with an "absolute" position over 
> it:
> 
> <svg style="position:relative" width="400" height="100">
>   <rect width="300" height="100" style="fill:rgb(255,0,0);stroke-width:3;stroke:rgb(0,0,0)" />
>   <div class="modbvalue" style="position:absolute;top:50px;left:50px" data-odb-path="/Runinfo/Run number"></div>
> </svg>
  2155   14 Apr 2021 Stefan RittBug ReportMinor bug: Change all time axes together doesn't work with +- buttons
> Version: release/midas-2020-12
> 
> In the new history display, the checkbox "Change all time axes together" works 
> well with the mouse-based zoom, but does not apply to the +- buttons.

Fixed in current commit.

Stefan
  2154   14 Apr 2021 Stefan RittBug ReportTime shift in history CSV export
I finally found some time to fix this issue in the latest commit. Please update and check if it's 
working for you.

Stefan
  2153   14 Apr 2021 Stefan RittInfoINT64/UINT64/QWORD not permitted in ODB and history... Change of TID_xxx data types
> These 64-bit data types do not work with ODB and they do not work with the MIDAS history.

They were never meant to work with the history. They were primarily implemented to put large 64-
bit data words into midas banks. We did not yet have a request to put these values into the ODB. 
Once such a request comes, we can address this.

Stefan
  2152   14 Apr 2021 Stefan RittSuggestionTime zone selection for web page
> The new history as well as the clock in the web page header show the local time 
> of the user's computer running the browser.
> Would it be possible to make it either always use the time zone of the Midas 
> server, or make it selectable from the config page?
> It's not ideal trying to relate error messages from the midas.log to history 
> plots if the time stamps don't match.

I implemented a new row in the config page to select the time zone. 

"Local": Time zone where the browser runs
"Server": Time zone where the midas server runs (you have to update mhttpd for that)
"UTC+X": Any other time zone

The setting affects both the status header and the history display.

I spent quite some time with "named" time zones like "PST" "EST" "CEST", but the 
support for that is not that great in JavaScript, so I decided to go with simple 
UTC+X. Hope that's ok.

Please give it a try and let me know if it's working for you.

Best,
Stefan
Attachment 1: Screenshot_2021-04-14_at_16.54.12_.png
Screenshot_2021-04-14_at_16.54.12_.png
  2151   13 Apr 2021 Stefan RittForumClient gets immediately removed when using a script button.
> I have followed your suggestions and the program still stops immediately. My status as returned from "cm_yield(100)" is always 412 (SS_TIMEOUT) which is fine. 
> The issue is that, when run with the script button, the do-wile loop stops immediately because the !ss_kbhit() always evaluates to FALSE.
> 
> My temporary solution has been to let the loop run forever :)

Ahh, could be that ss_kbhit() misbehaves if there is no keyboard, meaning that it is started in the background as a script. 
We never had the issue before, since all "standard" midas programs like mlogger, mhttpd etc. also use ss_kbhit() and they 
can be started in the background via the "-D" flag, but maybe the stdin is then handled differentlhy. 

So just remove the ss_kbhit(), but keep the break, so that you can stop your program via the web page, like

#include "midas.h"
#include "stdio.h"

int main() {
  cm_connect_experiment("", "", "logic_controller", NULL);

  do {
    int status = cm_yield(100);
    printf("cm_yield returned %d\n", status);
    if (status == SS_ABORT || status == RPC_SHUTDOWN)
      break;
  } while (TRUE);

  cm_disconnect_experiment();

  return 0;
}
  2150   13 Apr 2021 Konstantin OlchanskiInfobk_init32a data format
Until commit a4043ceacdf241a2a98aeca5edf40613a6c0f575 today, mdump mostly did not work with bank32a data.
K.O.


> In April 4th 2020 Stefan added a new data format that fixes the well known problem with alternating banks being 
> misaligned against 64-bit addresses. (cannot find announcement on this forum. midas commit 
> https://bitbucket.org/tmidas/midas/commits/541732ea265edba63f18367c7c9b8c02abbfc96e)
> 
> This brings the number of midas data formats to 3:
> 
> bk_init: bank_header_flags set to 0x0000001 (BANK_FORMAT_VERSION)
> bk_init32: bank_header_flags set to 0x0000011 (BANK_FORMAT_VERSION | BANK_FORMAT_32BIT)
> bk_init32a: bank_header_flags set to 0x0000031 (BANK_FORMAT_VERSION | BANK_FORMAT_32BIT | BANK_FORMAT_64BIT_ALIGNED;
> 
> TMEvent (midasio and manalyzer) support for "bk_init32a" format added today (commit 
> https://bitbucket.org/tmidas/midasio/commits/61b7f07bc412ea45ed974bead8b6f1a9f2f90868)
> 
> TMidasEvent (rootana) support for "bk_init32a" format added today (commit 
> https://bitbucket.org/tmidas/rootana/commits/3f43e6d30daf3323106a707f6a7ca2c8efb8859f)
> 
> ROOTANA should be able to handle bk_init32a() data now.
> 
> TMFE MIDAS c++ frontend switched from bk_init32() to bk_init32a() format (midas commit 
> https://bitbucket.org/tmidas/midas/commits/982c9c2f8b1e329891a782bcc061d4c819266fcc)
> 
> K.O.
  2149   13 Apr 2021 Isaac Labrie BoulayForumClient gets immediately removed when using a script button.
> I think it would be useful to find the minimal example that exhibits this behaviour.
> 
> What happens if your logic controller code is simply the 17 lines below? What happens if you create another script button that only starts the logic controller, not any of the other programs? etc. Gradually re-add features until you hit the problem (or scream in horror if it breaks with 17 lines of C++ and a 1 line shell script).
> 

Hi Ben,

I have followed your suggestions and the program still stops immediately. My status as returned from "cm_yield(100)" is always 412 (SS_TIMEOUT) which is fine. 
The issue is that, when run with the script button, the do-wile loop stops immediately because the !ss_kbhit() always evaluates to FALSE.

My temporary solution has been to let the loop run forever :)

Let me know what think. Thanks again!

Isaac

> 
> 
> #include "midas.h"
> #include "stdio.h"
> 
> int main() {
>    cm_connect_experiment("", "", "logic_controller", NULL);
> 
>    do {
>      int status = cm_yield(100);
>      printf("cm_yield returned %d\n", status);
>      if (status == SS_ABORT || status == RPC_SHUTDOWN)
>        break;
>    } while (!ss_kbhit());
> 
>    cm_disconnect_experiment();
> 
>    return 0;
> }
  2148   12 Apr 2021 Ben SmithForumClient gets immediately removed when using a script button.
I think it would be useful to find the minimal example that exhibits this behaviour.

What happens if your logic controller code is simply the 17 lines below? What happens if you create another script button that only starts the logic controller, not any of the other programs? etc. Gradually re-add features until you hit the problem (or scream in horror if it breaks with 17 lines of C++ and a 1 line shell script).



#include "midas.h"
#include "stdio.h"

int main() {
   cm_connect_experiment("", "", "logic_controller", NULL);

   do {
     int status = cm_yield(100);
     printf("cm_yield returned %d\n", status);
     if (status == SS_ABORT || status == RPC_SHUTDOWN)
       break;
   } while (!ss_kbhit());

   cm_disconnect_experiment();

   return 0;
}
  2147   12 Apr 2021 Isaac Labrie BoulayForumClient gets immediately removed when using a script button.
> > if I use the script button, the logic_controller program is immediately deleted by MIDAS.
> 
> This is indeed very curious, and I can't reproduce it on my test experiment. Can you redirect stdout and stderr from the logic_controller program into a file, to see how far the program gets? If it gets to the while loop at the end, then it would be useful to add some debug statements to see what condition causes it to exit the loop.

I have redirected stdout and stderr into a text file and I have attached it to this entry. From what the stdout says, it seems that the lambda
function gets called 4 times before the program disconnects from the experiment. Somehow the status must become SS_ABORT or RPC_SHUTDOWN.

> Are there any relevant messages in the midas message log about the program being killed? What's the value of "/Programs/logic_controller/Watchdog timeout"? 

There are no interesting messages in the midas.log and "/Programs/logic_controller/Watchdog timeout" is 10000 when I run the command from the terminal window.
What happens when you run it on your test experiment?

I'll try some more debugging.

Thanks for helping me out! Cheers.

Isaac
Attachment 1: debug_logic_controller.txt
Get definition for ODB key "/Modules/Logic"
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
Firmware version: 0
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get ODB key "/Modules/Logic/Default/width": 200
Get ODB key "/Modules/Logic/Default/delay": 10
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic"
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
Get definition for ODB key "/Modules/Logic/QDCGateA"
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/width"
Get ODB key "/Modules/Logic/QDCGateA/width": 200
Get definition for ODB key "/Modules/Logic/QDCGateA/delay"
Get ODB key "/Modules/Logic/QDCGateA/delay": 10
Get definition for ODB key "/Modules/Logic/QDCGateA/scale"
Get ODB key "/Modules/Logic/QDCGateA/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate"
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/TDCGate/width"
Get ODB key "/Modules/Logic/TDCGate/width": 200
Get definition for ODB key "/Modules/Logic/TDCGate/delay"
Get ODB key "/Modules/Logic/TDCGate/delay": 10
Get definition for ODB key "/Modules/Logic/TDCGate/scale"
Get ODB key "/Modules/Logic/TDCGate/scale": 200
Get definition for ODB key "/Modules/Logic/Default"
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/Default/width"
Get ODB key "/Modules/Logic/Default/width": 200
Get definition for ODB key "/Modules/Logic/Default/delay"
Get ODB key "/Modules/Logic/Default/delay": 10
Get definition for ODB key "/Modules/Logic/Default/scale"
Get ODB key "/Modules/Logic/Default/scale": 200
Get definition for ODB key "/Modules/Logic/V2495 Handle"
Get ODB key "/Modules/Logic/V2495 Handle": 0
  2146   12 Apr 2021 Ben SmithForumClient gets immediately removed when using a script button.
> if I use the script button, the logic_controller program is immediately deleted by MIDAS.

This is indeed very curious, and I can't reproduce it on my test experiment. Can you redirect stdout and stderr from the logic_controller program into a file, to see how far the program gets? If it gets to the while loop at the end, then it would be useful to add some debug statements to see what condition causes it to exit the loop.

Are there any relevant messages in the midas message log about the program being killed? What's the value of "/Programs/logic_controller/Watchdog timeout"? 
  2145   12 Apr 2021 Isaac Labrie BoulayForumClient gets immediately removed when using a script button.
Hi all,

I'm running into a curious problem when I try to run a program using my custom 
script button. I have been using a script button to start my DAQ, this button 
has always worked. It starts by exporting an absolute path to scripts and then 
runs scripts, my frontend, my analyzer, and mlogger relative to this path.

I recently added a line of code to run a new script "logic_controller". If I run 
the script_daq from my terminal (./start_daq), mhttpd accepts the client and the 
program works as intended. But, if I use the script button, the logic_controller 
program is immediately deleted by MIDAS. It can be seen appearing in the status 
page clients list and then immediately gets deleted. This is a client that runs 
on the local experiment host.

What might be the issue? What is the difference between running the script 
through the terminal as opposed to running it through the mhttpd button?

I have added a picture of my simple script and the logic_controller code.

Any help would be greatly appreciated.

Cheers.

Isaac
Attachment 1: logicCtrl.cpp
//
// Isaac Labrie-Boulay
//
// Program that enables the modification of gate and delay values 
// in the logic unit
//
// Last Edit: 2021-030-29
//

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <iostream>

using namespace std;

#include "CAEN_PLULib.h"
#include "midas.h"
#include "assert.h"
#include "mfe.h"
#include "mvmestd.h"
#include "odbxx.h"
//#include "CAEN_PLULib_TEST.h"

#ifdef WIN32 // Windows
#include <windows.h>
#include <conio.h>
#else // Linux
#define _popen popen
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>

char _getch() {
        char buf = 0;
        struct termios old = { 0 };
        fflush(stdout);
        if (tcgetattr(0, &old)<0)
                perror("tcsetattr()");
        old.c_lflag &= ~ICANON;
        old.c_lflag &= ~ECHO;
        old.c_cc[VMIN] = 1;
        old.c_cc[VTIME] = 0;
        if (tcsetattr(0, TCSANOW, &old)<0)
                perror("tcsetattr ICANON");
        if (read(0, &buf, 1)<0)
                perror("read()");
        old.c_lflag |= ICANON;
        old.c_lflag |= ECHO;
        if (tcsetattr(0, TCSADRAIN, &old)<0)
                perror("tcsetattr ~ICANON");
        printf("%c\n", buf);
        return buf;
}
#endif

char *base_address = "32100000";


void err_check(CAEN_PLU_ERROR_CODE err);

int main()
{

	cm_connect_experiment("", "", "logic_controller", NULL);
   	midas::odb::set_debug(true);

	//Establish a connection with the unit through the V1718
	int handle;
	CAEN_PLU_ERROR_CODE err_code;

	err_code = CAEN_PLU_OpenDevice(CAEN_PLU_CONNECT_VME_V1718, base_address, 0, 0, &handle);
	err_check(err_code);

	//Create an ODB key to hold the V2495 handle
	midas::odb hKey = {{"V2495 Handle", handle}};
	hKey.connect("/Modules/Logic");

	uint32_t firmware;
	err_code = CAEN_PLU_ReadReg(handle, 0x1000, &firmware);
	err_check(err_code);
	printf("Firmware version: %d\n", firmware);
	
	//Initialize Gate and Delay Generators
	err_code = CAEN_PLU_InitGateAndDelayGenerators(handle);
	err_check(err_code);

	//Take the Default gate values from the ODB
	midas::odb def("/Modules/Logic/Default");

	uint32_t commonGate = (uint32_t)def["width"];
        uint32_t commonDelay = (uint32_t)def["delay"];
        uint32_t commonScale = (uint32_t)def["scale"];

	//Set all gates to the same default settings
	err_code = CAEN_PLU_SetGateAndDelayGenerators(handle, commonGate, commonDelay, commonScale);
        err_check(err_code);

	//Watch the ODB subtree
	midas::odb to_watch("/Modules/Logic");
	
	//Lambda function
	//
	// if any of these keys are changed through the web server, 
	// write the new value to the logic unit
	//
	to_watch.watch([](midas::odb &logic){
      		
		//std::cout << "Value of key \"" + logic.get_full_path() + "\" changed to " << logic << std::endl;
		
		CAEN_PLU_ERROR_CODE err_code;

		//Retrieve the V2495 handle
		midas::odb temp("/Modules/Logic");
		int h = temp["V2495 Handle"];

		//Get the QDC parameters
		midas::odb qdc("/Modules/Logic/QDCGateA");
		uint32_t qdcGate = qdc["width"];
		uint32_t qdcDelay = qdc["delay"];
		uint32_t qdcScale = qdc["scale"];

		//Set the new values
		err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 0, 1,  qdcGate, qdcDelay, qdcScale);
                err_check(err_code);
		
		//Get the TDC parameters
		midas::odb tdc("/Modules/Logic/TDCGate");
                uint32_t tdcGate = tdc["width"];
                uint32_t tdcDelay = tdc["delay"];
                uint32_t tdcScale = tdc["scale"];

		//Set the new values
		err_code = CAEN_PLU_SetGateAndDelayGenerator(h, 1, 1, tdcGate, tdcDelay, tdcScale);
                err_check(err_code);

   	});
	
	do {
      		int status = cm_yield(100);
      		if (status == SS_ABORT || status == RPC_SHUTDOWN)
         		break;
   	} while (!ss_kbhit());

	cm_disconnect_experiment();

	return 0;
}

void err_check(CAEN_PLU_ERROR_CODE err)
{
	if (err != CAEN_PLU_OK)
        {
                printf("Error %d\n", err);
                exit(0);
        }
}















Attachment 2: start_daq.PNG
start_daq.PNG
  2144   09 Apr 2021 Lars MartinSuggestionTime zone selection for web page
The new history as well as the clock in the web page header show the local time 
of the user's computer running the browser.
Would it be possible to make it either always use the time zone of the Midas 
server, or make it selectable from the config page?
It's not ideal trying to relate error messages from the midas.log to history 
plots if the time stamps don't match.
  2143   05 Apr 2021 Konstantin OlchanskiInfoblog - convert mfe frontend to tmfe c++ framework
Result is here:
https://bitbucket.org/expalpha/chronobox_software/src/master/fechrono_tmfe.cxx

Original code is in fechrono.cxx. Not super pretty, but representative of most mfe-based frontends
we see around here. A good example of why the old mfe.c structure no longer works so well for us.

After conversion to tmfe, we do not win a beauty contest yet, but the path for further
clean up and refactoring into better c++ is quite clear. (And it is very obvious where
the missing "event object" wants to be here)

K.O.
  2142   05 Apr 2021 Konstantin OlchanskiInfoblog - convert mfe frontend to tmfe c++ framework
notes from converting ALPHA-g chronobox frontend fechrono to tmfe c++ framework.

the chronobox device is a timestamp/low resolution tdc/scaler/generic TTL and ECL io
mainboard with an altera DE10_NANO plugin board. it has a cyclone-5 FPGA SOC running Raspbian linux.
FPGA communication is done by avalon-bus memory mapped registers, main data readout
is PIO from an FPGA 32-bit wide FIFO (no DMA yet).

- login to main computer (daq16)
- cd packages
- git clone https://bitbucket.org/tmidas/midas midas-develop
- cd midas-develop
- make mini ### creates linux-x86_64/{bin,lib}
- ssh agdaq@cb02 ### private network
- cd ~/packages/midas-develop
- make mini ### creates linux-linux-armv7l/{bin/lib}
- cd ~/online/chronobox_software
- cat fechrono.cxx ~/packages/midas-develop/progs/tmfe_example_everything.cxx > fechrono_tmfe.cxx
- edit fechrono_tmfe.cxx:

- rename "FeEverything" to "FeChrono"
- copy contents of frontend_init() to HandleFrontendInit()
- copy contents of frontend_exit() to HandleFrontendExit()
- replace get_frontend_index() with fFe->fFeIndex
- replace "return SUCCESS" with return TMFeOk()
- replace "return !SUCCESS" with return TMFeErrorMessage("boo!!!")
- this frontend has 3 indexed equipments, copy EqEverything 3 times, rename EqEverything to EqCbHist, EqCbms, EqCbFlow
- copy contents of begin_of_run() to EqCbHist::HandleBeginRun()
- copy contents of end_of_run() to EqCbHist::HandleEndRun()
- pause_run(), resume_run() are empty, delete all HandlePauseRun() and all HandleResumeRun()
- frontend_loop() is empty, delete
- poll_event() and interrupt_configure() are empty, delete
- delete all HandleStartAbortRun(), delete all calls to RegisterTransitionStartAbort();
- examine equipment[]:
- "cbhist%02d" - periodic, copy contents of read_cbhist() to EqCbHist::HandlePeriodic()
- "cbms%02d" - polled, copy contents of read_cbms_fifo() to EqCbms::HandlePollRead()
- "cbflow%02d" - periodic, copy contents of read_flow() to EqCbFlow::HandlePeriodic()
- delete unused HandlePoll(), HandlePollRead() and HandlePeriodic()
- replace bk_init32() with "size_t event_size = 100*1024; char* event = (char*)malloc(event_size); ComposeEvent(event, 
event_size); BkInit(event, event_size);"
- replace bk_create(pevent) with BkOpen(event)
- replace bk_close(pevent, ...) with BkClose(event, ...)
- replace "return bk_size(pevent)" with "EqSendEvent(event); free(event);"
- remove unused example SendData()
- if there linker complains about references to "hDB", add "HNDLE hDB" is global scope, add "hDB = fMfe->fDB"
- replace set_equipment_status() with EqSetStatus()
- move equipment configuration from the equipment[] array to the equipment constructors
- remove unused HandleRpc()
- remove unused HandleBeginRun() and unused HandleEndRun()
- remove all example code from HandleInit(), breakup frontend_init() code into per-equipment HandleInit() functions
- EqCbms::HandlePoll() replace all example code with "return true"
- if desired, replace ODB functions from utils.cxx with MVOdb RI(), RD(), etc
- if desired, replace cm_msg() with Msg() and delete "const char* frontend_name"
- update FeChrono() constructor:
      FeSetName("fechrono%02d");
      FeAddEquipment(new EqCbHist("cbhist%02d", __FILE__));
      FeAddEquipment(new EqCbms("cbms%02d", __FILE__));
      FeAddEquipment(new EqCbFlow("cbflow%02d", __FILE__));
- build:
g++ -std=c++11 -Wall -Wuninitialized -g -Ialtera -Dsoc_cv_av -I/home/agdaq/packages/midas-develop/include -
I/home/agdaq/packages/midas-develop/mvodb -c fechrono_tmfe.cxx
g++ -o fechrono_tmfe.exe -std=c++11 -Wall -Wuninitialized -g -Ialtera -Dsoc_cv_av -I/home/agdaq/packages/midas-develop/include 
-I/home/agdaq/packages/midas-develop/mvodb fechrono_tmfe.o utils.o cb.o /home/agdaq/packages/midas-develop/linux-
armv7l/lib/libmidas.a -lm -lz -lutil -lnsl -lpthread -lrt
- run:
- bombs on bm_set_cache_size(), reduce default cache size, old mserver cannot deal with the new default size, set 
fEqConfWriteCacheSize = 100*1024;
- run:
- prints too many messages, comment out print "HandlePollRead!"
- run:
- good now!

success, was not too bad.

also:
- replace gHaveRun with fMfe->fStateRunning
- replace gRunNumber with fMfe->fRunNumber

see tmfe.md section "variables provided by the framework"

K.O.
  2141   04 Apr 2021 Konstantin OlchanskiInfoChange of TID_xxx data types
> 
> To be consistent, I renamed the old types:
> 
> TID_DWORD      -> TID_UINT32
> TID_INT        -> TID_INT32
> 

this created an incompatibility with old XML save files,
old versions of midas cannot load new XML save files,
variable types have changed i.e. from "INT" to "INT32".

it would have been better if XML save files kept using the old names.

now packages that read midas XML files also need updating.

specifically, in ROOTANA:
- the old TVirtualOdb/XmlOdb.cxx (no longer used, deleted),
- mvodb/mxmlodb.cxx

K.O.
  2140   04 Apr 2021 Konstantin OlchanskiInfobk_init32a data format
In April 4th 2020 Stefan added a new data format that fixes the well known problem with alternating banks being 
misaligned against 64-bit addresses. (cannot find announcement on this forum. midas commit 
https://bitbucket.org/tmidas/midas/commits/541732ea265edba63f18367c7c9b8c02abbfc96e)

This brings the number of midas data formats to 3:

bk_init: bank_header_flags set to 0x0000001 (BANK_FORMAT_VERSION)
bk_init32: bank_header_flags set to 0x0000011 (BANK_FORMAT_VERSION | BANK_FORMAT_32BIT)
bk_init32a: bank_header_flags set to 0x0000031 (BANK_FORMAT_VERSION | BANK_FORMAT_32BIT | BANK_FORMAT_64BIT_ALIGNED;

TMEvent (midasio and manalyzer) support for "bk_init32a" format added today (commit 
https://bitbucket.org/tmidas/midasio/commits/61b7f07bc412ea45ed974bead8b6f1a9f2f90868)

TMidasEvent (rootana) support for "bk_init32a" format added today (commit 
https://bitbucket.org/tmidas/rootana/commits/3f43e6d30daf3323106a707f6a7ca2c8efb8859f)

ROOTANA should be able to handle bk_init32a() data now.

TMFE MIDAS c++ frontend switched from bk_init32() to bk_init32a() format (midas commit 
https://bitbucket.org/tmidas/midas/commits/982c9c2f8b1e329891a782bcc061d4c819266fcc)

K.O.
  2139   30 Mar 2021 Konstantin OlchanskiForumINT INT32 in experim.h
> > 
> > /* define integer types with explicit widths */
> > #ifndef NO_INT_TYPES_DEFINE
> > typedef unsigned char      UINT8;
> > typedef char               INT8;
> > typedef unsigned short     UINT16;
> > typedef short              INT16;
> > typedef unsigned int       UINT32;
> > typedef int                INT32;
> > typedef unsigned long long UINT64;
> > typedef long long          INT64;
> > #endif
> > 

NIH at work. In C and C++ the standard fixed bit length data types are available
in #include <stdint.h> as uint8_t, uint16_t, uint32_t, uint64_t & co.

BTW, the definition of UINT32 as "unsigned int" is technically incorrect, on 16-bit machines
"int" is 16-bit wide and on some 64-bit machines "int" is 64-bit wide.

K.O.
  2138   30 Mar 2021 Konstantin OlchanskiInfoINT64/UINT64/QWORD not permitted in ODB and history... Change of TID_xxx data types
> We have to request of a 64-bit integer data type to be included in MIDAS banks.
> Since 64-bit integers are on some systems "long" and on other systems "long long",
> I decided to create the two new data types
> 
> TID_INT64
> TID_UINT64
> 

These 64-bit data types do not work with ODB and they do not work with the MIDAS history.

As of commits on 30 March 2021, mlogger will refuse to write them to the history and 
db_create_key() will refuse to create them in ODB.

Why these limitations:

a1) all reading of history is done using the "double" data type, IEEE-754 double precision 
floating point numbers have around 53 bits of precision and are too small to represent all 
possible values of 64-bit integers.
a2) SQL, SQLite and FILE history know nothing about reading and writing 64-bit integer data 
types (this should be easy to fix, as long as MySQL/MariaDB and PostgresQL support it)

b1) in ODB, odbedit and mhttd web pages do not display INT64/UINT64/QWORD data
b2) ODB save and restore from odb, xml and json formats most likely does not work for these 
data types

Fixing all this is possible, with a medium amount of work. As long as somebody needs it. 
Display of INT64/UINT64/QWORD on history plots will probably forever be truncated to 
"double" precision.

K.O.
ELOG V3.1.4-2e1708b5