X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=FMD%2FAliFMDRawReader.cxx;h=75392f6c13a71efb0762a3ccc1e067c5e4858bbb;hb=98dff241d22478e053fc4ff1db265f36931375c5;hp=96fee2fb4c9ab0c7b3adb3e22c5ac6fdb7e3c5ce;hpb=1e8f773ec10afa84ca5d4a654a27b44759f36097;p=u%2Fmrichter%2FAliRoot.git diff --git a/FMD/AliFMDRawReader.cxx b/FMD/AliFMDRawReader.cxx index 96fee2fb4c9..75392f6c13a 100644 --- a/FMD/AliFMDRawReader.cxx +++ b/FMD/AliFMDRawReader.cxx @@ -12,9 +12,13 @@ * about the suitability of this software for any purpose. It is * * provided "as is" without express or implied warranty. * **************************************************************************/ - /* $Id$ */ - +/** @file AliFMDRawReader.cxx + @author Christian Holm Christensen + @date Mon Mar 27 12:45:23 2006 + @brief Class to read raw data + @ingroup FMD_rec +*/ //____________________________________________________________________ // // Class to read ADC values from a AliRawReader object. @@ -42,22 +46,19 @@ // | AliAltroStream | // +----------------+ // -#include // ALILOG_H +// #include // ALILOG_H +#include "AliFMDDebug.h" // Better debug macros #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H #include "AliFMDDigit.h" // ALIFMDDIGIT_H #include "AliFMDRawStream.h" // ALIFMDRAWSTREAM_H -#include "AliRawReader.h" // ALIRAWREADER_H +// #include "AliRawReader.h" // ALIRAWREADER_H #include "AliFMDRawReader.h" // ALIFMDRAWREADER_H -#include "AliFMDAltroIO.h" // ALIFMDALTROIO_H -#include // ROOT_TArrayI +// #include "AliFMDAltroIO.h" // ALIFMDALTROIO_H +// #include // ROOT_TArrayI #include // ROOT_TTree #include // ROOT_TClonesArray -#include -#include -#include -#define PRETTY_HEX(N,X) \ - " 0x" << std::setfill('0') << std::setw(N) << std::hex << X \ - << std::setfill(' ') << std::dec +// #include +// #include //____________________________________________________________________ ClassImp(AliFMDRawReader) @@ -75,25 +76,121 @@ AliFMDRawReader::AliFMDRawReader(AliRawReader* reader, TTree* tree) // Default CTOR } - //____________________________________________________________________ void AliFMDRawReader::Exec(Option_t*) { - // Read raw data into the digits array, using AliFMDAltroReader. - if (!fReader->ReadHeader()) { - Error("ReadAdcs", "Couldn't read header"); + // Read the data + TClonesArray* array = new TClonesArray("AliFMDDigit"); + if (!fTree) { + AliError("No tree"); return; } - - TClonesArray* array = new TClonesArray("AliFMDDigit"); fTree->Branch("FMD", &array); + ReadAdcs(array); + Int_t nWrite = fTree->Fill(); + AliFMDDebug(1, ("Got a grand total of %d digits, wrote %d bytes to tree", + array->GetEntriesFast(), nWrite)); +} + + +#if 1 +//____________________________________________________________________ +Bool_t +AliFMDRawReader::ReadAdcs(TClonesArray* array) +{ + // Read raw data into the digits array, using AliFMDAltroReader. + if (!array) { + AliError("No TClonesArray passed"); + return kFALSE; + } + // if (!fReader->ReadHeader()) { + // AliError("Couldn't read header"); + // return kFALSE; + // } + // Get sample rate + AliFMDParameters* pars = AliFMDParameters::Instance(); + AliFMDRawStream input(fReader); + AliFMDDebug(5, ("Setting 7 word headers")); + input.SetShortDataHeader(!pars->HasCompleteHeader()); + + UShort_t stripMin = 0; + UShort_t stripMax = 127; + UShort_t preSamp = 14+5; + + UInt_t ddl = 0; + UInt_t rate = 0; + UInt_t last = 0; + UInt_t hwaddr = 0; + // Data array is approx twice the size needed. + UShort_t data[2048]; + + Bool_t isGood = kTRUE; + while (isGood) { + isGood = input.ReadChannel(ddl, hwaddr, last, data); + if (!isGood) break; + AliFMDDebug(5, ("Read channel 0x%x of size %d", hwaddr, last)); + UShort_t det, sec, str; + Char_t ring; + if (!pars->Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) { + AliError(Form("Failed to get detector id from DDL %d " + "and hardware address 0x%x", ddl, hwaddr)); + continue; + } + rate = pars->GetSampleRate(det, ring, sec, str); + stripMin = pars->GetMinStrip(det, ring, sec, str); + stripMax = pars->GetMaxStrip(det, ring, sec, str); + preSamp = pars->GetPreSamples(det, ring, sec, str); + AliFMDDebug(5, ("DDL 0x%04x, address 0x%03x maps to FMD%d%c[%2d,%3d]", + ddl, hwaddr, det, ring, sec, str)); + + // Loop over the `timebins', and make the digits + for (size_t i = 0; i < last; i++) { + if (i < preSamp) continue; + Int_t n = array->GetEntriesFast(); + Short_t curStr = str + stripMin + (i-preSamp) / rate; + if ((curStr-str) > stripMax) { + // AliInfo(Form("timebin %4d -> (%3d+%3d+(%4d-%d)/%d) -> %d", + // i, str, stripMin, i, preSamp, rate, curStr)); + // AliError(Form("Current strip is %3d (0x%04x,0x%03x,%4d) " + // "but DB says max is %3d (rate=%d)", + // curStr, ddl, hwaddr, i, str+stripMax, rate)); + // Garbage timebins - ignore + continue; + } + AliFMDDebug(5, ("making digit for FMD%d%c[%2d,%3d] from sample %4d", + det, ring, sec, curStr, i)); + new ((*array)[n]) AliFMDDigit(det, ring, sec, curStr, data[i], + (rate >= 2 ? data[i+1] : 0), + (rate >= 3 ? data[i+2] : 0), + (rate >= 4 ? data[i+3] : 0)); + if (rate >= 2) i++; + if (rate >= 3) i++; + if (rate >= 4) i++; + } + } + return kTRUE; +} +#else +//____________________________________________________________________ +Bool_t +AliFMDRawReader::ReadAdcs(TClonesArray* array) +{ + // Read raw data into the digits array, using AliFMDAltroReader. + if (!array) { + AliError("No TClonesArray passed"); + return kFALSE; + } + // if (!fReader->ReadHeader()) { + // AliError("Couldn't read header"); + // return kFALSE; + // } // Get sample rate AliFMDParameters* pars = AliFMDParameters::Instance(); // Select FMD DDL's - fReader->Select(AliFMDParameters::kBaseDDL>>8); + fReader->Select("FMD"); UShort_t stripMin = 0; UShort_t stripMax = 127; @@ -103,9 +200,9 @@ AliFMDRawReader::Exec(Option_t*) UChar_t* cdata; if (!fReader->ReadNextData(cdata)) break; size_t nchar = fReader->GetDataSize(); - UShort_t ddl = AliFMDParameters::kBaseDDL + fReader->GetDDLID(); - UShort_t rate = pars->GetSampleRate(ddl); - AliDebug(1, Form("Reading %d bytes (%d 10bit words) from %d", + UShort_t ddl = fReader->GetDDLID(); + UShort_t rate = 0; + AliFMDDebug(1, ("Reading %d bytes (%d 10bit words) from %d", nchar, nchar * 8 / 10, ddl)); // Make a stream to read from std::string str((char*)(cdata), nchar); @@ -115,7 +212,7 @@ AliFMDRawReader::Exec(Option_t*) // Data array is approx twice the size needed. UShort_t data[2048], hwaddr, last; while (r.ReadChannel(hwaddr, last, data) > 0) { - AliDebug(5, Form("Read channel 0x%x of size %d", hwaddr, last)); + AliFMDDebug(5, ("Read channel 0x%x of size %d", hwaddr, last)); UShort_t det, sec, str; Char_t ring; if (!pars->Hardware2Detector(ddl, hwaddr, det, ring, sec, str)) { @@ -123,19 +220,22 @@ AliFMDRawReader::Exec(Option_t*) "and hardware address 0x%x", ddl, hwaddr)); continue; } - AliDebug(5, Form("DDL 0x%04x, address 0x%03x maps to FMD%d%c[%2d,%3d]", + rate = pars->GetSampleRate(det, ring, sec, str); + stripMin = pars->GetMinStrip(det, ring, sec, str); + stripMax = pars->GetMaxStrip(det, ring, sec, str); + AliFMDDebug(5, ("DDL 0x%04x, address 0x%03x maps to FMD%d%c[%2d,%3d]", ddl, hwaddr, det, ring, sec, str)); // Loop over the `timebins', and make the digits for (size_t i = 0; i < last; i++) { if (i < preSamp) continue; - Int_t n = array->GetEntries(); + Int_t n = array->GetEntries(); UShort_t curStr = str + stripMin + i / rate; if ((curStr-str) > stripMax) { AliError(Form("Current strip is %d but DB says max is %d", curStr, stripMax)); } - AliDebug(5, Form("making digit for FMD%d%c[%2d,%3d] from sample %4d", + AliFMDDebug(5, ("making digit for FMD%d%c[%2d,%3d] from sample %4d", det, ring, sec, curStr, i)); new ((*array)[n]) AliFMDDigit(det, ring, sec, curStr, data[i], (rate >= 2 ? data[i+1] : 0), @@ -146,10 +246,11 @@ AliFMDRawReader::Exec(Option_t*) if (r.IsBof()) break; } } while (true); - AliDebug(1, Form("Got a grand total of %d digits", array->GetEntries())); + return kTRUE; } -#if 0 + + // This is the old method, for comparison. It's really ugly, and far // too convoluted. //____________________________________________________________________ @@ -157,10 +258,10 @@ void AliFMDRawReader::Exec(Option_t*) { // Read raw data into the digits array - if (!fReader->ReadHeader()) { - Error("ReadAdcs", "Couldn't read header"); - return; - } + // if (!fReader->ReadHeader()) { + // Error("ReadAdcs", "Couldn't read header"); + // return; + // } Int_t n = 0; TClonesArray* array = new TClonesArray("AliFMDDigit"); @@ -168,13 +269,13 @@ AliFMDRawReader::Exec(Option_t*) // Get sample rate AliFMDParameters* pars = AliFMDParameters::Instance(); - fSampleRate = pars->GetSampleRate(AliFMDParameters::kBaseDDL); + fSampleRate = pars->GetSampleRate(0); // Use AliAltroRawStream to read the ALTRO format. No need to // reinvent the wheel :-) AliFMDRawStream input(fReader, fSampleRate); // Select FMD DDL's - fReader->Select(AliFMDParameters::kBaseDDL); + fReader->Select("FMD"); Int_t oldDDL = -1; Int_t count = 0; @@ -192,14 +293,14 @@ AliFMDRawReader::Exec(Option_t*) count++; Int_t ddl = fReader->GetDDLID(); - AliDebug(10, Form("Current DDL is %d", ddl)); + AliFMDDebug(10, ("Current DDL is %d", ddl)); if (ddl != oldDDL || input.IsNewStrip() || !next) { // Make a new digit, if we have some data (oldDetector == 0, // means that we haven't really read anything yet - that is, // it's the first time we get here). if (oldDetector > 0) { // Got a new strip. - AliDebug(10, Form("Add a new strip: FMD%d%c[%2d,%3d] " + AliFMDDebug(10, ("Add a new strip: FMD%d%c[%2d,%3d] " "(current: FMD%d%c[%2d,%3d])", oldDetector, input.PrevRing(), input.PrevSector() , input.PrevStrip(), @@ -219,7 +320,7 @@ AliFMDRawReader::Exec(Option_t*) } if (!next) { - AliDebug(10, Form("Read %d channels for FMD%d", + AliFMDDebug(10, ("Read %d channels for FMD%d", count + 1, detector)); break; } @@ -228,15 +329,15 @@ AliFMDRawReader::Exec(Option_t*) // If we got a new DDL, it means we have a new detector. if (ddl != oldDDL) { if (detector != 0) - AliDebug(10, Form("Read %d channels for FMD%d", count + 1, detector)); + AliFMDDebug(10, ("Read %d channels for FMD%d", count + 1, detector)); // Reset counts, and update the DDL cache count = 0; oldDDL = ddl; // Check that we're processing a FMD detector Int_t detId = fReader->GetDetectorID(); - if (detId != (AliFMDParameters::kBaseDDL >> 8)) { + if (detId != (AliDAQ::DetectorID("FMD"))) { AliError(Form("Detector ID %d != %d", - detId, (AliFMDParameters::kBaseDDL >> 8))); + detId, (AliDAQ::DetectorID("FMD")))); break; } // Figure out what detector we're deling with @@ -249,7 +350,7 @@ AliFMDRawReader::Exec(Option_t*) AliError(Form("Unknown DDL 0x%x for FMD", ddl)); return; } - AliDebug(10, Form("Reading ADCs for 0x%x - That is FMD%d", + AliFMDDebug(10, ("Reading ADCs for 0x%x - That is FMD%d", fReader->GetEquipmentId(), detector)); } counts.Reset(-1); @@ -257,7 +358,7 @@ AliFMDRawReader::Exec(Option_t*) counts[input.Sample()] = input.Count(); - AliDebug(10, Form("ADC of FMD%d%c[%2d,%3d] += %d", + AliFMDDebug(10, ("ADC of FMD%d%c[%2d,%3d] += %d", detector, input.Ring(), input.Sector(), input.Strip(), input.Count())); oldDetector = detector;