]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFFEEReader.cxx
bugfix: corrected calculation of slice and partition from track point Id
[u/mrichter/AliRoot.git] / TOF / AliTOFFEEReader.cxx
index 08e755c86fc685f3cfe2da53e961a4776c615b36..8cd7420dccbd193570c60ca90951a8315b79470d 100644 (file)
 #include <TSystem.h>
 #include "AliTOFFEEReader.h"
 #include "AliTOFFEEConfig.h"
+#include "AliTOFFEElightConfig.h"
 #include "AliTOFRawStream.h"
 #include "AliTOFGeometry.h"
+#include "AliTOFcalibHisto.h"
 #include "AliLog.h"
 #include <fstream>
 
@@ -40,7 +42,10 @@ ClassImp(AliTOFFEEReader)
 AliTOFFEEReader::AliTOFFEEReader() :
   TObject(),
   fFEEConfig(new AliTOFFEEConfig()),
-  fChannelEnabled()
+  fFEElightConfig(new AliTOFFEElightConfig()),
+  fChannelEnabled(),
+  fMatchingWindow(),
+  fLatencyWindow()
 {
   /* 
    * 
@@ -48,13 +53,15 @@ AliTOFFEEReader::AliTOFFEEReader() :
    *
    */
 
+  Reset();
 }
 
 //_______________________________________________________________
 
 AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
   TObject(source),
-  fFEEConfig(new AliTOFFEEConfig())
+  fFEEConfig(new AliTOFFEEConfig()),
+  fFEElightConfig(new AliTOFFEElightConfig())
 {
   /* 
    * 
@@ -62,7 +69,9 @@ AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
    *
    */
 
+  Reset();
   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
+  memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
 }
 
 //_______________________________________________________________
@@ -76,11 +85,9 @@ AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
    * 
    */
 
-  if (this == &source)
-    return *this;
-
   TObject::operator=(source);
   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
+  memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
   return *this;
 }
 
@@ -95,6 +102,7 @@ AliTOFFEEReader::~AliTOFFEEReader()
    */
 
   delete fFEEConfig;
+  delete fFEElightConfig;
 }
 
 //_______________________________________________________________
@@ -114,6 +122,42 @@ AliTOFFEEReader::ResetChannelEnabledArray()
 
 //_______________________________________________________________
 
