]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/RCU/AliHLTAltroGenerator.cxx
Update DCS admins
[u/mrichter/AliRoot.git] / HLT / RCU / AliHLTAltroGenerator.cxx
index 1f146c8b17c967bb0a8669ba46b2b9c0a8571a6c..c7ef61eab8980181164dbf5738638f98202512d4 100644 (file)
@@ -29,7 +29,7 @@
 #include "TArrayC.h"
 #include "TRandom.h"
 #include "TDatime.h"
-#include "AliRawDataHeader.h"
+#include "AliRawDataHeaderV3.h"
 #include "AliHLTAltroEncoder.h"
 
 /** ROOT macro for the implementation of ROOT specific class methods */
@@ -79,8 +79,6 @@ AliHLTAltroGenerator::~AliHLTAltroGenerator()
 int AliHLTAltroGenerator::Generate()
 {
   // see header file for class documentation
-  int iResult=0;
-
   if (!fpSimData) fpSimData=new TArrayS;
   if (!fpSimData) {
     return -ENOMEM;
@@ -112,12 +110,13 @@ int AliHLTAltroGenerator::Generate()
     }
     repetitions=0;
     int totalBunches=0;
-    int bunchEndTime=fMaxTimebin;
+    int bunchEndTime=0;
+    int lastBunchEndTime=0;
 
     HLTDebug("simulate channel %d: address %d", channel, channelAddress);
 
     // save beginning of this channel for better navigation
-    AliChannelPosition position={channelAddress, dataPos, 0};
+    AliChannelPosition position={static_cast<AliHLTUInt16_t>(channelAddress), dataPos, 0};
 
     // add channel address and bunch count at the beginning
     if (fpSimData->GetSize()<dataPos+2) fpSimData->Set(dataPos+2);
@@ -125,9 +124,18 @@ int AliHLTAltroGenerator::Generate()
     dataPos++; // placeholder for number of bunches
 
     int bunch=0;
-    for (bunch=0; bunch<nofBunches && bunchEndTime>0; bunch++) {
-      bunchEndTime=GetRandom(0, bunchEndTime-1);
-      int bunchLength=GetRandom(0, bunchEndTime<fMaxBunchLength?bunchEndTime:fMaxBunchLength);
+
+    // Matthias Oct 2008:
+    // Data was simulated in the wrong order: bunches for the higher timebins
+    // first. But real data is the other way round: bunches are written in the order
+    // of ascending timebins. A new consistency check was added to AliAltroDecoder
+    // (AliAltroBunch) in revision 29090. Now the channels are checked for overlapping
+    // bunches, the time of a bunch must be smaller than time of the previous one
+    // minus its length.
+    // Data is now simulated in the right order in order to fullfil this check.
+    for (bunch=0; bunch<nofBunches && bunchEndTime<fMaxTimebin-3; bunch++) {
+      while ((bunchEndTime+=GetRandom(0, fMaxTimebin-bunchEndTime))-lastBunchEndTime<3) {/*empty body*/};
+      int bunchLength=GetRandom(0, bunchEndTime-lastBunchEndTime<fMaxBunchLength?bunchEndTime-lastBunchEndTime:fMaxBunchLength);
       if (bunchLength==0) continue;
       totalBunches++;
 
@@ -145,6 +153,8 @@ int AliHLTAltroGenerator::Generate()
       (*fpSimData)[dataPos++]=bunchEndTime;
       (*fpSimData)[dataPos++]=bunchLength;
       fNof10BitWords+=bunchLength+2;
+      lastBunchEndTime=bunchEndTime;
+      bunchEndTime+=bunchLength;
     }
     if (totalBunches>0) {
       (*fpSimData)[position.fPosition+1]=totalBunches;
@@ -164,10 +174,6 @@ int AliHLTAltroGenerator::Generate()
   }
 
   assert(fNof10BitWords%4==0);
-  if (iResult<0) {
-    fpSimData->Set(0);
-    return iResult;
-  }
   fpSimData->Set(dataPos);
   return GetDataSize();
 }
@@ -243,13 +249,13 @@ int AliHLTAltroGenerator::GetData(AliHLTUInt8_t* pBuffer, int size)
   return dataPos;
 }
 
-int AliHLTAltroGenerator::SetCDH(AliRawDataHeader* pCDH, int size)
+int AliHLTAltroGenerator::SetCDH(AliRawDataHeaderV3* pCDH, int size)
 {
   // see header file for class documentation
   int iResult=0;
   if (pCDH && size>0) {
     if (fpCDH) delete[] fpCDH;
-    fpCDH=new AliRawDataHeader;
+    fpCDH=new AliRawDataHeaderV3;
     if (fpCDH) {
       memcpy(fpCDH, pCDH, size);
       fCDHSize=size;
@@ -345,7 +351,6 @@ int AliHLTAltroGenerator::EncodeData(AliHLTUInt8_t* pBuffer, int size)
       int time=startTime;
       for (; time<startTime+bunchLength; time++) {
        iResult=encoder.AddSignal(fpSimData->At(dataPos++), time);
-       //iResult=encoder.AddChannelSignal(fpSimData->At(dataPos++), time, channelAddress);
       }
       assert(time-1==fpSimData->At(dataPos));
       dataPos++; // DO NOT PUT INTO ASSERT
@@ -361,9 +366,6 @@ int AliHLTAltroGenerator::EncodeData(AliHLTUInt8_t* pBuffer, int size)
     }
     encoder.SetChannel(channelAddress);
   }
-  if (iResult>=0 && channelAddress>=0) {
-    //encoder.SetChannel(channelAddress);
-  }
 
   if (iResult>=0) {
     iResult=(encoder.GetTotal40bitWords()*5)/4;
@@ -412,13 +414,13 @@ bool AliHLTAltroGenerator::Next()
   bool haveData=false;
   if (!fpSimData) return false;
   do {
-    if (haveData=(fCurrentTimeOffset>=0 &&
-                 fCurrentBunch>0 &&
-                 ++fCurrentTimeOffset<GetBunchSize())) {
+    if ((haveData=(fCurrentTimeOffset>=0 &&
+                  fCurrentBunch>0 &&
+                  ++fCurrentTimeOffset<GetBunchSize()))) {
       break;
     }
 
-    if (haveData=(NextBunch() && GetBunchSize()>0)) {
+    if ((haveData=(NextBunch()) && GetBunchSize()>0)) {
       fCurrentTimeOffset=0;
       break;
     }
@@ -444,7 +446,7 @@ bool AliHLTAltroGenerator::NextChannel()
 {
   // see header file for class documentation
   bool haveData=false;
-  if (fpSimData && fChannelPositions.size()==0) return false;
+  if (!fpSimData || fChannelPositions.size()==0) return false;
   fpSimData->GetArray();
   if (fCurrentPosition==-1) {
     if (fDirection==kForwards) fCurrentPosition=0;
@@ -491,7 +493,7 @@ bool AliHLTAltroGenerator::NextBunch()
     if (fDirection==kBackwards) {
       if (fCurrentBunch<0) {
        // bunch count in channel end - 1
-       if (haveData=(fpSimData->At(fChannelPositions[fCurrentPosition].fEnd-1))>0) {
+       if ((haveData=(fpSimData->At(fChannelPositions[fCurrentPosition].fEnd-1))>0)) {
          // first bunch length at channel end - 2
          fCurrentBunch=fChannelPositions[fCurrentPosition].fEnd-2;
        }
@@ -507,7 +509,7 @@ bool AliHLTAltroGenerator::NextBunch()
     } else if (fDirection==kForwards) {
       if (fCurrentBunch<0) {
        // bunch count in channel start + 1
-       if (haveData=(fpSimData->At(fChannelPositions[fCurrentPosition].fPosition+1))>0) {
+       if ((haveData=(fpSimData->At(fChannelPositions[fCurrentPosition].fPosition+1))>0)) {
          // first bunch length at channel start + 2
          fCurrentBunch=fChannelPositions[fCurrentPosition].fPosition+2;
        }