Sending/Receiving TClonesArray

Yves Schutz (schutz@in2p3.fr)
Thu, 28 Jan 1999 17:35:28 +0100


Hi,

I have followed the directives from the client/server tutorial and
from one of the entries to roottalk to send/receive a TClonesArray:

sender code:

fEmCal = new TClonesArray("CAREmCell", 4);

for (Int_t i=0; i<4; i++){
new( (*fEmCal)[i]) CAREmCell(i, i*10, i*20, i*30) ;
}

TMessage mess(kMESS_OBJECT); // sends a message
mess.Reset();
mess.WriteObject(fEmCal);
fSocket->Send(mess)

receiver code :

TSocket * s;
TMessage * mess=0;
TClonesArray * det=0;

s = fMonitor->Select();
s->SetOption(kNoBlock,0);
Int_t status = s->Recv(mess);

if (mess->What() == kMESS_OBJECT) {
TClass* clas = mess->GetClass();
if (clas) cout << clas->GetName() << endl ;
det = (TClonesArray *)mess->ReadObject(clas);
for (Int_t i=0; i < det->GetEntries(); i++){
CAREmCell * c = (CAREmCell *)(det->At(i));
// c->Print();
}
}

I get a segmentation fault on the line:

det = (TClonesArray *)mess->ReadObject(clas);

with the following traceback:

#2 0x........ in TBuffer::ReadObject()
#1 0x........ in TClonesArray::Streamer()
#0 0x........ in TClass::New()

It becomes really ennoying when I uncomment the line:

// c->Print();

then .... everything works fine!

Anybody has a clue to that ?

Thanks ... Yves

-- 
 __________________________________________________________________
|Yves SCHUTZ  (IN2P3 - CNRS) collaboration TAPS/WA98/ALICE         | 
|SUBATECH                                                          |
|Ecole des Mines de Nantes Telephone: (+33/0) 2 51 85 84 71        | 
|4, rue Alfred Kastler     Fax      : (+33/0) 2 51 85 84 79        |
|F-44070 Nantes cedex 03   e-mail   : yves.schutz@subatech.in2p3.fr|
|__________________________________________________________________|