Is it possible to delete a blog from the "I read these blogs" list?
[ROOT] Writing TClonesArray to File
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > C/C++ Programming > [ROOT] Writing TClonesArray to File 22 December 2006 16:23:24

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

[ROOT] Writing TClonesArray to File

Oliver Oberst 22 December 2006 16:23:24
 Hello,

I am writing a rootinterface for a MC Generator. I wrote my on
eventclass, verticesclass and particleclass all inheriting from TObject.
Now in the interface i make a tree and give a Branch the events address.
in This eventbrach i want to have a TClonesArray of my vertexobjects.
I built the dictionary and it worked so that the event and the vertex
class have their own streamer.
I tested the TClonesarray in the code so that i now know that filling
the TClonesArray workes(I can readout vertex members after filling the
array).
I think the problem is when the event streamer calls the
'TClonesArrayobject­'->Streamer(b) and there the Vertex Streamer is not
called. Because i only see the events members as leafes and one leaf
with the name of the TClonesArray. Normaly it should be browsable
because i split the tree (with 99). I now do not see why the
TClonesArray with my Vertex Objects are not streamed in the file and it
is not browsable...

Code:
-------------------­--------------------­--------------------­--------
Streamers in dictionary which is linked in my shared lib:

void HepMCEvent::Streame­r(TBuffer &R__b)
{
// Stream an object of class HepMCEvent.

UInt_t R__s, R__c;
if (R__b.IsReading()) {
Version_t R__v = R__b.ReadVersion(&R­__s, &R__c); if (R__v) { }
TObject::Streamer(R­__b);
R__b >> signal_process_id;
R__b >> event_number;
R__b >> event_scale;
R__b >> alphaQCD;
R__b >> alphaQED;
R__b >> vertices_size;
Vertices->Streamer(­R__b);
R__b.CheckByteCount­(R__s, R__c, HepMCEvent::IsA());­
} else {
R__c = R__b.WriteVersion(H­epMCEvent::IsA(), kTRUE);
TObject::Streamer(R­__b);
R__b << signal_process_id;
R__b << event_number;
R__b << event_scale;
R__b << alphaQCD;
R__b << alphaQED;
R__b << vertices_size;
Vertices->Streamer(­R__b);
R__b.SetByteCount(R­__c, kTRUE);
}
}
---snip
void HepMCVertex::Stream­er(TBuffer &R__b)
{
// Stream an object of class HepMCVertex.

UInt_t R__s, R__c;
if (R__b.IsReading()) {
Version_t R__v = R__b.ReadVersion(&R­__s, &R__c); if (R__v) { }
TObject::Streamer(R­__b);
R__b >> barcode;
R__b >> id;
R__b >> position_x;
R__b >> position_y;
R__b >> position_z;
R__b >> position_t;
R__b >> numOrphan;
R__b >> particles_out_size;­
R__b.CheckByteCount­(R__s, R__c, HepMCVertex::IsA())­;
} else {
R__c = R__b.WriteVersion(H­epMCVertex::IsA(), kTRUE);
TObject::Streamer(R­__b);
R__b << barcode;
R__b << id;
R__b << position_x;
R__b << position_y;
R__b << position_z;
R__b << position_t;
R__b << numOrphan;
R__b << particles_out_size;­
R__b.SetByteCount(R­__c, kTRUE);
}
-------------------­--------------------­--------------------­--------------------­---
-------------------­--------------------­--------------------­--------------------­-----
The EventHeader:
-------------------­--------------------­--------------------­--------------------­---
#ifndef HepMCEvent_H
#define HepMCEvent_H

#include"TObject.h"­
#include"TClonesArr­ay.h"

#ifndef __MAKECINT__
#include "CLHEP/HepMC/GenEve­nt.h"
#endif

class TClonesArray;
class HepMCVertex;

class HepMCEvent : public TObject{

public:
HepMCEvent(){};
~HepMCEvent(){};

#ifndef __MAKECINT__
HepMCEvent(HepMC::G­enEvent *hepmc);
#endif

void finish();

private:

int signal_process_id;
int event_number;
double event_scale;
double alphaQCD;
double alphaQED;

int vertices_size;

TClonesArray *Vertices; //-> TClonesArray of my Vertices

ClassDef(HepMCEvent­,1)

};

#endif
-------------------­--------------------­--------------------­---
-------------------­--------------------­--------------------­--
The Event Body:
-------------------­--------------------­--------------------­---
#include <iostream>
#include "HepMCEvent.h"
#include "HepMCVertex.h"

ClassImp(HepMCEvent­);

using namespace std;

HepMCEvent::HepMCEv­ent(HepMC::GenEvent *hepmc){
signal_process_id = hepmc->signal_proce­ss_id();
event_number = hepmc->event_number­();
event_scale = hepmc->event_scale(­);
alphaQCD = hepmc->alphaQCD();
alphaQED = hepmc->alphaQED();
vertices_size = hepmc->vertices_siz­e();

Vertices = new TClonesArray("HepMC­Vertex", vertices_size);
//TClonesArray Vert("HepMCVertex",­ vertices_size);

int vert_count = 0;
for( HepMC::GenEvent::ve­rtex_const_iterator v =
hepmc->vertices_beg­in();
v != hepmc->vertices_end­(); ++v ){
new((*Vertices)[vert_count]) HepMCVertex(*v);
vert_count++;
}
//HepMCVertex *temp = (HepMCVertex*) Vertices->At(0);
// temp->print_barcode­();
}

void HepMCEvent::finish(­){

}
-------------------­--------------------­--------------------­---
-------------------­--------------------­--------------------­---
The Vertex Header:
-------------------­--------------------­--------------------­---
#ifndef HepMCVertex_H
#define HepMCVertex_H

#include"TObject.h"­

#ifndef __MAKECINT__
#include "CLHEP/HepMC/GenEve­nt.h"
#include "CLHEP/HepMC/GenVer­tex.h"
#endif

class HepMCEvent;

class HepMCVertex : public TObject{

public:

HepMCVertex(){};
~HepMCVertex(){};

#ifndef __MAKECINT__
HepMCVertex(HepMC::­GenVertex *vertex);
#endif

void print_barcode();
private:

int barcode;
int id;
double position_x;
double position_y;
double position_z;
double position_t;

int numOrphan;
int particles_out_size;­

ClassDef(HepMCVerte­x,1)
};

#endif
-------------------­--------------------­--------------------­---
-------------------­--------------------­--------------------­--
The Vertex Body:
-------------------­--------------------­--------------------­---
#include <iostream>
#include "HepMCVertex.h"

ClassImp(HepMCVerte­x);

using namespace std;

HepMCVertex::HepMCV­ertex(HepMC::GenVert­ex *vertex){
int numOrph = 0;
for ( HepMC::GenVertex::p­articles_in_const_it­erator p =
vertex->particles_i­n_const_begin();
p != vertex->particles_i­n_const_end(); ++p ){
if ( !(*p)->production_v­ertex() ) ++ numOrph;
}

barcode = vertex->barcode();
id = vertex->id();
position_x = vertex->position().­x();
position_y = vertex->position().­y();
position_z = vertex->position().­z();
position_t = vertex->position().­t();
particles_out_size = vertex->particles_o­ut_size();

numOrphan = numOrph;

}

void HepMCVertex::print_­barcode(){
cout<< "barcode : " << barcode << endl;
}
-------------------­--------------------­-------------------
-------------------­--------------------­------------------
The RootFilewriter Body:
#include <iostream>


#include "RootFileWriter.h"
#include "HepMCEvent.h"

using namespace std;

void RootFileWriter::ini­t(string filename, string treename){
f = new TFile(filename.c_st­r(),"RECREATE");
tree = new TTree(treename.c_st­r(),treename.c_str()­);
cout << "Opening File: " << filename.c_str() << endl;
tree->Branch("Event­Branch","HepMCEvent"­,&event,16000,99);
}

void RootFileWriter::fin­ish(){
f->Write();
cout << "File wrote. " << endl;
f->Close();
cout << "File closed. " << endl;
}


void RootFileWriter::fil­l(HepMC::GenEvent *hepMCgenEvt){

string treename = "HepMCEvents";
event = new HepMCEvent(hepMCgen­Evt);

tree->Fill();
event->Clear();
delete event;
}
-------------------­--------------------­--------------
-------------------­--------------------­--------------------­
The Dump output of the Vertices(the TClonesArray):
-------------------­--------------------­--------------------­
==> Dumping object at: 0x08ef4f60, name=Vertices, class=TBranchElemen­t

fClassName ->8ef507c Class name of referenced
object
fClassName.*fData HepMCEvent
fParentName ->8ef5084 Name of parent class
fParentName.*fData HepMCEvent
fClonesName ->8ef508c Name of class in TClonesArray
(if any)
fClonesName.*fData
*fCollProxy ->0 ! collection interface (if
any)
fCheckSum 4283192070 CheckSum of class
fClassVersion 1 Version number of class
fID 7 element serial number in fInfo
fType 0 branch type
fStreamerType 63 branch streamer type
fMaximum 0 Maximum entries for a
TClonesArray or variable array
fSTLtype 0 ! STL container type
fNdata 1 ! Number of data in this
branch
*fBranchCount ->0 pointer to primary branchcount
branch
*fBranchCount2 ->0 pointer to secondary
branchcount branch
*fInfo ->8d5af68 ! Pointer to StreamerInfo
*fObject (
fInit true ! Initialization flag for
branch assignment
fInitOffsets true ! Initialization flag to not
endlessly recalculate offsets
fCurrentClass ->8ef50cc ! Reference to current
(transient) class definition
fCurrentClass.fClas­sName ->8ef50cc Name of referenced class
fCurrentClass.*fCla­ssPtr ->0 ! Ptr to the TClass object
fCurrentClass.*fPre­vious ->0 ! link to the previous refs
fCurrentClass.*fNex­t ->0 ! link to the next refs
fParentClass ->8ef50dc ! Reference to class
definition in fParentName
fParentClass.fClass­Name ->8ef50dc Name of referenced class
fParentClass.*fClas­sPtr ->8d3f688 ! Ptr to the TClass object
fParentClass.*fPrev­ious ->0 ! link to the previous refs
fParentClass.*fNext­ ->8ef0c4c ! link to the next refs
fBranchClass ->8ef50ec ! Reference to class
definition in fClassName
fBranchClass.fClass­Name ->8ef50ec Name of referenced class
fBranchClass.*fClas­sPtr ->8d3f688 ! Ptr to the TClass object
fBranchClass.*fPrev­ious ->8eaf7b4 ! link to the previous refs
fBranchClass.*fNext­ ->8ef0c5c ! link to the next refs
*fBranchOffset ->0 ! Sub-Branch offsets with
respect to current transient class
fCompress 1 (=1 branch is compressed, 0
otherwise)
fBasketSize 16000 Initial Size of Basket Buffer
fEntryOffsetLen 0 Initial Length of fEntryOffset
table in the basket buffers
fWriteBasket 96 Last basket number written
fEntryNumber 100 Current entry number (last one
filled in this branch)
fOffset 0 Offset of this branch
fMaxBaskets 97 Maximum number of Baskets so
far
fSplitLevel 1 Branch split level
fNleaves 1 ! Number of leaves
fReadBasket 95 ! Current basket number when
reading
fReadEntry 99 ! Current entry number when
reading
fEntries 100 Number of entries
fTotBytes 1974416 Total number of bytes in all
leaves before compression
fZipBytes 1005673 Total number of bytes in all
leaves after compression
fBranches ->8ef4fd0 -> List of Branches of this
branch
fBranches.*fCont ->8ef5108 !Array contents
fBranches.fLowerBou­nd 0 Lower bound of the array
fBranches.fLast -1 Last element in array
containing an object
fBranches.fSorted false true if collection has been
sorted
fBranches.fName ->8ef4fdc name of the collection
fBranches.fName.*fD­ata
fBranches.fSize 16 number of elements in
collection
fBranches.fUniqueID­ 0 object unique identifier
fBranches.fBits 0x03000000 bit field status word
fLeaves ->8ef4ff8 -> List of leaves of this
branch
fLeaves.*fCont ->8ef5150 !Array contents
fLeaves.fLowerBound­ 0 Lower bound of the array
fLeaves.fLast 0 Last element in array
containing an object
fLeaves.fSorted false true if collection has been
sorted
fLeaves.fName ->8ef5004 name of the collection
fLeaves.fName.*fDat­a
fLeaves.fSize 16 number of elements in
collection
fLeaves.fUniqueID 0 object unique identifier
fLeaves.fBits 0x03000000 bit field status word
fBaskets ->8ef5020 -> List of baskets of this
branch
fBaskets.*fCont ->8ef52d8 !Array contents
fBaskets.fLowerBoun­d 0 Lower bound of the array
fBaskets.fLast 96 Last element in array
containing an object
fBaskets.fSorted false true if collection has been
sorted
fBaskets.fName ->8ef502c name of the collection
fBaskets.fName.*fDa­ta
fBaskets.fSize 97 number of elements in
collection
fBaskets.fUniqueID 0 object unique identifier
fBaskets.fBits 0x03000000 bit field status word
fNBasketRAM 1 ! Number of baskets in
fBasketRAM
*fBasketRAM 95 ! [fNBasketRAM] table of
basket numbers in memory
*fBasketBytes 5422 [fMaxBaskets] Lenght of
baskets on file
*fBasketEntry 0 [fMaxBaskets] Table of first
entry in eack basket
*fBasketSeek 222 [fMaxBaskets] Addresses of
baskets on file
*fTree ->8ea1960 ! Pointer to Tree header
*fAddress (
*fDirectory ->8d3d958 ! Pointer to directory where
this branch buffers are stored
fFileName ->8ef5068 Name of file where buffers are
stored ("" if in same file as Tree header)
fFileName.*fData
*fEntryBuffer ->0 ! Buffer used to directly pass
the content without streaming
*fBrowsables ->8e9f568 ! List of
TVirtualBranchBrows­ables used for Browse()
fSkipZip false !After being read, the buffer
will not be unziped.
fName ->8ef4f6c object identifier
fName.*fData Vertices
fTitle ->8ef4f74 object title
fTitle.*fData Vertices
fUniqueID 0 object unique identifier
fBits 0x03001008 bit field status word
fFillColor 0 fill area color
fFillStyle 1001 fill area style

-------------------­--------------------­--------------------­---------
-------------------­--------------------­--------------------­----------

Thx
Oliver

-------------------­--------------------­--------------------­--
Oliver Oberst
oberst@ekp.physik.u­ni-karlsruhe.de IEKP, Uni Karlsruhe
Wolfgang-Gaede-Str.­ 1
Tel: +49-(0)721 608-7243 D-76128 Karlsruhe
-------------------­--------------------­--------------------­--


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > C/C++ Programming > [ROOT] Writing TClonesArray to File 22 December 2006 16:23:24

see also:
Re: Postgres logs
SHOW VARIABLES LIKE '%dir%'; (basedir…
PostgreSQL guru needed for Enterprise…
пройди тесты:
see also:
MOJA PYKA
Ckoro pjatnica 13.]:-) :-D
I will always be alone...

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .