ROOT logo
#ifndef ALIFMDALTROMAPPING_H
#define ALIFMDALTROMAPPING_H
/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights
 * reserved. 
 *
 * Latest changes by Christian Holm Christensen <cholm@nbi.dk>
 *
 * See cxx source for full Copyright notice                               
 */
/** @file    AliFMDAltroMapping.h
    @author  Christian Holm Christensen <cholm@nbi.dk>
    @date    Sun Mar 26 18:28:11 2006
    @brief   Map HW address to detector coordinates and back again. 
*/
#ifndef ALIALTROMAPPING_H
# include <AliAltroMapping.h>
#endif
//
// Map hardware address to detector coordinates. 
//
//    The hardware address consist of a DDL number and 12bits of ALTRO
//    addresses.  The ALTRO address are formatted as follows. 
//
//    12              7         4            0
//    |---------------|---------|------------|
//    | Board #       | ALTRO # | Channel #  |
//    +---------------+---------+------------+
//
//
//____________________________________________________________________
/** @class AliFMDAltroMapping 
    @brief Class that encodes a map to/from ALTRO hardware address to
    FMD detector coordinates.  
    
    The hardware address consist of a DDL number and 12bits of ALTRO
    addresses.  The ALTRO address are formatted as follows. 
    @verbatim 
    12              7         4            0
    |---------------|---------|------------|
    | Board #       | ALTRO # | Channel #  |
    +---------------+---------+------------+
    @endverbatim 

    @ingroup FMD_base
 */
class AliFMDAltroMapping : public AliAltroMapping
{
public:
  /**
   * Constructor 
   */
  AliFMDAltroMapping();
  /**
   * Destructor 
   */
  virtual ~AliFMDAltroMapping() {}
  /**
   * Return detector number corresponding to given DDL number 
   * 
   * @param ddl DDL number 
   * @return Detector number 
   */ 
  Short_t DDL2Detector(UInt_t ddl) const 
  { 
    return (ddl<=2 ? Short_t(ddl + 1) : -1); 
  }
  /**
   * Return the ring identifier corresponding to a board number 
   * 
   * @param board Board number 
   * @return Ring identifier 
   */ 
  Char_t Board2Ring(UShort_t board) const { return (board%2)?'O':'I'; }

  /**
   * Return the strip base number corresponding to a channel address 
   * 
   * @param board   Board number
   * @param altro   Altro number 
   * @param channel Channel number 
   * @param ring    On return, the ring ID 
   * @param sec     On return, the sector number 
   * @param strip   On return, the strip base offset 
   * @return @c true on success 
   */ 
  Bool_t Channel2StripBase(UShort_t  board, UShort_t  altro, 
			   UShort_t  chan,  Char_t&   ring, 
			   UShort_t& sec,   Short_t&  str) const;
  /**
   * Return the strip, sample corresponding to a timebin 
   * 
   * @param sec        Sector
   * @param timebin    Time bin 
   * @param preSamples Number of pre-samples 
   * @param sampleRate Oversampling rate 
   * @param strip      On return, the strip number in this channel
   * @param sam        On return, the sample number 
   */ 
  void Timebin2Strip(UShort_t sec,        UShort_t  timebin,
		     UShort_t preSamples, UShort_t  sampleRate, 
		     Short_t& strip,      UShort_t& sample) const;

  /**
   * Map a hardware address into a detector index. 
   * 
   * @param ddl        Hardware DDL number 
   * @param hwaddr     Hardware address.  
   * @param timebin    Timebin 
   * @param preSamples # of pre samples 
   * @param sampleRate Over sampling rate 
   * @param det        On return, the detector #
   * @param ring       On return, the ring ID
   * @param sec        On return, the sector #
   * @param str        On return, the base of strip #
   * @param sam        On return, the sample number for this strip
   * @return @c true on success, false otherwise 
   */
  Bool_t Hardware2Detector(UShort_t  ddl,        UShort_t hwaddr, 
			   UShort_t  timebin,    UShort_t preSamples, 
			   UShort_t  sampleRate,
			   UShort_t& det,        Char_t&   ring, 
			   UShort_t& sec,        Short_t&  str,
			   UShort_t& sam) const;
  /**
   * Map a hardware address into a detector index. 
   * 
   * @param ddl        Hardware DDL number 
   * @param board      FEC number
   * @param altro      ALTRO number 
   * @param channel    Channel number 
   * @param timebin    Timebin 
   * @param preSamples # of pre samples 
   * @param sampleRate Over sampling rate 
   * @param det        On return, the detector #
   * @param ring       On return, the ring ID
   * @param sec        On return, the sector #
   * @param str        On return, the base of strip #
   * @param sam        On return, the sample number for this strip
   * @return @c true on success, false otherwise 
   */
  Bool_t Hardware2Detector(UShort_t  ddl,        UShort_t  board, 
			   UShort_t  altro,      UShort_t  chan,
			   UShort_t  timebin,    UShort_t  preSamples,
			   UShort_t  sampleRate,
			   UShort_t& det,        Char_t&   ring, 
			   UShort_t& sec,        Short_t&  str,
			   UShort_t& sam) const;



  /**
   * Return DDL number corresponding to given detector number 
   * 
   * @param det Detector number 
   * @return DDL number 
   */ 
  UShort_t Detector2DDL(UShort_t det) const { return det - 1; }
  /**
   * Return board address corresponding to a sector 
   * 
   * @param ring  Ring identifier 
   * @param sec   Sector number 
   * @return The board number, or negative number in case of failure 
   */
  Short_t Sector2Board(Char_t ring, UShort_t sec) const;
    /**
   * Convert strip address to a channel address. 
   * 
   * @param ring  Ring identifier 
   * @param sec   Sector number 
   * @param str   Strip number 
   * @param board On return, contains the board number 
   * @param altro On return, contains the altro number 
   * @param chan  On return, contains the channel number 
   * @return @c true on success. 
   */
  Bool_t Strip2Channel(Char_t    ring,  UShort_t  sec,   
		       UShort_t  str,   UShort_t& board,
		       UShort_t& altro, UShort_t& chan) const;
  /**
   * Get the timebin correspoding to a strip and sample 
   * 
   * @param sec        Sector number 
   * @param str        Strip number 
   * @param sam        Sample number 
   * @param preSamples Number of pre-samples. 
   * @param sampleRate The over-sampling rate 
   * @return the timebin corresponding to the passed strip 
   */
  UShort_t Strip2Timebin(UShort_t sec, UShort_t strip, 
			 UShort_t sam, UShort_t preSamples, 
			 UShort_t sampleRate) const;
  
  /**
   * Map a detector index into a hardware address. 
   * 
   * @param det         The detector #
   * @param ring        The ring ID
   * @param sec         The sector #
   * @param str         The strip #
   * @param sam         The sample number 
   * @param preSamples  Number of pre-samples
   * @param sampleRate  The oversampling rate 
   * @param ddl         On return, hardware DDL number 
   * @param board       On return, the FEC board address (local to DDL)
   * @param altro       On return, the ALTRO number (local to FEC)
   * @param channel     On return, the channel number (local to ALTRO)
   * @param timebin     On return, the timebin number (local to ALTRO)
   * @return @c true on success, false otherwise 
   */
  Bool_t Detector2Hardware(UShort_t  det,        Char_t    ring, 
			   UShort_t  sec,        UShort_t  str,
			   UShort_t  sam, 
			   UShort_t  preSamples, UShort_t  sampleRate,
			   UShort_t& ddl,        UShort_t& board, 
			   UShort_t& altro,      UShort_t& channel, 
			   UShort_t& timebin) const;
  /**
   * Map a detector index into a hardware address. 
   * 
   * @param det         The detector #
   * @param ring        The ring ID
   * @param sec         The sector #
   * @param str         The strip #
   * @param sam         The sample number 
   * @param preSamples  Number of pre-samples
   * @param sampleRate  The oversampling rate 
   * @param ddl         On return, hardware DDL number 
   * @param hwaddr      On return, hardware address.  
   * @param timebin     On return, the timebin number (local to ALTRO)
   * @return @c true on success, false otherwise 
   */
  Bool_t Detector2Hardware(UShort_t  det,        Char_t    ring, 
			   UShort_t  sec,        UShort_t  str,
			   UShort_t  sam, 
			   UShort_t  preSamples, UShort_t  sampleRate,
			   UShort_t& ddl,        UShort_t& hwaddr, 
			   UShort_t& timebin) const;
  /**
   * Convert board, chip, channel to a hardware address 
   * 
   * @param board   Board number 
   * @param altro   Altro number 
   * @param channel Channel number 
   * @return hardware address of a channel 
   */ 
  UInt_t ChannelAddress(UShort_t board, UShort_t altro, UShort_t channel) const;
  /**
   * Convert a channel address to board, altro, channel fields 
   * 
   * @param hwaddr  Channel address
   * @param board   On return, the Board number 
   * @param altro   On return, the Altro number 
   * @param channel On return, the Channel number 
   */
  void ChannelAddress(UShort_t hwaddr, UShort_t& board, UShort_t& altro, 
		      UShort_t& channel) const;
  /**
   * convert a partial detector index into a hardware address
   * 
   * @param sector Sector number
   * @param str    Strip number
   * @param ring   Ring ID as an integer 
   * @return Hardware address 
   */
  Int_t  GetHWAddress(Int_t sector, Int_t str, Int_t ring);
  /**
   * Get the pad-row (or sector) corresponding to hardware address
   * 
   * @param hwaddr hardware address
   * @return Sector number 
   */
  Int_t  GetPadRow(Int_t hwaddr) const;
  /**
   * Get the pad (or strip) corresponding to hardware address
   * 
   * @param hwaddr hardware address
   * @return Strip number 
   */
  Int_t  GetPad(Int_t hwaddr) const;
  /**
   * Get the sector (or ring) corresponding to hardware address
   * 
   * @param hwaddr hardware address
   * @return Ring ID as an integer 
   */
  Int_t  GetSector(Int_t hwaddr) const;
  /**
   * Print map to standard out 
   * 
   * @param option Option string (hw, or det) 
   */
  void Print(Option_t* option="hw") const;
protected:
  /**
   * Read map from file - not used 
   * 
   * @return @c true on success 
   */
  virtual Bool_t ReadMapping();
  /**
   * Create the inverse mapping arrays 
   */ 
  virtual Bool_t CreateInvMapping();
  
  ClassDef(AliFMDAltroMapping, 2) // Read raw FMD Altro data 
};

#endif
//____________________________________________________________________
//
// Local Variables:
//   mode: C++
// End:
//
// EOF
//
 AliFMDAltroMapping.h:1
 AliFMDAltroMapping.h:2
 AliFMDAltroMapping.h:3
 AliFMDAltroMapping.h:4
 AliFMDAltroMapping.h:5
 AliFMDAltroMapping.h:6
 AliFMDAltroMapping.h:7
 AliFMDAltroMapping.h:8
 AliFMDAltroMapping.h:9
 AliFMDAltroMapping.h:10
 AliFMDAltroMapping.h:11
 AliFMDAltroMapping.h:12
 AliFMDAltroMapping.h:13
 AliFMDAltroMapping.h:14
 AliFMDAltroMapping.h:15
 AliFMDAltroMapping.h:16
 AliFMDAltroMapping.h:17
 AliFMDAltroMapping.h:18
 AliFMDAltroMapping.h:19
 AliFMDAltroMapping.h:20
 AliFMDAltroMapping.h:21
 AliFMDAltroMapping.h:22
 AliFMDAltroMapping.h:23
 AliFMDAltroMapping.h:24
 AliFMDAltroMapping.h:25
 AliFMDAltroMapping.h:26
 AliFMDAltroMapping.h:27
 AliFMDAltroMapping.h:28
 AliFMDAltroMapping.h:29
 AliFMDAltroMapping.h:30
 AliFMDAltroMapping.h:31
 AliFMDAltroMapping.h:32
 AliFMDAltroMapping.h:33
 AliFMDAltroMapping.h:34
 AliFMDAltroMapping.h:35
 AliFMDAltroMapping.h:36
 AliFMDAltroMapping.h:37
 AliFMDAltroMapping.h:38
 AliFMDAltroMapping.h:39
 AliFMDAltroMapping.h:40
 AliFMDAltroMapping.h:41
 AliFMDAltroMapping.h:42
 AliFMDAltroMapping.h:43
 AliFMDAltroMapping.h:44
 AliFMDAltroMapping.h:45
 AliFMDAltroMapping.h:46
 AliFMDAltroMapping.h:47
 AliFMDAltroMapping.h:48
 AliFMDAltroMapping.h:49
 AliFMDAltroMapping.h:50
 AliFMDAltroMapping.h:51
 AliFMDAltroMapping.h:52
 AliFMDAltroMapping.h:53
 AliFMDAltroMapping.h:54
 AliFMDAltroMapping.h:55
 AliFMDAltroMapping.h:56
 AliFMDAltroMapping.h:57
 AliFMDAltroMapping.h:58
 AliFMDAltroMapping.h:59
 AliFMDAltroMapping.h:60
 AliFMDAltroMapping.h:61
 AliFMDAltroMapping.h:62
 AliFMDAltroMapping.h:63
 AliFMDAltroMapping.h:64
 AliFMDAltroMapping.h:65
 AliFMDAltroMapping.h:66
 AliFMDAltroMapping.h:67
 AliFMDAltroMapping.h:68
 AliFMDAltroMapping.h:69
 AliFMDAltroMapping.h:70
 AliFMDAltroMapping.h:71
 AliFMDAltroMapping.h:72
 AliFMDAltroMapping.h:73
 AliFMDAltroMapping.h:74
 AliFMDAltroMapping.h:75
 AliFMDAltroMapping.h:76
 AliFMDAltroMapping.h:77
 AliFMDAltroMapping.h:78
 AliFMDAltroMapping.h:79
 AliFMDAltroMapping.h:80
 AliFMDAltroMapping.h:81
 AliFMDAltroMapping.h:82
 AliFMDAltroMapping.h:83
 AliFMDAltroMapping.h:84
 AliFMDAltroMapping.h:85
 AliFMDAltroMapping.h:86
 AliFMDAltroMapping.h:87
 AliFMDAltroMapping.h:88
 AliFMDAltroMapping.h:89
 AliFMDAltroMapping.h:90
 AliFMDAltroMapping.h:91
 AliFMDAltroMapping.h:92
 AliFMDAltroMapping.h:93
 AliFMDAltroMapping.h:94
 AliFMDAltroMapping.h:95
 AliFMDAltroMapping.h:96
 AliFMDAltroMapping.h:97
 AliFMDAltroMapping.h:98
 AliFMDAltroMapping.h:99
 AliFMDAltroMapping.h:100
 AliFMDAltroMapping.h:101
 AliFMDAltroMapping.h:102
 AliFMDAltroMapping.h:103
 AliFMDAltroMapping.h:104
 AliFMDAltroMapping.h:105
 AliFMDAltroMapping.h:106
 AliFMDAltroMapping.h:107
 AliFMDAltroMapping.h:108
 AliFMDAltroMapping.h:109
 AliFMDAltroMapping.h:110
 AliFMDAltroMapping.h:111
 AliFMDAltroMapping.h:112
 AliFMDAltroMapping.h:113
 AliFMDAltroMapping.h:114
 AliFMDAltroMapping.h:115
 AliFMDAltroMapping.h:116
 AliFMDAltroMapping.h:117
 AliFMDAltroMapping.h:118
 AliFMDAltroMapping.h:119
 AliFMDAltroMapping.h:120
 AliFMDAltroMapping.h:121
 AliFMDAltroMapping.h:122
 AliFMDAltroMapping.h:123
 AliFMDAltroMapping.h:124
 AliFMDAltroMapping.h:125
 AliFMDAltroMapping.h:126
 AliFMDAltroMapping.h:127
 AliFMDAltroMapping.h:128
 AliFMDAltroMapping.h:129
 AliFMDAltroMapping.h:130
 AliFMDAltroMapping.h:131
 AliFMDAltroMapping.h:132
 AliFMDAltroMapping.h:133
 AliFMDAltroMapping.h:134
 AliFMDAltroMapping.h:135
 AliFMDAltroMapping.h:136
 AliFMDAltroMapping.h:137
 AliFMDAltroMapping.h:138
 AliFMDAltroMapping.h:139
 AliFMDAltroMapping.h:140
 AliFMDAltroMapping.h:141
 AliFMDAltroMapping.h:142
 AliFMDAltroMapping.h:143
 AliFMDAltroMapping.h:144
 AliFMDAltroMapping.h:145
 AliFMDAltroMapping.h:146
 AliFMDAltroMapping.h:147
 AliFMDAltroMapping.h:148
 AliFMDAltroMapping.h:149
 AliFMDAltroMapping.h:150
 AliFMDAltroMapping.h:151
 AliFMDAltroMapping.h:152
 AliFMDAltroMapping.h:153
 AliFMDAltroMapping.h:154
 AliFMDAltroMapping.h:155
 AliFMDAltroMapping.h:156
 AliFMDAltroMapping.h:157
 AliFMDAltroMapping.h:158
 AliFMDAltroMapping.h:159
 AliFMDAltroMapping.h:160
 AliFMDAltroMapping.h:161
 AliFMDAltroMapping.h:162
 AliFMDAltroMapping.h:163
 AliFMDAltroMapping.h:164
 AliFMDAltroMapping.h:165
 AliFMDAltroMapping.h:166
 AliFMDAltroMapping.h:167
 AliFMDAltroMapping.h:168
 AliFMDAltroMapping.h:169
 AliFMDAltroMapping.h:170
 AliFMDAltroMapping.h:171
 AliFMDAltroMapping.h:172
 AliFMDAltroMapping.h:173
 AliFMDAltroMapping.h:174
 AliFMDAltroMapping.h:175
 AliFMDAltroMapping.h:176
 AliFMDAltroMapping.h:177
 AliFMDAltroMapping.h:178
 AliFMDAltroMapping.h:179
 AliFMDAltroMapping.h:180
 AliFMDAltroMapping.h:181
 AliFMDAltroMapping.h:182
 AliFMDAltroMapping.h:183
 AliFMDAltroMapping.h:184
 AliFMDAltroMapping.h:185
 AliFMDAltroMapping.h:186
 AliFMDAltroMapping.h:187
 AliFMDAltroMapping.h:188
 AliFMDAltroMapping.h:189
 AliFMDAltroMapping.h:190
 AliFMDAltroMapping.h:191
 AliFMDAltroMapping.h:192
 AliFMDAltroMapping.h:193
 AliFMDAltroMapping.h:194
 AliFMDAltroMapping.h:195
 AliFMDAltroMapping.h:196
 AliFMDAltroMapping.h:197
 AliFMDAltroMapping.h:198
 AliFMDAltroMapping.h:199
 AliFMDAltroMapping.h:200
 AliFMDAltroMapping.h:201
 AliFMDAltroMapping.h:202
 AliFMDAltroMapping.h:203
 AliFMDAltroMapping.h:204
 AliFMDAltroMapping.h:205
 AliFMDAltroMapping.h:206
 AliFMDAltroMapping.h:207
 AliFMDAltroMapping.h:208
 AliFMDAltroMapping.h:209
 AliFMDAltroMapping.h:210
 AliFMDAltroMapping.h:211
 AliFMDAltroMapping.h:212
 AliFMDAltroMapping.h:213
 AliFMDAltroMapping.h:214
 AliFMDAltroMapping.h:215
 AliFMDAltroMapping.h:216
 AliFMDAltroMapping.h:217
 AliFMDAltroMapping.h:218
 AliFMDAltroMapping.h:219
 AliFMDAltroMapping.h:220
 AliFMDAltroMapping.h:221
 AliFMDAltroMapping.h:222
 AliFMDAltroMapping.h:223
 AliFMDAltroMapping.h:224
 AliFMDAltroMapping.h:225
 AliFMDAltroMapping.h:226
 AliFMDAltroMapping.h:227
 AliFMDAltroMapping.h:228
 AliFMDAltroMapping.h:229
 AliFMDAltroMapping.h:230
 AliFMDAltroMapping.h:231
 AliFMDAltroMapping.h:232
 AliFMDAltroMapping.h:233
 AliFMDAltroMapping.h:234
 AliFMDAltroMapping.h:235
 AliFMDAltroMapping.h:236
 AliFMDAltroMapping.h:237
 AliFMDAltroMapping.h:238
 AliFMDAltroMapping.h:239
 AliFMDAltroMapping.h:240
 AliFMDAltroMapping.h:241
 AliFMDAltroMapping.h:242
 AliFMDAltroMapping.h:243
 AliFMDAltroMapping.h:244
 AliFMDAltroMapping.h:245
 AliFMDAltroMapping.h:246
 AliFMDAltroMapping.h:247
 AliFMDAltroMapping.h:248
 AliFMDAltroMapping.h:249
 AliFMDAltroMapping.h:250
 AliFMDAltroMapping.h:251
 AliFMDAltroMapping.h:252
 AliFMDAltroMapping.h:253
 AliFMDAltroMapping.h:254
 AliFMDAltroMapping.h:255
 AliFMDAltroMapping.h:256
 AliFMDAltroMapping.h:257
 AliFMDAltroMapping.h:258
 AliFMDAltroMapping.h:259
 AliFMDAltroMapping.h:260
 AliFMDAltroMapping.h:261
 AliFMDAltroMapping.h:262
 AliFMDAltroMapping.h:263
 AliFMDAltroMapping.h:264
 AliFMDAltroMapping.h:265
 AliFMDAltroMapping.h:266
 AliFMDAltroMapping.h:267
 AliFMDAltroMapping.h:268
 AliFMDAltroMapping.h:269
 AliFMDAltroMapping.h:270
 AliFMDAltroMapping.h:271
 AliFMDAltroMapping.h:272
 AliFMDAltroMapping.h:273
 AliFMDAltroMapping.h:274
 AliFMDAltroMapping.h:275
 AliFMDAltroMapping.h:276
 AliFMDAltroMapping.h:277
 AliFMDAltroMapping.h:278
 AliFMDAltroMapping.h:279
 AliFMDAltroMapping.h:280
 AliFMDAltroMapping.h:281
 AliFMDAltroMapping.h:282
 AliFMDAltroMapping.h:283
 AliFMDAltroMapping.h:284
 AliFMDAltroMapping.h:285
 AliFMDAltroMapping.h:286
 AliFMDAltroMapping.h:287
 AliFMDAltroMapping.h:288
 AliFMDAltroMapping.h:289
 AliFMDAltroMapping.h:290
 AliFMDAltroMapping.h:291
 AliFMDAltroMapping.h:292
 AliFMDAltroMapping.h:293
 AliFMDAltroMapping.h:294
 AliFMDAltroMapping.h:295
 AliFMDAltroMapping.h:296
 AliFMDAltroMapping.h:297
 AliFMDAltroMapping.h:298
 AliFMDAltroMapping.h:299
 AliFMDAltroMapping.h:300
 AliFMDAltroMapping.h:301
 AliFMDAltroMapping.h:302
 AliFMDAltroMapping.h:303
 AliFMDAltroMapping.h:304
 AliFMDAltroMapping.h:305
 AliFMDAltroMapping.h:306
 AliFMDAltroMapping.h:307
 AliFMDAltroMapping.h:308
 AliFMDAltroMapping.h:309
 AliFMDAltroMapping.h:310
 AliFMDAltroMapping.h:311
 AliFMDAltroMapping.h:312
 AliFMDAltroMapping.h:313
 AliFMDAltroMapping.h:314
 AliFMDAltroMapping.h:315
 AliFMDAltroMapping.h:316
 AliFMDAltroMapping.h:317