Using THashTable

From: Piotr Swiat (ufswiat@if.uj.edu.pl)
Date: Fri Mar 05 1999 - 14:59:14 MET


I've tried to used THashTable class in order to give every parameter in
event
a nickname. I am using root v2.20 and I have following files:

MPar.h
//-------------------------
#ifndef __MPar__
#define __MPar__
#include <TObject.h>
#include <TString.h>

class MPar : public TObject {
private:
   Double_t value;  // parameter value
   TString  name;   // parameter name

public:
   MPar(TString newname = "",Double_t newvalue = 0.0);
   ~MPar() {}

   void SetVal(Double_t newvalue) { value = newvalue; }
   void SetName(TString newname)  { name = newname; }

   Double_t GetVal() { return value; }

   ULong_t Hash() { return name.Hash(); }

   void Print(Option_t *opt = "");

   ClassDef(MPar,1)
};
#endif
//-----------------------------------

MPar.C
//-----------------------------------
#include <iostream.h>
#include "MPar.h"

ClassImp(MPar)
MPar::MPar(TString newname, Double_t newvalue)
{
  name = newname;
  value = newvalue;
}

void MPar::Print(Option_t *opt)
{
  cout << "MPar:: " << name << endl
       << "       " << value << endl;
}
//------------------------------------

MParLinkDef.h
//------------------------------------
#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class MPar;

#endif
/--------------------------------------

MPar_main.C
//------------------------------------
#include <iostream.h>
#include "MPar.h"
#include <TROOT.h>
#include <THashTable.h>

TROOT t("t","test THashTable and MPar");
main()
{
  MPar params[3];
  THashTable tb;

  params[0].SetVal(100);
  params[0].SetName("first");
  params[1].SetVal(200);
  params[1].SetName("second");
  params[2].SetVal(300);
  params[2].SetName("third");

  tb.Add(params);
  tb.Add(params+1);
  tb.Add(params+2);

  tb.Print();

  cout << "first  = " << ((MPar *)tb.FindObject("first")) -> GetVal() <<
endl;
  cout << "second = " << ((MPar *)tb.FindObject("second")) -> GetVal()
<< endl;
  cout << "third  = " << ((MPar *)tb.FindObject("third")) -> GetVal() <<
endl;

  return 0;
}
//-------------------------------------------------

and I used following Makefile for AIX 4.1

ObjSuf        = .o
SrcSuf        = .C
ExeSuf        =
OutPutOpt     = -o
# IBM AIX
CXX           = xlC
CXXFLAGS      = -O -qnoro -qnoroconst -qmaxmem=-1 -I$(ROOTSYS)/include
LD            = xlC
LDFLAGS       = -g
SOFLAGS       =
ROOTLIBS      = -L$(ROOTSYS)/lib -lRoot -lCint
LIBS          = $(ROOTLIBS) -lm -lcurses
#------------------------------------------------------------------------------

MPARAMO     = MPar$(ObjSuf)
MPARAMS     = MPar$(SrcSuf)
MPMAINX      = MPar_main$(ExeSuf)
MPMAINO      = MPar_main$(ObjSuf)
MPMAINS      = MPar_main$(SrcSuf)

PROGRAMS     = $(MPMAINX)
OBJS         = $(MPARAMO) $(MPMAINO) MParDict$(ObjSuf)

all:           $(PROGRAMS)

$(MPMAINX): $(OBJS)
        $(LD) $(LDFLAGS) $(LIBS) $(MPARAMO) MParDict$(ObjSuf) $(MPMAINO)
\
        $(OutPutOpt) $(MPMAINX)

###

clean:
        @rm -f $(OBJS) *Dict.* core

.SUFFIXES: $(SrcSuf)

###

$(MPARAMO): MPar.h
$(MPARAMS): MPar.h

MParDict$(SrcSuf): MPar.h MParLinkDef.h
        @echo "Generating dictionary MParDict..."
        @$(ROOTSYS)/bin/rootcint -f MParDict$(SrcSuf) -c MPar.h
MParLinkDef.h

$(SrcSuf)$(ObjSuf):
        $(CXX) $(CXXFLAGS) -c $<

I can compile it:
xlC -O -qnoro -qnoroconst -qmaxmem=-1 -I/scratch/piotrek/root/include -c
MPar.C
xlC -O -qnoro -qnoroconst -qmaxmem=-1 -I/scratch/piotrek/root/include -c
MPar_main.C
Generating dictionary MParDict...
Note: operator new() masked 1c
Note: operator delete() masked 1c
xlC -O -qnoro -qnoroconst -qmaxmem=-1 -I/scratch/piotrek/root/include -c
MParDict.C
xlC -g -L/scratch/piotrek/root/lib -lRoot -lCint -lm -lcurses MPar.o
MParDict.o MPar_main.o  \
-o MPar_main

but after running the program:
MPar:: second
       200
MPar:: first
       100
MPar:: third
       300
Warning in <TClass::TClass>: no dictionary for class MPar is available
first  = 0
second = 0
third  = 0

Any sugestions?

Piotre Swiat
ufswiat@if.uj.edu.pl



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:30 MET