Re: [ROOT] gObjectTable

From: Paolo ADRAGNA (paolo.adragna@pi.infn.it)
Date: Thu May 22 2003 - 17:52:42 MEST


Hello Rene,

I didn't answer immediately just to make some more trials on my code, but 
after so much time I still don't understand what is the matter. I then accept 
your offer and send to you a complete description of what I am doing, hoping 
in some new idea.

To begin with, here is the source of  used classes:

/***************************************************************************
                          TC_RawData.cpp  -  description
                             -------------------
    begin                : Fri Mar 14 2003
    copyright            : (C) 2003 by Paolo ADRAGNA
    email                : paolo.adragna@pi.infn.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "TC_RawData.h"

#include <TBuffer.h>
#include <iostream>
#include <TTree.h>
#include <TBranch.h>
#include <TObjectTable.h>

//#include "tile_event.c"
#include "event_header.h"
#include "event_header_static.h"

#include "TC_Drawer.h"

ClassImp(TC_RawData)

#define MAX_RAW_FRAG 6
#define MAX_FRAGS    3
#define BCID_SIZE  1000

TC_RawData::TC_RawData(unsigned int nrod, unsigned int nfrag)
{
  fNROD = nrod;
  fNFrag = nfrag;

  fDrawer = 0;

  fBeamTDCData = 0;
  fBeamADCData = 0;
 // fMuonADCData = 0;
  fAddrADCData = 0;
 // fLasePtnData = 0;
  fLaseADCData = 0;
  fDigiParData = 0;
 // fAddFADCData = 0;
 flag = 0;

}

TC_RawData::~TC_RawData()
{

//if  delete header;
if (fBeamTDCData) delete fBeamTDCData ;
//if (fBeamADCData) delete fBeamADCData ;
//if (fMuonADCData) delete fMuonADCData ;
//if (fAddrADCData) delete fAddrADCData ;
//if (fLasePtnData) delete fLasePtnData ;
//if (fLaseADCData) delete fLaseADCData ;
//if (fDigiParData) delete fDigiParData ;
//if (fAddFADCData) delete fAddFADCData ;
if (fDrawer)
  {
    delete fDrawer;
    fDrawer = 0;
  }

}

void TC_RawData::ReadFromMem(TC_RawAtlasEvent* evt)
{

  TC_RODFragment* ROD;

  cout <<"fNROD = "<<fNROD <<endl;
  if (fDrawer == 0)
  {
    cout <<"fNFrag = " << fNFrag <<endl;
    fDrawer = new TClonesArray ("TC_Drawer", fNFrag);
  }

  TClonesArray& Drawer = *fDrawer;

  unsigned int f = 0;
  TC_Drawer* fTCDrawer;
 
  fFragments = new vector<unsigned int*>;
  fFragments->reserve(fNFrag);
  fFragments->assign(fNFrag, 0);
  vector<unsigned int*>& Fragment = *fFragments;

  printf("fFragment.size() = %u\n",Fragment.size());
  printf("fFragment.capacity() = %u\n",Fragment.capacity());

  unsigned int h;

  for (h=0; h<fNROD; h++)
  {
    ROD = &(evt->SubDetectorFragment[0].ROC_Fragment[0].ROB_Fragment[0].
      ROD_Fragment[h]);
    vector<unsigned int*>* Frags;
    Frags = ROD->GetDataFragments();
    vector<unsigned int*>& Frag = *Frags;
    printf("*(ROD->GetSourceIdentifier()) = 
%x\n",*(ROD->GetSourceIdentifier()));
    switch (*(ROD->GetSourceIdentifier()))
    {
      case 0x500000ff :
        cout << "case 0x500000ff" << endl;
        Fill_Beam (ROD->GetStartOfHeader(), ROD->GetFragmentSize(), Frag);
        break;
      case 0x50000000 :
      case 0x50000001 :
        cout << "case 0x50000000" << endl;
        for (unsigned int k = 0; k< 3; k++)
        {
          cout << "f = " << f<< " k = " << k <<" 3f+k = "<<3*f+k<<endl;
          Fragment[3*f+k] = Frag[k];
          printf("fFragment[%u] = %x\n",3*f+k, *Fragment[3*f+k]);
        }
        f++;
        break;
      default :
        cout <<"Something went wrong" <<endl;
        break;
    }
  }

  int last = Drawer.GetLast();
  cout << "Drawer.GetLast = " << last <<endl;

  printf("fFragment.size() = %u\n",Fragment.size());

>-------------------------------------------------<
  for (h=0; h<fNFrag; h++)
    {
      cout<<"h = "<<h<<endl;
      fTCDrawer = new (Drawer[h]) TC_Drawer();
      printf("Pointer Drawer = %x\n", Drawer[h]);
      printf("Pointer fTCDrawer = %x\n", fTCDrawer);
      fTCDrawer = (TC_Drawer*)Drawer[h];
      printf("Pointer fTCDrawer = %x\n", fTCDrawer);
      Fill_Drawer (Fragment[h], fTCDrawer);
      if (h == 5) gObjectTable->Print();
    }
>--------------------------------------------------<
  last = Drawer.GetLast();
  cout << "Drawer.GetLast = " << last <<endl;  
}

void TC_RawData::Fill_Beam( void * rod, unsigned int rodsize, vector<unsigned 
int*>& fragm)
{

    unsigned int f, id,size;
    unsigned long *data;

  for (f=0; f<fNFrag; ++f)
  {
      id   = *(fragm[f] + 1);
      size = *fragm[f] - 2;
      data = (unsigned long*)fragm[f] + 2;
      
      printf("size = %u, data = %x\n",size, *data);
      switch (id) {

  case BEAM_TDC_FRAG:
    
    if (!fBeamTDCData)   
      fBeamTDCData = new TC_BeamTDCData();
    fBeamTDCData->Decode(size, data);
    fBeamTDCData->Print();
    break;

  case BEAM_ADC_FRAG:

    if (!fBeamADCData)
      fBeamADCData = new TC_BeamADCData();
    fBeamADCData->Decode(size, data);
    fBeamADCData->Print();
    break;

  case MUON_ADC_FRAG:
       /*
       fMuonADCData = new TC_MuonADCData();
       fMuonADCData->Decode(size, data);
       fMuonADCData->Print(); */
       break;

  case ADDR_ADC_FRAG:

    if (!fAddrADCData)
      fAddrADCData = new TC_AddrADCData();
    fAddrADCData->Decode(size, data);
    fAddrADCData->Print();
    break;

  case LASE_PTN_FRAG:
       /*
       fLasePtnData = new TC_LasePtnData();
       fLasePtnData->Decode(size, data); ;
       fLasePtnData->Print();*/
       break;

  case LASE_ADC_FRAG:
    
    if(!fLaseADCData)
      fLaseADCData = new TC_LaseADCData();
    fLaseADCData->Decode(size, data);
    fLaseADCData->Print();
    break;

  case DIGI_PAR_FRAG:

    if (!fDigiParData)
    fDigiParData = new TC_DigiParData();
    fDigiParData->Decode(size, data);
    fDigiParData->Print();
    break;

  case ADD_FADC_FRAG:
      /*
      fAddFADCData = new TC_AddFADCData();
      fAddFADCData->Decode(size, data);
      fAddFADCData->Print(); */
      break;

	default:
	    printf("\nUnknown fragment [%#x], %d words found\n",id,size);
	    break;
	}
    }
}



void TC_RawData::Fill_Drawer(unsigned int* Data, TC_Drawer* Drawer)
{
   unsigned int size = *Data;
   printf("size = %x\n", size);
   unsigned int* id = Data + 1;
   printf("id = %x\n", *id);

   if ( size > 0 )
   {
    printf("Data = %x\n", *(Data + 2));
    unsigned long* dat = (unsigned long*)Data;
    Drawer->Decode(dat);
    cout << "Drawer Decoded"<<endl;
   }

}

void TC_RawData::CreateBranches (TTree* tree)
{

printf("Creating branches...\n");

tree->Branch("BeamTDC", "TC_BeamTDCData", &(fBeamTDCData), 32000, 3);
tree->Branch("BeamADC", "TC_BeamADCData", &(fBeamADCData), 32000, 3);


TClonesArray& Drawer = *fDrawer;
char title[30];

for (unsigned int j=0; j<fNFrag; ++j)
  {
    sprintf(title, "Drawer %d", j);
    cout << title << endl;   
   >----------------------------------------------------------------<
    tree->Branch(title, "TC_Drawer", &(Drawer[j]), 32000, 3);
  >-----------------------------------------------------------------<
  }
  cout <<"Branches made up"<<endl;
}

void TC_RawData::Clear(Option_t* option)
{
  printf("TC_RawData Clear called\n");
  fDrawer->Clear("C");
}


The part of code with problems is emphasized by >----------<.

After the loop I should have 6 istances of TC_Drawer but as shown by 
gObjectTable->Print() I can see only one or noone of those instances.
Following your suggestion I put some printout in cstr and dstr, by everything 
seems ok: at that moment I must have 6 TC_Drawers. What's more, 
Drawer.GetLast() gets correctly 5. Note that other objects deriving from 
TObject and created by me are correctly reported.