+void
+AliTOFFEEReader::ResetTriggerMaskArray()
+{
+  /*
+   *
+   * reset trigger mask array
+   *
+   */
+
+  for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
+    fTriggerMask[iddl] = 0x0;
+}
+
+//_______________________________________________________________
+
+void
+AliTOFFEEReader::Reset()
+{
+  /*
+   *
+   * reset 
+   *
+   */
+
+  for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
+    fChannelEnabled[iIndex] = kFALSE;
+    fMatchingWindow[iIndex] = 0;
+    fLatencyWindow[iIndex] = 0;
+  }
+
+  for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++)
+    fTriggerMask[iddl] = 0x0;
+}
+
+//_______________________________________________________________
+
 void
 AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
 {
@@ -132,6 +176,24 @@ AliTOFFEEReader::LoadFEEConfig(const Char_t *FileName) const
 
 //_______________________________________________________________
 
+void
+AliTOFFEEReader::LoadFEElightConfig(const Char_t *FileName) const
+{
+  /*
+   *
+   * load FEElight config
+   *
+   */
+
+  Char_t *expandedFileName = gSystem->ExpandPathName(FileName);
+  std::ifstream is;
+  is.open(expandedFileName, std::ios::binary);
+  is.read((Char_t *)fFEElightConfig, sizeof(AliTOFFEElightConfig));
+  is.close();
+}
+
+//_______________________________________________________________
+
 Int_t
 AliTOFFEEReader::ParseFEEConfig()
 {
@@ -144,14 +206,14 @@ AliTOFFEEReader::ParseFEEConfig()
    *
    */
 
-  AliInfo("parsing TOF FEE config")
+  AliInfo("parsing TOF FEE config");
 
   AliTOFRawStream rawStream;
   Int_t nEnabled = 0;
   Int_t volume[5], index;
   Int_t temp;
 
-  ResetChannelEnabledArray();
+  Reset();
 
   /* loop over all FEE channels */
   for (Int_t iDDL = 0; iDDL < GetNumberOfDDLs(); iDDL++)
@@ -165,12 +227,20 @@ AliTOFFEEReader::ParseFEEConfig()
              rawStream.EquipmentId2VolumeId(iDDL, iTRM + 3, iChain, iTDC, iChannel, volume);
              /* swap padx and padz to fit AliTOFGeometry::GetIndex behaviour */
              temp = volume[4]; volume[4] = volume[3]; volume[3] = temp; 
+             /* check if index is ok */
+             if (volume[0] < 0 || volume[0] > 17 ||
+                 volume[1] < 0 || volume[1] > 4 ||
+                 volume[2] < 0 || volume[2] > 18 ||
+                 volume[3] < 0 || volume[3] > 1 ||
+                 volume[4] < 0 || volume[4] > 47)
+               continue;
              /* convert detector indexes into calibration index */
              index = AliTOFGeometry::GetIndex(volume);
              /* check calibration index */
              if (index != -1 && index < GetNumberOfIndexes()) {
                /* set calibration channel enabled */
                fChannelEnabled[index] = kTRUE;
+               fMatchingWindow[index] = GetMatchingWindow(iDDL, iTRM + 3, iChain, iTDC, iChannel);
                nEnabled++;
              }
            }
@@ -179,6 +249,50 @@ AliTOFFEEReader::ParseFEEConfig()
 
 //_______________________________________________________________
 
+Int_t
+AliTOFFEEReader::ParseFEElightConfig()
+{
+  /* 
+   *
+   * parse FEElight config
+   *
+   * loops over all FEE channels, checks whether they are enabled
+   * and sets channel enabled 
+   *
+   */
+
+  AliInfo("parsing TOF FEElight config");
+
+  Reset();
+
+  AliTOFcalibHisto calibHisto;
+  calibHisto.LoadCalibHisto();
+
+  Int_t nEnabled = 0, index;
+  AliTOFFEEchannelConfig *channelConfig = NULL;
+  for (Int_t i = 0; i < GetNumberOfIndexesEO(); i++) {
+    channelConfig = fFEElightConfig->GetChannelConfig(i);
+    if (!channelConfig->IsEnabled()) continue;
+    /* get index DO from index EO */
+    index = (Int_t)calibHisto.GetCalibMap(AliTOFcalibHisto::kIndex, i);
+    if (index == -1) continue;
+    nEnabled++;
+    fChannelEnabled[index] = channelConfig->IsEnabled();
+    fMatchingWindow[index] = channelConfig->GetMatchingWindow();
+    fLatencyWindow[index] = channelConfig->GetLatencyWindow();
+  }
+
+  AliTOFFEEtriggerConfig *triggerConfig = NULL;
+  for (Int_t iddl = 0; iddl < GetNumberOfDDLs(); iddl++) {
+    triggerConfig = fFEElightConfig->GetTriggerConfig(iddl);
+    fTriggerMask[iddl] = triggerConfig->GetStatusMap();
+  }
+  return nEnabled;
+}
+
+//_______________________________________________________________
+
 Bool_t 
 AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
 {
@@ -194,7 +308,7 @@ AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iT
   AliTOFFEEConfig *feeConfig;
   AliTOFCrateConfig *crateConfig;
   AliTOFTRMConfig *trmConfig;
-  Int_t maskPB, maskTDC;
+  Int_t maskPB, maskTDC, activeChip;
   
   /* get and check fee config */
   if (!(feeConfig = GetFEEConfig()))
@@ -223,6 +337,8 @@ AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iT
     /* check chain enabled */
     if (trmConfig->GetChainAFlag() != 1)
       return kFALSE;
+    /* get active chip mask */
+    activeChip = trmConfig->GetActiveChipA();
     /* switch TDC */
     switch (iTDC) {
     case 0: case 1: case 2:
@@ -250,6 +366,8 @@ AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iT
     /* check chain enabled */
     if (trmConfig->GetChainBFlag() != 1)
       return kFALSE;
+    /* get active chip mask */
+    activeChip = trmConfig->GetActiveChipB();
     /* switch TDC */
     switch (iTDC) {
     case 0: case 1: case 2:
@@ -277,6 +395,10 @@ AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iT
     break;
   } /* switch chain */
 
+  /* check chip enabled */
+  if (!(activeChip & (0x1 << iTDC)))
+    return kFALSE;
+
   /* check channel enabled */
   maskTDC = (maskPB & (0xFF << ((iTDC % 3) * 8))) >> ((iTDC % 3) * 8);
   if (maskTDC & (0x1 << iChannel))
@@ -286,6 +408,48 @@ AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iT
   
 }
 
+//_______________________________________________________________
+
+Int_t 
+AliTOFFEEReader::GetMatchingWindow(Int_t iDDL, Int_t iTRM, Int_t, Int_t, Int_t) const
+{
+  /*
+   *
+   * get matching window
+   *
+   * checks whether a FEE channel is enabled using the
+   * TOF FEE config object and return the associated
+   * matching window
+   *
+   */
+  
+  AliTOFFEEConfig *feeConfig;
+  AliTOFCrateConfig *crateConfig;
+  AliTOFTRMConfig *trmConfig;
+
+  /* get and check fee config */
+  if (!(feeConfig = GetFEEConfig()))
+    return 0;
+  
+  /* get and check crate config */
+  if (!(crateConfig = feeConfig->GetCrateConfig(iDDL)))
+    return 0;
+  
+  /* get and check TRM config */
+  if (!(trmConfig = crateConfig->GetTRMConfig(iTRM - 3)))
+    return 0;
+
+  /* check DRM enabled */
+  if (!crateConfig->IsDRMEnabled())
+    return 0;
+
+  /* check TRM enabled */
+  if (!crateConfig->IsTRMEnabled(iTRM - 3))
+    return 0;
+
+  return trmConfig->GetMatchingWindow();
+}
+
 
 void
 AliTOFFEEReader::DumpFEEConfig()
@@ -306,7 +470,7 @@ AliTOFFEEReader::DumpFEEConfig()
   AliInfo("dumping TOF FEE config");
   AliInfo("-------------------------------------");
   AliInfo(Form("version: %d", feeConfig->GetVersion()));
-  AliInfo(Form("dump time: %d", feeConfig->GetDumpTime()));
+  AliInfo(Form("dump time: %d", (Int_t)feeConfig->GetDumpTime()));
   AliInfo(Form("run number: %d", feeConfig->GetRunNumber()));
   AliInfo(Form("run type: %d", feeConfig->GetRunType()));
   AliInfo("-------------------------------------");
@@ -358,12 +522,12 @@ AliTOFFEEReader::DumpFEEConfig()
       
       /* check TRM chain A flag */
       if (trmConfig->GetChainAFlag() == 1) {
-       AliInfo(Form("TRM%02d chainA is enabled: PB0=%06X, PB1=%06X, PB2=%06X, PB3=%06X, PB4=%06X", iTRM + 3, trmConfig->GetMaskPB0(), trmConfig->GetMaskPB1(), trmConfig->GetMaskPB2(), trmConfig->GetMaskPB3(), trmConfig->GetMaskPB4()));
+       AliInfo(Form("TRM%02d chainA is enabled: activeChip=%04X, PB0=%06X, PB1=%06X, PB2=%06X, PB3=%06X, PB4=%06X", iTRM + 3, trmConfig->GetActiveChipA(), trmConfig->GetMaskPB0(), trmConfig->GetMaskPB1(), trmConfig->GetMaskPB2(), trmConfig->GetMaskPB3(), trmConfig->GetMaskPB4()));
       }
 
       /* check TRM chain B flag */
       if (trmConfig->GetChainBFlag() == 1) {
-       AliInfo(Form("TRM%02d chainB is enabled: PB5=%06X, PB6=%06X, PB7=%06X, PB8=%06X, PB9=%06X", iTRM + 3, trmConfig->GetMaskPB5(), trmConfig->GetMaskPB6(), trmConfig->GetMaskPB7(), trmConfig->GetMaskPB8(), trmConfig->GetMaskPB9()));
+       AliInfo(Form("TRM%02d chainB is enabled: activeChip=%04X, PB5=%06X, PB6=%06X, PB7=%06X, PB8=%06X, PB9=%06X", iTRM + 3, trmConfig->GetActiveChipB(), trmConfig->GetMaskPB5(), trmConfig->GetMaskPB6(), trmConfig->GetMaskPB7(), trmConfig->GetMaskPB8(), trmConfig->GetMaskPB9()));
       }
       
 
@@ -373,3 +537,36 @@ AliTOFFEEReader::DumpFEEConfig()
   } /* loop over crates */
 }
 
+//_______________________________________________________________
+
+void
+AliTOFFEEReader::CreateFEElightConfig(const Char_t *filename)
+{
+  /*
+   *
+   * create FEElight config 
+   *
+   */
+
+  AliTOFFEElightConfig lightConfig;
+
+  for (Int_t i = 0; i < GetNumberOfIndexes(); i++) {
+    if (fChannelEnabled[i]) {
+      lightConfig.GetChannelConfig(i)->SetStatus(AliTOFFEEchannelConfig::kStatusEnabled);
+      lightConfig.GetChannelConfig(i)->SetMatchingWindow(fMatchingWindow[i]);
+      lightConfig.GetChannelConfig(i)->SetLatencyWindow(fLatencyWindow[i]);
+    }
+    else {
+      lightConfig.GetChannelConfig(i)->SetStatus(0x0);
+      lightConfig.GetChannelConfig(i)->SetMatchingWindow(0);
+      lightConfig.GetChannelConfig(i)->SetLatencyWindow(0);
+    }
+  }
+
+  Char_t *expandedFileName = gSystem->ExpandPathName(filename);
+  std::ofstream os;
+  os.open(expandedFileName, std::ios::binary);
+  os.write((Char_t *)&lightConfig, sizeof(AliTOFFEElightConfig));
+  os.close();
+  
+}