Hi rooters, I have a problem when trying to create a TBranch object. The program crashes, giving a "segmentation violation". I deeply investigated my code concerning the classes involved (TFndHdt, TFndTrig), and I couldn't find the reason. I have an object of class TFndHdt, which is composed by some integers and a set of pointers (to objects of TFndTrig, TFndCorbo, TFndHHdr classes and to 4 TObjArray objects). I would like to store it in a Tree (and then on file), associating one branch to each of the objects. I tried both with the splitlevel = 1 option and with the detailed declaration of all the branches. The code compiles, but then it crashes when I try to define the branch corresponding to the TFndTrig object, giving a segmentation violation. In the following, you'll find the main program (with only the mentioned branch definition) and the source code for the class TFndTrig. I'm running under OSF, and the funny thing is that the same code, on another OSF machine, runs correctly. Any suggestion? Thanks in advance, Cheers, Piergiorgio // header file for TFndTrig #ifndef FIN_FndTrig #define FIN_FndTrig //____________________________________________________________________ // // TFndTrig // // #include "TObject.h" #include "TFndRawEqp.h" class TFndTrig : public TObject { private: Int_t fTB; // Top-Bottom trigger Int_t fTBCtfCtr; // Top-Bottom && (Central Front || Rear) Int_t fCtf; // Central Front Int_t fCtr; // Central Rear public: TFndTrig(TFndRawEqp *); TFndTrig(); ~TFndTrig(); Int_t GetTB() const { return fTB; } // Get TB trigger Int_t GetTBCtfCtr() const { return fTBCtfCtr; } // TB && (F || R) Int_t GetCtf() const { return fCtf; } // Central Front Int_t GetCtr() const { return fCtr; } // Central Rear void Print(); // Print the Trigger variables ClassDef(TFndTrig,1) // The Trigger }; #endif // source file for TFndTrig #include "iostream.h" #include "TFndRawEqp.h" #include "TFndTrig.h" ClassImp(TFndTrig); TFndTrig::TFndTrig() { fTB = -1; fTBCtfCtr = -1; fCtr = -1; fCtf = -1; } TFndTrig::~TFndTrig() { } TFndTrig::TFndTrig(TFndRawEqp *ptrg) { // Trig equipment UInt_t *ltrgptr = ptrg->GetEqp(21); UInt_t ltrglen = ptrg->GetEqpLen(21); if(ltrglen) { fTB = (*ltrgptr)&0x1; fTBCtfCtr = ((*ltrgptr)>>1)&0x1; fCtr = ((*ltrgptr)>>4)&0x1; fCtf = ((*ltrgptr)>>5)&0x1; } else { fTB = -1; fTBCtfCtr = -1; fCtr = -1; fCtf = -1; } } //******************************************************************/ //* Print Trigger */ //******************************************************************/ void TFndTrig::Print() { cout << "**** Trigger ****" << endl; cout << "Top*Bottom = " << fTB << endl; cout << "Top*Bottom*(Central Front || Central Rear) = " << fTBCtfCtr << endl; cout << "Central Front = " << fCtf << endl; cout << "Central Rear = " << fCtr << endl; } // main program #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <iostream.h> //******************************************************************/ //* ROOT include files */ //******************************************************************/ #include "TROOT.h" #include "TFile.h" #include "TH1.h" #include "TH2.h" #include "TProfile.h" #include "TNtuple.h" #include "TRandom.h" #include "TTree.h" #include "TBranch.h" #include "TObjArray.h" #include "TDirectory.h" #include "TServerSocket.h" #include "TSocket.h" #include "TMessage.h" #include "TBuffer.h" //******************************************************************/ //* FINUDA include files */ //******************************************************************/ #include "TFndFeeMap.h" #include "TFndConst.h" #include "TFndHHdr.h" #include "TFndRawEqp.h" #include "TFndRawSil.h" #include "TFndRdt.h" #include "TFndHdt.h" #include "TFndHSil.h" #include "TFndHTof.h" #include "TFndHLmd.h" #include "TFndHStb.h" #include "TFndTrig.h" #include "TFndCorbo.h" #include "TFndDate.h" #include "TFndGenInfo.h" //******************************************************************/ //*-------> UNIX only */ //******************************************************************/ #include <fcntl.h> #include <sys/file.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include <netinet/in.h> #include <netdb.h> //******************************************************************/ //*-------> ZEBRA Common Block */ //******************************************************************/ #include "cfortran.h" #include "TFndZebini.h" ZEBINI_DEF Zebini; #ifdef __SC__ long G__globalvarpointer; #endif TROOT geb2hdt("geb2hdt","FINUDA geb2hdt conversion"); //******************************************************************/ //* main */ //******************************************************************/ main(Int_t argc, Char_t **argv) { //******************************************************************/ //* Read the mSQL database */ //******************************************************************/ // connect to mSQL database char *host = argv[1]; cout << "mSQL host is " << host << endl; TFndFeeMap *fndfeemap = new TFndFeeMap(host); if(fndfeemap->IsThere()) fndfeemap->Print(); const Int_t EVHEAD=0x10; const Int_t N_DET = 6; // build up input file name const char *fpth = argv[2]; const char *fgeb = "/geb/"; const char *fnam = argv[3]; const char *fonl = "onl"; const char *fraw = ".raw"; Int_t onlflg = 0; cout << argv[3] << endl; if(!strcmp(fnam,fonl)) onlflg = 1; cout << "Online flag is " << onlflg << endl; Int_t kSCALE = 1; if(onlflg) kSCALE = 10; Int_t ilen = strlen(fpth)+strlen(fgeb)+strlen(fnam)+strlen(fraw); Char_t *ifn = new Char_t[ilen]; strcpy(ifn,fpth); ifn = strcat(ifn,fgeb); ifn = strcat(ifn,fnam); ifn = strcat(ifn,fraw); // open input file FILE *f; if(!onlflg) { f = fopen(ifn,"rb"); if (f==NULL) { cout << "file " << ifn << " does not exist" << endl; exit(0); } } // build up output file name const char *frdt = "/HDT/"; const char *frot = ".hdt"; Int_t olen = strlen(fpth)+strlen(frdt)+strlen(fnam)+strlen(frot); Char_t *ofn = new Char_t[olen]; strcpy(ofn,fpth); ofn = strcat(ofn,frdt); ofn = strcat(ofn,fnam); ofn = strcat(ofn,frot); // open connection with the Global Event Builder Int_t fSockId = 0; Int_t rawsize = 0; Int_t ierr = 0; if (onlflg) { Int_t port_ev = 1242; struct sockaddr_in myaddr; bzero((char *) &myaddr, sizeof(struct sockaddr_in)); myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr = INADDR_ANY; myaddr.sin_port = htons(port_ev); fSockId = socket(AF_INET, SOCK_DGRAM, 0); cout << " fSockId = " << fSockId << endl; if(fSockId == -1) { ierr = -1; cout << "ierr from FndRun(socket) is " << ierr << endl; } rawsize = 32000; setsockopt(fSockId,SOL_SOCKET,SO_RCVBUF,(char *) &rawsize,sizeof(rawsize)); ierr = bind(fSockId, (sockaddr *) &myaddr, sizeof(struct sockaddr_in)); if(ierr == -1) { ierr = -2; cout << "ierr from FndRun(socket) is " << ierr << endl; } rawsize /= 4; } if(!onlflg) { // read "event 0" header UInt_t *raw = new UInt_t[EVHEAD]; if (fread(raw,sizeof(UInt_t), EVHEAD,f) !=EVHEAD) { cout << "file " << ifn << " is shorter than event header" << endl; exit(0); } rewind(f); // swap "event 0" header if needed for (Int_t j = 0; j< EVHEAD;j++ ) raw[j] = host2net(raw[j]); delete [] raw; } // open output file TFile *of = new TFile(ofn,"RECREATE","Finuda ROOT histograms"); // create RDT & HDT Trees TTree *rdtt = new TTree("RawTree", "FINUDA raw event tree"); TTree *hdtt = new TTree("F","FINUDA HDT tree"); hdtt->SetAutoSave(10000000); // autosave when 10 Mbytes written rdtt->SetAutoSave(10000000); // autosave when 10 Mbytes written // create RDT & HDT TFndRdt *fndrdt = new TFndRdt(); TFndHdt *fndhdt = new TFndHdt(); // create general run information TFndGenInfo *g = new TFndGenInfo(); // RDT branches TFndHHdr *hdr = 0; TFndRawEqp *gts = 0; TFndRawEqp *tof = 0; TFndRawSil *ism = 0; TFndRawSil *osm = 0; TFndRawEqp *lmd = 0; TFndRawEqp *stb = 0; TBranch *Bhdr = rdtt->Branch("hdr","TFndHHdr",&hdr,64000,0); TBranch *Bdet[N_DET]; Bdet[0] = rdtt->Branch("gts","TFndRawEqp",>s,64000,0); Bdet[1] = rdtt->Branch("tof","TFndRawEqp",&tof,64000,0); Bdet[2] = rdtt->Branch("ism","TFndRawSil",&ism,64000,0); Bdet[3] = rdtt->Branch("osm","TFndRawSil",&osm,64000,0); Bdet[4] = rdtt->Branch("lmd","TFndRawEqp",&lmd,64000,0); Bdet[5] = rdtt->Branch("stb","TFndRawEqp",&stb,64000,0); // HDT branches TFndTrig *fAgts = 0; TBranch *BTrig = hdtt->Branch("fTrig","TFndTrig",&fAgts,64000,0); // loop over events UInt_t evlen=-1; UInt_t ec=0; Int_t istop = 0; UInt_t *raw; if(onlflg) { Int_t one=1,n; ioctl(fSockId ,FIONBIO,&one); raw = new UInt_t[rawsize]; } Int_t RefRunNumber = 0; while (istop == 0) { ec++; cout << "process event " << ec; // get event fron file if(!onlflg) { if(fread(&evlen, sizeof(UInt_t), 1 , f)!=1) { istop = 1; continue; } evlen = host2net(evlen); raw = new UInt_t[evlen]; raw[0] = evlen; cout << ", length " << evlen << endl; if (1+fread(raw+1, sizeof(UInt_t), evlen-1, f) !=evlen) break; } // get event from socket if(onlflg) { struct sockaddr_in claddr; Int_t addrlen = sizeof(struct sockaddr_in); bzero((char *) &claddr,sizeof(struct sockaddr_in)); evlen = -1; while(evlen == -1) { bzero((char *) raw,sizeof(raw)); evlen = recvfrom(fSockId,raw,rawsize*sizeof(int),0,(struct sockaddr *) &claddr,&addrlen); usleep(10000); } printf(" Socket size %d Event %d addresses %X\n",evlen,raw[0],claddr.sin_addr.s_addr); evlen = evlen/sizeof(int); } // swap if needed for (Int_t j=0; j<evlen; j++) raw[j] = host2net(raw[j]); if(raw[13]) cout << "event 0" << endl; // next cicle if "Event 0" // event header hdr = new TFndHHdr(raw); // create GenInfo object (run general information) Int_t RunNumber = hdr->GetRun(); if(RunNumber != RefRunNumber) { RefRunNumber = RunNumber; if(g) delete g; TFndGenInfo *g = new TFndGenInfo(raw); g->Print(); g->Write(); } // fill RDT branches Bhdr->Fill(); gts = 0; tof = 0; ism = 0; osm = 0; lmd = 0; stb = 0; for (Int_t j=0; j<N_DET; j++) { UInt_t *det = raw[7+j]? raw+raw[7+j] : (UInt_t*) NULL; if (det) { if(j == 0) gts = new TFndRawEqp(raw,j); if(j == 1) tof = new TFndRawEqp(raw,j); if(j == 2) ism = new TFndRawSil(raw,j); if(j == 3) osm = new TFndRawSil(raw,j); if(j == 4) lmd = new TFndRawEqp(raw,j); if(j == 5) stb = new TFndRawEqp(raw,j); Bdet[j]->Fill(); } } // create TFndRdt object fndrdt = new TFndRdt(hdr,gts,tof,ism,osm,lmd,stb); // create TFndHdt object TFndHHdr *hdrf = new TFndHHdr(raw); fAgts = new TFndTrig(tof); fndhdt = new TFndHdt(ec,hdrf,fAgts); // map RDT to HDT cout << "GTS" << gts << endl; if(gts) fndrdt->GtsTree(fndhdt,fndfeemap); cout << "TOF" << tof << endl; if(tof) fndrdt->TofTree(fndhdt,fndfeemap); cout << "ISM " << ism << endl; if(ism) fndrdt->IsmTree(fndhdt,fndfeemap); cout << "OSM " << osm << endl; if(osm) fndrdt->OsmTree(fndhdt,fndfeemap); cout << "LMD " << lmd << endl; if(lmd) fndrdt->LmdTree(fndhdt,fndfeemap); cout << "STB " << stb << endl; if(stb) fndrdt->StbTree(fndhdt,fndfeemap); // fill HDT branches cout << "TOF " << endl; if(tof) { fAgts = fndhdt->GetTrig(); BTrig->Fill(); } // print multiplicities Int_t nhtof = fndhdt->GetNHTof(); Int_t nhsil = fndhdt->GetNHSil(); Int_t nhlmd = fndhdt->GetNHLmd(); Int_t nhstb = fndhdt->GetNHStb(); Int_t nhtot = fndhdt->GetNHTot(); cout << nhtot << " hits in event " << ec << ": "; cout << nhsil << " sil_hits, " << nhtof << " tof_hits, " << nhlmd << " lmd_hits, " << nhstb << " stb_hits" << endl; // checks & output if(!(ec%(TFndConst::kCHECK/kSCALE))) { cout << "store on output file at event " << ec << endl; hdr->Print(); hdtt->Print(); rdtt->Print(); of->Write(); of->cd(); of->Purge(); } // cout << "delete raw, hdt and rdt" << endl; delete fndrdt; delete fndhdt; if(!onlflg) delete [] raw; } // Write Events & database information fndfeemap->Write(); of->Write(); of->cd(); of->Purge(); // Close output file of->Close(); }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET