ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

//
// Macro to generate manu list per buspatch for station 3, 4 and 5
// Christian Finck, Subatech
// 17/03/09  Not working

#if !defined(__CINT__) || defined(__MAKECINT__)

#include "AliMpSegmentation.h"
#include "AliMpVSegmentation.h"
#include "AliMpDEManager.h"
#include "AliMpBusPatch.h"
#include "AliMpIntPair.h"

#include <TArrayI.h>
#include <TList.h>

#endif

void testManuListSt345(Char_t* fileNamePre = "BusPatchToManu")
{
   
  Int_t planeOffset = 1024;
  Int_t nBusPatch = 0;
  Int_t nManu = 0;

  Char_t fileName[255];
  AliMpBusPatch* busPatchManager = new AliMpBusPatch();
  busPatchManager->ReadBusPatchFile();

  // loop over DDL station 345
  for (Int_t iDDL = 8; iDDL < 20; ++iDDL) {

    sprintf(fileName,"%s%d%s", fileNamePre, iDDL, ".dat");
 
    FILE* fp = fopen(fileName,"w");
    printf("DDL # %d\n", iDDL);
    fprintf(fp, "DDL # %d\n", iDDL);
    TArrayI deArray = busPatchManager->GetDeInDDL(iDDL);

    // list of DE in the given DDL
    for (Int_t detElemId = 0; detElemId < deArray.GetSize(); ++detElemId) {

      // list of bus patch for a given DE
      TArrayI* busArray = busPatchManager->GetBusfromDE(deArray[detElemId]);

      // list of manu per DE
      TList manuList;
      for ( Int_t cath = 0; cath <=1 ; ++cath ) {
	const AliMpVSegmentation* seg 
	  = AliMpSegmentation::Instance()->GetMpSegmentation(deArray[detElemId],cath);
        
	TArrayI manus;

	seg->GetAllElectronicCardIDs(manus);
          
	// filling class
	for ( Int_t im = 0; im < manus.GetSize(); ++im ) {

	  AliMpIntPair* manu = new AliMpIntPair((manus[im] & 0x3FF), cath, kTRUE);// remove the offfset
	  manuList.Add(manu);
	}        
      }
      manuList.Sort();
      //      printf("Number of manu %d\n", manuList.GetEntries());

      // writing into files/stdout
      Int_t posPrev = -1;
      Int_t manuIdPrev = 0;
      for (Int_t iEntry = 0; iEntry < manuList.GetEntries(); iEntry++) {

	AliMpIntPair* manuPtr = (AliMpIntPair*)manuList.At(iEntry);
	Int_t pos = manuPtr->GetFirst()/100;
	Int_t manuId;
	nManu++;

	if (manuPtr->GetSecond())
	  manuId = manuPtr->GetFirst() + planeOffset;
	else
	  manuId = manuPtr->GetFirst();

	if (pos != posPrev) {
	  if (posPrev != -1) {
	    printf("%d;\n", manuIdPrev);
	    fprintf(fp,"%d;\n", manuIdPrev);

	  }
	  printf("%d %d %d-", deArray[detElemId], 
		 AliMpBusPatch::GetLocalBusID(busArray->At(pos),iDDL), manuId);
	  fprintf(fp,"%d %d-", AliMpBusPatch::GetLocalBusID(busArray->At(pos),iDDL), manuId);
	  nBusPatch++;

	} else if ( manuId != manuIdPrev+1) {
	  printf("%d; ", manuIdPrev);
	  printf("%d-", manuId);
	  fprintf(fp,"%d; ", manuIdPrev);
	  fprintf(fp,"%d-", manuId);

	}
     
	posPrev = pos;
	manuIdPrev = manuId;
	if (iEntry ==  manuList.GetEntries()-1) {
	  printf("%d;\n", manuId);
	  fprintf(fp,"%d;\n", manuId);
	}
      }
    }
    fclose(fp);
  }
  fflush(stdout);
  printf("Number of buspatches %d and manus %d\n", nBusPatch, nManu);

  delete busPatchManager;
}

 testManuListSt345.C:1
 testManuListSt345.C:2
 testManuListSt345.C:3
 testManuListSt345.C:4
 testManuListSt345.C:5
 testManuListSt345.C:6
 testManuListSt345.C:7
 testManuListSt345.C:8
 testManuListSt345.C:9
 testManuListSt345.C:10
 testManuListSt345.C:11
 testManuListSt345.C:12
 testManuListSt345.C:13
 testManuListSt345.C:14
 testManuListSt345.C:15
 testManuListSt345.C:16
 testManuListSt345.C:17
 testManuListSt345.C:18
 testManuListSt345.C:19
 testManuListSt345.C:20
 testManuListSt345.C:21
 testManuListSt345.C:22
 testManuListSt345.C:23
 testManuListSt345.C:24
 testManuListSt345.C:25
 testManuListSt345.C:26
 testManuListSt345.C:27
 testManuListSt345.C:28
 testManuListSt345.C:29
 testManuListSt345.C:30
 testManuListSt345.C:31
 testManuListSt345.C:32
 testManuListSt345.C:33
 testManuListSt345.C:34
 testManuListSt345.C:35
 testManuListSt345.C:36
 testManuListSt345.C:37
 testManuListSt345.C:38
 testManuListSt345.C:39
 testManuListSt345.C:40
 testManuListSt345.C:41
 testManuListSt345.C:42
 testManuListSt345.C:43
 testManuListSt345.C:44
 testManuListSt345.C:45
 testManuListSt345.C:46
 testManuListSt345.C:47
 testManuListSt345.C:48
 testManuListSt345.C:49
 testManuListSt345.C:50
 testManuListSt345.C:51
 testManuListSt345.C:52
 testManuListSt345.C:53
 testManuListSt345.C:54
 testManuListSt345.C:55
 testManuListSt345.C:56
 testManuListSt345.C:57
 testManuListSt345.C:58
 testManuListSt345.C:59
 testManuListSt345.C:60
 testManuListSt345.C:61
 testManuListSt345.C:62
 testManuListSt345.C:63
 testManuListSt345.C:64
 testManuListSt345.C:65
 testManuListSt345.C:66
 testManuListSt345.C:67
 testManuListSt345.C:68
 testManuListSt345.C:69
 testManuListSt345.C:70
 testManuListSt345.C:71
 testManuListSt345.C:72
 testManuListSt345.C:73
 testManuListSt345.C:74
 testManuListSt345.C:75
 testManuListSt345.C:76
 testManuListSt345.C:77
 testManuListSt345.C:78
 testManuListSt345.C:79
 testManuListSt345.C:80
 testManuListSt345.C:81
 testManuListSt345.C:82
 testManuListSt345.C:83
 testManuListSt345.C:84
 testManuListSt345.C:85
 testManuListSt345.C:86
 testManuListSt345.C:87
 testManuListSt345.C:88
 testManuListSt345.C:89
 testManuListSt345.C:90
 testManuListSt345.C:91
 testManuListSt345.C:92
 testManuListSt345.C:93
 testManuListSt345.C:94
 testManuListSt345.C:95
 testManuListSt345.C:96
 testManuListSt345.C:97
 testManuListSt345.C:98
 testManuListSt345.C:99
 testManuListSt345.C:100
 testManuListSt345.C:101
 testManuListSt345.C:102
 testManuListSt345.C:103
 testManuListSt345.C:104
 testManuListSt345.C:105
 testManuListSt345.C:106
 testManuListSt345.C:107
 testManuListSt345.C:108
 testManuListSt345.C:109
 testManuListSt345.C:110
 testManuListSt345.C:111
 testManuListSt345.C:112
 testManuListSt345.C:113
 testManuListSt345.C:114
 testManuListSt345.C:115
 testManuListSt345.C:116
 testManuListSt345.C:117
 testManuListSt345.C:118
 testManuListSt345.C:119
 testManuListSt345.C:120
 testManuListSt345.C:121
 testManuListSt345.C:122
 testManuListSt345.C:123
 testManuListSt345.C:124
 testManuListSt345.C:125
 testManuListSt345.C:126
 testManuListSt345.C:127
 testManuListSt345.C:128
 testManuListSt345.C:129
 testManuListSt345.C:130
 testManuListSt345.C:131
 testManuListSt345.C:132
 testManuListSt345.C:133