Segmentation violation 2 TFile in "UPDATE" mode

Hi,

I am using Root 6.08 on Ubuntu 16.04 and I’m having segmentation violation when I try to open two *.root files in “UPDATE” mode. It occurs when I try to write in the second file if it already exist. Whether the root file is not in the folder, i.e. the update just create new files, it perfectly works.
The problem doesn’t happen if I open the the second file in “RECREATE” or “READ” modes. I wonder if there is a manner to overcome this problem. Following the part of code that matters:

	// check which histograms are in the "histograms_ang.root" file..

	TFile p("histograms_ang.root","update");
	TIter next(p.GetListOfKeys());
   	TKey *key;
	int nangs = 0;
	vector<string> angPreps;
   	while ((key=(TKey*)next())) 
	{
		// Histogram names storage in angPreps and count in nangs...
		nangs++;
		angPreps.push_back(key->GetName());
   	}

         if (nangs == 7)  
		{
			GTposition = "nothing"; // No more Groung Truth?? MSR is able to determine a proposition.
			Eigen::VectorXf Qui2_ang(7); 
			  TH2D *h_in = (TH2D*)p.Get("in");
			  TH2D *h_right = (TH2D*)p.Get("right");
			  TH2D *h_left = (TH2D*)p.Get("left");
			  TH2D *h_above = (TH2D*)p.Get("above");
			  TH2D *h_below = (TH2D*)p.Get("below");
			  TH2D *h_front = (TH2D*)p.Get("front");
			  TH2D *h_behind = (TH2D*)p.Get("behind");
			Qui2_ang[0] = h_in->Chi2Test(h_th_phi, "CHI2");
			Qui2_ang[1] = h_right->Chi2Test(h_th_phi, "CHI2");
			Qui2_ang[2] = h_left->Chi2Test(h_th_phi, "CHI2");
			Qui2_ang[3] = h_above->Chi2Test(h_th_phi, "CHI2");
			Qui2_ang[4] = h_below->Chi2Test(h_th_phi, "CHI2");
			Qui2_ang[5] = h_front->Chi2Test(h_th_phi, "CHI2");
			Qui2_ang[6] = h_behind->Chi2Test(h_th_phi, "CHI2");
			Eigen::MatrixXf::Index maxRow, maxCol;
			Qui2_ang.maxCoeff(&maxRow, &maxCol);
			std::string MSRPrep = namePrep[maxRow];	
			std::cout << MSRPrep << std::endl;		  

		}
        if (GTposition != "nothing")
	{
		 if (std::find(angPreps.begin(), angPreps.end(), GTposition) != angPreps.end())
		  {
		   TH2D *h_temp = (TH2D*)p.Get(GTposition.c_str());
		   h_temp->Add(h_th_phi); // adding to existing histogram
		   h_temp->Write(GTposition.c_str(),TObject::kWriteDelete);
		  }
  		 else 
		  {
		   TH2D* h_temp = (TH2D*) h_th_phi->Clone();
		   h_temp->Write(GTposition.c_str(),TObject::kSingleKey);
		  }

      p.Close();

        TFile f("histograms_dist.root","update");
	// check which hisograms are in the "histograms_dist.root" file..
	TIter next2(f.GetListOfKeys());
   	TKey *key2;
	int ndists = 0;
	vector<string> distPreps;
   	while ((key2=(TKey*)next2())) 
	{
		// Histogram names storage in distPreps and count in ndists...
		ndists++;
		distPreps.push_back(key->GetName());
   	}

	if (ndists == 3) 
	{
		GTtouching = "nothing";
		Eigen::VectorXf Qui2_dist(3); 
		TH1D *h_touch = (TH1D*)f.Get("touch");
		TH1D *h_nontouch = (TH1D*)f.Get("nontouch");
		TH1D *h_far = (TH1D*)f.Get("far");
		Qui2_dist[0] = h_touch->Chi2Test(h_dist, "CHI2");
		Qui2_dist[1] = h_nontouch->Chi2Test(h_dist, "CHI2");
		Qui2_dist[2] = h_far->Chi2Test(h_dist, "CHI2");
		Eigen::MatrixXf::Index maxRow2, maxCol2;
		Qui2_dist.maxCoeff(&maxRow2, &maxCol2);
		std::string MSRdist = nameDist[maxRow2];
	
	}

	if (GTtouching != "nothing")
	{
cout << "GTtouching = " << GTtouching << endl;
		if (std::find(distPreps.begin(), distPreps.end(), GTtouching) != distPreps.end())
		{ 
		  TH1D *h_temp1D = (TH1D*)f.Get(GTtouching.c_str());
		  h_temp1D->Add(h_dist); // adding to existing histogram
		  h_temp1D->Write(GTtouching.c_str(),TObject::kWriteDelete);
		}
  		else
	        {
		    TH1D* h_temp1D = (TH1D*)h_dist->Clone(); 
		    h_temp1D->Write(GTtouching.c_str(),TObject::kSingleKey);
		}
	}

And following the error message:

*** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f877f2b907a in __GI___waitpid (pid=26406, stat_loc=stat_loc
entry=0x7ffe30b5fb00, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007f877f231fbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f8780b7e4a4 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x12cb6c0) at /home/tmot987/Tiago/root-6.08.06/core/unix/src/TUnixSystem.cxx:2118
#3  TUnixSystem::StackTrace (this=0x12cb6c0) at /home/tmot987/Tiago/root-6.08.06/core/unix/src/TUnixSystem.cxx:2405
#4  0x00007f8780b80b0c in TUnixSystem::DispatchSignals (this=0x12cb6c0, sig=kSigSegmentationViolation) at /home/tmot987/Tiago/root-6.08.06/core/unix/src/TUnixSystem.cxx:3625
#5  <signal handler called>
#6  0x00000000004083aa in main ()
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00000000004083aa in main ()
===========================================================

Thank you very much.

Tiago.

Hello everybody,

Please don’t waste your time analyzing my code. I was able to find my stupid mistake by myself: I’ve created two keys (key and key2) but used only key in both files.

Sorry.

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