DetectorLib implementation problem inside the RawLib process

System : Linux
REST version : v2.3.10
Commit: 7148a3e0

Hi,

I am working on the process that works with the TRestRawSignalEvent.
Inside this process, I have to check which RawSignal corresponds to which Readout Channel, thus I include TRestDetectorReadout, identifying it with REST_DetectorLib in the header file:

#ifdef REST_DetectorLib
    TRestDetectorReadout* fReadout;  //!
#endif

However, when I try to do some preliminary printouts inside the ProcessEvent, like here:

// setting the readout of this run
#ifdef REST_DetectorLib
    fReadout = GetMetadata<TRestDetectorReadout>();

    if (fReadout == nullptr) {
        if (!this->GetError()) this->SetError("The readout was not properly initialized.");
    }
#endif
.
.
.
#ifdef REST_DetectorLib
        for( int p = 0; p < readout->GetNumberOfReadoutPlanes(); p++ )
        {
            fReadout->GetPlaneModuleChannel(signalID, planeID, readoutModule, readoutChannel);
            TRestReadoutPlane *plane = readout->GetReadoutPlane( p );
            readoutPlaneID   = plane->GetID();
            for( int m = 0; m < plane->GetNumberOfModules(); ++m )
            {
                TRestReadoutModule *mod = plane->GetModule( m );
                Int_t readoutModuleID  = mod->GetModuleID();
                cout << "readoutPlaneID: " << readoutPlaneID << " readoutModuleID: " << readoutModuleID << endl;
                printf("readoutPlaneID: %d readoutModuleID: %d \n", readoutPlaneID, readoutModuleID);
            }
        }
#endif

I receive no output when I employ my process into the config.rml file.
I’ve found out, that similarly it was done in the TResetRawSignalChannelActivityProcess.
Feels like a basic problem, but I can’t figure out what’s missing.

Would appreciate any comment on what I am doing wrong
Thanks in advance

Sincerely,
Andrii

Hi Andrii,

if you do

rest-config --libs

it is -lRestDetector between the libraries available?

Yes, it’s there:

> rest-config --libs
...Soft/rest-framework2_3/install/master/lib -lRestFramework -lRestConnectors -lRestDetector -lRestGeant4 -lRestRaw -lRestTrack

The most likely is that the problem is connected with REST_DetectorLib not being defined. In principle, after swimming a bit in the cmake files I do not see where this is defined, so it might be it is not defined.

I guess the right place for doing add_definitions("-DREST_${library}Lib") would be inside the following loop at source/CMakeLists.txt, where ${library} would be Detector, same as directory name, but with the first letter uppercase.

# loop all the dirs and set the option
set(dirs "libraries" "packages")
foreach (dir ${dirs})
    SUBDIRLIST(subdirs "${CMAKE_CURRENT_SOURCE_DIR}/${dir}")
    foreach (subdir ${subdirs})
        set(fullname "${dir}/${subdir}")
        DIRNAME2OPTION(option ${fullname})

        file(GLOB ff "*/${subdir}/CMakeLists.txt")
        if (ff) # if dir not empty, set the option to ON
            if (NOT DEFINED ${option})
                IF (${REST_ALL_LIBS} MATCHES "ON")
                    set(${option} ON)
                else ()
                    set(${option} OFF)
                endif ()
            endif ()
            message("Submodule found: ${fullname}. Option: ${option}=${${option}}")
        else ()
            set(${option} OFF)
            message("Empty submodule dir: ${fullname}. Option: ${option}=${${option}}")
        endif ()
    endforeach ()
endforeach ()

It could be done directly inside source/libraries/detector/CMakeLists.txt but this way it could be more generic, I guess. @nkx @lobis

Perhaps it could be tried the following I found on the web

string(SUBSTRING ${subdir} 0 1 FIRST_LETTER)
string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" Subdir "${subdir}")
add_definitions("-DREST_${Subdir}Lib")

of course, that should be included at the end of the loop, only if ${option} is ON`.

if ( ${option} MATCHES ON)
    string(SUBSTRING ${subdir} 0 1 FIRST_LETTER)
    string(TOUPPER ${FIRST_LETTER} FIRST_LETTER)
    string(REGEX REPLACE "^.(.*)" "${FIRST_LETTER}\\1" Subdir "${subdir}")
    add_definitions("-DREST_${Subdir}Lib")
if ( ${option} MATCHES ON)

Probably this is dirty and not elegant, so I let others implement it better :slight_smile: @lobis?

I made a PR referencing this here: Added preprocessor definition via cmake STRING by lobis · Pull Request #185 · rest-for-physics/framework · GitHub. Please let me know if this fixes the issue (I think it should)

Hi @jgalan and @lobis ,

Thank you for your replies

I’ve tested the latest merge (which I mistakenly decided to do) and updated my local branch with:

git fetch origin master
git reset --hard FETCH_HEAD

With that I found out that there are a lot of errors during the compilation; I’ve saved cmake and make install logs accordingly:
install_.txt (98.6 KB)
cmake_.txt (26.5 KB)

I cannot see the errors on that file, you could try executing

python3 pull-submodules.py --force --dontask --latest:lobis-regex-lib-compile-def

to get on the latest version of any lobis-regex-lib-compile-def submodule branch, or master if that branch does not exist in the submodule.

Sorry, yes, error messages were not written


All submodules, except one, were pulled (I guess it’s not significant)

Pulling latest submodules from their git repository, instead of the version recorded by REST.
This may cause the submodules to be uncompilable.
        
Force pulling submodules.
Framework branch name: lobis-regex-lib-compile-def
source/libraries/axion[ OK ] (287282b)
source/libraries/geant4[ OK ] (94f10a4)
source/libraries/raw[ OK ] (e0da179)
source/libraries/track[ OK ] (ab8d673)
source/libraries/detector[ OK ] (8f6c3d0)
source/libraries/connectors[ OK ] (c32c182)
packages/restG4[ OK ] (49246db)
packages/restSQL[ OK ] (639a01a)
projects/basic-geometries[ OK ] (992517b)
projects/basic-readouts[ OK ] (a0767ae)
scripts/batch-scripts[ OK ] (c7e6c1c)
/local/home/al264242/Documents/Soft/rest-framework2_3/doc/userguide[ Failed ]
source/libraries/axion/data[ OK ] (d1a1bd0)
source/libraries/axion/external/solarAxionFlux[ OK ] (905d740)

REST was compiled without errors. I assume that after every update I have to pull all the submodules?

However, there are still no outputs from the config.rml file, related to the TRestDetectorReadout.
Moreover, I’ve got additional errors:
config_rml_log.txt (3.1 KB)

Did the line Adding compile definition: REST_DetectorLib appeared when you invoked cmake?

Yes, there is such information:

-- making build files in /local/home/al264242/Documents/Soft/rest-framework2_3/source/libraries/detector, dependency: 
-- 37 source files in total, 37 classes to generete, 0 additional source files
-- Adding compile definition: REST_DetectorLib

Hi Andrii, I see now that it is not exactly at TRestRawSignalChannelActivityProcess where you got troubles. It would be good if you share the complete process implementation. Perhaps via a branch that you push to a remote?

On the other hand, make sure you have a readout definition inside TRestRun, it might be a problem of the RML.

First, add a cout inside #ifdef REST_DetectorLib to make sure it is executed that part of the code or not. It is not clear to me from the pieces of code you pasted, would be better to see it complete. For example, what happens if there is no readout definition and fReadout=null?

See how it is done for TREX-DM

I haven’t resolved the problem with pushing to a remote repository, unfortunately

Concerning the readout definition, here is how I define it in my .rml file:

<!-- This is where you define your readout -->
    <addMetadata type="TRestReadout" name="Panda-140kg"
        file="${REST_FILES}/FullSetup/Panda_140kg_root624.root"
        value="ON" overwrite="false"/>

configFile_Signal_To_RAW_To_Signal.rml (7.4 KB)

I can provide my repository with all the necessary files regarding this project for simplicity


I have corrected my process as follows:

#ifdef REST_DetectorLib
    // fReadout = GetMetadata<TRestDetectorReadout>();
    fReadout = null;

    if (fReadout == nullptr) {
        if (!this->GetError()) this->SetError("The readout was not properly initialized.");
    }
#endif
....
....
#ifdef REST_DetectorLib
        cout << "Test Cout\n";
        for( int p = 0; p < readout->GetNumberOfReadoutPlanes(); p++ )
        {
            fReadout->GetPlaneModuleChannel(signalID, planeID, readoutModule, readoutChannel);
            TRestReadoutPlane *plane = readout->GetReadoutPlane( p );
            readoutPlaneID   = plane->GetID();
            for( int m = 0; m < plane->GetNumberOfModules(); ++m )
            {
                TRestReadoutModule *mod = plane->GetModule( m );
                Int_t readoutModuleID  = mod->GetModuleID();
                cout << "readoutPlaneID: " << readoutPlaneID << " readoutModuleID: " << readoutModuleID << endl;
                printf("readoutPlaneID: %d readoutModuleID: %d \n", readoutPlaneID, readoutModuleID);
            }
        }
#endif

There are no couts when I run an .rml file provided earlier

Here are header and cxx files for my process. I have added them into the raw library directory
TRestRawSignalDataCollectionProcess.h (2.9 KB)
TRestRawSignalDataCollectionProcess.cxx (7.3 KB)

Ok, same problem for me. Likely the problem is that the REST_DetectorLib definition is only having effect on the compilation of detectorlib itself, and not at any library. Perhaps it would be solved if the code is placed at source/CMakeLists.txt? @lobis?

1 Like

I will look into it, but it should be defined everywhere, perhaps the regular expression is not working due to cmake version?

Could you @andriiL add the cmake output? if there is a problem with the cmake / regex we should be able to see it there.

Hi @lobis ,
Sorry for the long reply.

I’ve resolved my problem by moving the process into the connectors library.

I’ll update you with the cmake output later

There was recently a fix dealing with the proper use of REST_DetectorLib precompiler directive

Thank you very much!