]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDRawWriter.cxx
ALIROOT-5486 Add method to get trigger deviation sign
[u/mrichter/AliRoot.git] / FMD / AliFMDRawWriter.cxx
index 6cd64b0aac218968584d52717336c1f4165d2229..1bd500224c4ee535afd79a6d0cc0f4491125f277 100644 (file)
@@ -50,6 +50,7 @@
 #include <TArrayF.h>           // ROOT_TArrayI
 #include <TArrayC.h>           // ROOT_TArrayI
 #include <TClonesArray.h>      // ROOT_TClonesArray
+#include <TTree.h>
 // #include <fstream>
 #include "AliDAQ.h"
 
@@ -140,14 +141,15 @@ AliFMDRawWriter::Exec(Option_t*)
     return;
   }
   
-  TClonesArray* digits = new TClonesArray("AliFMDDigit", 1000);
   fFMD->SetTreeAddress();
-  TBranch* digitBranch = digitTree->GetBranch(fFMD->GetName());
-  if (!digitBranch) {
-    AliError(Form("no branch for %s", fFMD->GetName()));
-    return;
-  }
-  digitBranch->SetAddress(&digits);
+  TClonesArray* digits = fFMD->Digits(); 
+  // new TClonesArray("AliFMDDigit", 1000);
+  // TBranch* digitBranch = digitTree->GetBranch(fFMD->GetName());
+  // if (!digitBranch) {
+  //   AliError(Form("no branch for %s", fFMD->GetName()));
+  //   return;
+  // }
+  // digitBranch->SetAddress(&digits);
   
   Int_t nEvents = Int_t(digitTree->GetEntries());
   AliFMDDebug(5, ("Got a total of %5d events from tree", nEvents));
@@ -159,20 +161,22 @@ AliFMDRawWriter::Exec(Option_t*)
     WriteDigits(digits);
   }
   loader->UnloadDigits();
+  //delete digits;
 }
 
 #if 1
 //____________________________________________________________________
-void
+Long_t
 AliFMDRawWriter::WriteDigits(TClonesArray* digits)
 {
   // WRite an array of digits to disk file 
   Int_t nDigits = digits->GetEntries();
-  if (nDigits < 1) return;
+  if (nDigits < 1) return 0;
   AliFMDDebug(5, ("Got a total of %5d digits from tree", nDigits));
 
   AliFMDParameters* pars = AliFMDParameters::Instance();
   UShort_t threshold    = 0;
+  UShort_t factor       = 0;
   UInt_t   prevddl      = 0xFFFF;
   UInt_t   prevaddr     = 0xFFF;
   // UShort_t prevStrip    = 0;
@@ -191,9 +195,10 @@ AliFMDRawWriter::WriteDigits(TClonesArray* digits)
   // The Altro buffer 
   AliAltroBufferV3* altro = 0;
   
-  Int_t totalWords = 0;
-  Int_t nCounts    = 0;
-  
+  Int_t  totalWords = 0;
+  Int_t  nCounts    = 0;
+  Long_t nBits      = 0;
+
   // Loop over the digits in the event.  Note, that we assume the
   // the digits are in order in the branch.   If they were not, we'd
   // have to cache all channels before we could write the data to
@@ -213,10 +218,11 @@ AliFMDRawWriter::WriteDigits(TClonesArray* digits)
     threshold  = pars->GetZeroSuppression(det, ring, sector, strip);
     sampleRate = pars->GetSampleRate(det, ring, sector, strip);
     preSamples = pars->GetPreSamples(det, ring, sector, strip);
+    factor     = UShort_t(pars->GetPedestalFactor());
 
     if (det != oldDet) {
       AliFMDDebug(5, ("Got new detector: %d (was %d)", det, oldDet));
-      oldDet = det;
+      oldDet = det;      
     }
     AliFMDDebug(15, ("Sample rate is %d", sampleRate));
     
@@ -239,7 +245,8 @@ AliFMDRawWriter::WriteDigits(TClonesArray* digits)
                         time, prevaddr, nWords));
        totalWords += nWords;
        ZeroSuppress(data.fArray, nWords, peds.fArray, noise.fArray, threshold);
