]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFFEEReader.cxx
Add class to access simulation parameters, AliEMCALSimParam, to be set in configurati...
[u/mrichter/AliRoot.git] / TOF / AliTOFFEEReader.cxx
index a75aea271622070cb789b30f77429427f222da3a..c19ff41622f5422b38fd043805f5faef72bafc99 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,8 +42,10 @@ ClassImp(AliTOFFEEReader)
 AliTOFFEEReader::AliTOFFEEReader() :
   TObject(),
   fFEEConfig(new AliTOFFEEConfig()),
+  fFEElightConfig(new AliTOFFEElightConfig()),
   fChannelEnabled(),
-  fMatchingWindow()
+  fMatchingWindow(),
+  fLatencyWindow()
 {
   /* 
    * 
@@ -56,7 +60,8 @@ AliTOFFEEReader::AliTOFFEEReader() :
 
 AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
   TObject(source),
-  fFEEConfig(new AliTOFFEEConfig())
+  fFEEConfig(new AliTOFFEEConfig()),
+  fFEElightConfig(new AliTOFFEElightConfig())
 {
   /* 
    * 
@@ -65,6 +70,7 @@ AliTOFFEEReader::AliTOFFEEReader(const AliTOFFEEReader &source) :
    */
 
   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
+  memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
 }
 
 //_______________________________________________________________
@@ -80,6 +86,7 @@ AliTOFFEEReader::operator=(const AliTOFFEEReader &source)
 
   TObject::operator=(source);
   memcpy(fFEEConfig, source.fFEEConfig, sizeof(AliTOFFEEConfig));
+  memcpy(fFEElightConfig, source.fFEElightConfig, sizeof(AliTOFFEElightConfig));
   return *this;
 }
 
@@ -94,6 +101,7 @@ AliTOFFEEReader::~AliTOFFEEReader()
    */
 
   delete fFEEConfig;
+  delete fFEElightConfig;
 }
 
 //_______________________________________________________________
@@ -125,6 +133,7 @@ AliTOFFEEReader::Reset()
   for (Int_t iIndex = 0; iIndex < GetNumberOfIndexes(); iIndex++) {
     fChannelEnabled[iIndex] = kFALSE;
     fMatchingWindow[iIndex] = 0;
+    fLatencyWindow[iIndex] = 0;
   }
 }
 
@@ -148,6 +157,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()
 {
@@ -160,7 +187,7 @@ AliTOFFEEReader::ParseFEEConfig()
    *
    */
 
-  AliInfo("parsing TOF FEE config")
+  AliInfo("parsing TOF FEE config");
 
   AliTOFRawStream rawStream;
   Int_t nEnabled = 0;
@@ -203,6 +230,42 @@ 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");
+
+  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();
+  }
+  return nEnabled;
+}
+
+//_______________________________________________________________
+
 Bool_t 
 AliTOFFEEReader::IsChannelEnabled(Int_t iDDL, Int_t iTRM, Int_t iChain, Int_t iTDC, Int_t iChannel) const
 {
@@ -218,7 +281,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()))
@@ -247,6 +310,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:
@@ -274,6 +339,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:
@@ -301,6 +368,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))
@@ -426,12 +497,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()));
       }
       
 
@@ -441,3 +512,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();
+  
+}