42 #include <AliAltroBufferV3.h> 52 #include <TClonesArray.h> 65 : TTask(
"FMDRawWriter",
"Writer of Raw ADC values from the FMD"),
138 TTree* digitTree = loader->
TreeD();
154 Int_t nEvents = Int_t(digitTree->GetEntries());
155 AliFMDDebug(5, (
"Got a total of %5d events from tree", nEvents));
156 for (Int_t event = 0;
event < nEvents;
event++) {
158 digitTree->GetEvent(event);
173 Int_t nDigits = digits->GetEntries();
174 if (nDigits < 1)
return 0;
175 AliFMDDebug(5, (
"Got a total of %5d digits from tree", nDigits));
178 UShort_t threshold = 0;
180 UInt_t prevddl = 0xFFFF;
181 UInt_t prevaddr = 0xFFF;
186 UShort_t preSamples = 0;
187 UShort_t sampleRate = 0;
196 AliAltroBufferV3* altro = 0;
198 Int_t totalWords = 0;
206 UShort_t oldDet = 1000;
207 for (Int_t i = 0; i < nDigits; i++) {
211 Char_t ring = digit->
Ring();
212 UShort_t sector = digit->
Sector();
213 UShort_t strip = digit->
Strip();
214 UShort_t ddl, addr, time;
216 AliFMDDebug(15, (
"Processing digit # %5d FMD%d%c[%2d,%3d]",
217 i, det, ring, sector, strip));
224 AliFMDDebug(5, (
"Got new detector: %d (was %d)", det, oldDet));
227 AliFMDDebug(15, (
"Sample rate is %d", sampleRate));
229 for (UShort_t j = 0; j < sampleRate; j++) {
231 AliError(Form(
"Failed to get hardware address for FMD%d%c[%2d,%3d]-%d",
232 det, ring, sector, strip, j));
236 AliFMDDebug(10, (
"FMD%d%c[%2d,%3d]-%d-> 0x%x/0x%x/%04d",
237 det, ring, sector, strip, j, ddl, addr, time));
238 if (addr != prevaddr) {
240 AliFMDDebug(5, (
"Now hardware address 0x%x from FMD%d%c[%2d,%3d]-%d" 241 "(b: 0x%02x, a: 0x%01x, c: 0x%02x, t: %04d), " 242 "flushing old channel at 0x%x with %d words",
243 addr, det, ring, sector, strip, j,
244 (addr >> 7), (addr >> 4) & 0x7, addr & 0xf,
245 time, prevaddr, nWords));
246 totalWords += nWords;
247 ZeroSuppress(data.fArray, nWords, peds.fArray, noise.fArray, threshold);
249 altro->WriteChannel(prevaddr,nWords,data.fArray,threshold);
256 if (ddl != prevddl) {
257 AliFMDDebug(10, (
"FMD: New DDL, was %d, now %d", prevddl, ddl));
272 AliFMDDebug(5, (
"New altro buffer with DDL file %s", filename.Data()));
275 altro =
new AliAltroBufferV3(filename.Data());
280 altro->WriteDataHeader(kTRUE, kFALSE);
284 peds[time] = pars->
GetPedestal(det, ring, sector, strip);
288 AliFMDDebug(15, (
"Storing FMD%d%c[%02d,%03d]-%d in timebin %d (%d)",
289 det, ring, sector, strip, j, time, preSamples));
290 data[time] = digit->
Count(j);
293 if (time == preSamples) {
294 AliFMDDebug(15, (
"Filling in %4d for %d presamples",
295 data[time], preSamples));
296 for (
int k = 0; k < preSamples; k++) {
297 peds[k] = peds[time];
298 noise[k] = noise[time];
299 data[k] = data[time];
301 nWords += preSamples;
308 ZeroSuppress(data.fArray, nWords, peds.fArray, noise.fArray, threshold);
310 altro->WriteChannel(prevaddr,nWords,data.fArray,threshold);
314 AliFMDDebug(5, (
"Wrote a total of %d words in %ld bytes for %d counts",
315 nWords, nBits / 8, nCounts));
328 altro->WriteDataHeader(kFALSE, kFALSE);
332 altro->SetZeroSupp(zs);
337 altro->SetNNonZSPostsamples(factor);
340 altro->SetNPretriggerSamples(rate);
342 altro->SetActiveFECsA((ddl == 0 ? 0x1 : 0x3));
343 altro->SetActiveFECsB((ddl == 0 ? 0x1 : 0x3));
346 altro->SetNSamplesPerCh(rate * 128);
347 AliDebug(5,Form(
"Writing RCU trailer @ DDL %d w/zs=%d, factor=%d, rate=%d",
348 ddl, zs > 0, factor, rate));
349 altro->WriteRCUTrailer(ddl);
356 const Float_t* noise, UShort_t threshold)
const 364 if (threshold <= 0)
return;
375 TArrayC mask(nWords+1);
376 for (Short_t i = 0; i < nWords; i++) {
377 Float_t val = data[i] - peds[i] - factor * noise[i];
378 if (val < 0.5) val = 0;
379 if (pedSubtract) data[i] = Int_t(val) & 0x3FF;
381 mask[i] = (val > threshold ? 1 : 0);
382 AliFMDDebug(10, (
"Comparing sample %d %d-%f-%f*%f=%f to %d -> %s",
383 i, data[i], peds[i], factor, noise[i], val, threshold,
384 (mask[i] ?
"above" :
"below")));
387 for (Short_t i = 0; i < nWords; i++) {
390 if (i < nWords-1 && !mask[i+1]) {
393 AliFMDDebug(10, (
"At sample %d, next is below, skipping %d to %d",
400 Short_t lookahead = TMath::Min(Short_t(nWords), Short_t(i+pre));
401 AliFMDDebug(10, (
"Sample %d, below, look to %d", i, lookahead));
402 if (mask[lookahead] && pre > 0) {
403 AliFMDDebug(10, (
"Sample %d is a pre-sample to %d", i, lookahead));
411 data[i] = threshold - 1;
423 Int_t nDigits = digits->GetEntries();
424 if (nDigits < 1)
return;
427 AliFMDAltroWriter* writer = 0;
428 Int_t sampleRate = -1;
431 std::ofstream* file = 0;
433 for (Int_t i = 0; i < nDigits; i++) {
436 UInt_t thisDDL, thisHwaddr;
438 Char_t ring = digit->
Ring();
439 UShort_t sector = digit->
Sector();
440 UShort_t strip = digit->
Strip();
442 AliError(Form(
"Failed to get hardware address for FMD%d%c[%2d,%3d]",
443 det, ring, sector, strip));
446 AliFMDDebug(40, (
"Got DDL=%d and address=%d from FMD%d%c[%2d,%3d]",
447 thisDDL, thisHwaddr, det, ring, sector, strip));
449 if (thisHwaddr != hwaddr) {
450 AliFMDDebug(30, (
"Now hardware address 0x%x from FMD%d%c[%2d,%3d] " 451 "(board 0x%x, chip 0x%x, channel 0x%x)",
452 thisHwaddr, det, ring, sector, strip,
453 (thisHwaddr >> 7), (thisHwaddr >> 4) & 0x7,
455 if (writer) writer->AddChannelTrailer(hwaddr);
459 if (ddl != thisDDL) {
461 AliFMDDebug(1, (
"Closing altro writer %p", writer));
462 if ((ret = writer->Close()) < 0) {
463 AliError(Form(
"Error: %s", writer->ErrorString(ret)));
477 AliFMDDebug(1, (
"Opening new ALTRO writer w/file %s",
480 if (!file || !*file) {
481 AliFatal(Form(
"Failed to open file %s",
485 writer =
new AliFMDAltroWriter(*file);
490 writer->AddSignal(digit->
Count1());
491 if (sampleRate >= 2) writer->AddSignal(digit->
Count2());
492 if (sampleRate >= 3) writer->AddSignal(digit->
Count3());
495 writer->AddChannelTrailer(hwaddr);
static const char * DdlFileName(const char *detectorName, Int_t ddlIndex)
UShort_t GetZeroSuppression(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
TClonesArray * Digits() const
AliFMDRawWriter(AliFMD *fmd)
void ZeroSuppress(Int_t *&data, Int_t nWords, const Float_t *peds, const Float_t *noise, UShort_t threshold) const
Class to write ALTRO formated raw data from an array of AliFMDDigit objects.
This class is a singleton that handles various parameters of the FMD detectors. This class reads from...
Manager of FMD parameters.
AliFMDAltroMapping * GetAltroMap() const
Forward Multiplicity Detector based on Silicon wafers. This class is the driver for especially simula...
UShort_t GetZSPostSamples() const
Map HW address to detector coordinates and back again.
void UnloadDigits() const
Declaration of AliFMD detector driver.
virtual void SetTreeAddress()
#define AliFMDDebug(N, A)
virtual Long_t WriteDigits(TClonesArray *digits)
static AliFMDParameters * Instance()
#define AliFatal(message)
virtual void Exec(Option_t *option="")
#define AliDebug(logLevel, message)
UShort_t GetPreSamples(UShort_t, Char_t, UShort_t, UShort_t) const
AliLoader * GetLoader() const
Bool_t Detector2Hardware(UShort_t det, Char_t ring, UShort_t sec, UShort_t str, UShort_t sam, UShort_t &ddl, UShort_t &board, UShort_t &altro, UShort_t &channel, UShort_t &timebin) const
UShort_t Detector() const
void WriteRCUTrailer(AliAltroBufferV3 *altro, UInt_t ddl, Bool_t zs, UShort_t factor, UShort_t rate) const
#define AliError(message)
Float_t GetPedestalFactor() const
UShort_t GetZSPreSamples() const
Int_t LoadDigits(Option_t *opt="")
virtual void ResetDigits()
Int_t Count(UShort_t i=0) const
Float_t GetPedestal(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Float_t GetPedestalWidth(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
UShort_t GetChannelsPerAltro() const
UShort_t GetSampleRate(UShort_t detector, Char_t ring, UShort_t sector, UShort_t strip) const
Bool_t IsZSPedSubtract() const