-       if (altro) altro->WriteChannel(prevaddr,nWords,data.fArray,threshold);
+       if (altro) 
+         /*nBits+=*/altro->WriteChannel(prevaddr,nWords,data.fArray,threshold);
        data.Reset(-1);
        peds.Reset(0);
        noise.Reset(0);
@@ -254,8 +261,8 @@ AliFMDRawWriter::WriteDigits(TClonesArray* digits)
          // When the first argument is false, we write the real
          // header. 
          AliFMDDebug(15, ("Closing output"));
-         altro->Flush();
-         altro->WriteDataHeader(kFALSE, kFALSE);
+         WriteRCUTrailer(altro, prevddl, threshold > 0, factor, sampleRate); 
+    
          delete altro;
          altro = 0;
        }
@@ -299,14 +306,49 @@ AliFMDRawWriter::WriteDigits(TClonesArray* digits)
   // already 
   if (altro) {
     ZeroSuppress(data.fArray, nWords, peds.fArray, noise.fArray, threshold);
-    if (nWords > 0) altro->WriteChannel(prevaddr,nWords,data.fArray,threshold);
-    altro->Flush();
-    altro->WriteDataHeader(kFALSE, kFALSE);
+    if (nWords > 0) 
+      /* nBits += */ altro->WriteChannel(prevaddr,nWords,data.fArray,threshold);
+    WriteRCUTrailer(altro, prevddl, threshold > 0, factor, sampleRate); 
     delete altro;
   }
-  AliFMDDebug(5, ("Wrote a total of %d words for %d counts", 
-                 nWords, nCounts));
+  AliFMDDebug(5, ("Wrote a total of %d words in %ld bytes for %d counts", 
+                 nWords, nBits / 8, nCounts));
+  return nBits;
+}
+//____________________________________________________________________
+void
+AliFMDRawWriter::WriteRCUTrailer(AliAltroBufferV3* altro,
+                                UInt_t ddl,
+                                Bool_t zs,
+                                UShort_t factor,
+                                UShort_t rate) const
+{
+  // Flush and write the data header
+  altro->Flush();
+  altro->WriteDataHeader(kFALSE, kFALSE);
+    
+  // Set parameters in RCU trailer. 
+  // Zero-suppression flag
+  altro->SetZeroSupp(zs); // bool
+  // WARNING: We store the noise factor in the 2nd baseline
+  // filters excluded post samples, since we'll never use that
+  // mode. 
+  // altro->SetNPostsamples(factor); // 
+  altro->SetNNonZSPostsamples(factor);
+  // WARNING: We store the sample rate in the number of pre-trigger
+  // samples, since we'll never use that mode.
+  altro->SetNPretriggerSamples(rate); // fSampleRate[ddl]
+  // Active front-end cars 
+  altro->SetActiveFECsA((ddl == 0 ? 0x1 : 0x3));
+  altro->SetActiveFECsB((ddl == 0 ? 0x1 : 0x3));
+
+  // Calculate number of samples 
+  altro->SetNSamplesPerCh(rate * 128);
+  AliDebug(5,Form("Writing RCU trailer @ DDL %d w/zs=%d, factor=%d, rate=%d",
+                 ddl, zs > 0, factor, rate));
+  altro->WriteRCUTrailer(ddl);
 }
+
 //____________________________________________________________________
 void
 AliFMDRawWriter::ZeroSuppress(Int_t*& data, Int_t nWords, 
@@ -375,6 +417,9 @@ AliFMDRawWriter::ZeroSuppress(Int_t*& data, Int_t nWords,
 void
 AliFMDRawWriter::WriteDigits(TClonesArray* digits)
 {
+  // 
+  // Write digits to file 
+  //
   Int_t nDigits = digits->GetEntries();
   if (nDigits < 1) return;