27 Nov 2025, Konstantin Olchanski, Forum, Control external process from inside MIDAS
|
> Rather than investing time to re-invent the wheel here, better try to modify your EPICS driver process to
become a midas process.
I am with Stefan on this. Quite a bit of work went into the tmfe c++ framework to make it easy/easier to do
this - take an existing standalone c/c++ program and midas-ize it: in main(), "just add" calls to connect to
midas and to start the midas threads - rpc handler, watchdog, etc.
Alternatively, one can write a midas "stdout+stderr bridge", and start your standalone program
from the programs page like this:
myprogram |& cm_msg_bridge --name "myprogram" (redirect both stdout and stderr to cm_msg_bridge stdin)
cm_msg_bridge would read stdin and put them in cm_msg(). it will connect to midas using the name "myprogram"
to make it show "green" on the status page and it will be stoppable from the programs page.
care will need to be taken for myprogram to die cleanly when stdout and stderr are closed after cm_msg_bridge
exits.
K.O. |
09 Jan 2026, Stefan Ritt, Forum, MIDAS installation
|
Since we have no many RaspberryPi based control systems running at our lab with midas, I want to
streamline the midas installation, such that a non-expert can install it on these devices.
First, midas has to be cloned under "midas" in the user's home directory with
git clone https://bitbucket.org/tmidas/midas.git --recurse-submodules
For simplicity, this puts midas right into /home/<user>/midas, and not into any "packages" subdirectory
which I believe is not necessary.
Then I wrote a setup script midas/midas_setup.sh which does the following:
- Add midas environment variables to .bashrc / .zschenv depending on the shell being used
- Compile and install midas to midas/bin
- Load an initial ODB which allows insecure http access to port 8081
- Install mhttpd as a system service and start it via systemctl
Since I'm not a linux system expert, the current file might be a bit clumsy. I know that automatic shell
detection can be made much more elaborate, but I wanted a script which can easy be understood even by
non-experts and adapted slightly if needed.
If you know about shell scripts and linux administration, please have a quick look at the attached script
and give me any feedback.
Stefan |
10 Jan 2026, Marius Koeppel, Forum, MIDAS installation
|
Dear Stefan,
That’s a great idea. For a private home automation project using a Raspberry Pi Zero, I used the
following setup:
https://github.com/makoeppel/midasHome/
This server has been running for about a year now
and reports the temperature in my home. Looking at your script, I think we are conceptually doing the same
thing.
I see three parts I would do slightly differently:
1. I would create an .env file to hold the
variables:
export PATH="$HOME/midas/bin:$PATH"
export MIDASSYS="$HOME/midas"
export MIDAS_DIR="$HOME/online"
export MIDAS_EXPT_NAME="Online"
2. For odbedit -c "load midas_setup.odb" > /dev/null
I would consider making
this a bit more explicit (using odbedit) so users can change the configuration if needed—possibly by
introducing a .conf file.
3. In my project, I used the MIDAS Python bindings, which are currently missing in
your script:
export PYTHONPATH=$PYTHONPATH:$MIDASSYS/python
I also have one additional comment regarding
Docker. I think it would make sense to support a Docker image for MIDAS. This would give non-expert users an
even simpler setup. I created a related project some time ago:
https://github.com/makoeppel/midasDocker
I'd
be happy to help with this part as well.
Best regards,
Marius |
13 Jan 2026, Stefan Ritt, Forum, MIDAS installation
|
Thanks for your feedback. I reworked the installation script, and now also called it "install.sh" since it includes also the git clone. I modeled it after
homebrew a mit (https://brew.sh). This means you can now run the script on a prison linux system with:
/bin/bash -c "$(curl -sS https://bitbucket.org/tmidas/midas/raw/HEAD/install.sh)"
It contains three defaults for MIDASSYS, MIDAS_DIR and MIDAS_EXPT_NAME, but when you run in, you can overwrite these
defaults interactively. The script creates all directories, clones midas, compiles and installs it, installs and runs mhttpd as a system
service, then starts the logger and the example frontend. I also added your PYTHONPATH variable. The RC file is now automatically
detected.
Yes one could add more config files, but I want to have this basic install as simple as possible. If more things are needed, they
should be added as separate scripts or .ODB files.
Please have a look and let me know what you think about. I tested it on a RaspberryPi, but not yet on other systems.
Stefan |
13 Jan 2026, Stefan Ritt, Forum, MIDAS installation
|
I put the documentation under
https://daq00.triumf.ca/MidasWiki/index.php/Install_Script
Would be good if anybody could check that.
Stefan |
09 Apr 2026, David Perez Loureiro, Forum, Migrate Legacy code to current Midas version
|
I am an applied physicist at Canadian Nuclear Laboratories and am in the process
of migrating the full experiment configuration—including the front-end interface—
of the CRIPT muon tomography detector from a legacy version of MIDAS (SVN Rev.
5238, circa 2012) to a more modern release.
The current system runs on Scientific Linux 6 and very old hardware. Due to
substantial changes in the MIDAS codebase over the years, I have encountered
multiple compatibility issues during the migration. I have also attempted to build
and run the legacy MIDAS version and the front-end code using GCC 4.8 on a modern
Linux system (Ubuntu 24.04), but without success.
Could you please advise on the recommended approach for upgrading or refactoring
legacy MIDAS front-end code to the current framework? Any guidance or best
practices would be greatly appreciated.
Many thanks in advance.
David Perez Loureiro, PhD (he/him)
Applied Physicist, Applied Physics Branch
Canadian Nuclear Laboratories |
09 Apr 2026, Nick Hastings, Forum, Migrate Legacy code to current Midas version
|
> I am an applied physicist at Canadian Nuclear Laboratories and am in the process
> of migrating the full experiment configuration—including the front-end interface—
> of the CRIPT muon tomography detector from a legacy version of MIDAS (SVN Rev.
> 5238, circa 2012) to a more modern release.
> The current system runs on Scientific Linux 6 and very old hardware. Due to
> substantial changes in the MIDAS codebase over the years, I have encountered
> multiple compatibility issues during the migration. I have also attempted to build
> and run the legacy MIDAS version and the front-end code using GCC 4.8 on a modern
> Linux system (Ubuntu 24.04), but without success.
I suggest updating the midas version. You should be able to get to at least midas 2024-12-a
without breaking anything.
> Could you please advise on the recommended approach for upgrading or refactoring
> legacy MIDAS front-end code to the current framework? Any guidance or best
> practices would be greatly appreciated.
Start here: https://daq00.triumf.ca/MidasWiki/index.php/Changelog
The 2019-06 release was the c -> c++ transition. Read that section carefully.
The 2020-12 update also had a change that you will also likely want to update your FEs for.
You will also likely encounter a quite a few non-midas issues related to the newer compilers.
Updates to your front ends may include things like needing to use "const char*" instead of "char*",
adding extra headers like <cstring> and <cstdlib>, using ctime_r() instead of ctime(), etc
Post back if you have specific questions.
P.S. I'm maintaining a number of midas FEs mostly written around 2007-2009.
These were running on SL5 and SL6 for many years and are now on Alma 9 with
midas 2024-12-a. |
16 Apr 2026, Konstantin Olchanski, Forum, Migrate Legacy code to current Midas version
|
> I am migrating the full CRIPT muon tomography detector from MIDAS (SVN Rev.
> 5238, circa 2012) to a more modern release.
> The current system runs on Scientific Linux 6 and very old hardware.
Right, good vintage midas and linux. But in the current security environment,
we must run currently supported OS (and MIDAS), and we must never fall off
the yearly/bi-yearly OS upgrade threadmill.
How old is your computer hardware and do you plan to update it, as well? If you OS
is installed on an HDD, definitely move to an SSD would be good. If you are hard
on money, a RaspberryPi5 with 16GB RAM may be good enough for what you have.
Anyhow new OS choice would be Ubuntu 24 or Debian 13. I do not recommend Red Hat based OS (vanilla
RHEL, Fedora, Alma, Rocky), they have become niche OSes with minimal vendor and community support.
> Due to substantial changes in the MIDAS codebase over the years ...
The big change in MIDAS land is move to c++, then c++11, then to c++17, and move from vanilla make to
cmake.
MIDAS API has been reasonably stable since then, but very old MIDAS frontends would fail to build with
latest compilers because of changes in c++ language and changes in the c and c++ libraries.
> I have encountered multiple compatibility issues during the migration. I have also attempted to
build and run the legacy MIDAS version and the front-end code using GCC 4.8 on a modern Linux system
(Ubuntu 24.04), but without success.
this is non-viable, latest C/C++ compilers reject perfectly good SL6-era C/C++ code, old MIDAS would
not compile, old frontends would not compile.
> Could you please advise on the recommended approach ...
What you are doing, we have done several times with TRIUMF experiments,
updating SL6 and CentOS-7 MIDAS instances to current MIDAS, C++ and OS:
1) new computer with Ubuntu 24 (or Debian or Raspbian). (U-26 will come out roughly in August, fo rth
epurposes of this discussion).
2) new MIDAS. we generally recommend the head of the develop branch, but older tagged version are
okey, too.
3) apache https proxy, etc, for secure browser connections, see
https://daq00.triumf.ca/DaqWiki/index.php/Ubuntu#Install_apache_httpd_proxy_for_midas_and_elog
4) reload your old ODB into the new MIDAS
5) your old history, etc should work
6a) build your old frontends, this will be a chore, but if you look at the compile errors, you will
see that most changes are very mechanical (i.e. const char*, etc). biggest hassle is ot make your old
C/C++ code to build with current C++17 compiler, smaller hassle is to update for minor changes in the
mfe.h API.
6b) bite the bullet and rewrite your frontends using the C++ tmfe API, start with
tmfe_example_everything.cxx, remove unnecessary, add required, pretty straightforward, I can guide you
through this (contact me directly by email).
7) minor tweeks to mlogger, mhttpd and history settings
8) rewrite all customs pages to the current mjsonrpc API
Best of luck, if you have more questions, please ask here or by direct email.
K.O. |
13 Oct 2004, Konstantin Olchanski, Bug Report, db_paste: found string exceeding MAX_STRING_LENGTH
|
I am updating TWIST to the latest MIDAS and when I load a saved .odb file, I get
these messages. Their text ought to say where and what strings it does not like.
K.O.
[twistonl@midtwist ~/online]$ odbedit
Please define environment variable 'MIDASSYS'
pointing to the midas installation directory.
[local:twist:S]/>load /twist/data_onl/current/run17548.odb
[odb.c:5600:db_paste] found string exceeding MAX_STRING_LENGTH
[odb.c:5600:db_paste] found string exceeding MAX_STRING_LENGTH
[odb.c:5600:db_paste] found string exceeding MAX_STRING_LENGTH |
13 Oct 2004, Stefan Ritt, Bug Report, db_paste: found string exceeding MAX_STRING_LENGTH
|
Can you attach
/twist/data_onl/current/run17548.odb
so I can reproduce the problem? |
13 Oct 2004, Konstantin Olchanski, Bug Report, silly odbedit "rename Display xxx/yyy"
|
odbedit command "rename Display xxx/yyy" creates a key named "xxx/yyy" (yes,
with a slash in the name) and this key cannot be deleted or renamed...
K.O. |
13 Oct 2004, Stefan Ritt, Bug Report, silly odbedit "rename Display xxx/yyy"
|
> odbedit command "rename Display xxx/yyy" creates a key named "xxx/yyy" (yes,
> with a slash in the name) and this key cannot be deleted or renamed...
> K.O.
"rename" is "rename", not "mv" under Unix. If you want this functionality, put it
in and don't complain! |
13 Oct 2004, Konstantin Olchanski, Bug Report, TWIST upgrade bombed...
|
The upgrade of TWIST to the latest midas has bombed- we see mevb and mlogger
crashes during shared memory data buffer accesses. I am looking into it and I
will add information as I figure things out. K.O. |
13 Oct 2004, Pierre-Andre Amaudruz, Bug Report, TWIST upgrade bombed...
|
> The upgrade of TWIST to the latest midas has bombed- we see mevb and mlogger
> crashes during shared memory data buffer accesses. I am looking into it and I
> will add information as I figure things out. K.O.
Since 1.9.5 the EventBuilder has been modified. Please consult the documentation
where the new mevb scheme is explained.
Test of the mevb with up to 16 frontends (15 different CPUs) has been tested
successfully. Data rate at the EventBuilder were measured about 50MB/s without the
logger and ~30MB/s with the logger. |
13 Oct 2004, Konstantin Olchanski, Bug Report, TWIST upgrade bombed...
|
> The upgrade of TWIST to the latest midas has bombed- we see mevb and mlogger
> crashes during shared memory data buffer accesses. I am looking into it and I
> will add information as I figure things out. K.O.
I traced buffer memory corruption to a logic error in system.c::ss_shm_open(). If
a .SHM file exists, it's size is used as the size of the sysv shared memory
segment, even if the requested shared memory size is bigger, but the caller of
ss_shm_open() thinks it got all the requested memory. Eventually we try to use
the unallocated memory and crash. This is the proposed fix and I will commit it
after I retest the upgrade during the next few days.
[olchansk@send src]$ cvs diff -u system.c
olchansk@midas.psi.ch's password:
Index: system.c
===================================================================
RCS file: /usr/local/cvsroot/midas/src/system.c,v
retrieving revision 1.83
diff -u -r1.83 system.c
--- system.c 4 Oct 2004 07:04:01 -0000 1.83
+++ system.c 14 Oct 2004 05:51:16 -0000
@@ -544,8 +544,14 @@
} else {
/* if file exists, retrieve its size */
file_size = (INT) ss_file_size(file_name);
- if (file_size > 0)
+ if (file_size > 0) {
+ if (file_size < size) {
+ cm_msg(MERROR, "ss_shm_open", "Shared memory segment \'%s\' size
%d is smaller than requested size %d. Please remove it and try
again",file_name,file_size,size);
+ return SS_NO_MEMORY;
+ }
+
size = file_size;
+ }
}
/* get the shared memory, create if not existing */
K.O. |
13 Oct 2004, Konstantin Olchanski, Bug Report, TWIST upgrade bombed...
|
> > The upgrade of TWIST to the latest midas has bombed- we see mevb and mlogger
> > crashes during shared memory data buffer accesses. I am looking into it and I
> > will add information as I figure things out. K.O.
>
> Since 1.9.5 the EventBuilder has been modified. Please consult the documentation
> where the new mevb scheme is explained.
> Test of the mevb with up to 16 frontends (15 different CPUs) has been tested
> successfully. Data rate at the EventBuilder were measured about 50MB/s without the
> logger and ~30MB/s with the logger.
It turns out that TWIST uses a private mevb.c. We will consider upgrading to the
standard one.
K.O. |
14 Oct 2004, Stefan Ritt, Bug Report, TWIST upgrade bombed...
|
Agree.
Once you did the modification, please check following situation: Create a fresh
ODB withe increased size ("odbedit -s 2000000" for example). Then check that the
other clients "adopt" this increased size. Note that some experiments need a
bigger ODB, and I don't want to have them recompile all clients, that's why the
code in ss_shm_open() can attach to a *larger* shared memory. However, it should
not matter to the process, since the ODB (or SYSTEM) shared memory size is
stored in the pheader->key_size and pheader->data_size of each participating
process. So they should never write beyond the limits defined in that header.
The size to ss_shm_open() is only a "hint" if the shared memory does not exist,
and is nowhere later used in the code. |
14 Oct 2004, Konstantin Olchanski, Bug Report, lazylogger complains about zero-size files
|
With latest midas, I see this:
Thu Oct 14 19:31:17 2004 [Lazy_Tape] [lazylogger.c:1717:Lazy] lazy_file_exists
file run17567.ybs doesn't exists
Thu Oct 14 19:31:27 2004 [Lazy_Tape] [lazylogger.c:1717:Lazy] lazy_file_exists
file run17567.ybs doesn't exists
The file run17567.ybs has size zero:
-rw-r--r-- 1 twistonl users 950272 Oct 13 19:29
/twist/data_onl/current/run17565.ybs
-rw-r--r-- 1 twistonl users 950272 Oct 13 19:45
/twist/data_onl/current/run17566.ybs
-rw-r--r-- 1 twistonl users 0 Oct 13 20:00
/twist/data_onl/current/run17567.ybs
-rw-r--r-- 1 twistonl users 983040 Oct 13 20:03
/twist/data_onl/current/run17568.ybs
-rw-r--r-- 1 twistonl users 950272 Oct 13 20:26
/twist/data_onl/current/run17569.ybs
I am not sure how to fix this lazylogger logic. Please help.
K.O. |
14 Oct 2004, Konstantin Olchanski, Bug Report, TWIST upgrade bombed...
|
> The upgrade of TWIST to the latest midas has bombed- we see mevb and mlogger
> crashes during shared memory data buffer accesses. I am looking into it and I
> will add information as I figure things out. K.O.
On second try, it looks like we are in business- the first try did not work
because of two mistakes:
1) I did not delete *all* old .SHM files (.ODB.SHM, .SYSTEM.SHM, .YBUF1.SHM,
.YBUF2.SHM). I deleted ODB.SHM, so odb worked, but forgot about the data buffers
SYSTEM.SHM & co and ended up with segmentation faults and core dumps in the buffer
management code caused by a mismatch of the old-midas buffers and new-midas code.
2) while debugging these core dumps, I made an error in my test code, so even
after I deleted the old data buffers, things still did not work. Talk about
over-debugging a problem...
K.O. |
20 Jan 2005, Konstantin Olchanski, Bug Report, Persistency problem with h1_book() & co
|
The current h1_book() macros (and the previous example analyzer code) have an
odd persistency problem: for example, the user wants to change some histogram
limits, edits the h1_book() calls, rebuilds and restarts the analyzer, starts a
new run, and observes that all histograms are filled using the old limits, his
changes "did not take". The user panics, I get paged during the Holy Lunch Hour,
everybody is unhappy.
This is what I think happens:
1) analyzer starts
2) LoadRootHistgrams() loads old histograms from file
3) user code calls h1_book()
4) h1_book template in midas.h does this (roughly):
hist = (TH1X *) gManaHistosFolder->FindObjectAny(name);
if (hist == NULL) {
hist = new TH1X(name, title, bins, min, max);
5) since the histogram already exists (loaded from the file, with the old
limits), the TH1X constructor is not called at all, new histogram limits are
utterly ignored.
A possible solution is to unconditionally create the ROOT objects, like I do in
the example code posted at http://dasdevpc.triumf.ca:9080/Midas/191. That code
produces an annoying warning from ROOT about possible memory leaks. This could
be fixed by adding a two liner to "find and delete" the object before it is
created, trippling the number of user code lines per histogram (find & delete,
then create). Highly ugly.
midas.h macros (h1_book & co) can be fixed by adding checks for histogram limits
and such, but I would much prefer a generic solution/convention that would work
for arbitrary ROOT objects without MIDAS-specific wrappers (think TProfile,
TGraph, etc...).
Any suggestions?
K.O. |
|