]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCmapper.cxx
Fix for coverity 17562
[u/mrichter/AliRoot.git] / TPC / AliTPCmapper.cxx
index 384a079a180c545c920396835d4bfd1d1bbbd74c..0b33888e1306f6ad7d0b135808c7b9a7e18ef0aa 100644 (file)
 #include "AliDAQ.h"
 
 ClassImp(AliTPCmapper)
+//______________________________________________________________
+AliTPCmapper::AliTPCmapper() :
+  fNside(0),
+  fNsector(0),
+  fNrcu(0),
+  fNbranch(0),
+  fNaltro(0),
+  fNchannel(0),
+  fNpadrow(0),
+  fNpadrowIROC(0),
+  fNpadrowOROC(0),
+  fTpcDdlOffset(0)
+{
+  //
+  // Constructor
+  //
+  for ( Int_t i = 0; i < 6; i++ )  fMapping[i]=0;
+}
 
 //______________________________________________________________
 AliTPCmapper::AliTPCmapper(const char * dirname) :
@@ -58,8 +76,7 @@ AliTPCmapper::AliTPCmapper(const char * dirname) :
   fNpadrow(0),
   fNpadrowIROC(0),
   fNpadrowOROC(0),
-  fTpcDdlOffset(0),
-  fROC(NULL)
+  fTpcDdlOffset(0)
 {
   //
   // Constructor
@@ -74,8 +91,6 @@ AliTPCmapper::~AliTPCmapper()
 {
   // Destructor
 
-  delete fROC;
-
   for ( Int_t i = 0; i < fNrcu; i++ ) {
     delete fMapping[i];
     fMapping[i] = 0;
@@ -95,10 +110,10 @@ AliTPCmapper::AliTPCmapper(const AliTPCmapper& mapper) :
   fNpadrow(mapper.fNpadrow),
   fNpadrowIROC(mapper.fNpadrowIROC),
   fNpadrowOROC(mapper.fNpadrowOROC),
-  fTpcDdlOffset(mapper.fTpcDdlOffset),
-  fROC(mapper.fROC)
+  fTpcDdlOffset(mapper.fTpcDdlOffset)
 {
   // Copy Constructor
+  for ( Int_t i = 0; i < 6; i++ )  fMapping[i]=0;
   for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
 }
 
@@ -111,7 +126,6 @@ AliTPCmapper& AliTPCmapper::operator = (const AliTPCmapper& mapper)
   ((TObject *)this)->operator=(mapper);
 
   for ( Int_t i = 0; i < fNrcu; i++ ) fMapping[i] = mapper.fMapping[i];
-  fROC = mapper.fROC;
 
   fNside = mapper.fNside;
   fNsector = mapper.fNsector;
@@ -136,7 +150,7 @@ void AliTPCmapper::Init(const char *dirname)
   fNrcu     = 6;
   fNbranch  = 2;
   fNaltro   = 8;
-  fNchannel = 15;
+  fNchannel = 16;
 
   // Load and read mapping files. AliTPCAltroMapping contains the mapping for
   // each patch (rcu).
@@ -157,12 +171,11 @@ void AliTPCmapper::Init(const char *dirname)
     fMapping[i] = new AliTPCAltroMapping(path2.Data());
   }
 
-  // Create instance of AliTPCROC object
-  fROC = AliTPCROC::Instance();
-
+  // Get instance of AliTPCROC object
+  AliTPCROC *fROC = AliTPCROC::Instance();
   fNpadrowIROC = fROC->GetNRows(0);
   fNpadrowOROC = fROC->GetNRows(36);
-  fNpadrow = fNpadrowIROC+fNpadrowOROC;
+  fNpadrow     = fNpadrowIROC+fNpadrowOROC;
 
   AliDAQ daq;
   fTpcDdlOffset = daq.DdlIDOffset("TPC");
@@ -185,17 +198,20 @@ Int_t AliTPCmapper::GetHWAddressSector(Int_t globalpadrow, Int_t pad) const
 {
   // Get the hardware address from pad coordinates
   Int_t patch = 0;
+  Int_t hwAddress=-1;
   if ( globalpadrow < fNpadrowIROC   ) {
     patch = GetPatch(0,  globalpadrow, pad);
-    return fMapping[patch]->GetHWAddress(globalpadrow, pad, 0);
+    if (patch>-1)
+      hwAddress = fMapping[patch]->GetHWAddress(globalpadrow, pad, 0);
   } else if ( globalpadrow < fNpadrow ) {
     patch = GetPatch(36, globalpadrow - fNpadrowIROC, pad);
-    return fMapping[patch]->GetHWAddress(globalpadrow - fNpadrowIROC,
-                                        pad, 36);
+    if (patch>-1)
+      hwAddress = fMapping[patch]->GetHWAddress(globalpadrow - fNpadrowIROC, pad, 36);
   } else {
     AliWarning(Form("Padrow outside range (globalpadrow %d) !", globalpadrow));
-    return -1;
+    hwAddress = -1;
   }
+  return hwAddress;
 }
 
 
@@ -220,7 +236,7 @@ Int_t AliTPCmapper::GetPatch(Int_t roc, Int_t padrow, Int_t pad) const
   }
 
   if ( roc < 36 ) {
-    // IROC (0 ... 35)
+    // IROC (ROCs 0 ... 35)
     Int_t padsInRow = GetNpads(padrow);
     if ( (padsInRow < 0) || (pad >= padsInRow) ) {
       AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
@@ -236,7 +252,7 @@ Int_t AliTPCmapper::GetPatch(Int_t roc, Int_t padrow, Int_t pad) const
       return -1;
     }
   } else if ( roc < 72 ) {
-    // OROC (36 ... 71)
+    // OROC (ROCs 36 ... 71)
     Int_t padsInRow = GetNpads(fNpadrowIROC+padrow);
     if ( (padsInRow < 0) || (pad >= padsInRow) ) {
       AliWarning(Form("Pad index outside range (padrow %d, pad %d, roc %d) !", padrow, pad, roc));
@@ -506,7 +522,9 @@ Int_t AliTPCmapper::DecodedHWAddressChanneladdr(Int_t hwAddress) const
 //______________________________________________________________
 Int_t AliTPCmapper::GetNpads(Int_t roc, Int_t padrow) const{
   // Get number of pads in padrow for this ROC.
-  return fROC->GetNPads((UInt_t)roc, (UInt_t)padrow);
+  AliTPCROC *fROC = AliTPCROC::Instance();
+  Int_t retval = fROC->GetNPads((UInt_t)roc, (UInt_t)padrow);
+  return retval;
 }
 
 
@@ -529,7 +547,9 @@ Int_t AliTPCmapper::GetNpads(Int_t globalpadrow) const{
 Int_t AliTPCmapper::GetNpadrows(Int_t roc) const
 {
   // Get number of padrows
-  return fROC->GetNRows(roc);
+  if      (roc < 36) return fNpadrowIROC;
+  else if (roc < 72) return fNpadrowOROC;
+  return -1;
 }
 
 
@@ -722,6 +742,7 @@ Int_t AliTPCmapper::GetNfec(Int_t patch, Int_t branch) const
   if( (branch == 1) && (patch == 1) ){
     retval = 12;
   }
+
   return retval;
 }
 
@@ -881,13 +902,20 @@ Int_t AliTPCmapper::GetSectorFromEquipmentID(Int_t equipmentID) const
 {
   // Get sector index (0 ... 17) from equipment ID
   Int_t retval = 0;
-
-  if ( (equipmentID < fTpcDdlOffset) || (equipmentID > 983) ) {
+  if ( (equipmentID < fTpcDdlOffset) || (equipmentID >= fTpcDdlOffset+216) ) {
     AliWarning(Form("Equipment ID (%d) outside range !", equipmentID));
     return -1;
   }
-  if ( (equipmentID - 840) < 0 ) retval = (equipmentID-768)/2;
-  else                           retval = (equipmentID-840)/4;
+  Int_t side   = GetSideFromEquipmentID(equipmentID);
+  if ( side < 0 ) return -1;
+
+  if ( (equipmentID - 840) < 0 ) { // IROC
+    if ( side == 0 ) retval = (equipmentID-fTpcDdlOffset)/2;
+    else             retval = (equipmentID-fTpcDdlOffset-18*2)/2;
+  } else {                         // OROC
+    if ( side == 0 ) retval = (equipmentID-840)/4;
+    else             retval = (equipmentID-840-18*4)/4;
+  }
   return retval;
 }
 
@@ -975,8 +1003,8 @@ Int_t AliTPCmapper::GetRocFromPatch(Int_t side, Int_t sector, Int_t patch) const
     if ( patch < 2 ) return sector;         // IROC
     else             return 36+sector;      // OROC
   } else {           // C side
-    if ( patch < 2 ) return 18+(17-sector); // IROC
-    else             return 54+(17-sector); // OROC
+    if ( patch < 2 ) return 18+sector;      // IROC
+    else             return 54+sector;      // OROC
   }
 }