X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=FMD%2FAliFMDRawStream.cxx;h=485e40fae3f1a99fb9bff8e39458098a532bd4ac;hb=17fdf3eeae2f0d26449202a53c5252954744750b;hp=d698fbcdd530f45638e6637172686aa68e149b84;hpb=56b1929b4687f57bebdd95309d2994db32b6255c;p=u%2Fmrichter%2FAliRoot.git diff --git a/FMD/AliFMDRawStream.cxx b/FMD/AliFMDRawStream.cxx index d698fbcdd53..485e40fae3f 100644 --- a/FMD/AliFMDRawStream.cxx +++ b/FMD/AliFMDRawStream.cxx @@ -19,38 +19,104 @@ // // Buffer to read RAW ALTRO FMD format from a AliRawReader // +// This class derives from AliAltroBuffer, but overloads the memer +// function Next to do some extra processing. In particular, it tries +// to autodetect the sample rate. If zero-suppression was used when +// writing the raw data, then the automatic discovery will not work, +// and the sample rate should be set explicitly. // #include "AliFMDRawStream.h" // ALIFMDRAWSTREAM_H -#include // ALIRAWREADER_H +// #include // ALIRAWREADER_H +#include "AliFMDParameters.h" +// #include +#include "AliFMDDebug.h" // Better debug macros +// #include +// #include +#include "AliRawReader.h" +#include //____________________________________________________________________ -ClassImp(AliFMDRawStream); +ClassImp(AliFMDRawStream) +#if 0 + ; // This is here to keep Emacs for indenting the next line +#endif //____________________________________________________________________ -AliFMDRawStream::AliFMDRawStream(AliRawReader* reader, UShort_t sampleRate) - : AliAltroRawStream(reader), - fSampleRate(sampleRate), - fPrevTime(-1), - fExplicitSampleRate(kFALSE) +AliFMDRawStream::AliFMDRawStream(AliRawReader* reader) + : AliAltroRawStream(reader) { - if (fSampleRate > 0) fExplicitSampleRate = kTRUE; + // CTOR + reader->Reset(); + // Select FMD DDL's + SelectRawData("FMD"); } //_____________________________________________________________________________ Bool_t -AliFMDRawStream::Next() +AliFMDRawStream::ReadChannel(UInt_t& ddl, UInt_t& addr, + UInt_t& len, volatile UShort_t* data) { - // read the next raw digit - // returns kFALSE if there is no digit left - fPrevTime = fTime; - if (AliAltroRawStream::Next()) { - if (!fExplicitSampleRate && fPrevPad != fPad) - fSampleRate = fTimeBunch / 128; - return kTRUE; - } - return kFALSE; + // Read one channel and return. Returns 0 when there's no more + // data. + Int_t l = 0; + static Int_t last = 0xFFFF; // 0xFFFF means signal is used + Bool_t next = kTRUE; + do { + Int_t signal = last; + if (last > 0x3FF) { + AliFMDDebug(30, ("Last is 0x%x, so reading a new word", last)); + next = Next(); + if(!next){ + AliFMDDebug(15, ("Read word # %d (!next)", l)); + addr = GetPrevHWAddress(); + ddl = (GetPrevDDLNumber() < 0 ? UINT_MAX: UInt_t(GetPrevDDLNumber())); + len = l+1; // Need to add one - l points to last valid index + last = signal; + break; + } + signal = GetSignal(); + if (GetHWAddress() != GetPrevHWAddress() && GetPrevHWAddress() >= 0) { + AliFMDDebug(15, ("New hardware address, was 0x%x, now 0x%x", + GetPrevHWAddress(), GetHWAddress())); + addr = GetPrevHWAddress(); + ddl = (GetPrevDDLNumber() < 0 ? UINT_MAX : UInt_t(GetPrevDDLNumber())); + len = l+1; // Need to add one - l points to last valid index + last = signal; + break; + } + } + // Sanity check - if the total bunch length is less than 1, then + // read until we get the next bunch. + Int_t b = GetTimeLength(); + if (b < 1) { + AliWarning(Form("Bunch length %0d is less than 0 for " + "DDL %4d address 0x%03x", + b, ddl, addr)); + last = 0xFFFF; + continue; + } + + // Sanity check - if the current time is less than 0, then read + // until we get a new bunch. + Int_t t = GetTime(); + if (t < 0) { + AliWarning(Form("Time %0d is less than 0 for DDL %4d address 0x%03x", + t, ddl, addr)); + last = 0xFFFF; + continue; + } + l = TMath::Max(l, t); + data[t] = signal; + last = 0xFFFF; +#if 0 + AliFMDDebug(signal > 512 ? 1 : 0, ("Signal @ %d (%d) is %d", + time, t, data[t])); +#endif + } while (next); + return next; } + //_____________________________________________________________________________ // // EOF