Template class dictionary generation

Hi everybody,

I have a bunch of “inherited” template classes which I would like to use it with root.
I tried building a dynamic library. The library generation fails when calling rootcint with
the message:

Error: class,struct,union or type (doublelfVal){ not defined C1DHisto.h:45:

Here is the code:

#ifndef C1DHISTO_H_
#define C1DHISTO_H_

#include "C1DTable.h"

namespace gen_math_gi{

template <typename T>
class C1DHisto: public C1DTable<T> {
public:
	C1DHisto();
	virtual ~C1DHisto();

	bool addCols(valarray<T>&, valarray<T>&);
	bool addCols(T*, T*, size_t);

	const valarray<T>* getBins()const{return C1DTable<T>::getCol(0);};
	const valarray<T>* getNs()const{return C1DTable<T>::getCol(1);};

	virtual bool saveToFile(ofstream*, const char* sFilename=0);
	virtual bool readFromFile(ifstream*, const char* sFilename=0);

	bool areCompatible(C1DHisto<T>&);
	C1DHisto<T>& operator+=(C1DHisto<T>&);
	C1DHisto<T>& operator*=(double);
};

template <typename T>
C1DHisto<T>::C1DHisto(){
}

template <typename T>
C1DHisto<T>::~C1DHisto(){
}

template <typename T>
C1DHisto<T>& C1DHisto<T>::operator*=(double lfVal){
	string sDbg("C1DHisto<T>::operator*=");

	valarray<T>* lfLocalData = const_cast<valarray<T>*>(this->getNs());

	(*lfLocalData)*=lfVal;

	return *this;
};

template <typename T>
C1DHisto<T>& C1DHisto<T>::operator+=(C1DHisto<T>& histo){
	string sDbg("C1DHisto<T>::operator+=");

	if( !areCompatible(histo) ){
		CError::Error(sDbg.data(), "histograms have different binnings, line %d", __LINE__);
		return *this;
	}

	valarray<T>* lfLocalData = const_cast<valarray<T>*>(this->getNs());
	const valarray<T>* lfData = histo.getNs();

	(*lfLocalData)+=(*lfData);

	return *this;
}

template <typename T>
bool C1DHisto<T>::areCompatible(C1DHisto<T>& histo){
	const valarray<T>* lfLocalBins = this->getBins();
	const valarray<T>* lfBins = histo.getBins();

	if( lfLocalBins->size() != lfBins->size() )return false;
	for( size_t ii=0 ; ii<lfLocalBins->size() ; ii++ )
		if( (*lfLocalBins)[ii] != (*lfBins)[ii])return false;

	return true;
}

template <typename T>
bool C1DHisto<T>::addCols(valarray<T>& vBins, valarray<T>& vNs){
	string sDbg("C1DHisto<T>::addCols");

	if( (vBins.size()-1) != vNs.size() ){
		CError::Warning(sDbg.data(), "looks like a cum histo, line %d", __LINE__);
//		return false;
	}

	if( !addCol(vBins) ){
		CError::Error(sDbg.data(), "error setting the bins, line %d", __LINE__);
		return false;
	}
	if( !addCol(vNs) ){
		CError::Error(sDbg.data(), "error setting the data, line %d", __LINE__);
		return false;
	}

	return true;
}

template <typename T>
bool C1DHisto<T>::addCols(T* pBins, T* pNs, size_t nSize){
	string sDbg("C1DHisto<T>::addCols");

	if( pBins == 0 || pNs == 0 ){
		CError::Error(sDbg.data(), "invalid input, line %d", __LINE__);
		return false;
	}

	if( !addCol(pBins, nSize+1) ){
		CError::Error(sDbg.data(), "error setting the bins, line %d", __LINE__);
		return false;
	}
	if( !addCol(pNs, nSize) ){
		CError::Error(sDbg.data(), "error setting the data, line %d", __LINE__);
		return false;
	}

	return true;
}

template <typename T>
bool C1DHisto<T>::saveToFile(ofstream* pOFstream, const char* sFilename){
	return C1DTable<T>::saveToFile(pOFstream, sFilename);
}

template <typename T>
bool C1DHisto<T>::readFromFile(ifstream* pIFstream, const char* sFilename){
	return C1DTable<T>::readFromFile(pIFstream, sFilename);
}

};
#endif /* C1DHISTO_H_ */

Any idea why?

Thank you in advance.

Here I marked the line.

#ifndef C1DHISTO_H_
#define C1DHISTO_H_

#include "C1DTable.h"

namespace gen_math_gi{

template <typename T>
class C1DHisto: public C1DTable<T> {
public:
	C1DHisto();
	virtual ~C1DHisto();

	bool addCols(valarray<T>&, valarray<T>&);
	bool addCols(T*, T*, size_t);

	const valarray<T>* getBins()const{return C1DTable<T>::getCol(0);};
	const valarray<T>* getNs()const{return C1DTable<T>::getCol(1);};

	virtual bool saveToFile(ofstream*, const char* sFilename=0);
	virtual bool readFromFile(ifstream*, const char* sFilename=0);

	bool areCompatible(C1DHisto<T>&);
	C1DHisto<T>& operator+=(C1DHisto<T>&);
	C1DHisto<T>& operator*=(double);
};

template <typename T>
C1DHisto<T>::C1DHisto(){
}

template <typename T>
C1DHisto<T>::~C1DHisto(){
}

template <typename T>
C1DHisto<T>& C1DHisto<T>::operator*= (double lfVal){

	string sDbg("C1DHisto<T>::operator*=");
	valarray<T>* lfLocalData = const_cast<valarray<T>*>(this->getNs());

	(*lfLocalData)*=lfVal;

	return *this;
};

template <typename T>
C1DHisto<T>& C1DHisto<T>::operator+=(C1DHisto<T>& histo){
	string sDbg("C1DHisto<T>::operator+=");

	if( !areCompatible(histo) ){
		CError::Error(sDbg.data(), "histograms have different binnings, line %d", __LINE__);
		return *this;
	}

	valarray<T>* lfLocalData = const_cast<valarray<T>*>(this->getNs());
	const valarray<T>* lfData = histo.getNs();

	(*lfLocalData)+=(*lfData);

	return *this;
}

template <typename T>
bool C1DHisto<T>::areCompatible(C1DHisto<T>& histo){
	const valarray<T>* lfLocalBins = this->getBins();
	const valarray<T>* lfBins = histo.getBins();

	if( lfLocalBins->size() != lfBins->size() )return false;
	for( size_t ii=0 ; ii<lfLocalBins->size() ; ii++ )
		if( (*lfLocalBins)[ii] != (*lfBins)[ii])return false;

	return true;
}

template <typename T>
bool C1DHisto<T>::addCols(valarray<T>& vBins, valarray<T>& vNs){
	string sDbg("C1DHisto<T>::addCols");

	if( (vBins.size()-1) != vNs.size() ){
		CError::Warning(sDbg.data(), "looks like a cum histo, line %d", __LINE__);
//		return false;
	}

	if( !addCol(vBins) ){
		CError::Error(sDbg.data(), "error setting the bins, line %d", __LINE__);
		return false;
	}
	if( !addCol(vNs) ){
		CError::Error(sDbg.data(), "error setting the data, line %d", __LINE__);
		return false;
	}

	return true;
}

template <typename T>
bool C1DHisto<T>::addCols(T* pBins, T* pNs, size_t nSize){
	string sDbg("C1DHisto<T>::addCols");

	if( pBins == 0 || pNs == 0 ){
		CError::Error(sDbg.data(), "invalid input, line %d", __LINE__);
		return false;
	}

	if( !addCol(pBins, nSize+1) ){
		CError::Error(sDbg.data(), "error setting the bins, line %d", __LINE__);
		return false;
	}
	if( !addCol(pNs, nSize) ){
		CError::Error(sDbg.data(), "error setting the data, line %d", __LINE__);
		return false;
	}

	return true;
}

template <typename T>
bool C1DHisto<T>::saveToFile(ofstream* pOFstream, const char* sFilename){
	return C1DTable<T>::saveToFile(pOFstream, sFilename);
}

template <typename T>
bool C1DHisto<T>::readFromFile(ifstream* pIFstream, const char* sFilename){
	return C1DTable<T>::readFromFile(pIFstream, sFilename);
}

};
#endif /* C1DHISTO_H_ */

Hi,

works for me. Which ROOT version, which platform? Could you try with the trunk or the release v5.25/04 from a few minutes ago?

Cheers, Axel.