Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  28 Jan 2024, Pavel Murat, Forum, number of entries in a given ODB subdirectory ? 
    Reply  28 Jan 2024, Konstantin Olchanski, Forum, number of entries in a given ODB subdirectory ? 
       Reply  28 Jan 2024, Stefan Ritt, Forum, number of entries in a given ODB subdirectory ? Screenshot_2024-01-29_at_07.20.50.png
          Reply  29 Jan 2024, Pavel Murat, Forum, number of entries in a given ODB subdirectory ? 
          Reply  29 Jan 2024, Konstantin Olchanski, Forum, number of entries in a given ODB subdirectory ? 
             Reply  03 Feb 2024, Pavel Murat, Forum, number of entries in a given ODB subdirectory ? a.cc
                Reply  08 Feb 2024, Stefan Ritt, Forum, number of entries in a given ODB subdirectory ? 
                   Reply  11 Feb 2024, Pavel Murat, Forum, number of entries in a given ODB subdirectory ? 
                      Reply  13 Feb 2024, Stefan Ritt, Forum, number of entries in a given ODB subdirectory ? 
                         Reply  15 Feb 2024, Konstantin Olchanski, Forum, number of entries in a given ODB subdirectory ? 
                            Reply  15 Feb 2024, Konstantin Olchanski, Forum, number of entries in a given ODB subdirectory ? 
                               Reply  15 Feb 2024, Stefan Ritt, Forum, number of entries in a given ODB subdirectory ? 
                                  Reply  19 Feb 2024, Pavel Murat, Forum, number of entries in a given ODB subdirectory ? 
Message ID: 2701     Entry time: 03 Feb 2024     In reply to: 2698     Reply to this: 2705
Author: Pavel Murat 
Topic: Forum 
Subject: number of entries in a given ODB subdirectory ? 
Konstantin is right: KEY.num_values is not the same as the number of subkeys (should it be ?)
For those looking for an example in the future, I attach a working piece of code converted 
from the ChatGPT example, together with its printout.

-- regards, Pasha
Attachment 1: a.cc  1 kB  | Hide | Hide all
#include <stdio.h>
#include <stdlib.h>
#include "midas.h"

int main(int argc, char **argv) {
  HNDLE hDB, hKey;
  INT   status, num_subkeys;
  KEY   key;

  cm_connect_experiment     (NULL, NULL, "Example", NULL);
  cm_get_experiment_database(&hDB, NULL);

  char dir[] = "/ArtdaqConfigurations/demo/mu2edaq09.fnal.gov";

  status = db_find_key(hDB, 0, dir , &hKey);
  if (status != DB_SUCCESS) {
    printf("Error: Cannot find the ODB directory\n");
    return 1;
  }
//-----------------------------------------------------------------------------
// Iterate over all subkeys in the directory
// note: key.num_values is NOT the number of subkeys in the directory
//-----------------------------------------------------------------------------
  db_get_key(hDB, hKey, &key);
  printf("key.num_values: %d\n",key.num_values);

  HNDLE hSubkey;
  KEY   subkey;
  num_subkeys = 0;
  for (int i=0; db_enum_key(hDB, hKey, i, &hSubkey) != DB_NO_MORE_SUBKEYS; ++i) {
    db_get_key(hDB, hSubkey, &subkey);
    printf("Subkey %d: %s, Type: %d\n", i, subkey.name, subkey.type);
    num_subkeys++;
  }

  printf("number of subkeys: %d\n",num_subkeys);

  // Disconnect from MIDAS
  cm_disconnect_experiment();
  return 0;
}
------------------------------------------------------ output:
mu2etrk@mu2edaq09:~/test_stand>test_001
key.num_values: 1
Subkey 0: BoardReader_01, Type: 15
Subkey 1: BoardReader_02, Type: 15
Subkey 2: EventBuilder_01, Type: 15
Subkey 3: EventBuilder_02, Type: 15
Subkey 4: DataLogger_01, Type: 15
Subkey 5: Dispatcher_01, Type: 15
number of subkeys: 6
---------------------------------------------------------------
ELOG V3.1.4-2e1708b5