Skip to content

Code unloading fails assert: "Can not revert previous transactions" #9187

@Axel-Naumann

Description

@Axel-Naumann

From https://root-forum.cern.ch/t/segmentation-violation-when-re-compiling-cpp-file-after-running/47373

// minimal.cpp
# include <TRandom3.h>
# include <TH1D.h>
# include <TFile.h>
# include <TCanvas.h>
# include <TStyle.h>

# include <Riostream.h>
# include <iostream>

void particles_decay(int N0, double delta_t, double alpha, int seed = 1) {
    double t=0.;
    double T = 300.;

    int N_survived = N0;
    int N_decayed;

    int N_steps = (int)(T/delta_t);
    int step = 0;

    double r;

    TRandom3 *gRandom = new TRandom3();
    gRandom -> SetSeed(seed);


    TFile file("particles_decay.root", "recreate");

    TCanvas* f = new TCanvas("f");

    //creo oggetto TH1D per disegnare la funzione di decadimento
    TH1D* N_vs_t = new TH1D("N_vs_t", "Number of particles in time", N_steps, 0, T);

    while((t < T) && (N_survived > 0)) {

        N_vs_t -> SetBinContent(step, N_survived);

        //simulo decadimento radioattivo sulle particelle sopravvisute
        N_decayed = 0;
        for(int j=0; j<N_survived; j++){
            r = gRandom -> Rndm();
            if (r < alpha*delta_t) N_decayed++;
        }

        if (N_survived <= N_decayed) break;
        N_survived -= N_decayed;

        t += delta_t;
        step++;
    }

    gStyle -> SetOptFit();
    N_vs_t -> Fit("expo");

    N_vs_t -> DrawCopy();

    //Metto sul file root tutte le robe sovrapposte, nota che f punta al TCanvas aperto sopra, 
    //mentre il file .root con quel nome era stato anche lui creato sopra.
    f -> Print("particles_decay.root");

    file.Close();
}

This gives

root [0] .L minimal.C
root [1] particles_decay(500, 1., 0.01)
 FCN=51.0153 FROM MIGRAD    STATUS=CONVERGED      40 CALLS          41 TOTAL
                     EDM=4.6871e-07    STRATEGY= 1      ERROR MATRIX ACCURATE 
  EXT PARAMETER                                   STEP         FIRST   
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE 
   1  Constant     6.20101e+00   7.29140e-03   1.63914e-05  -1.00223e-01
   2  Slope       -1.01929e-02   6.74151e-05   1.51443e-07   4.24243e+00
Info in <TCanvas::SaveAs>: ROOT file particles_decay.root has been created
root [2] .L minimal.C
root.exe: /home/axel/build/root/master/src/interpreter/cling/lib/Interpreter/Interpreter.cpp:1513: void cling::Interpreter::unload(cling::Transaction&): Assertion `!T.getTopmostParent()->getNext() && "Can not revert previous transactions"' failed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions