(As a forewarning, this will be long due to the code I am including....sorry...) Actually there are 2 strange behaviors. The first (brief) one is this: TRQMD FileList = new TRQMD(filename,10); (FileList+0)->function(); // Root Seg fault TRQMD *temp = FileList + 0; temp->function(); // Root ok If (in ROOT), I type .g FileList, .g FileList+0, and .g temp....I get the same address values for all 3. What's even more confusing is that I use the (pointer+index) syntax in the COMPILED .so for the 3 classes and root doesn't complain about those!!! (And yes, index does take a 0 value for each occurrence of the syntax) (Aye carumba) The second strange behavior is more complicated.... Background: I've compiled my own "dll" (.so for linux) with 3 classes to use for my research. Since this is my first real attempt at classes (I'm mainly a C guy), the heirarchy may not be the greatest (*shrug*). One class for the file (and an array of pointers to the events in the file), one class for the event (with an array of pointers to the particles), and one class for the particles (with Int_t and Float_t for 4P, mass, and PID). The best way I can describe the problem is thus (and this may be a generic C++ thing, for which I apologize for my newbie-ness): A Class created by Files = new TRQMD[NumFiles]; with a subsequent call to the overloaded constructor TRQMD *TempRQMD = Files + x; // x is loop var TempRQMD->TRQMD(filename, NumEvents); does *NOT* work the same as: TRQMD *File = new TRQMD(filename, NumEvents); assuming NumFiles == 1 above. Now, here is the funny part: Both code sequences ACTUALLY read the file as it should!!!!(in the TRQMD(char *,int) call) However, when I try to access the TempRQMD class functions, they return member values that were set with TRQMD() despite the TRQMD(filename, NumEvents) call. Lemme illustrate with the command line entries that I got from root: gSystem.Load("stage1.so"); FileList = new TRQMD[1]; // Same results is no [1] TRQMD *TempRQMD = FileList; TempRQMD->TRQMD("central-500evts-1.ascii", 10); // Normal output from the function returning the // Correct values read from the file TempRQMD->GetEvents() // Should return 10...as passed in prev. -->Root returns this: (Int_t)(-1) -->Which is the value set by TRQMD() (from new construction) However, this is the alternate output: gSystem.Load("stage1.so"); FileList = new TRQMD("central-500evts-1.ascii", 10); FileList->GetEvents() -->Root returns this: (Int_t)10 // This is right! Ok, as promised, here is some source code: (This is from TRQMD.cxx) TRQMD::TRQMD() { fTotalEvents = -1; fEventList = 0; } TRQMD::TRQMD(Char_t *filename, Int_t eventnum) { // Some temp var declarations omitted fTotalEvents = eventnum; cout << "Eventnumber is " << fTotalEvents << endl; // In root this prints out as 10!!!! // rest of file read in code removed. } -- ~~ WWW Page: http://quantum.phy.vanderbilt.edu/~tim/ ~~ Tim Miller | "Am I mature enough to get old?" Vanderbilt University | --Me. Graduate Studies in Physics | Relativistic Heavy Ions | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:26:23 MET