Weird behaviour(?) in compiled code of std::cout in event loop of rdataframe

Dear experts,

i have a compiled code which uses RDataFrame to create container of objects and i am trying to print - event by event the content, however the function whcih is supposed to print the input container sizes is not showing any message when the event loop is executed. Does anyone know what is going on?

My example code does something like this :


ROOT::RDF::RNode EventMaker::Make_ALL( ROOT::RDF::RNode node){
    /* make call all previous*/
    // std::cout<<"Make-MCParticles"<<std::endl;
    node = EventMaker::Make_MCParticles( node);
    node = EventMaker::Make_MPHits( node);
    node = EventMaker::Make_UPHits( node);
    node = EventMaker::Make_TVHits( node);
    node = EventMaker::Make_FTHits( node);



    auto dummy_check = [&]( ULong64_t rdfentry_ ,
                           unsigned int rdfslot_ , 
                           const std::vector<MCParticle> & mcps , 
                           const std::vector<MCHit>      & tvs , 
                           const std::vector<MCHit>      & ups , 
                           const std::vector<MCHit>      & fts , 
                           const std::vector<MCHit>      & mps ) -> int {
        std::cout<< "Slot "<< rdfslot_ << ", Entry "<< rdfentry_ << std::endl;
        std::cout<< "\t nMCPs   "<< mcps.size() << std::endl;
        std::cout<< "\t nTVHits "<< tvs.size() << std::endl;
        std::cout<< "\t nUPHits "<< ups.size() << std::endl;
        std::cout<< "\t nFTHits "<< fts.size() << std::endl;
        std::cout<< "\t nMPHits "<< mps.size() << std::endl;
        return 0;
    };
    
    
    node = node.Define("dummy", dummy_check, { "rdfentry_", "rdfslot_" , 
                                                Names::MCPS_Container.Data(),
                                                Names::TV_Container.Data(),
                                                Names::UP_Container.Data(),
                                                Names::MP_Container.Data(),
                                                Names::FT_Container.Data()});
    

    // ROOT::RDF::Experimental::AddProgressBar(node);


    
    return node;
};

which is called from my executable :

int Process( std::vector< std::string> infiles){
    ROOT::DisableImplicitMT();

    for( auto & f: infiles){
        if(gSystem->AccessPathName(f.data() )){
            std::cerr << "test does not exist" << endl;
            abort();       
        } 
    }
    auto fin = TFile::Open( TString(infiles[0]), "READ");
    fin->ls();

    TChain chain_main( Names::MCPS);
    TChain chain_1(    Names::UP);
    TChain chain_2(    Names::TV);
    TChain chain_3(    Names::FT);
    TChain chain_4(    Names::MP);

    for( auto & f : infiles){
        cout<< "Add File to chains: " << f << endl;
        chain_main.AddFile( TString(f) );
        chain_1.AddFile( TString(f) );
        chain_2.AddFile( TString(f) );
        chain_3.AddFile( TString(f) );
        chain_4.AddFile( TString(f) );
    }
    chain_main.AddFriend( & chain_1);
    chain_main.AddFriend( & chain_2);
    chain_main.AddFriend( & chain_3);
    chain_main.AddFriend( & chain_4);

    ROOT::RDataFrame df( chain_main);
    

    auto node = ROOT::RDF::AsRNode( df);



    auto fNODE = EventMaker::Make_ALL(node);
    for( auto c : fNODE.GetDefinedColumnNames() ){
        cout<< "Column in node = "<<c << endl;
    }    
    cout<< "Processed " << fNODE.Count().GetValue()<<endl;
    return 0;
}

the code compile successfully but when i run it i just see on the terminal :

 TFile*         /afs/cern.ch/user/r/rquaglia/work/PostDoc/Upgrade2/stack/generate_scripts/gaudipython/test.root
  KEY: TTree    TVHits;1        TVHits
  KEY: TTree    UPHits;1        UPHits
  KEY: TTree    FTHits;1        FTHits
  KEY: TTree    MPHits;1        MPHits
  KEY: TTree    MCParticles;1   MCParticles
Add File to chains: /afs/cern.ch/user/r/rquaglia/work/PostDoc/Upgrade2/stack/generate_scripts/gaudipython/test.root
Column in node = MCPs
Column in node = MPs
Column in node = UPs
Column in node = TVs
Column in node = FTs
Column in node = dummy
Processed 1000

Is there a generic flag switching off all the messaging in event loops?

Best,
Renato


ROOT Version: 6.32.02
Built for linuxx8664gcc on Jul 08 2024, 10:25:47
From heads/master@tags/v6-32-02


Hello,

I don’t think there’s any flag suppressing output. Could it be that the node never runs?

You might have to actually read the “dummy” column (i.e. histogram it or pass it into another node). If nobody requests the value, it wouldn’t make sense to compute it.

1 Like

AH! you are right! is this a special feature of having a compiled code ?
If no-one consumes the output of a Define, the code is never exectude even asking on the actual node output of the Define to trigger the loop?

Best, Renato

Adding an histogram to dummy makes it printing infact…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.