]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Introduce a names array
authorfca <fca@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 17 Dec 1999 09:03:12 +0000 (09:03 +0000)
committerfca <fca@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 17 Dec 1999 09:03:12 +0000 (09:03 +0000)
TGeant3/TGeant3.cxx
TGeant3/TGeant3.h

index 49a03a51dd8774bed0f46ee2eb8c00463eeaab45..6388fc3298253ab37e2222e6a8e5b811f3ebad25 100644 (file)
@@ -15,6 +15,9 @@
 
 /*
 $Log$
+Revision 1.18  1999/11/26 16:55:39  fca
+Reimplement CurrentVolName() to avoid memory leaks
+
 Revision 1.17  1999/11/03 16:58:28  fca
 Correct source of address violation in creating character string
 
@@ -596,10 +599,9 @@ Int_t TGeant3::NextVolUp(Text_t *name, Int_t &copy)
   fNextVol--;
   if(fNextVol>=0) {
     gname=fGcvolu->names[fNextVol];
-    strncpy(name,(char *) &gname, 4);
-    name[4]='\0';
     copy=fGcvolu->number[fNextVol];
     i=fGcvolu->lvolum[fNextVol];
+    name = fVolNames[i-1];
     if(gname == fZiq[fGclink->jvolum+i]) return i;
     else printf("GeomTree: Volume %s not found in bank\n",name);
   }
@@ -653,16 +655,13 @@ const char* TGeant3::CurrentVolName() const
   // Returns the current volume name
   //
   Int_t i, gname;
-  static char name[5];
   if( (i=fGcvolu->nlevel-1) < 0 ) {
     Warning("CurrentVolName","Stack depth %d\n",fGcvolu->nlevel);
   } else {
     gname=fGcvolu->names[i];
-    strncpy(name,(char *) &gname, 4);
-    name[4]='\0';
     i=fGcvolu->lvolum[i];   
-    if(gname == fZiq[fGclink->jvolum+i]) return name;
-    else Warning("CurrentVolName","Volume %4s not found\n",name);
+    if(gname == fZiq[fGclink->jvolum+i]) return fVolNames[i-1];
+    else Warning("CurrentVolName","Volume %4s not found\n",(char*) &gname);
   }
   return 0;
 }
@@ -676,18 +675,14 @@ const char* TGeant3::CurrentVolOffName(Int_t off) const
   // if name=0 no name is returned
   //
   Int_t i, gname;
-  char *name;
   if( (i=fGcvolu->nlevel-off-1) < 0 ) {
     Warning("CurrentVolOffName",
            "Offset requested %d but stack depth %d\n",off,fGcvolu->nlevel);
   } else {
     gname=fGcvolu->names[i];
-    name = new char[5];
-    strncpy(name,(char *) &gname, 4);
-    name[4]='\0';
     i=fGcvolu->lvolum[i];    
-    if(gname == fZiq[fGclink->jvolum+i]) return name;
-    else Warning("CurrentVolOffName","Volume %4s not found\n",name);
+    if(gname == fZiq[fGclink->jvolum+i]) return fVolNames[i-1];
+    else Warning("CurrentVolOffName","Volume %4s not found\n",(char*)&gname);
   }
   return 0;
 }
@@ -997,13 +992,11 @@ const char* TGeant3::VolName(Int_t id) const
   //
   // Return the volume name given the volume identifier
   //
-  static char name[5];
+  const char name[5]="NULL";
   if(id<1 || id > fGcnum->nvolum || fGclink->jvolum<=0) 
-    strcpy(name,"NULL");
+    return name;
   else
-    strncpy(name,(char *)&fZiq[fGclink->jvolum+id],4);
-  name[4]='\0';
-  return name;
+    return fVolNames[id-1];
 }
 
 //_____________________________________________________________________________
@@ -1581,6 +1574,13 @@ void  TGeant3::Ggclos()
   //   through the routine GHCLOS. 
   //
   ggclos(); 
+  // Create internal list of volumes
+  fVolNames = new char[fGcnum->nvolum][5];
+  Int_t i;
+  for(i=0; i<fGcnum->nvolum; ++i) {
+    strncpy(fVolNames[i], (char *) &fZiq[fGclink->jvolum+i+1], 4);
+    fVolNames[i][4]='\0';
+  }
 } 
  
 //_____________________________________________________________________________
index 87ba5db8f2244c73290df104701b3f6b5647b00c..be6882cb8d49543f72bb90f1399ce1e8e5808be7 100644 (file)
@@ -527,6 +527,10 @@ private:
   Eroptc_t *fEroptc;
   Erwork_t *fErwork;
 
+  //Put here all volume names
+
+  char (*fVolNames)[5];           //! Names of geant volumes as C++ chars
+
   enum {kMaxParticles = 100};
 
   Int_t fNPDGCodes;
@@ -536,7 +540,10 @@ private:
 public: 
   TGeant3(); 
   TGeant3(const char *title, Int_t nwgeant=0); 
-  virtual ~TGeant3() {} 
+  virtual ~TGeant3() {if(fVolNames) {
+    delete [] fVolNames;
+    fVolNames=0;}
+  } 
   virtual void LoadAddress(); 
  
 ///////////////////////////////////////////////////////////////////////