]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSModuleDaSSD.cxx
Fixes for Coverity warnings
[u/mrichter/AliRoot.git] / ITS / AliITSModuleDaSSD.cxx
index 698acdb73534ccf7198ae6db17f797af2734f993..2b3efb489bf77690d0e391d22d78ac4ee6ff10b9 100644 (file)
 ///
 /// This class provides storage container ITS SSD module callibration data
 /// used by DA. 
-///
+/// 
+/// Date: 09/07/2009
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "AliITSNoiseSSD.h"
+#include "AliITSPedestalSSD.h"
+#include "AliITSBadChannelsSSD.h"
 #include "AliITSModuleDaSSD.h"
 #include "TString.h"
 #include "AliLog.h"
@@ -53,6 +56,7 @@ AliITSModuleDaSSD::AliITSModuleDaSSD() :
   fStrips(NULL),
   fNumberOfChips(0),
   fCm(NULL),
+  fCmFerom(NULL),
   fEventsNumber(0)
 {
 // Default constructor
@@ -71,6 +75,7 @@ AliITSModuleDaSSD::AliITSModuleDaSSD(const UChar_t ddlID, const UChar_t ad, cons
   fStrips(NULL),
   fNumberOfChips(0),
   fCm(NULL),
+  fCmFerom(NULL),
   fEventsNumber(0)
 {
 // Constructor, set module id data
@@ -90,9 +95,10 @@ AliITSModuleDaSSD::AliITSModuleDaSSD(const Int_t numberofstrips) :
   fStrips(NULL),
   fNumberOfChips(0),
   fCm(NULL),
+  fCmFerom(NULL),
   fEventsNumber(0)
 {
-// Constructor, allocates memory for AliITSChannelDaSSD*
+// Constructor, allocates memory for AliITSChannelDaSSD* and TArrayS* array for CM calculated in FEROM
   if (numberofstrips != fgkStripsPerModule) 
     AliWarning(Form("AliITSModuleDaSSD: ALICE ITS SSD Module contains %i strips", fgkStripsPerModule));
   fStrips = new (nothrow) AliITSChannelDaSSD* [numberofstrips];
@@ -119,6 +125,7 @@ AliITSModuleDaSSD::AliITSModuleDaSSD(const Int_t numberofstrips, const Long_t ev
   fStrips(NULL),
   fNumberOfChips(0),
   fCm(NULL),
+  fCmFerom(NULL),
   fEventsNumber(0)
 {
 // Constructor, allocates memory for AliITSChannelDaSSD* and events data
@@ -151,14 +158,54 @@ AliITSModuleDaSSD::AliITSModuleDaSSD(const AliITSModuleDaSSD& module) :
   fAdc(module.fAdc),
   fModuleId(module.fModuleId),
   fNumberOfStrips(module.fNumberOfStrips),
-  fStrips(module.fStrips),
+  fStrips(NULL),
   fNumberOfChips(module.fNumberOfChips),
-  fCm(module.fCm),
+  fCm(NULL),
+  fCmFerom(NULL),
   fEventsNumber(module.fEventsNumber)
 {
 // copy constructor
-
-  AliFatal("AliITSModuleDaSSD, copy constructor not implemented");
+  if ((module.fNumberOfStrips > 0) && (module.fStrips)) {
+    fStrips = new (nothrow) AliITSChannelDaSSD* [module.fNumberOfStrips];
+    if (fStrips) {
+      for (Int_t strind = 0; strind < module.fNumberOfStrips; strind++) {
+        if (module.fStrips[strind]) {
+         fStrips[strind] = new AliITSChannelDaSSD(*(module.fStrips[strind]));
+         if (!fStrips[strind]) { 
+           AliError("AliITSModuleDaSSD: Error copy constructor");
+            for (Int_t i = (strind - 1); i >= 0; i--) delete fStrips[strind];
+           delete [] fStrips;
+           fStrips = NULL;
+           break;
+         }
+       } else fStrips[strind] = NULL; 
+      }          
+    } else {
+       AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", module.fNumberOfStrips));
+       fNumberOfStrips = 0;
+       fStrips = NULL;
+    }  
+  }
+  if (module.fCm) {
+    fCm = new (nothrow) TArrayF [module.fNumberOfChips];
+    if (fCm) {
+      for (Int_t chind = 0; chind < module.fNumberOfChips; chind++) fCm[chind] = module.fCm[chind]; 
+    } else {
+       AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", module.fNumberOfChips));
+       fNumberOfChips = 0;
+       fCm = NULL;
+    }  
+  }
+  
+  if (module.fCmFerom) {
+    fCmFerom = new (nothrow) TArrayS [fgkChipsPerModule];
+    if (fCmFerom) {
+      for (Int_t chind = 0; chind < fgkChipsPerModule; chind++) fCmFerom[chind] = module.fCmFerom[chind]; 
+    } else {
+       AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
+       fCmFerom = NULL;
+    }  
+  }
 }
 
 
@@ -167,8 +214,68 @@ AliITSModuleDaSSD::AliITSModuleDaSSD(const AliITSModuleDaSSD& module) :
 AliITSModuleDaSSD& AliITSModuleDaSSD::operator = (const AliITSModuleDaSSD& module)
 {
 // assignment operator
-
-  AliFatal("AliITSModuleDaSSD: operator =, assignment operator not implemented");
+  if (this == &module)  return *this;  
+  TObject::operator=(module);
+  if (fStrips) {
+    for (Long_t i = 0; i < fNumberOfStrips; i++) if (fStrips[i]) delete fStrips[i];
+    delete [] fStrips;
+    fStrips = NULL;
+  } 
+  fEquipId = module.fEquipId;
+  fEquipType = module.fEquipType;
+  fDdlId = module.fDdlId;
+  fAd = module.fAd;
+  fAdc = module.fAdc;
+  fModuleId = module.fModuleId;
+  fStrips = NULL;
+  fNumberOfChips = module.fNumberOfChips;
+  fCm = NULL;
+  fEventsNumber = module.fEventsNumber;
+  if ((module.fNumberOfStrips > 0) && (module.fStrips)) {
+    fStrips = new (nothrow) AliITSChannelDaSSD* [module.fNumberOfStrips];
+    if (fStrips) {
+      memset(fStrips, 0, (sizeof(AliITSChannelDaSSD*) * module.fNumberOfStrips));
+      for (Int_t strind = 0; strind < module.fNumberOfStrips; strind++) {
+        if (module.fStrips[strind]) {
+          fStrips[strind] = new AliITSChannelDaSSD(*(module.fStrips[strind]));
+          if (!fStrips[strind]) { 
+            AliError("AliITSModuleDaSSD: Error copy constructor");
+            for (Int_t i = (strind - 1); i >= 0; i--) delete fStrips[strind];
+            delete [] fStrips;
+            fStrips = NULL;
+            fNumberOfStrips = 0;
+            break;
+          }
+        } else fStrips[strind] = NULL; 
+      }
+      fNumberOfStrips = module.fNumberOfStrips;
+    } else {
+       AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i AliITSChannelDaSSD* objects!", module.fNumberOfStrips));
+       fNumberOfStrips = 0;
+       fStrips = NULL;
+    }  
+  }
+  if (fCm) delete [] fCm;
+  if (module.fCm) {
+    fCm = new (nothrow) TArrayF [module.fNumberOfChips];
+    if (fCm) {
+      for (Int_t chind = 0; chind < module.fNumberOfChips; chind++) fCm[chind] = module.fCm[chind]; 
+    } else {
+       AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayF objects!", module.fNumberOfChips));
+       fNumberOfChips = 0;
+       fCm = NULL;
+    }  
+  }  
+  if (fCmFerom) { delete [] fCmFerom; fCmFerom = NULL; }
+  if (module.fCmFerom) {
+    fCmFerom = new (nothrow) TArrayS [module.fNumberOfChips];
+    if (fCmFerom) {
+      for (Int_t chind = 0; chind < fgkChipsPerModule; chind++) fCmFerom[chind] = module.fCmFerom[chind]; 
+    } else {
+       AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
+       fCmFerom = NULL;
+    }  
+  }  
   return *this;
 }
     
@@ -187,6 +294,7 @@ AliITSModuleDaSSD::~AliITSModuleDaSSD()
     delete [] fStrips;
   } 
   if (fCm) delete [] fCm;
+  if (fCmFerom) delete [] fCmFerom;
 }
 
 
@@ -284,14 +392,14 @@ Bool_t AliITSModuleDaSSD::SetEventsNumber(const Long_t eventsnumber)
   Int_t i;
   if (!fStrips) return kFALSE;
   for (i = 0; i < fNumberOfStrips; i++) {
-    if (fStrips[i])  
+    if (fStrips[i]) { 
       if (!fStrips[i]->SetEvenetsNumber(eventsnumber)) {
         for (Int_t j = 0; j < i; j++) fStrips[j]->DeleteSignal();
-        AliError(Form("AliITSModuleDaSSD: Error allocating memory for i% events for module %i, strip %i", 
-                                   eventsnumber, (Int_t)fModuleId, i));
+        AliError(Form("AliITSModuleDaSSD: Error allocating memory for %ld event for module %d, strip %d",eventsnumber, (Int_t)fModuleId, i));
         return kFALSE;
       }
-    else 
+    }
+    else { 
       if (!(fStrips[i] = new AliITSChannelDaSSD(i, eventsnumber))) {
         for (Int_t j = 0; j < i; j++) delete fStrips[j];
         delete [] fStrips;
@@ -300,7 +408,9 @@ Bool_t AliITSModuleDaSSD::SetEventsNumber(const Long_t eventsnumber)
         AliError(Form("AliITSModuleDaSSD: Error allocating memory for strip %i of module %i!", (Int_t)fModuleId, i));
         return kFALSE;
       }
-  } 
+    }
+  }
+  fEventsNumber = eventsnumber;
   return kTRUE;
 }
 
@@ -328,24 +438,60 @@ Float_t  AliITSModuleDaSSD::GetCM(const Int_t chipn, const Long_t evn)   const
 }
 
 
+//______________________________________________________________________________
+Bool_t  AliITSModuleDaSSD::AllocateCMFeromArray(void)
+{
+// Allocates memory for the channels which contains CM calculated in Ferom
+ if (!fCmFerom) { 
+    fCmFerom = new (nothrow) TArrayS [fgkChipsPerModule];
+    if (!fCmFerom) {
+       AliError(Form("AliITSModuleDaSSD: Error allocating memory for %i TArrayS objects!", fgkChipsPerModule));
+       fCmFerom = NULL;
+       return kFALSE;
+    }
+  }
+  return kTRUE;
+}
+
 
 //______________________________________________________________________________
-AliITSNoiseSSD* AliITSModuleDaSSD::GetCalibrationSSDModule() const
+Bool_t  AliITSModuleDaSSD::SetCMFeromEventsNumber(const Long_t eventsnumber)
 {
-// Creates the AliITSNoiseSSD objects with callibration data
-  AliITSNoiseSSD  *mc;
-  Float_t          noise;
-  if (!fStrips) return NULL;
-  mc = new AliITSNoiseSSD();
-  mc->SetMod(fModuleId);
-  mc->SetNNoiseP(fgkPNStripsPerModule);
-  mc->SetNNoiseN(fgkPNStripsPerModule);
-  for (Int_t i = 0; i < fNumberOfStrips; i++) {
-    if (!fStrips[i]) noise = AliITSChannelDaSSD::GetUndefinedValue();
-    else  noise = fStrips[i]->GetNoiseCM();
-    if (i < fgkPNStripsPerModule)
-          mc->AddNoiseP(i, noise);
-    else  mc->AddNoiseN((AliITSChannelDaSSD::GetMaxStripIdConst() - i), noise);                     
+// Allocates memory for the values of CM calculated in Ferom
+  if (!fCmFerom) return kFALSE;
+  for (Int_t chipind = 0; chipind < fgkChipsPerModule; chipind++) {
+      fCmFerom[chipind].Set(eventsnumber);
+      fCmFerom[chipind].Reset(0);
   }
-  return mc;
+  return kTRUE;
+}
+
+//______________________________________________________________________________
+Bool_t AliITSModuleDaSSD::SetCMFerom (const Short_t cm, const Int_t chipn, const Int_t evn)
+{ 
+// Set value of FeromCM for a given chip and event 
+  if ((!fCmFerom) || (chipn >= fgkChipsPerModule)) return kFALSE;
+  if (evn >= fCmFerom[chipn].GetSize()) return kFALSE;
+  else fCmFerom[chipn][evn] = cm;
+  return kTRUE;
+}
+
+
+void  AliITSModuleDaSSD::SetCMFerom (Short_t* cm, const Int_t chipn)
+// Set value of FeromCM for a given chip
+{ 
+  if (!fCmFerom) 
+    if (!AllocateCMFeromArray()) return;
+  if (chipn < fgkChipsPerModule) fCmFerom[chipn].Set(fCmFerom[chipn].GetSize(), cm); 
 }
+
+
+//______________________________________________________________________________
+Short_t  AliITSModuleDaSSD::GetCMFerom(const Int_t chipn, const Long_t evn)   const 
+{ 
+// Get value of FeromCM for a given chip and event 
+  if ((!fCmFerom) || (chipn >= fgkChipsPerModule)) return 0;
+  if (evn >= fCmFerom[chipn].GetSize()) return 0;
+  else return fCmFerom[chipn][evn];
+}
+