Dear Rene,
I had tried it already;
output of tree->print, after I send 1 event , is:
******************************************************************************
*Tree :FDEventTree: Event Tree
*
*Entries : 1 : Total Size = 0 bytes File Size =0
*
* : : Tree compression factor = 1.00
*
******************************************************************************
*Branch :FDEvent : FDEvent
*
*Entries : 1 : Total Size = 0 bytes File Size =0 *
*Baskets : 0 : Basket Size = 64000 bytes Compression= 1.00
*
*............................................................................*
Thank you very much .
Stefano
On Mon, 13 Mar 2000, Rene Brun wrote:
> Could you replace the statement:
> tree->Branch("FDEvent","FDEvent",&curEvent,64000,1);
> by
> tree->Branch("FDEvent","FDEvent",&curEvent,64000,0);
>
> and let me know ?
>
> Rene Brun
>
>
> On Mon, 13 Mar 2000, Stefano Argiro' wrote:
>
> >
> > Hi Rooters,
> >
> > I know we went through this hundreds of times, but still ...
> > The tree structure is created correctly with all the sub-branches, but it
> > looks like I am filling it with empty objects, as if the pointer to
> > curEvent pointed to an empty area (which is not, 'cause if I do
> > curEvent->Printf() I can see that there are data).
> >
> > I am using root 2.22 on Debian with egcs.
> >
> > I would appreciate your help.
> > Many thanks
> > Stefano
> >
> >
> > Stefano Argiro'
> > Universita' di Milano, Dipartimento di Fisica delle Particelle
> > and INFN
> > ______________________________________________________________
> > FDDaqMain.cxx
> > -------------------------------------------------------------
> > #include "TBranch.h"
> > #include "TTree.h"
> > #include "TFile.h"
> > #include "TGraph.h"
> > #include "TMapFile.h"
> > #include "TArrayI.h"
> > #include "TObjArray.h"
> >
> > #include "Pixel.h"
> > #include "FDEvent.h"
> > #include "NICSocket.h"
> > #include "FDMon.h"
> > #include "TROOT.h"
> > #include <fstream.h>
> > #include <iostream.h>
> >
> > int main(int argc, char **argv)
> > {
> > TROOT FDdaq("FDDaq","FD daq program");
> >
> > TFile * file= new TFile("EvTree.root","RECREATE");
> > TTree * tree= new TTree("FDEventTree","Event Tree");
> >
> >
> > Int_t evno=0;
> > char filename[30];
> >
> > NICSocket * thisSocket = new NICSocket();
> > FDMon * thisMonitor = new FDMon(thisSocket);
> > FDEvent * curEvent = new FDEvent();
> >
> > thisSocket -> SetEventAddr(curEvent);
> >
> > tree->Branch("FDEvent","FDEvent",&curEvent,64000,1);
> >
> >
> > while(evno<5){
> >
> > sprintf(filename,"event%d.dat",evno);
> >
> > cout<< "FDDaq : accepting connection " <<endl;
> >
> > thisSocket->AcceptData();
> > thisSocket->UnpackData();
> >
> >
> >
> > curEvent-> Printf(); // event is filled OK
> > tree->Fill();
> > tree->Print();
> >
> > ofstream file(filename);
> > curEvent-> Writef( file);
> > thisMonitor->Update();
> >
> >
> >
> > evno++;
> > }
> > tree->Print();
> >
> >
> > file->Write();
> > file->Close();
> > return 0;
> > }
> > ---------------------------------------------------------------------
> > FDEvent.h
> > ----------------------------------------------------------------------
> >
> > #ifndef FDEVENT_H
> > #define FDEVENT_H
> > #include "TObjArray.h"
> > #include "TDatime.h"
> >
> > class Pixel;
> >
> >
> > class FDEvent: public TObject {
> >
> > // in this version:
> > // create event calling FDEvent();
> > // fill header calling SetHeader;
> > // fill traces
> >
> >
> > private:
> >
> > TDatime fgDateOfEvent;
> > Int_t keventNumber;
> > Int_t kNPops;
> > Int_t kNPMBs;
> >
> > TObjArray *fPixelList;
> >
> >
> > public:
> >
> > FDEvent();
> > FDEvent(TDatime dandt, Int_t npops,Int_t evno,Int_t npmb);
> > FDEvent(const FDEvent & cevent);
> > ~FDEvent();
> >
> > void SetHeader(TDatime dandt, Int_t npops,Int_t evno,Int_t
> > npmb);
> > void AddTrace(Int_t pixel_id, Int_t *trace);
> > Int_t * GetTrace(Int_t pixel_id);
> > Int_t GetNPops() {return kNPops;}
> > Int_t GetNChannels(){return kNPMBs * 16;}
> > void Printf();
> > void Writef(ofstream& outfile);
> >
> > ClassDef(FDEvent,1)
> > };
> > #endif
> > -------------------------------------------------------------------
> > FDEvent.cxx
> > ------------------------------------------------------------------
> >
> > #include "TObject.h"
> > #include "TObjArray.h"
> > #include "Pixel.h"
> > #include "FDEvent.h"
> > #include <iostream.h>
> > #include <fstream.h>
> > #include "TArrayI.h"
> >
> > ClassImp(FDEvent)
> >
> >
> > FDEvent::FDEvent(){
> >
> > fgDateOfEvent.Set(2000,1,1,0,0,0);
> > kNPops = 128;
> > keventNumber = 1;
> > kNPMBs = 1;
> > fPixelList = NULL;
> > }
> >
> >
> > FDEvent::FDEvent(TDatime dandt,Int_t npops,Int_t evno,Int_t npmb)
> >
> > {fgDateOfEvent = dandt;
> > kNPops = npops;
> > keventNumber = evno;
> > kNPMBs = npmb;
> >
> > fPixelList = new TObjArray(16*kNPMBs);
> >
> > }
> >
> >
> > FDEvent::FDEvent(const FDEvent & cevent){
> > fgDateOfEvent= cevent.fgDateOfEvent;
> > kNPops = cevent.kNPops;
> > keventNumber = cevent.keventNumber;
> > kNPMBs = cevent.kNPMBs;
> > fPixelList = cevent.fPixelList;
> > }
> >
> > FDEvent::~FDEvent(){
> >
> > delete fPixelList;
> > }
> >
> > void FDEvent::SetHeader(TDatime dandt, Int_t npops,Int_t evno,Int_t
> > npmb){
> > fgDateOfEvent = dandt;
> > kNPops = npops;
> > keventNumber = evno;
> > kNPMBs = npmb;
> >
> > if (fPixelList==NULL) fPixelList = new
> > TObjArray(16*kNPMBs);
> >
> > }
> >
> > void FDEvent::AddTrace(Int_t pixel_id, Int_t *trace)
> > {
> > Pixel * p = new Pixel(kNPops,trace);
> > //printf("adding trace %d\n",pixel_id);
> > fPixelList->AddAt(p,pixel_id);
> > }
> >
> >
> > Int_t* FDEvent::GetTrace(Int_t pixel_id)
> > {
> > Pixel * p = (Pixel *) fPixelList->At(pixel_id);
> > return p->GetFADCTrace();
> > }
> >
> >
> >
> >
> >
> > void FDEvent::Printf(){
> > cout << "Event Infos" << endl;
> > cout << keventNumber << " " <<
> > fgDateOfEvent.GetDate() << " " <<
> > fgDateOfEvent.GetTime() << " " <<
> > kNPops << " " <<
> > kNPMBs << endl;
> >
> >
> > Int_t last_id =GetNChannels();
> >
> > cout <<"Last id :" << last_id <<endl;
> > for (Int_t j=0; j<kNPops; j++){
> > for (Int_t i=0; i<last_id; i++){
> >
> > Int_t * trace = GetTrace(i);
> >
> > cout << trace[j] << " ";
> > }
> > cout << endl;
> > }
> >
> > ;}
> >
> > // Event-> Writef : coulumn = Channel, row= pop
> >
> > void FDEvent::Writef(ofstream& outfile){
> > outfile << "Event Infos" << endl;
> > outfile << keventNumber << " " <<
> > fgDateOfEvent.GetDate() << " " <<
> > fgDateOfEvent.GetTime() << " " <<
> > kNPops << " " <<
> > kNPMBs << endl;
> >
> >
> > Int_t last_id =GetNChannels();
> >
> > outfile <<"Last id :" << last_id <<endl;
> >
> > for (Int_t j=0; j<kNPops; j++){
> > for (Int_t i=0; i<last_id; i++){
> >
> > Int_t * trace = GetTrace(i);
> >
> > outfile << trace[j] << " ";
> > }
> > outfile << endl;
> > }
> > }
> > ---------------------------------------------------------------
> > Pixel.h
> > --------------------------------------------------------------
> >
> >
> > #ifndef PIXEL_H
> > #define PIXEL_H
> >
> > #include "TArrayI.h"
> > #include "TObject.h"
> >
> > class Pixel: public TObject {
> >
> > // a preliminary implementation
> > // for each pixel, one FADC trace
> >
> >
> > private:
> >
> > TArrayI *FADCTrace;
> >
> > public:
> > Pixel() ;
> > ~Pixel(){delete FADCTrace;};
> > Pixel(Int_t n, Int_t *trace);
> > Int_t * GetFADCTrace();
> >
> > ClassDef(Pixel,1)
> > };
> >
> > #endif
> > -----------------------------------------------------------------------
> > Pixel.cxx
> > -----------------------------------------------------------------------
> > #include "Pixel.h"
> >
> > ClassImp(Pixel)
> >
> > Pixel::Pixel(){ FADCTrace = NULL; }
> >
> > Pixel::Pixel(Int_t n, Int_t *trace):TObject(){FADCTrace = new TArrayI(n,
> > trace);}
> >
> > Int_t * Pixel::GetFADCTrace(){return FADCTrace->GetArray() ;}
> >
> > --------------------------------------------------------------------
> > NICSocket.h
> > ---------------------------------------------------------------
> >
> > #ifndef H_NICSocket
> > #define H_NICSocket
> >
> > // A class for handling connections, unpack data and create FDEvents
> >
> >
> >
> > // Event header structure
> >
> > // word 0: Event Number
> > // word 1: Event Day
> > // word 2: Event Month
> > // word 3: Event Year
> > // word 4: Event h
> > // word 5: Event mm
> > // word 6: Event ss
> > // word 7: Number of Pops
> >
> > class NICSocket{
> >
> > private:
> >
> > Int_t eventNumber;
> > TDatime eventDate;
> > Int_t eventNPops;
> > Int_t eventNPMBs;
> > Int_t *dataBuffer;
> > Int_t **FADCtrace;
> > int *headerBuffer;
> > FDEvent *thisEvent;
> >
> > static const int kNBoaChannels = 16 ;
> > static const int kAckSize = 100 ;
> > int kAckBuf[kAckSize] ;
> > static const Int_t kEventHeaderSize = 9 ;
> > static const Int_t ktcp_port = 8000;
> > Char_t kPeeraddr[20] ;
> > static const Char_t kHostname[20] ;
> >
> >
> > public:
> >
> > NICSocket();
> > ~NICSocket();
> >
> > FDEvent * GetEvent(){return thisEvent;}
> > void SetEventAddr(FDEvent * evaddr){thisEvent =
> > evaddr;}
> > void AcceptData();
> > void UnpackData();
> > // void AddtoTree(){tree->Fill();}
> > void WriteTree();
> > Int_t Swap2Bits(Int_t byte);
> >
> > };
> >
> >
> > #endif
> > --------------------------------------------------------
> > NICSocket.cxx
> > ------------------------------------------------------
> >
> >
> > include "nic.h"
> > #include "TObject.h"
> > #include "TClonesArray.h"
> > #include "TBranch.h"
> > #include "TTree.h"
> > #include "TBranch.h"
> > #include "TArrayI.h"
> > #include "TDatime.h"
> >
> > #include "TObjArray.h"
> > #include "Pixel.h"
> > #include "FDEvent.h"
> > #include "NICSocket.h"
> > #include <stdio.h>
> >
> >
> > NICSocket::NICSocket(){ //constructor
> >
> > for (Int_t i = 0; i<kAckSize;i++) kAckBuf[i]= 1;
> > //fill acknowledge buffer
> > headerBuffer= new int[kEventHeaderSize];
> >
> >
> > }
> >
> >
> > /**********************************************************************************/
> > // AcceptData:
> > // 1:listen for clients
> > // 2:accept connection
> > // 3:receive event header, send ack
> > // 4:receive data, send ack
> > // 5:alloc memory for FADCtraces
> >
> > void NICSocket:: AcceptData(){
> >
> > Int_t year,month,day,hour,min,sec;
> >
> > //1.
> > Int_t listenSocket= NIC_listen(ktcp_port, 0); //open listen
> > socket
> > if (listenSocket < 0) {
> > fprintf(stderr,
> > "NICSocket::AcceptData: %s\n",NIC_perror(listenSocket));
> > return;
> > }
> > //2.
> > Int_t socket = NIC_accept(listenSocket, 0); //accept
> > connection;
> > Int_t diag = NIC_close(listenSocket); //close
> > listenSocket;
> > if (diag < 0) {
> > fprintf(stderr,
> > "NICSocket::AcceptData: %s\n",NIC_perror(diag));
> > return;
> > }
> >
> > diag = NIC_peeraddress(socket,(char *)kPeeraddr );
> > if (diag < 0) {
> > fprintf(stderr,
> > "NICSocket::AcceptData: %s\n",NIC_perror(diag));
> > return;
> > }
> > fprintf(stderr, "Connected to : %s\n",kPeeraddr);
> >
> > /********* Receive message ***************************/
> >
> > //3. Read Event Header
> >
> > diag = NIC_ireceive((int*)headerBuffer, kEventHeaderSize, socket);
> > if (diag < 0) {
> > fprintf(stderr,
> > "NICSocket::AcceptData: %s\n",NIC_perror(diag));
> > return;
> > }
> >
> > // Unpack Header
> > eventNumber = (Int_t) headerBuffer[0];
> > eventNPops = (Int_t) headerBuffer[7];
> > eventNPMBs = (Int_t) headerBuffer[8];
> > year = (Int_t) headerBuffer[3] +3000; // problems
> > : root does not like year< 1995
> > month = (Int_t) headerBuffer[2];
> > day = (Int_t) headerBuffer[1];
> > hour = (Int_t) headerBuffer[4];
> > min = (Int_t) headerBuffer[5];
> > sec = (Int_t) headerBuffer[6];
> >
> >
> > eventDate.Set(year, month,day,hour,min,sec);
> >
> > //alloc databuffer
> >
> > Int_t eventLenght = eventNPops* eventNPMBs * kNBoaChannels;
> > dataBuffer= new Int_t[eventLenght];
> >
> >
> > //send acknoledge
> >
> > diag = NIC_isend((int *)kAckBuf, kAckSize, socket);
> >
> > if (diag < 0) {
> > fprintf(stderr, "NICSocket::AcceptData: %s\n",
> > NIC_perror(diag));
> > return;
> > }
> >
> > //4. receive data
> >
> >
> > diag = NIC_ireceive(dataBuffer, eventLenght, socket);
> >
> >
> > //send acknowledge
> > diag = NIC_isend((int *)kAckBuf, kAckSize, socket);
> >
> > if (diag < 0) {
> > fprintf(stderr, "NICSocket::AcceptData: %s\n",
> > NIC_perror(diag));
> > return;
> > }
> >
> >
> > #ifdef DEBUG
> > // print header
> > printf("Header: ");
> > for(Int_t i=0; i<kEventHeaderSize; i++)printf("%d
> > ",headerBuffer[i]);
> > printf ("\n");
> > #endif
> >
> > //5: alloc memory for FADCtraces
> >
> >
> >
> > FADCtrace= new Int_t*[kNBoaChannels* eventNPMBs];
> >
> > for (Int_t i=0; i<kNBoaChannels* eventNPMBs;i++) {
> > FADCtrace[i] = new Int_t[eventNPops];
> > }
> >
> > #ifdef DEBUG
> > printf("AcceptData: Done \n");
> > #endif
> >
> > }
> >
> >
> > Int_t NICSocket::Swap2Bits(Int_t byte){
> >
> > Int_t temp1,temp3,temp;
> >
> >
> > temp1 = (byte & (0x800)) >>3;
> > temp3 = (byte & (0x100)) <<3;
> >
> > temp = (byte & (0x6ff)) |temp1 |temp3;
> >
> > return temp;
> > };
> >
> > void NICSocket::UnpackData(){
> >
> > thisEvent->SetHeader(eventDate,eventNPops,eventNumber,eventNPMBs);
> >
> > for (Int_t j=0; j<eventNPMBs; j++){ //loop on boards
> > for (Int_t i=0; i<eventNPops;i++){ //loop on pops
> > for (Int_t k=0; k<kNBoaChannels; k++){ //loop on ch
> >
> > Int_t sample = dataBuffer[k + i*kNBoaChannels+
> > j*kNBoaChannels*eventNPops];
> > //unpack from
> > message buffer
> >
> > if (k%2) sample = Swap2Bits(sample); //bit swapping
> > for odd channels
> > FADCtrace[k+ j*kNBoaChannels][i]= sample; //store in array
> > }
> > }
> > }
> >
> > for (Int_t i=0; i<kNBoaChannels* eventNPMBs;i++) // fill Pixels
> > thisEvent-> AddTrace(i,FADCtrace[i]);
> >
> > #ifdef DEBUG
> > printf("Unpackdata : done\n");
> > #endif
> >
> > }
> >
> > -----------------------------------------------------------
> > Makefile
> > ---------------------------------------------------------
> >
> >
> >
> > ObjSuf = o
> >
> > SrcSuf = cxx
> > ExeSuf =
> > DllSuf = so
> >
> > OutPutOpt = -o
> >
> > ROOTCFLAGS = $(shell root-config --cflags)
> > ROOTLIBS = $(shell root-config --libs)
> > ROOTGLIBS = $(shell root-config --glibs)
> >
> > # Linux with egcs
> > CXX = g++
> > CXXFLAGS = -O -Wall -fPIC -g
> > LD = g++
> > LDFLAGS = -g
> > SOFLAGS = -shared
> >
> >
> > CXXFLAGS += $(ROOTCFLAGS)
> > LIBS = $(ROOTLIBS)
> > GLIBS = $(ROOTGLIBS)
> >
> > NICLIB = -L/home/argiro/daq/NIC -lNIC
> > #------------------------------------------------------------------------------
> >
> >
> >
> > NICSOCKETO = NICSocket.$(ObjSuf)
> > NICSOCKETS = NICSocket.$(SrcSuf)
> >
> > FDEVENTO = FDEvent.$(ObjSuf)\
> > FDEventDict.$(ObjSuf)
> >
> >
> > FDEVENTS = FDEvent.$(SrcSuf)\
> > FDEventDict.$(SrcSuf)
> >
> > PIXELS = Pixel.$(SrcSuf)
> > PIXELO = Pixel.$(ObjSuf)
> >
> > FDEVENT =
> > FDEVENTSO = FDEvent.$(DllSuf)
> >
> > FDMONO = FDMon.$(ObjSuf)
> > FDMONS = FDMon.$(SrcSuf)
> >
> > FDDAQO = FDDaqMain.$(ObjSuf)
> > FDDAQS = FDDaqMain.$(SrcSuf)
> > FDDAQ = FDDaq$(ExeSuf)
> >
> > READTREE = readTree$(ExeSuf)
> > READTREEO = readTree.$(ObjSuf)
> > READTREES = readTree.$(SrcSuf)
> >
> > OBJS = $(NICSOCKETO) $(FDDAQO) $(FDMONO) $(PIXELO) $(FDEVENTO)
> >
> > all: $(FDDAQ) $(FDEVENTSO)
> >
> > $():
> >
> > $(FDDAQ): $(FDDAQO) $(NICSOCKETO) $(FDMONO) $(FDEVENTO) $(PIXELO)
> >
> > $(LD) $(LDFLAGS) $(NICSOCKETO) $(FDDAQO) $(FDMONO) $(FDEVENTO) $(PIXELO)\
> > $(GLIBS) $(NICLIB)\
> > $(OutPutOpt) $(FDDAQ)
> > @echo "$(FDDAQ) done"
> >
> >
> > $(READTREE): $(READTREEO) $(FDEVENTO) $(PIXELO)
> > $(LD) $(LDFLAGS) $(FDEVENTO) $(PIXELO) $(READTREEO) $(GLIBS) \
> > $(OutPutOpt) $(READTREE)
> > @echo "$(FDDAQ) done"
> >
> >
> > $(FDEVENTSO): $(FDEVENTO) $(PIXELO)
> >
> > $(LD) $(SOFLAGS) $(LDFLAGS) $(FDEVENTO) $(PIXELO) $(OutPutOpt) $(FDEVENTSO)
> >
> > clean:
> > @rm -f $(OBJS) *Dict.* core
> >
> > .SUFFIXES: .$(SrcSuf)
> >
> > ###
> >
> >
> > FDDaqMain.$(SrcSuf): NICSocket.h FDEvent.h Pixel.h
> >
> > NICSocket.$(SrcSuf): NICSocket.h FDEvent.h Pixel.h
> >
> > Pixel.$(SrcSuf) : Pixel.h
> >
> > FDEvent.$(SrcSuf) : FDEvent.h Pixel.h
> >
> > FDEventDict.$(SrcSuf): FDEvent.h FDEventLinkDef.h
> > @echo "Generating dictionary EventDict..."
> > @$(ROOTSYS)/bin/rootcint -f FDEventDict.$(SrcSuf) -c \
> > Pixel.h FDEvent.h FDEventLinkDef.h
> >
> >
> > FDMon.$(SrcSuf) : FDMon.h NICSocket.h FDEvent.h Pixel.h
> >
> >
> > .$(SrcSuf).$(ObjSuf):
> > $(CXX) $(CXXFLAGS) -c $<
> >
> >
>
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET