Invalid memory pointer passed to a callee:

root [0] .L Correlator.C
root [1] Correlator a
Warning in TClass::Init: no dictionary for class UEvent is available
Warning in TClass::Init: no dictionary for class UParticle is available
Warning in TClass::Init: no dictionary for class URun is available
(Correlator &) @0x7f741f898000
root [2] a.Loop()

Error in : Trying to access a pointer that points to an invalid memory address.
Execution of your code was aborted.
In file included from input_line_8:1:
/home/arshad/WorkSpace/2024/correlations/Correlator.C:39:2: warning: invalid memory pointer passed to a callee:
correlations[0][0]->Fill(0.5,two.Re(),wTwo); // <<cos(h1phi1+h2phi2)>>
Correlator.C (1.6 KB)
Correlator.h (13.5 KB)

Hi @Arshad_Ahmad_Masoodi, it looks like you are missing the header files for these custom U* classes stored in your TTree. Why did you comment them out in the macro when you need them?

From your script:

// Header file for the classes stored in the TTree if any.
//#include "UEvent.h"
#include "TObject.h"
//#include "UParticle.h"

These UEvent, URun, and UParticle classes are not part of ROOT, so we can’t help you much here. Are they part of the experiment framework you are using? In any case, you should ask your colleagues how to set up an environment that can read these files.

Thanks for responding
Yes i will do it…But the current error is not related to these …
As my macro runs successfully for a small input file with 2 events only

Regards

Hard to tell why there is a memory error, it looks to me that the correlations array is correctly initialized.

Only one thing looks fishy to me:

   correlations[cs][c] = new TProfile("","",1,0.,1.);

I don’t think it’s valid to pass an empty name to the constructor of a ROOT class, maybe the error comes from there. Also, the names need to be unique. I guess this would work:

   std::string profileName = "profile_" + std::to_string(cs) + "_" + std::to_string(c);
   correlations[cs][c] = new TProfile(profileName.c_str(),"",1,0.,1.);

Let us know if this solves the problem!

Jonas

root [0] .L Correlator.C
In file included from input_line_8:1:
In file included from /home/arshad/WorkSpace/2024/correlations/Correlator.C:2:
/home/arshad/WorkSpace/2024/correlations/Correlator.h:272:66: error: expected ‘;’ at end of declaration
std::string profileName = “profile_” + std::to_string(cs) + “_” std::to_string(c);

######################################

Sorry i am not that good at programming

Do i have to copy paste ,these two lines or i have to use this profileName in

correlations[cs][c] = new TProfile("","",1,0.,1.);

Regards

Hi, I edited my previous answer. Indeed there was a typo because I missed a plus sign, and then of course the intention was to use that variable in the TProfile constructor as the name (the first argument, the second parameter is the title that should not matter).

Still the same error!!!

root [2] a.Loop()

Error in : Trying to access a pointer that points to an invalid memory address.
Execution of your code was aborted.
In file included from input_line_8:1:
/home/arshad/WorkSpace/2024/correlations/Correlator.C:39:2: warning: invalid memory pointer passed to a callee:
correlations[0][0]->Fill(0.5,two.Re(),wTwo); // <<cos(h1phi1+h2phi2)>>

Then I ran out of ideas :frowning:

Can you share this ampt01-100-1-1.root so we can fully reproduce the problem and don’t have to guess?

sure…i am attaching ampt01-100-1-1.root which has 100 events…and also the ampt01-2-1-1.root with 2 events with which the macro runs successfully
ampt01-100-1-1.root (881.6 KB)
ampt01-2-1-1.root (29.4 KB)

Thanks for sharing!

I see, indeed it was not possible for us to understand the problem with the file :+1:

You have hardcoded the maximum number of particles per event in your reader:

// Fixed size dimensions of array or collections stored in the TTree if any.
   static constexpr Int_t kMaxfParticles = 854;

This determines the size of the buffers the branches are read into. However, if I print the fNpa variable for each event, I can see that the maximum number of particles is actually higher than that! It’s 930. That’s why your memory gets completely corrupted, because there is a classic buffer overflow.

You should increase kMaxfParticles to maybe 1024 and add some checks like this in the event loop to prevent this problem in the future:

      if (fNpa > kMaxfParticles) {
          std::cout << "fNpa is larger than kMaxfParticles!" << std::endl;
      }

Cheers,
Jonas

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