LCOV - code coverage report
Current view: top level - FMD/FMDrec - AliFMDRawReader.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 150 485 30.9 %
Date: 2016-06-14 17:26:59 Functions: 8 18 44.4 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : /* $Id$ */
      16             : /** @file    AliFMDRawReader.cxx
      17             :     @author  Christian Holm Christensen <cholm@nbi.dk>
      18             :     @date    Mon Mar 27 12:45:23 2006
      19             :     @brief   Class to read raw data 
      20             :     @ingroup FMD_rec
      21             : */
      22             : //____________________________________________________________________
      23             : //
      24             : // Class to read ADC values from a AliRawReader object. 
      25             : //
      26             : // This class uses the AliFMDRawStreamer class to read the ALTRO
      27             : // formatted data. 
      28             : // 
      29             : //          +-------+
      30             : //          | TTask |
      31             : //          +-------+
      32             : //              ^
      33             : //              |
      34             : //      +-----------------+  <<references>>  +--------------+
      35             : //      | AliFMDRawReader |<>----------------| AliRawReader |
      36             : //      +-----------------+                  +--------------+
      37             : //              |                                  ^
      38             : //              | <<uses>>                         |
      39             : //              V                                  |
      40             : //      +-----------------+      <<uses>>          |
      41             : //      | AliFMDRawStream |------------------------+
      42             : //      +-----------------+
      43             : //              |
      44             : //              V
      45             : //      +----------------+
      46             : //      | AliAltroStream |
      47             : //      +----------------+
      48             : //
      49             : // #include <AliLog.h>            // ALILOG_H
      50             : #include "AliFMDDebug.h" // Better debug macros
      51             : #include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
      52             : #include "AliFMDDigit.h"      // ALIFMDDIGIT_H
      53             : #include "AliFMDSDigit.h"     // ALIFMDSDIGIT_H
      54             : // #include "AliFMDRawStream.h"       // ALIFMDRAWSTREAM_H 
      55             : #include "AliRawReader.h"     // ALIRAWREADER_H 
      56             : #include "AliFMDRawReader.h"  // ALIFMDRAWREADER_H 
      57             : #include "AliFMDDebug.h"
      58             : #include "AliFMDCalibSampleRate.h"
      59             : #include "AliFMDCalibStripRange.h"
      60             : #include "AliFMDAltroMapping.h"
      61             : #include "AliFMDUShortMap.h"
      62             : // #include "AliFMDAltroIO.h" // ALIFMDALTROIO_H 
      63             : #include "AliAltroRawStreamV3.h"
      64             : #include <TArrayS.h>              // ROOT_TArrayS
      65             : #include <TTree.h>                // ROOT_TTree
      66             : #include <TClonesArray.h> // ROOT_TClonesArray
      67             : #include <TString.h>
      68             : #include <iostream>
      69             : #include <climits>
      70             : // #include <iomanip>
      71             : 
      72             : //____________________________________________________________________
      73          12 : ClassImp(AliFMDRawReader)
      74             : #if 0
      75             :   ; // This is here to keep Emacs for indenting the next line
      76             : #endif
      77             : 
      78             : //____________________________________________________________________
      79             : AliFMDRawReader::AliFMDRawReader(AliRawReader* reader, TTree* tree) 
      80           4 :   : TTask("FMDRawReader", "Reader of Raw ADC values from the FMD"),
      81           4 :     fTree(tree),
      82           4 :     fReader(reader), 
      83             :     // fSampleRate(1),
      84           4 :     fData(0),
      85           4 :     fNbytes(0), 
      86           4 :     fMinStrip(0),
      87           4 :     fMaxStrip(127), 
      88           4 :     fPreSamp(14+5),
      89           4 :     fSeen(0), 
      90           4 :     fVerbose(false), 
      91           4 :     fErrors("TObject"),
      92           4 :     fNErrChanLen(0), 
      93           4 :     fNErrAddress(0)
      94          20 : {
      95             :   // Default CTOR
      96          32 :   for (Int_t i = 0; i < 3; i++) { 
      97          12 :     fSampleRate[i]   = 0;
      98          12 :     fZeroSuppress[i] = kFALSE;
      99          12 :     fNoiseFactor[i]  = 1;
     100          12 :     fL1Phase[i]      = 0;
     101          12 :     fNErrors[i]      = 0;
     102             :   }
     103           8 : }
     104             : 
     105             : //____________________________________________________________________
     106             : void
     107             : AliFMDRawReader::Exec(Option_t*) 
     108             : {
     109             :   // Read the data 
     110           0 :   TClonesArray* array = new TClonesArray("AliFMDDigit");
     111           0 :   if (!fTree) {
     112           0 :     AliError("No tree");
     113           0 :     return;
     114             :   }
     115           0 :   fTree->Branch("FMD", &array);
     116             :   
     117             :   
     118           0 :   ReadAdcs(array);
     119           0 :   Int_t nWrite = fTree->Fill();
     120           0 :   AliDebugF(1,"Got a grand total of %d digits, wrote %d bytes to tree", 
     121             :             array->GetEntriesFast(), nWrite);
     122           0 :   delete array;
     123           0 : }
     124             : 
     125             : //____________________________________________________________________
     126             : void
     127             : AliFMDRawReader::AddError(Int_t ddl, Int_t hwaddr)
     128             : {
     129           0 :   Int_t nErr = fErrors.GetEntries();
     130           0 :   TObject* o = new (fErrors[nErr]) TObject;
     131           0 :   o->SetUniqueID((ddl & 0xFF) << 12 | (hwaddr & 0xFFF));
     132           0 : }
     133             : //____________________________________________________________________
     134             : void
     135             : AliFMDRawReader::ReadbackError(const AliAltroRawStreamV3& input,
     136             :                                const char* format, ...)
     137             : {
     138             :   static char buf[512];
     139           0 :   va_list ap;
     140           0 :   va_start(ap, format);
     141           0 :   vsnprintf(buf, 511, format, ap);
     142           0 :   buf[511] = '\0';
     143           0 :   va_end(ap);
     144             : 
     145             :   // { AliWarning(buf); }
     146           0 :   if (AliDebugLevel() > 10) {
     147           0 :     AliLog::Flush();
     148           0 :     AliWarning(buf);
     149           0 :     input.HexDumpChannel();
     150           0 :   }
     151             : 
     152           0 :   Int_t    ddl    = input.GetDDLNumber();
     153           0 :   Int_t    hwaddr = input.GetHWAddress();
     154             :   
     155           0 :   fReader->AddMinorErrorLog(AliAltroRawStreamV3::kAltroPayloadErr,buf);
     156           0 :   AddError(ddl, hwaddr); 
     157           0 :   fNErrors[ddl]++;
     158           0 : }
     159             : 
     160             : //____________________________________________________________________
     161             : Int_t
     162             : AliFMDRawReader::NewDDL(AliAltroRawStreamV3& input, UShort_t& det)
     163             : {
     164             :   // Process a new DDL.  Sets the internal data members fZeroSuppress, 
     165             :   // fSampleRate, and fNoiseFactor based on information in the RCU trailer. 
     166             :   // 
     167             :   // Parameters:
     168             :   //   input Input stream
     169             :   //   det   On return, the detector number
     170             :   // 
     171             :   // Return value:
     172             :   //   negative value in case of problems, the DDL number otherwise
     173             : 
     174             :   // Get the DDL number
     175          24 :   UInt_t ddl = input.GetDDLNumber();
     176          36 :   AliDebugF(2,"DDL number %d", ddl);
     177             : 
     178             :   // Note, previously, the ALTROCFG1 register was interpreted as 
     179             :   // 
     180             :   // Bits    Value    Description
     181             :   //   0- 3      0/1   1st Baseline filter, mode 
     182             :   //   4- 5   Over-1   2nd baseline filter, # of pre-samples
     183             :   //   6- 9   factor   2nd baseline filter, # of post-samples 
     184             :   //  10-          0   2nd baseline filter, enable
     185             :   //  11-12       00   Zero suppression, glitch filter mode
     186             :   //  13-15      001   Zero suppression, # of post samples
     187             :   //  16-17       01   Zero suppression, # of pre  samples
     188             :   //  18         0/1   Zero suppression, enable
     189             :   //
     190             :   // The interpretation used in AliAltroRawStreamerV3 - which
     191             :   // corresponds directly to ALTRO DPCFG register - is 
     192             :   //
     193             :   // Bits    Value  Description
     194             :   //   0- 3    0/1   1st Baseline filter, mode 
     195             :   //   4         0   Polarity (if '1', then "1's inverse")
     196             :   //   5- 6     01   Zero suppression, # of pre samples
     197             :   //   7-10   0001   Zero suppression, # of post samples
     198             :   //  11         0   2nd baseline filter, enable
     199             :   //  12-13     00   Zero suppression, glitch filter mode
     200             :   //  14-16 factor   2nd baseline filter, # of post-samples
     201             :   //  17-18     01   2nd baseline filter, # of pre-samples 
     202             :   //  19       0/1   Zero suppression, enable
     203             :   //
     204             :   // From ALTRO DPCF2 we get 
     205             :   // 
     206             :   //  20-23   rate   Pre-samples 
     207             :   // 
     208             :   //  Writing 'x' for variable values, that means we have the
     209             :   //  following patterns for the 2 cases 
     210             :   //
     211             :   //    bit #  20   16   12    8    4    0
     212             :   //     old    |0x01|0010|00xx|xxxx|xxxx|
     213             :   //     new    |x01x|xx00|0000|1010|xxxx|
     214             :   //
     215             :   //  That means that we can check if bits 10-13 are '1000' or
     216             :   //  '0000', which will tell us if the value was written with the
     217             :   //  new or the old interpretation.    That is, we can check that 
     218             :   //
     219             :   //    if (((altrocfg1 >> 10) & 0x8) == 0x8) { 
     220             :   //      // old interpretation 
     221             :   //    }
     222             :   //    else { 
     223             :   //      // New interpretation 
     224             :   //    }
     225             :   //
     226             :   // That means, that we should never 
     227             :   //
     228             :   //  - change the # of zero suppression post samples 
     229             :   //  - Turn on 2nd baseline correction 
     230             :   //  - Change the zero-suppression glitch filter mode
     231             :   //
     232             :   // This change as introduced in version 1.2 of Rcu++
     233             :   //
     234          12 :   UInt_t cfg1 = input.GetAltroCFG1();
     235          12 :   if (((cfg1 >> 10) & 0x8) == 0x8) {
     236           0 :     UInt_t cfg2 = input.GetAltroCFG2();
     237           0 :     AliDebugF(3,"We have data from older MiniConf 0x%x cfg2=0x%08x", 
     238             :               ((cfg1 >> 10) & 0x8), cfg2);
     239           0 :     fZeroSuppress[ddl] = (cfg1 >>  0) & 0x1;
     240           0 :     fNoiseFactor[ddl]  = (cfg1 >>  6) & 0xF;
     241           0 :     fSampleRate[ddl]   = (cfg2 >> 20) & 0xF;
     242           0 :   }
     243             :   else {
     244          36 :     AliDebugF(3,"We have data from newer MiniConf 0x%x", 
     245             :               ((cfg1 >> 10) & 0x8));
     246          12 :     fZeroSuppress[ddl] = input.GetZeroSupp();
     247             :     // WARNING: We store the noise factor in the 2nd baseline
     248             :     // filters excluded post samples, since we'll never use that
     249             :     // mode. 
     250             :     // fNoiseFactor[ddl]  = input.GetNPostsamples();
     251          12 :     fNoiseFactor[ddl]  = input.GetNNonZSPostsamples();
     252             :     // WARNING: We store the sample rate in the number of pre-trigger
     253             :     // samples, since we'll never use that mode.
     254          12 :     fSampleRate[ddl]     = input.GetNPretriggerSamples();
     255             :     // 
     256             :   }
     257          36 :   AliDebugF(10,"Phase of DDL=%d is %g (%d)", ddl, input.GetL1Phase(),
     258             :             input.GetAltroCFG2() & 0x1F);
     259          12 :   fL1Phase[ddl] = input.GetAltroCFG2() & 0x1F; // input.GetL1Phase();
     260          36 :   AliDebugF(3,"RCU @ DDL %d zero suppression: %s", 
     261             :                    ddl, (fZeroSuppress[ddl] ? "yes" : "no"));
     262          36 :   AliDebugF(3,"RCU @ DDL %d noise factor: %d", ddl,fNoiseFactor[ddl]);    
     263          36 :   AliDebugF(3,"RCU @ DDL %d sample rate: %d", ddl,fSampleRate[ddl]);
     264             :   
     265             :   
     266             :   // Get Errors seen 
     267          12 :   Int_t nChAddrMismatch = input.GetNChAddrMismatch();
     268          12 :   Int_t nChLenMismatch  = input.GetNChLengthMismatch();
     269          12 :   if (nChAddrMismatch != 0) {
     270           0 :     ReadbackError(input, 
     271             :                   "Got %d channels with address mis-matches for 0x%03x",
     272             :                   nChAddrMismatch, ddl);
     273           0 :     fNErrAddress += nChAddrMismatch;
     274           0 :   }
     275          12 :   if (nChLenMismatch != 0) {
     276           0 :     ReadbackError(input, 
     277             :                   "Got %d channels with length mis-matches for 0x%03x",
     278             :                   nChLenMismatch, ddl);
     279           0 :     fNErrChanLen += nChLenMismatch;
     280           0 :   }
     281             : 
     282             :   // Map DDL number to the detector number 
     283          12 :   AliFMDParameters*    pars   = AliFMDParameters::Instance();
     284          12 :   AliFMDAltroMapping*  map    = pars->GetAltroMap();
     285          12 :   if (map->DDL2Detector(ddl) < 0) return -1;
     286          12 :   det = map->DDL2Detector(ddl);
     287             : 
     288          12 :   if (AliLog::GetDebugLevel("FMD", 0) > 5) 
     289           0 :     input.PrintRCUTrailer();
     290          12 :   return ddl;
     291          12 : }
     292             : 
     293             : //____________________________________________________________________
     294             : Int_t
     295             : AliFMDRawReader::NewChannel(const AliAltroRawStreamV3& input,  UShort_t det,
     296             :                             Char_t&  ring, UShort_t& sec, Short_t& strbase)
     297             : {
     298             :   // Processs a new channel.  Sets the internal data members
     299             :   // fMinStrip, fMaxStrip, and fPreSamp. 
     300             :   //
     301             :   // Parameter:
     302             :   //   input   Input stream
     303             :   //   ring    On return, the ring identifier 
     304             :   //   sec     On return, the sector number
     305             :   //   strbase On return, the strip base
     306             :   // 
     307             :   // Return value
     308             :   //   negative value in case of problems, hardware address otherwise
     309             : 
     310             :   // Get the hardware address, and map that to detector coordinates 
     311        3200 :   UShort_t board, chip, channel;
     312        1600 :   Int_t    ddl    = input.GetDDLNumber();
     313        1600 :   Int_t    hwaddr = input.GetHWAddress();
     314        1600 :   if (input.IsChannelBad()) { 
     315           0 :     ReadbackError(input, "Ignoring channel %03d/0x%03x with errors", 
     316             :                   ddl, hwaddr); 
     317           0 :     return 0xFFFF;
     318             :   }
     319             :   
     320        1600 :   AliFMDParameters*    pars   = AliFMDParameters::Instance();
     321        1600 :   AliFMDAltroMapping*  map    = pars->GetAltroMap();
     322             :   // Map to hardware stuff 
     323        1600 :   map->ChannelAddress(hwaddr, board, chip, channel);
     324             :   // Then try to map to detector address
     325        1600 :   if (!map->Channel2StripBase(board, chip, channel, ring, sec, strbase)) {
     326           0 :     AliErrorF("Failed to get detector id from DDL %d, "
     327             :               "hardware address 0x%03x", ddl, hwaddr);
     328           0 :     return -1;
     329             :   }
     330        4800 :   AliDebugF(7,"Board: 0x%02x, Altro: 0x%x, Channel: 0x%x", 
     331             :             board, chip, channel);
     332             : 
     333             :   // Get the 'conditions'
     334        1600 :   fMinStrip = pars->GetMinStrip(det, ring, sec, strbase);
     335        1600 :   fMaxStrip = pars->GetMaxStrip(det, ring, sec, strbase);
     336        1600 :   fPreSamp  = pars->GetPreSamples(det, ring, sec, strbase);
     337        1600 :   if (fSampleRate[ddl] == 0) {
     338           0 :     AliDebugF(7,"Get sample rate for RCU @ DDL %d from OCDB", ddl);
     339           0 :     fSampleRate[ddl] = pars->GetSampleRate(det, ring, sec, strbase);
     340           0 :   }
     341        4800 :   AliDebugF(7,"RCU @ DDL %d sample rate: %d", ddl,fSampleRate[ddl]);
     342             : 
     343        1600 :   return hwaddr;
     344        1600 : }
     345             : 
     346             : //____________________________________________________________________
     347             : Bool_t
     348             : AliFMDRawReader::NewBunch(const AliAltroRawStreamV3& input, 
     349             :                           UShort_t&  start, UShort_t& length)
     350             : {
     351             :   // 
     352             :   // Do some checks on the bunch data 
     353             :   // 
     354        3200 :   Int_t    ddl      = input.GetDDLNumber();
     355        1600 :   Int_t    hwaddr   = input.GetHWAddress();  
     356        1600 :   UShort_t nSamples = input.GetNSamplesPerCh() + fPreSamp;
     357        1600 :   UShort_t tstart   = input.GetStartTimeBin();
     358        1600 :   length            = input.GetBunchLength();
     359             : 
     360        1600 :   if (tstart >= nSamples) {
     361           0 :     ReadbackError(input, 
     362             :                   "Bunch in %03d/0x%03x has an start time greater "
     363             :                   "than number of samples: 0x%x >= 0x%x", 
     364             :                   ddl, hwaddr, tstart, nSamples);
     365           0 :     return false;
     366             :   }
     367        1600 :   if ((int(tstart) - length + 1) < 0) { 
     368           0 :     ReadbackError(input, 
     369             :                   "Bunch in %03d/0x%03x has an invalid length and "
     370             :                   "start time: 0x%x,0x%x (%d-%d+1=%d<0)", 
     371             :                   ddl, hwaddr, length, tstart, tstart, length, 
     372             :                   int(tstart)-length+1);
     373           0 :     return false;
     374             :   }
     375        1600 :   if (tstart >= start) { 
     376           0 :     ReadbackError(input, 
     377             :                   "Bunch in %03d/0x%03x has early start time: "
     378             :                   "0x%x >= 0x%x", ddl, hwaddr, tstart, start);
     379           0 :     return false;
     380             :   }
     381        1600 :   start = tstart;
     382        1600 :   return true;
     383        1600 : }
     384             : 
     385             : //____________________________________________________________________
     386             : Int_t
     387             : AliFMDRawReader::NewSample(const AliAltroRawStreamV3& input, 
     388             :                            Int_t i, UShort_t t, UShort_t sec,
     389             :                            UShort_t  strbase, Short_t&  str, UShort_t& samp)
     390             : {
     391             :   // Process a new timebin
     392             :   // 
     393             :   // Parameters:
     394             :   //   input   Input stream
     395             :   //   i       Index into bunch data
     396             :   //   t       Time
     397             :   //   strbase Base of strip numbers for this channel
     398             :   //   str     On return, the strip number
     399             :   //   samp    On return, the sample number
     400             :   // 
     401             :   // Return value
     402             :   //   negative value in case of problems, ADC value otherwise
     403     1729600 :   if (t < fPreSamp) return -1;
     404             : 
     405      819200 :   Int_t           ddl  = input.GetDDLNumber();
     406      819200 :   Int_t           hwa  = input.GetHWAddress();
     407      819200 :   const UShort_t* data = input.GetSignals();
     408      819200 :   Short_t         adc  = data[i];
     409     2457600 :   AliDebugF(10,"0x%04x/0x%03x/%04d %4d", ddl, hwa, t, adc);
     410             : 
     411      819200 :   AliFMDParameters*    pars   = AliFMDParameters::Instance();
     412      819200 :   AliFMDAltroMapping*  map    = pars->GetAltroMap();
     413             : 
     414      819200 :   samp            = 0;
     415      819200 :   Short_t  stroff = 0;
     416      819200 :   map->Timebin2Strip(sec, t, fPreSamp, fSampleRate[ddl], stroff, samp);
     417      819200 :   str             = strbase + stroff;
     418             :       
     419     2457600 :   AliDebugF(20,"0x%04x/0x%03x/%04d=%4d maps to strip %3d sample %d " 
     420             :             "(pre: %d, min: %d, max: %d, rate: %d)",
     421             :             ddl, hwa, t, adc, str, samp, fPreSamp, 
     422             :             fMinStrip, fMaxStrip, fSampleRate[ddl]);
     423      819200 :   if (str < 0) { 
     424           0 :     AliDebugF(10,"Got presamples at timebin %d", i);
     425           0 :     return -1;
     426             :   }
     427             :           
     428             :   // VA1 Local strip number 
     429      819200 :   Short_t lstrip = (t - fPreSamp) / fSampleRate[ddl] + fMinStrip;
     430             :       
     431     2457600 :   AliDebugF(15,"Checking if strip %d (%d) in range [%d,%d]", 
     432             :             lstrip, str, fMinStrip, fMaxStrip);
     433     1638400 :   if (lstrip < fMinStrip || lstrip > fMaxStrip) {
     434           0 :     AliDebugF(10,"Strip %03d-%d (%d,%d) from t=%d out of range (%3d->%3d)", 
     435             :               str, samp, lstrip, stroff, t, fMinStrip, fMaxStrip);
     436             :     adc = -1;
     437           0 :   }
     438             :   // Possibly do pedestal subtraction of signal 
     439      819200 :   if (adc > 1023) 
     440           0 :     AliWarningF("ADC value out of range: %4d", adc);
     441             :   return adc;
     442     1668800 : }
     443             : 
     444             : //____________________________________________________________________
     445             : Int_t
     446             : AliFMDRawReader::NextSample(UShort_t& det, Char_t&   rng, UShort_t& sec, 
     447             :                             UShort_t& str, UShort_t& sam, UShort_t& rat, 
     448             :                             Short_t&  adc, Bool_t&   zs,  UShort_t& fac)
     449             : {
     450             :   // Scan current event for next signal.   It returns kFALSE when
     451             :   // there's no more data in the event. 
     452             :   // 
     453             :   // Note, that this member function is in principle very fast, but
     454             :   // contains less error checking.  In particular, channels that have
     455             :   // bad bunches cannot be checked here.  Seeing a bad bunch will only
     456             :   // skip the remainder of the channel and not reset the already read
     457             :   // digits.   This is potentially dangerous. 
     458             :   //
     459             :   // Parameters: 
     460             :   //    det         On return, contain the detector number 
     461             :   //    rng         On return, contain the ring identifier 
     462             :   //    sec         On return, contain the sector number 
     463             :   //    str         On return, contain the strip number 
     464             :   //    sam         On return, contain the sample number 
     465             :   //    rat         On return, contain the sample rate 
     466             :   //    adc         On return, contain the ADC counts 
     467             :   //    zs          On return, contain the zero-supp. flag 
     468             :   //    fac         On return, contain the zero-supp. noise factor 
     469             :   // 
     470             :   // Return values: 
     471             :   //    0    No more data 
     472             :   //    -1   Read sample belongs to a bad bunch 
     473             :   //    >0   Good status - contains bit mask of values 
     474             :   //       Bit 1    New DDL
     475             :   //       Bit 2    New Channel
     476             :   //       Bit 3    New Bunch
     477             :   //       Bit 4    New Sample
     478           0 :   static AliAltroRawStreamV3 stream(fReader); //    = 0;
     479             :   static Int_t               ddl      = -1;
     480             :   static UShort_t            tdet     = 0;
     481             :   static Char_t              trng     = '\0';
     482             :   static UShort_t            tsec     = 0;
     483             :   static Short_t             tstr     = 0;   
     484             :   static Short_t             bstr     = -1;
     485             :   static UShort_t            tsam     = 0;   
     486             :   // static UInt_t           trate    = 0;
     487             :   static Int_t               hwaddr   = -1;
     488             :   static UShort_t            start    = 0;
     489             :   static UShort_t            length   = 0;
     490             :   static Short_t             t        = -1;
     491             :   static Int_t               i        = 0; 
     492             :   // First entry!
     493           0 :   if (stream.GetDDLNumber() < 0) { 
     494           0 :     fReader->Reset();
     495           0 :     fReader->Select("FMD");
     496           0 :     stream.Reset();
     497           0 :     stream.SelectRawData("FMD");
     498           0 :     stream.SetCheckAltroPayload(false);
     499           0 :     for (Int_t j = 0; j < kNDDL; j++) fNErrors[j] = 0;
     500             : 
     501             :     // Reset variables
     502           0 :     ddl    = -1;  
     503             :     // trate= 0;   
     504           0 :     tdet   = 0;   
     505           0 :     trng   = '\0';
     506           0 :     tsec   = 0;   
     507           0 :     tstr   = 0;  
     508           0 :     tsam   = -1;
     509           0 :     hwaddr = -1;
     510           0 :   }
     511             : 
     512             :   UShort_t ret = 0;
     513           0 :   do { 
     514           0 :     AliDebugF(15, "t=%4d, start=%4d, length=%4d", t, start, length);
     515           0 :     if (t < start - length + 1) { 
     516           0 :       AliDebugF(10,"Time t=%d < start-length+1=%d-%d+1 (%3d/0x%03x)", 
     517             :                 t, start, length, ddl, hwaddr);
     518           0 :       if (hwaddr > 0xFFF || 
     519           0 :           hwaddr < 0 || 
     520           0 :           !stream.NextBunch()) { 
     521           0 :         if (AliDebugLevel() >= 10 && hwaddr > 0xFFF) {
     522           0 :           AliDebug(10,"Last channel read was marked bad");
     523             :         }
     524           0 :         if (AliDebugLevel() >= 10 && hwaddr < 0) {
     525           0 :           AliDebug(10,"No more channels");
     526             :         }
     527           0 :         AliDebug(10,"No next bunch, or first entry");
     528           0 :         if (ddl < 0 || !stream.NextChannel()) { 
     529           0 :           if (AliDebugLevel() >= 10 && ddl < 0) { 
     530           0 :             AliDebug(10,"No DDL");
     531             :           }
     532           0 :           AliDebug(10,"No next channel, or first entry");
     533           0 :           if (!stream.NextDDL()) {
     534           0 :             AliDebug(10,"No more DDLs");
     535           0 :             stream.Reset();
     536           0 :             return 0;
     537             :           }
     538           0 :           ddl = NewDDL(stream, tdet);
     539           0 :           AliDebugF(5,"New DDL: %d (%d)", ddl, tdet);
     540           0 :           ret |= 0x1;
     541           0 :           continue;
     542             :         }
     543           0 :         hwaddr = NewChannel(stream, tdet, trng, tsec, bstr);
     544           0 :         if (hwaddr > 0xFFF) fNErrors[ddl] += 1;
     545           0 :         AliDebugF(5,"New Channel: %3d/0x%03x", ddl, hwaddr);
     546           0 :         start  = 1024;
     547           0 :         ret |= 0x2;
     548           0 :         continue;
     549             :       }
     550           0 :       if (!NewBunch(stream, start, length)) { 
     551             :         // AliWarning(Form("Bad bunch in %3d/0x%03x read - "
     552             :         //                 "should progress to next channel "
     553             :         //                 "(t=%4d,start=%4d,length=%4d)", 
     554             :         //                 ddl, hwaddr, t,start, length));
     555           0 :         hwaddr = 0xFFFF; // Bad channel
     556           0 :         return -1;
     557             :       }
     558           0 :       AliDebugF(5, "New bunch in  %3d/0x%03x: start=0x%03x, length=%4d", 
     559             :                 ddl, hwaddr, start, length);
     560           0 :       ret |= 0x4;
     561           0 :       t      = start;
     562           0 :       i      = 0;
     563           0 :       AliDebugF(10,"Got new bunch FMD%d%c[%2d], bunch @ %d, length=%d", 
     564             :                 tdet, trng, tsec, start, length);
     565             :     }
     566           0 :     Int_t tadc = NewSample(stream, i, t, tsec, bstr, tstr, tsam);
     567           0 :     AliDebugF(10,"New sample FMD%d%c[%2d,%3d]-%d = 0x%03x", 
     568             :               tdet, trng, tsec, tstr, tsam, tadc);
     569           0 :     ret |= 0x8;
     570           0 :     if (tadc >= 0) { 
     571           0 :       det = tdet;
     572           0 :       rng = trng;
     573           0 :       sec = tsec;
     574           0 :       str = tstr;
     575           0 :       sam = tsam;
     576           0 :       adc = tadc;
     577           0 :       rat = fSampleRate[ddl];
     578           0 :       zs  = fZeroSuppress[ddl];
     579           0 :       fac = fNoiseFactor[ddl];
     580           0 :       t--;
     581           0 :       i++;
     582           0 :       AliDebugF(10,"Returning FMD%d%c[%2d,%3d]-%d = 0x%03x (%d,%d,%d)",
     583             :                 det, rng, sec, str, sam, adc, rat, zs, fac);
     584           0 :       break;
     585             :     }
     586           0 :     t--;
     587           0 :     i++;
     588           0 :   } while (true);
     589           0 :   AliDebugF(5,"Returning 0x%02x", ret);
     590           0 :   return ret;
     591           0 : }
     592             : 
     593             : 
     594             : //____________________________________________________________________
     595             : Int_t
     596             : AliFMDRawReader::NextSignal(UShort_t& det, Char_t&   rng, 
     597             :                             UShort_t& sec, UShort_t& str, 
     598             :                             Short_t&  adc, Bool_t&   zs, 
     599             :                             UShort_t& fac)
     600             : {
     601             :   // 
     602             :   // Get the next signal
     603             :   // 
     604             :   // Parameters:
     605             :   //    det  On return, the detector
     606             :   //    rng  On return, the ring
     607             :   //    sec  On return, the sector
     608             :   //    str  On return, the strip
     609             :   //    adc  On return, the ADC value
     610             :   //    zs   On return, whether zero-supp. is enabled
     611             :   //    fac  On return, the usd noise factor
     612             :   // 
     613             :   // Return:
     614             :   //    true if valid data is returned
     615             :   //
     616             :   Int_t ret = 0;
     617           0 :   do { 
     618           0 :     UShort_t samp, rate;
     619           0 :     if ((ret = NextSample(det, rng, sec, str, samp, rate, adc, zs, fac)) <= 0)
     620           0 :       return ret;
     621             : 
     622           0 :     Bool_t take = SelectSample(samp, rate);
     623           0 :     if (!take) continue;
     624           0 :     break;
     625           0 :   } while (true);
     626           0 :   return ret;
     627           0 : }
     628             : 
     629             : //____________________________________________________________________
     630             : Bool_t
     631             : AliFMDRawReader::SelectSample(UShort_t samp, UShort_t rate) 
     632             : {
     633             :   // Check if the passed sample is the one we need
     634             :   Bool_t take = kFALSE;
     635           0 :   switch (rate) { 
     636           0 :   case 1:                      take = kTRUE; break;
     637           0 :   case 2:  if (samp == 1)      take = kTRUE; break;
     638           0 :   case 3:  if (samp == 1)      take = kTRUE; break; 
     639           0 :   case 4:  if (samp == 2)      take = kTRUE; break;
     640           0 :   default: if (samp == rate-2) take = kTRUE; break;
     641             :   }
     642             :   
     643           0 :   return take;
     644             : }
     645             :   
     646             : //____________________________________________________________________
     647             : Bool_t
     648             : AliFMDRawReader::ReadAdcs(TClonesArray* array) 
     649             : {
     650             :   // Read ADC values from raw input into passed TClonesArray of AliFMDDigit
     651             :   // objects. 
     652          16 :   AliDebug(3,"Reading ADC values into a TClonesArray");
     653             : 
     654             :   // Read raw data into the digits array, using AliFMDAltroReader. 
     655           4 :   if (!array) {
     656           0 :     AliError("No TClonesArray passed");
     657           0 :     return kFALSE;
     658             :   }
     659             :   // static ULong_t unique = 0;
     660           4 :   const UShort_t kUShortMax = (1 << 16) - 1;
     661           4 :   fSeen.Reset(kUShortMax);
     662           4 :   fErrors.Clear();
     663           4 :   fNErrChanLen = 0;
     664           4 :   fNErrAddress = 0;
     665          32 :   for (Int_t ddl = 0; ddl < kNDDL; ddl++) fNErrors[ddl] = 0;
     666             : 
     667           4 :   AliAltroRawStreamV3  input(fReader);
     668           4 :   input.Reset();
     669           4 :   input.SetCheckAltroPayload(false);
     670           4 :   input.SelectRawData("FMD");
     671             :   
     672             :   // Loop over input RORCs
     673          32 :   while (input.NextDDL()) { 
     674          12 :     UShort_t det = 0;
     675          12 :     Int_t    ddl = NewDDL(input, det);
     676          12 :     if (ddl < 0) break;
     677          12 :     fNErrors[ddl] = 0;
     678             : 
     679        3236 :     while (input.NextChannel()) { 
     680             :       // Get the hardware address, and map that to detector coordinates 
     681        1600 :       Char_t   ring;
     682        1600 :       UShort_t sec;
     683        1600 :       Short_t  strbase;
     684        1600 :       Int_t    hwaddr   = NewChannel(input, det, ring, sec, strbase);
     685        1600 :       if (hwaddr < 0) break;
     686        1600 :       if (hwaddr > 0xFFF) continue;  
     687             : 
     688        1600 :       UShort_t start    = 0x3FF;
     689             :       Bool_t   errors   = false;
     690             :       Int_t    first    = -1;
     691             :       Int_t    last     = -1;
     692             :       // Loop over bunches 
     693        8000 :       while (input.NextBunch()) { 
     694             :         // Get Lenght of bunch, and pointer to the data 
     695        1600 :         const UShort_t* data   = input.GetSignals();
     696        1600 :         UShort_t        length;
     697        3200 :         if (!NewBunch(input, start, length)) {
     698             :           errors = true;
     699           0 :           break;
     700             :         }
     701             : 
     702             :       
     703             :         // Loop over the data and store it. 
     704     1702400 :         for (Int_t i = 0; i < length; i++) { 
     705             :           // Time 
     706      849600 :           Short_t  str;
     707      849600 :           UShort_t samp;
     708      849600 :           Int_t    t    = start - i;
     709      849600 :           Int_t    adc  = NewSample(input, i, t, sec, strbase, str, samp);
     710      880000 :           if (adc <= 0) continue;
     711      819200 :           UShort_t counts = adc;
     712             :       
     713     4096000 :           AliDebugF(10,"FMD%d%c[%02d,%03d]-%d: %4d", 
     714             :                     det, ring, sec, str, samp, counts);
     715             :           // Check the cache of indicies
     716     1638400 :           Int_t idx = fSeen(det, ring, sec, str);
     717             :           AliFMDDigit* digit = 0;
     718     1638400 :           if (idx == kUShortMax) { 
     719             :             // We haven't seen this strip yet. 
     720     1433600 :             fSeen(det, ring, sec, str) = idx = array->GetEntriesFast();
     721     1024000 :             AliDebugF(7, "making digit @ %5d for FMD%d%c[%2d,%3d]-%d "
     722             :                       "from %3d/0x%03x/%4d (def: %d)", 
     723             :                       idx, det, ring, sec, str, samp, ddl, hwaddr, t,
     724             :                       fSampleRate[ddl]);
     725      614400 :             digit = new ((*array)[idx]) AliFMDDigit(det, ring, sec, str);
     726      204800 :             digit->SetDefaultCounts(fSampleRate[ddl]);
     727      204800 :           }
     728             :           else {
     729     1228800 :             digit = static_cast<AliFMDDigit*>(array->At(idx));
     730             :           }
     731      820800 :           if (first < 0) first = idx;
     732             :           last = idx;
     733     4096000 :           AliDebugF(5,"Setting FMD%d%c[%2d,%3d]-%d from timebin "
     734             :                     "%4d=%4d (%4d)", det, ring, sec, str, samp, t, 
     735             :                     counts, data[i]);
     736      819200 :           digit->SetCount(samp, counts);
     737     1638400 :           if (AliLog::GetDebugLevel("FMD","") >= 5) digit->Print();
     738     1668800 :         } // for (i)
     739        3200 :       } // while (bunch)
     740        1600 :       if (errors) { 
     741           0 :         AliDebugF(2,"Channel %3d/0x%03x contain errors, "
     742             :                   "resetting index %d to %d", ddl, hwaddr, first, last);
     743           0 :         if (first >= 0) {
     744           0 :           for (Int_t i = first; i <= last; i++) { 
     745           0 :             AliFMDDigit* digit = static_cast<AliFMDDigit*>(array->At(i));
     746           0 :             for (Int_t j = 0; j < fSampleRate[ddl]; j++) {
     747           0 :               AliDebugF(10,"Resetting strip %s=%d",
     748             :                         digit->GetName(),digit->Counts());
     749           0 :               digit->SetCount(j, kBadSignal);
     750             :             }
     751             :           }
     752           0 :         }
     753             :       }
     754             :       // if (errors && (AliDebugLevel() > 0)) input.HexDumpChannel();
     755        3200 :     } // while (channel)
     756          24 :   } // while (ddl)
     757          16 :   if (fNErrors[0] > 0 || fNErrors[1] > 0 || fNErrors[2] > 0 || 
     758           8 :       fNErrChanLen > 0 || fNErrAddress > 0) {
     759             :     // AliLog::Flush();
     760           0 :     AliLog::SetPrintRepetitions(false);
     761           0 :     AliWarningF("R/O errors: FMD1=%d, FMD2=%d, FMD3=%d, "
     762             :                 "Channel Length=%d, address=%d", 
     763             :                 fNErrors[0], fNErrors[1], fNErrors[2], 
     764             :                 fNErrChanLen, fNErrAddress);
     765           0 :     AliLog::SetPrintRepetitions(true);
     766             :   }
     767           4 :   if (fVerbose && fErrors.GetEntries() > 0) {
     768           0 :     TString msg;
     769           0 :     Int_t   nErr = fErrors.GetEntries();
     770           0 :     for (Int_t i = 0; i < nErr; i++) {
     771           0 :       UInt_t where = fErrors.At(i)->GetUniqueID();
     772           0 :       if (i % 6 == 0) msg.Append("\n");
     773           0 :       msg.Append(Form("  %3d/0x%03x", (where >> 12) & 0xFF, (where & 0xFFF)));
     774             :     }
     775             :     // AliLog::Flush();
     776           0 :     AliLog::SetPrintRepetitions(false);
     777           0 :     AliWarningF("Got %d errors in channels %s", nErr, msg.Data());
     778           0 :     AliLog::SetPrintRepetitions(true);
     779           0 :   }
     780             :   return kTRUE;
     781           8 : }
     782             : //____________________________________________________________________
     783             : Bool_t
     784             : AliFMDRawReader::ReadAdcs(AliFMDUShortMap& map) 
     785             : {
     786             :   // Read ADC values from raw input into passed TClonesArray of AliFMDDigit
     787             :   // objects. 
     788           0 :   AliDebug(3,"Reading ADC values into a map");
     789             : 
     790             :   // const UShort_t kUShortMax = (1 << 16) - 1;
     791           0 :   for (Int_t ddl = 0; ddl < kNDDL; ddl++) fNErrors[ddl] = 0;
     792             : 
     793           0 :   AliAltroRawStreamV3  input(fReader);
     794           0 :   input.Reset();
     795           0 :   input.SetCheckAltroPayload(false);
     796           0 :   input.SelectRawData("FMD");
     797             :   
     798             :   // Loop over input RORCs
     799           0 :   while (input.NextDDL()) { 
     800           0 :     UShort_t det = 0;
     801           0 :     Int_t    ddl = NewDDL(input, det);
     802           0 :     if (ddl < 0) break;
     803           0 :     fNErrors[ddl] = 0;
     804             : 
     805           0 :     while (input.NextChannel()) { 
     806             :       // Get the hardware address, and map that to detector coordinates 
     807           0 :       Char_t   ring;
     808           0 :       UShort_t sec;
     809           0 :       Short_t  strbase;
     810           0 :       Int_t    hwaddr   = NewChannel(input, det, ring, sec, strbase);
     811           0 :       if (hwaddr < 0) break;
     812           0 :       if (hwaddr > 0xFFF) continue;  
     813             : 
     814           0 :       UShort_t start    = 0x3FF;
     815             :       Bool_t   errors   = false;
     816             :       Int_t    first    = -1;
     817             :       Int_t    last     = -1;
     818             :       // Loop over bunches 
     819           0 :       while (input.NextBunch()) { 
     820             :         // Get Lenght of bunch, and pointer to the data 
     821             :         // const UShort_t* data   = input.GetSignals();
     822           0 :         UShort_t        length;
     823           0 :         if (!NewBunch(input, start, length)) {
     824             :           errors = true;
     825           0 :           break;
     826             :         }
     827             : 
     828             :       
     829             :         // Loop over the data and store it. 
     830           0 :         for (Int_t i = 0; i < length; i++) { 
     831             :           // Time 
     832           0 :           Short_t  str;
     833           0 :           UShort_t samp;
     834           0 :           Int_t    t    = start - i;
     835           0 :           Int_t    adc  = NewSample(input, i, t, sec, strbase, str, samp);
     836           0 :           if (adc < 0) continue;
     837           0 :           UShort_t counts = adc;
     838             :       
     839           0 :           AliDebugF(10, "FMD%d%c[%02d,%03d]-%d: %4d", 
     840             :                     det, ring, sec, str, samp, counts);
     841           0 :           if (SelectSample(samp, fSampleRate[ddl]))
     842           0 :             map(det,ring,sec,str) = counts; 
     843           0 :           if (first < 0) first = str;
     844           0 :           last = str;
     845           0 :         } // for (i)
     846           0 :       } // while (bunch)
     847           0 :       if (errors) { 
     848           0 :         AliDebugF(2, "Channel %3d/0x%03x contain errors, "
     849             :                   "resetting strips %d to %d", ddl, hwaddr, first, last);
     850           0 :         if (first >= 0) {
     851           0 :           Int_t ds = first <= last ? 1 : -1;
     852           0 :           for (Int_t i = first; i != last+ds; i += ds) { 
     853           0 :             AliDebugF(10, "Resetting strip FMD%d%c[%02d,%03d]=%d",
     854             :                       det,ring,sec,i,map(det,ring,sec,i));
     855           0 :             map(det,ring,sec,i) = kBadSignal;
     856             :           }
     857           0 :         }
     858             :       }
     859           0 :     } // while (channel)
     860           0 :   } // while (ddl)
     861             :   return kTRUE;
     862           0 : }
     863             : 
     864             : //____________________________________________________________________
     865             : Bool_t AliFMDRawReader::ReadSODevent(AliFMDCalibSampleRate* sampleRate, 
     866             :                                      AliFMDCalibStripRange* stripRange, 
     867             :                                      TArrayS &pulseSize, 
     868             :                                      TArrayS &pulseLength, 
     869             :                                      Bool_t* detectors) 
     870             : {
     871             :   // 
     872             :   // Read SOD event into passed objects.
     873             :   // 
     874             :   // Parameters:
     875             :   //    samplerate   The sample rate object to fill
     876             :   //    striprange   The strip range object to fill
     877             :   //    pulseSize    The pulse size object to fill
     878             :   //    pulseLength  The pulse length (in events) object to fill
     879             :   // 
     880             :   // Return:
     881             :   //    @c true on success
     882             :   //  
     883           0 :   AliDebug(0,"Start of SOD/EOD");
     884             :   
     885           0 :   UInt_t shift_clk[18];
     886           0 :   UInt_t sample_clk[18];
     887           0 :   UInt_t strip_low[18];
     888           0 :   UInt_t strip_high[18];
     889           0 :   UInt_t pulse_size[18];
     890           0 :   UInt_t pulse_length[18];  
     891           0 :   for (size_t i = 0; i < 18; i++) { 
     892           0 :     shift_clk[i]    = 0;
     893           0 :     sample_clk[i]   = 0;
     894           0 :     strip_low[i]    = 0;
     895           0 :     strip_high[i]   = 0;
     896           0 :     pulse_size[i]   = 0;
     897           0 :     pulse_length[i] = 0;
     898             :   }
     899           0 :   AliFMDParameters*   param = AliFMDParameters::Instance();
     900           0 :   AliFMDAltroMapping* map   = param->GetAltroMap();
     901             :   
     902           0 :   AliAltroRawStreamV3  streamer(fReader);
     903           0 :   streamer.Reset();
     904           0 :   streamer.SelectRawData("FMD");
     905             :   //fReader->GetDDLID();
     906           0 :   while (streamer.NextDDL()) {
     907           0 :     Int_t ddl   = streamer.GetDDLNumber();
     908           0 :     Int_t detID = fReader->GetDetectorID();
     909           0 :     if (detectors) detectors[map->DDL2Detector(ddl)-1] = kTRUE;
     910           0 :     AliDebugF(0," From reader: DDL number is %d , det ID is %d",ddl,detID);
     911             :     
     912           0 :     ULong_t  nPayloadWords = streamer.GetRCUPayloadSizeInSOD();
     913           0 :     UChar_t* payloadData   = streamer.GetRCUPayloadInSOD();
     914           0 :     UInt_t*  payloadWords  = reinterpret_cast<UInt_t*>(payloadData);
     915             :     //UInt_t*   payloadWords  = streamer.GetRCUPayloadInSOD();
     916             : 
     917             :     //std::cout<<nPayloadWords<<"    "<<ddl<<std::endl;
     918           0 :     for (ULong_t i = 1; i <= nPayloadWords ; i++, payloadWords++) {
     919           0 :       UInt_t payloadWord = *payloadWords; // Get32bitWord(i);
     920             :     
     921             :       //std::cout<<i<<Form("  word: 0x%x",payloadWord)<<std::endl;
     922             :       // address is only 24 bit
     923           0 :       UInt_t address       = (0xffffff & payloadWord);
     924           0 :       UInt_t type          = ((address >> 21) & 0xf);
     925           0 :       UInt_t error         = ((address >> 20) & 0x1);
     926           0 :       UInt_t bcast         = ((address >> 18) & 0x1);
     927           0 :       UInt_t bc_not_altro  = ((address >> 17) & 0x1);
     928           0 :       UInt_t board         = ((address >> 12) & 0x1f);
     929             :       UInt_t instruction   = 0;
     930             :       UInt_t chip          = 0;
     931             :       UInt_t channel       = 0;
     932           0 :       if(bc_not_altro)
     933           0 :         instruction        = address & 0xfff;
     934             :       else {
     935           0 :         chip               = ((address >> 9) & 0x7);
     936           0 :         channel            = ((address >> 5) & 0x5);
     937           0 :         instruction        = (address & 0x1f);
     938             :       }
     939             :         
     940             :       Bool_t readDataWord = kFALSE;
     941           0 :       switch(type) {
     942             :       case 0x0: // Fec read
     943           0 :         readDataWord = kTRUE;  
     944             :       case 0x1: // Fec cmd
     945             :       case 0x2: // Fec write
     946           0 :         i++;  
     947           0 :         payloadWords++;
     948           0 :         break;
     949             :       case 0x4: // Loop
     950             :       case 0x5: // Wait
     951             :         break;
     952             :       case 0x6: // End sequence
     953             :       case 0x7: // End Mem
     954           0 :         i = nPayloadWords + 1;
     955           0 :         break;
     956             :       default:    
     957             :         break;
     958             :       }
     959             :         
     960             :       //Don't read unless we have a FEC_RD
     961           0 :       if(!readDataWord)  continue;
     962             : 
     963           0 :       UInt_t dataWord      = *payloadWords;//Get32bitWord(i);
     964           0 :       UInt_t data          = (0xFFFFF & dataWord) ;
     965             :       //UInt_t data          = (0xFFFF & dataWord) ;
     966             :         
     967           0 :       if(error) {
     968           0 :         AliWarningF("error bit detected at Word 0x%06x; "
     969             :                     "error % d, type %d, bc_not_altro %d, "
     970             :                     "bcast %d, board 0x%02x, chip 0x%x, "
     971             :                     "channel 0x%02x, instruction 0x%03x",
     972             :                     address, error, type, bc_not_altro, 
     973             :                     bcast,board,chip,channel,instruction);
     974             :         //process error
     975           0 :         continue;
     976             :       }
     977             :         
     978             :         
     979           0 :       switch(instruction) {
     980             :           
     981             :       case 0x01: break;  // First ADC T           
     982             :       case 0x02: break; // I  3.3 V              
     983             :       case 0x03: break; // I  2.5 V altro digital
     984             :       case 0x04: break; // I  2.5 V altro analog 
     985             :       case 0x05: break; // I  2.5 V VA           
     986             :       case 0x06: break; // First ADC T           
     987             :       case 0x07: break; // I  3.3 V              
     988             :       case 0x08: break; // I  2.5 V altro digital
     989             :       case 0x09: break; // I  2.5 V altro analog 
     990             :       case 0x0A: break; // I  2.5 V VA           
     991             :       case 0x2D: break; // Second ADC T           
     992             :       case 0x2E: break; // I  1.5 V VA            
     993             :       case 0x2F: break; // I -2.0 V               
     994             :       case 0x30: break; // I -2.0 V VA            
     995             :       case 0x31: break; //    2.5 V Digital driver
     996             :       case 0x32: break; // Second ADC T           
     997             :       case 0x33: break; // I  1.5 V VA            
     998             :       case 0x34: break; // I -2.0 V               
     999             :       case 0x35: break; // I -2.0 V VA            
    1000             :       case 0x36: break; //    2.5 V Digital driver
    1001             :       case 0x37: break; // Third ADC T             
    1002             :       case 0x38: break; // Temperature sens. 1     
    1003             :       case 0x39: break; // Temperature sens. 2     
    1004             :       case 0x3A: break; // U  2.5 altro digital (m)
    1005             :       case 0x3B: break; // U  2.5 altro analog (m) 
    1006             :       case 0x3C: break; // Third ADC T             
    1007             :       case 0x3D: break; // Temperature sens. 1     
    1008             :       case 0x3E: break; // Temperature sens. 2     
    1009             :       case 0x3F: break; // U  2.5 altro digital (m)
    1010             :       case 0x40: break; // U  2.5 altro analog (m) 
    1011             :       case 0x41: break; // Forth ADC T  
    1012             :       case 0x42: break; // U  2.5 VA (m)
    1013             :       case 0x43: break; // U  1.5 VA (m)
    1014             :       case 0x44: break; // U -2.0 VA (m)
    1015             :       case 0x45: break; // U -2.0 (m)   
    1016             :       case 0x46: break; // Forth ADC T  
    1017             :       case 0x47: break; // U  2.5 VA (m)
    1018             :       case 0x48: break; // U  1.5 VA (m)
    1019             :       case 0x49: break; // U -2.0 VA (m)
    1020             :       case 0x4A: break;  // U -2.0 (m)   
    1021             :         // Counters 
    1022             :       case 0x0B: break; // L1 trigger CouNTer
    1023             :       case 0x0C: break; // L2 trigger CouNTer
    1024             :       case 0x0D: break; // Sampling CLK CouNTer
    1025             :       case 0x0E: break; // DSTB CouNTer
    1026             :         // Test mode 
    1027             :       case 0x0F: break; // Test mode word
    1028             :       case 0x10: break; // Undersampling ratio.
    1029             :         // Configuration and status 
    1030             :       case 0x11: break; // Config/Status Register 0
    1031             :       case 0x12: break; // Config/Status Register 1
    1032             :       case 0x13: break; // Config/Status Register 2
    1033             :       case 0x14: break; // Config/Status Register 3
    1034             :       case 0x15: break; // Free
    1035             :         // Comands:
    1036             :       case 0x16: break; // Latch L1, L2, SCLK Counters
    1037             :       case 0x17: break; // Clear counters
    1038             :       case 0x18: break; // Clear CSR1
    1039             :       case 0x19: break; // rstb ALTROs
    1040             :       case 0x1A: break; // rstb BC
    1041             :       case 0x1B: break; // Start conversion
    1042             :       case 0x1C: break; // Scan event length
    1043             :       case 0x1D: break; // Read event length
    1044             :       case 0x1E: break; // Start test mode
    1045             :       case 0x1F: break; // Read acquisition memory
    1046             :         // FMD
    1047             :       case 0x20: break; // FMDD status
    1048             :       case 0x21: break; // L0 counters
    1049             :       case 0x22: break; // FMD: Wait to hold
    1050             :       case 0x23: break; // FMD: L1 timeout
    1051             :       case 0x24: break; // FMD: L2 timeout
    1052             :       case 0x25: // FMD: Shift clk 
    1053           0 :         shift_clk[board] = ((data >> 8 ) & 0xFF); 
    1054           0 :         AliDebugF(30, "Read shift_clk=%d for board 0x%02x", 
    1055             :                   shift_clk[board], board);
    1056             :         break; 
    1057             :       case 0x26: // FMD: Strips 
    1058           0 :         strip_low[board]  = ((data >> 0 ) & 0xFF); 
    1059           0 :         strip_high[board] = ((data >> 8 ) & 0xFF);  
    1060           0 :         break; 
    1061             :       case 0x27: // FMD: Cal pulse 
    1062           0 :         pulse_size[board]  =  ((data >> 8 ) & 0xFF);
    1063           0 :         break; 
    1064             :       case 0x28: break; // FMD: Shape bias
    1065             :       case 0x29: break; // FMD: Shape ref
    1066             :       case 0x2A: break; // FMD: Preamp ref
    1067             :       case 0x2B: // FMD: Sample clk 
    1068           0 :         sample_clk[board] = ((data >> 8 ) & 0xFF); 
    1069           0 :         AliDebugF(30,"Read sample_clk=%d for board 0x%02x", 
    1070             :                   sample_clk[board], board);
    1071             :         break; 
    1072             :       case 0x2C: break; // FMD: Commands
    1073             :       case 0x4B: // FMD: Cal events 
    1074           0 :         pulse_length[board] = ((data >> 0 ) & 0xFF);
    1075           0 :         break; 
    1076             :       default: break;
    1077             :         
    1078             :       }
    1079           0 :       AliDebugF(50,"instruction 0x%x, dataword 0x%x",
    1080             :                 instruction,dataWord);
    1081           0 :     } // End of loop over Result memory event
    1082             :     
    1083             :     UShort_t det    = 0;
    1084           0 :     UShort_t sector = 0;
    1085           0 :     Short_t  strip  = -1;
    1086           0 :     Char_t   ring   = '\0';
    1087             :    
    1088             :     const UInt_t boards[4] = {0,1,16,17};
    1089           0 :     for(Int_t i=0;i<4;i++) {
    1090           0 :       if(ddl==0 && (i==1 || i==3)) continue;
    1091             : 
    1092             :       UInt_t chip =0, channel=0;
    1093           0 :       det = map->DDL2Detector(ddl);
    1094           0 :       map->Channel2StripBase(boards[i], chip, channel, ring, sector, strip);
    1095             :      
    1096             :       UInt_t samplerate = 0;
    1097             : #if USE_VOTE
    1098             :       if(sample_clk[boards[i]] == 0) {
    1099             :         if(ddl == 0) {
    1100             :           Int_t sample1 = sample_clk[boards[0]];
    1101             :           Int_t sample2 = sample_clk[boards[2]];            
    1102             :           if(sample1) sample_clk[boards[i]] = sample1;
    1103             :           else sample_clk[boards[i]] = sample2;
    1104             :         }
    1105             :         else {
    1106             :           Int_t sample1 = sample_clk[boards[0]];
    1107             :           Int_t sample2 = sample_clk[boards[1]];
    1108             :           Int_t sample3 = sample_clk[boards[2]];
    1109             :           Int_t sample4 = sample_clk[boards[3]];
    1110             :           Int_t agreement = 0;
    1111             :           if(sample1 == sample2) agreement++;
    1112             :           if(sample1 == sample3) agreement++;
    1113             :           if(sample1 == sample4) agreement++;
    1114             :           if(sample2 == sample3) agreement++;
    1115             :           if(sample2 == sample4) agreement++;
    1116             :           if(sample3 == sample4) agreement++;
    1117             :             
    1118             :           Int_t idx = 0;
    1119             :           if(i<3) idx = i+1;
    1120             :           else  idx = i-1;
    1121             :           if(agreement == 3) {
    1122             :             sample_clk[boards[i]] = sample_clk[boards[idx]];
    1123             :             shift_clk[boards[i]] = shift_clk[boards[idx]];
    1124             :             strip_low[boards[i]] = strip_low[boards[idx]];
    1125             :             strip_high[boards[i]] = strip_high[boards[idx]];
    1126             :             pulse_length[boards[i]] = pulse_length[boards[idx]];
    1127             :             pulse_size[boards[i]] = pulse_size[boards[idx]];
    1128             :             AliDebugF(3,"Vote taken for ddl %d, board 0x%x",
    1129             :                       ddl,boards[i]);
    1130             :           }
    1131             :         }
    1132             :       } 
    1133             : #endif
    1134             :       
    1135           0 :       if(sample_clk[boards[i]])
    1136           0 :         samplerate = shift_clk[boards[i]]/sample_clk[boards[i]];
    1137           0 :       AliDebugF(10,"Sample rate for board 0x%02x is %d", 
    1138             :                 boards[i], samplerate);
    1139           0 :       sampleRate->Set(det,ring,sector,0,samplerate);
    1140           0 :       stripRange->Set(det,ring,sector,0,
    1141           0 :                       strip_low[boards[i]],strip_high[boards[i]]);
    1142             :       
    1143           0 :       AliDebugF(20,"det %d, ring %c, ",det,ring);
    1144           0 :       pulseLength.AddAt(pulse_length[boards[i]],
    1145           0 :                         GetHalfringIndex(det,ring,boards[i]/16));
    1146           0 :       pulseSize.AddAt(pulse_size[boards[i]],
    1147           0 :                       GetHalfringIndex(det,ring,boards[i]/16));
    1148             :       
    1149             :       
    1150             :       
    1151           0 :       AliDebugF(20,": Board: 0x%02x\n"
    1152             :                 "\tstrip_low  %3d, strip_high   %3d\n"
    1153             :                 "\tshift_clk  %3d, sample_clk   %3d\n"
    1154             :                 "\tpulse_size %3d, pulse_length %3d",
    1155             :                 boards[i], 
    1156             :                 strip_low[boards[i]], strip_high[boards[i]],
    1157             :                 shift_clk[boards[i]], sample_clk[boards[i]],
    1158             :                 pulse_size[boards[i]],pulse_length[boards[i]]);
    1159           0 :     }
    1160             :     
    1161           0 :   }
    1162             :   
    1163           0 :   AliFMDParameters::Instance()->SetSampleRate(sampleRate);
    1164           0 :   AliFMDParameters::Instance()->SetStripRange(stripRange);
    1165             :   
    1166           0 :   AliDebug(0,"End of SOD/EOD");
    1167             :   
    1168             :   return kTRUE;
    1169           0 : }
    1170             : //____________________________________________________________________
    1171             : 
    1172             : UInt_t AliFMDRawReader::Get32bitWord(Int_t idx)
    1173             : {
    1174             :   // This method returns the 32 bit word at a given
    1175             :   // position inside the raw data payload.
    1176             :   // The 'index' points to the beginning of the next word.
    1177             :   // The method is supposed to be endian (platform)
    1178             :   // independent.
    1179           0 :   if (!fData) {
    1180           0 :     AliFatal("Raw data paylod buffer is not yet initialized !");
    1181           0 :   }
    1182             : 
    1183           0 :   Int_t index = 4*idx;
    1184             :   
    1185           0 :   if (index < 4) {
    1186             :     //  fRawReader->AddFatalErrorLog(k32bitWordReadErr,Form("pos = %d",index));
    1187             :     //    PrintDebug();
    1188           0 :     AliWarningF("Invalid raw data payload position (%d) !",index);
    1189           0 :   }
    1190             : 
    1191             :   UInt_t word = 0;
    1192             :    
    1193           0 :   word  = fData[--index] << 24;
    1194           0 :   word |= fData[--index] << 16;
    1195           0 :   word |= fData[--index] << 8;
    1196           0 :   word |= fData[--index] << 0 ;
    1197             : 
    1198           0 :   return word;
    1199           0 : }
    1200             : //_____________________________________________________________________ 
    1201             : Int_t AliFMDRawReader::GetHalfringIndex(UShort_t det, Char_t ring, 
    1202             :                                         UShort_t board) const
    1203             : {
    1204             :   // 
    1205             :   // Get short index for a given half-ring
    1206             :   // 
    1207             :   // Parameters:
    1208             :   //    det   Detector number
    1209             :   //    ring  Ring identifer
    1210             :   //    board Board number
    1211             :   // 
    1212             :   // Return:
    1213             :   //    
    1214             :   //
    1215           0 :   UShort_t iring  =  (ring == 'I' ? 1 : 0);
    1216             :   
    1217           0 :   Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
    1218             :   
    1219           0 :   return index-2;
    1220             :   
    1221             : }
    1222             : 
    1223             : //____________________________________________________________________
    1224             : // 
    1225             : // EOF
    1226             : //
    1227             : 

Generated by: LCOV version 1.11