+ //
+ // Write digits to file
+ //
+ Int_t nDigits = digits->GetEntries();
+ if (nDigits < 1) return;
+
+ AliFMDParameters* pars = AliFMDParameters::Instance();
+ AliFMDAltroWriter* writer = 0;
+ Int_t sampleRate = -1;
+ UShort_t hwaddr = 0;
+ UShort_t ddl = 0;
+ std::ofstream* file = 0;
+ Int_t ret = 0;
+ for (Int_t i = 0; i < nDigits; i++) {
+ // Get the digit
+ AliFMDDigit* digit = static_cast<AliFMDDigit*>(digits->At(i));
+ UInt_t thisDDL, thisHwaddr;
+ UShort_t det = digit->Detector();
+ Char_t ring = digit->Ring();
+ UShort_t sector = digit->Sector();
+ UShort_t strip = digit->Strip();
+ if (!pars->Detector2Hardware(det,ring,sector,strip,thisDDL,thisHwaddr)) {
+ AliError(Form("Failed to get hardware address for FMD%d%c[%2d,%3d]",
+ det, ring, sector, strip));
+ continue;
+ }
+ AliFMDDebug(40, ("Got DDL=%d and address=%d from FMD%d%c[%2d,%3d]",
+ thisDDL, thisHwaddr, det, ring, sector, strip));
+ // Check if we're still in the same channel
+ if (thisHwaddr != hwaddr) {
+ AliFMDDebug(30, ("Now hardware address 0x%x from FMD%d%c[%2d,%3d] "
+ "(board 0x%x, chip 0x%x, channel 0x%x)",
+ thisHwaddr, det, ring, sector, strip,
+ (thisHwaddr >> 7), (thisHwaddr >> 4) & 0x7,
+ thisHwaddr & 0xf));
+ if (writer) writer->AddChannelTrailer(hwaddr);
+ hwaddr = thisHwaddr;
+ }
+ // Check if we're still in the same detector (DDL)
+ if (ddl != thisDDL) {
+ if (writer) {
+ AliFMDDebug(1, ("Closing altro writer %p", writer));
+ if ((ret = writer->Close()) < 0) {
+ AliError(Form("Error: %s", writer->ErrorString(ret)));
+ return;
+ }
+ delete writer;
+ writer = 0;
+ file->close();
+ delete file;
+ file = 0;
+ }
+ ddl = thisDDL;
+ }
+ // If we haven't got a writer (either because none were made so
+ // far, or because we've switch DDL), make one.
+ if (!writer) {
+ AliFMDDebug(1, ("Opening new ALTRO writer w/file %s",
+ AliDAQ::DdlFileName("FMD",ddl)));
+ file = new std::ofstream(AliDAQ::DdlFileName("FMD",ddl));
+ if (!file || !*file) {
+ AliFatal(Form("Failed to open file %s",
+ AliDAQ::DdlFileName("FMD",ddl)));
+ return;
+ }
+ writer = new AliFMDAltroWriter(*file);
+ writer->SetThreshold(pars->GetZeroSuppression(det, ring, sector, strip));
+ }
+ // Write out our signal
+ sampleRate = pars->GetSampleRate(det,ring,sector,strip);
+ writer->AddSignal(digit->Count1());
+ if (sampleRate >= 2) writer->AddSignal(digit->Count2());
+ if (sampleRate >= 3) writer->AddSignal(digit->Count3());
+ }
+ if (writer) {
+ writer->AddChannelTrailer(hwaddr);
+ writer->Close();
+ delete writer;
+ file->close();
+ delete file;
+ }