These are header of TC_RawData and TC Drawer:

/***************************************************************************
                          TC_RawData.h  -  description
                             -------------------
    begin                : Fri Mar 14 2003
    copyright            : (C) 2003 by Paolo ADRAGNA
    email                : paolo.adragna@pi.infn.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef TC_RAWDATA_H
#define TC_RAWDATA_H

#include <vector>
#include <TObject.h>
#include <TTree.h>
#include <TClonesArray.h>


#include "TC_RODFragment.h"
#include "TC_BeamTDCData.h"
#include "TC_BeamTDCData.h"
#include "TC_BeamADCData.h"
//#include "TC_MuonADCData.h"
#include "TC_AddrADCData.h"
//#include "TC_LasePtnData.h"
#include "TC_LaseADCData.h"
#include "TC_DigiParData.h"
//#include "TC_AddFADCData.h"
#include "TC_RawAtlasEvent.h"
#include "TC_Drawer.h"

class TC_RawData : public TObject
{

  public:

  TC_BeamTDCData* fBeamTDCData;
  TC_BeamADCData* fBeamADCData;
  //TC_MuonADCData* fMuonADCData;
  TC_AddrADCData* fAddrADCData;
  //TC_LasePtnData* fLasePtnData;
  TC_LaseADCData* fLaseADCData;
  TC_DigiParData* fDigiParData;
  //TC_AddFADCData* fAddFADCData;

  TC_RawData(unsigned int nrod=3, unsigned int nfrag=6);
  virtual ~TC_RawData();

  void ReadFromMem(TC_RawAtlasEvent *evt);
  void CreateBranches (TTree* tree);

  void Fill_Beam( void* rod, unsigned int rodsize, vector<unsigned int*>&);
  void Fill_Drawer (unsigned int*, TC_Drawer*);

  void Clear(Option_t* option="");

  ClassDef(TC_RawData,1)

  private:

  unsigned int flag;
  unsigned int fNROD, fNFrag;

  TClonesArray* fDrawer; //->
  vector<unsigned int*>* fFragments;

};

#endif

/***************************************************************************
                          TC_Drawer.h  -  description
                             -------------------
    begin                : Wed Apr 9 2003
    copyright            : (C) 2003 by Paolo ADRAGNA
    email                : paolo.adragna@pi.infn.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TC_DRAWER_H
#define TC_DRAWER_H

#include <TObject.h>
#include <TClonesArray.h>

#include "TC_Calibration.h"

class TC_Drawer : public TObject
{
 public:

  TC_Drawer();
  virtual ~TC_Drawer();
  void Decode (unsigned long* frag);
  void Clear(Option_t* option="");
  
  ClassDef(TC_Drawer, 1)
    
 private :
  

  unsigned long CheckParity(unsigned long *frame, int length);
  unsigned long CheckStartBit(unsigned long *frame, int length, unsigned long 
startbit);
  unsigned long CheckCRC(unsigned long* frame, int framelen, int delta);


  unsigned int id;
  TClonesArray* fChannel;

};

#endif

Another matter is in the second emphasized fragment.

The program brakes with segmentation violation when attempting to create 
branches in tree. It is useful to note that when program doesn't crash 
reports 1 TC_Drawer while no TC_Drawer istances are reported in case of 
segmentation violation.

Last, the two different behaviours occur for the same program: if you compile 
the first time you can obtain a working program or not, but if you obtained a 
working one and you decide to recompile, you can get a not working program.
And viceversa is of course true. It is very strange. I compile using a very 
simple macro:

{
gROOT->Reset();

......etc

gROOT->ProcessLine(".L TC_PMTChannel.cpp+");
gROOT->ProcessLine(".L TC_Drawer.cpp+");
gROOT->ProcessLine(".L TC_RawData.cpp+");

...etc
gROOT->ProcessLine(".L TC_MainFrame.cpp+");

//create and start monitor object
TC_MainFrame *TBM = new TC_MainFrame();

}

So my application run under ROOT environment.

Last information, I use ROOT v3.04/02 on gcc 2.96 
(Red Hat Linux 7.3 2.96-112).

My program is being written for this summer Atlas Tile Calorimeter
Test Beam. If you think it is useful, I'll be at CERN from Monday, 22 May and 
also at ROOT class in June. 

If you need more information don't hesitate to ask.
Thank a lot and sorry for the length.

					Paolo Adragna


On Tuesday 20 May 2003 18:34, you wrote:
> Can you send me the output og gObjectTable->Print() at a time when
> you think that at least one object of the class is instantiated.
> Could you put a print statement in your constructor AND destructor
> to monitor the creation/deletion of this class?
>
> Rene
>



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET