Root 5.12/00a on Suse 10.1: problem loading class

Hi,
I recently upgraded my computer from Suse 9.2, gcc 3.3.5, root 5.10/00 to Suse 10.1, gcc 4.1 and root 5.12/00a.

Now, when I try to compile one of my class, there is a error:

Info in : creating shared library /home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./TCompound_cpp.so
/home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./fileXM0WqD.cxx: In function ‘int G__fileXM0WqD_1418_6_0(G__value*, const char*, G__param*, int)’:
/home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./fileXM0WqD.cxx:342: error: invalid cast from type ‘std::vector<TString, std::allocator >’ to type ‘long int’
g++: /home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./fileXM0WqD.o: No such file or directory
Error in : Compilation failed!

The class is:

TCompound.h

#ifndef TCOMPOUND_HH
#define TCOMPOUND_HH

#include
#include
#include

#define COMPOUNDS_FILE “./COMPOUNDS.DAT”

/// \brief Class describing a chemical compound.
class TCompound {
public:
TCompound(TString COMPOUND_NAME, Bool_t VERBOSE=1);
~TCompound();
inline TString GetCompoundName() {return CompoundName;}
inline Double_t GetFraction() {return Fraction;}
inline void SetFraction(Double_t FRACTION) {Fraction = FRACTION;}
inline Int_t GetnElementsInCompound() {return nElementsInCompound;}
inline std::vector GetElementsInCompound() {return ElementsInCompound;}
inline std::vector<Int_t> GetnAtomsInCompound() {return nAtomsInCompound;}

private:
Bool_t Verbose;
TString CompoundName;
Double_t Fraction;
Int_t nElementsInCompound;
std::vector ElementsInCompound;
std::vector<Int_t> nAtomsInCompound;
};

#endif

TCompound.cpp

#include “TCompound.h”

//*******************************************************************************
/// \brief Basic constructor. *
//*******************************************************************************
TCompound::TCompound(TString COMPOUND_NAME, Bool_t VERBOSE)
{
Verbose = VERBOSE;
CompoundName = “NONE”;
// Open the file containing the compound informations and skip the file header…
ifstream CompoundsFile;
CompoundsFile.open(COMPOUNDS_FILE);
TString Dummy = “”;
while (Dummy != “BEGIN:”) CompoundsFile >> Dummy;
// Read the compound properties.
TString ElementTemp;
Int_t nAtomsTemp;
while (!CompoundsFile.eof()){
CompoundsFile >> CompoundName;
CompoundsFile >> nElementsInCompound;
for (Int_t i=0; i> ElementTemp;
ElementsInCompound.push_back(ElementTemp);
CompoundsFile >> nAtomsTemp;
nAtomsInCompound.push_back(nAtomsTemp);
}
if (CompoundName == COMPOUND_NAME){
CompoundsFile.close();
if (Verbose){
std::cout << "Compound name: " << CompoundName << std::endl;
std::cout << "Number of elements: " << nElementsInCompound << std::endl;
for (Int_t j=0; j<nElementsInCompound; j++){
std::cout << "Element: " << ElementsInCompound[j] << ", ";
std::cout << "number of atoms: " << nAtomsInCompound[j] << std::endl;
}
}
return;
}
else{
ElementsInCompound.clear();
nAtomsInCompound.clear();
}
}
// If the compound is not available…
std::cout << COMPOUND_NAME << " is not available. Please edit by hand the file " <<
COMPOUNDS_FILE << std::endl;
CompoundsFile.close();
CompoundName = “NONE”;
return;
}

//*******************************************************************************
/// \brief Basic destructor. *
//*******************************************************************************
TCompound::~TCompound()
{

}

Any suggestion?

Thanks in advance.

Fabio

Your files are corrupted. Post them as attachement.
In TCompound.h, you should at least add
#include

Rene

I added line

#include

to TCompound.h but error remains the same:

Info in : creating shared library /home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./TCompound_cpp.so
/home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./file9Whw7U.cxx: In function ‘int G__file9Whw7U_1418_6_0(G__value*, const char*, G__param*, int)’:
/home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./file9Whw7U.cxx:342: error: invalid cast from type ‘std::vector<TString, std::allocator >’ to type ‘long int’
g++: /home/fabio/PolarimeterSimulatorRND+VER+SHELL+DIR/SimPol/./file9Whw7U.o: No such file or directory
Error in : Compilation failed!

Fabio
TCompound.cpp (1.98 KB)
TCompound.h (1.05 KB)

Hi,

just to let you know about the status: I’m working on it, I have a solution, but I would prefer to understand where the problem comes from. I will let you know when the fix arrives in ROOT’s CVS. Your code should work even now if you use std::vectorstd::string. Note that you are passing copies of your containers around; usually passing a (const?) reference is sufficient, and it’s a lot more efficient.

Cheers, Axel.

Thanks for your help!

My program works replacing “TString” with “string”, but I’ll try your fix when it’ll be available.

Can you explain in more details your suggestion:

I’m not an expert programmer but I’m interesting in optimization of my program.

Cheers,
Fabio

Hi,

assume you have [code]class TMyFriends {
private:
std::liststd::string fNames;

public:
TMyFriends() {…}
std::liststd::string GetNames() { return fNames; }
};[/code] When you call TMyFriends myFriends; std::list<std::string> names = myFriends.GetNames(); std::cout << "Look how many friends I have: " << names.size() << std::endl; the compiler will create a copy of myFriends.fNames. GetNames() returns that copy. Afterwards, it is copied to names. So that list is copied twice - including all its strings! This might be avoided by smart compilers - but I would not rely on it, and it isn’t avoided in all cases. This version is better:

[code]class TMyFriends {
private:
std::liststd::string fNames;

public:
TMyFriends() {…}
const std::liststd::string &GetNames() const { return fNames; }
};[/code] where you’d call TMyFriends myFriends; const std::list<std::string> &names = myFriends.GetNames(); std::cout << "Look how many friends I have: " << names.size() << std::endl; Here, not even a single list is copied.

Cheers, Axel.

Thank you for your clear example!

Fabio

I’m just curious as to the status of this fix. I am also running 5.12/00f, and am receiving similar messages:

/tmp/moffit/pan/./panguin/file9FnURB.cxx: In function ‘int G__file9FnURB_1795_6_3(G__value*, const char*, G__param*, int)’:
/tmp/moffit/pan/./panguin/file9FnURB.cxx:1085: error: invalid cast from type ‘std::vector<TString, std::allocator<TString> >’ to type ‘long int’

Unfortunately… I do not think that I’ll be able to use the simple TString to string fix without quite an overhaul, since my code heavily uses the TString subroutines.

Thanks.

Could you check with ROOT 5.14/00?

Thanks,
Philippe

With 5.14.00b, these error messages disappear. Thanks.