ROOT logo
#if !defined(__CINT__) || defined(__MAKECINT__)
#include "AliITSDDLModuleMapSDD.h"
#include <TSystem.h>
#endif

/*  $Id$    */

// Macro to extract and print the configuration parameters of SDD modules 
// from JTAG hexadecimal files 
// Origin: F. Prino,   prino@to.infn.it

void DecodeJTAG(Int_t nDDL, Int_t nCarlos=0, TString type="PHY"){

  AliITSDDLModuleMapSDD* dmap=new AliITSDDLModuleMapSDD();
  dmap->SetJun09Map();
  Int_t theMod=-1;
  if(nDDL>=0 && nDDL<23){
    theMod=dmap->GetModuleNumber(nDDL,nCarlos);
  }else if(nDDL>=240 && nDDL<500){
    theMod=nDDL;
    dmap->FindInDDLMap(theMod,nDDL,nCarlos);
  }else{
    printf("ERROR: wronng DDL/Module number %d\n",nDDL); 
    return;
  }
  TString crate;
  if(nDDL<8) crate="TOP";
  else if(nDDL<16) crate="MED";
  else if(nDDL<24) crate="BOT";

  Int_t numSlot=nDDL%8+1;
  Int_t car1,car2;
  if(nCarlos%2==0){
    car1=nCarlos;
    car2=nCarlos+1;
  }else{
    car2=nCarlos;
    car1=nCarlos-1;
  }
  TString filnam=Form("%s%d/%s_jtag_carlos%02d%02d.txt",crate.Data(),numSlot,
		      type.Data(),car1,car2);
  gSystem->Exec(Form("ls -l %s\n",filnam.Data()));
  FILE* fil=fopen(filnam.Data(),"r");
  UInt_t word;
  Int_t retcode;

  retcode=fscanf(fil,"%x\n",&word);
  Int_t modNum=word&0x0000000F;
  for(Int_t iMod=0; iMod<2; iMod++){
    retcode=fscanf(fil,"%x\n",&word);
    if(iMod==0 && word!=0xFFFFFF00){printf("ERROR - mod 0\n"); return;}
    if(iMod==1 && word!=0xFFFFFF11){printf("ERROR - mod 1\n"); return;}
    retcode=fscanf(fil,"%x\n",&word); // CarlosRX word
    if(iMod==0){
      Int_t maskMod=(word&0x000FFF00)>>8;  
      printf("Active modules: ");
      for(Int_t i=0;i<12;i++){ 
	if(maskMod&(1<<i)) printf(" 1 ");
	else printf(" 0 ");
      }
      printf("\n");
    }
    // CARLOS words 
    Bool_t doPrint=kFALSE;
    if(modNum+iMod==nCarlos)doPrint=kTRUE;
    if(doPrint) printf("*********** Module %d DDL %d (%s%d) Carlos %d **********\n",theMod,nDDL,crate.Data(),numSlot,modNum+iMod);
    retcode=fscanf(fil,"%x\n",&word);
    retcode=fscanf(fil,"%x\n",&word);
    Int_t th1=(word&0xFF000000)>>24;
    Int_t th0=(word&0x00FF0000)>>16;
    Int_t tl1=(word&0x0000FF00)>>8;
    Int_t tl0=(word&0x000000FF);
    if(doPrint) printf("High Thresholds = %d %d\n",th1,th0);
    if(doPrint) printf("Low Thresholds  = %d %d\n",tl1,tl0);
    retcode=fscanf(fil,"%x\n",&word);
    retcode=fscanf(fil,"%x\n",&word);
    for(Int_t iSide=0; iSide<2; iSide++){
      if(doPrint) printf("------------------ Hybrid %d -------------\n",iSide);
      // AMBRA WORDS
      for(Int_t iAmbra=0; iAmbra<4; iAmbra++){
	for(Int_t iw=0;iw<5;iw++){
	  retcode=fscanf(fil,"%x\n",&word);
	  if(doPrint && iw==1) {
	    printf("AMBRA %d --- SOP %d",iAmbra,word&0x000000FF);
	  }
	}
	if(word&0x0000FF00){
	  if(doPrint) printf(" --- Baselines present");
	  for(Int_t iwb=0;iwb<16;iwb++) retcode=fscanf(fil,"%x\n",&word);
	}else{
	  if(doPrint) printf(" --- No baseline equalization");
	}
	if(doPrint) printf("\n");
      }
      // PASCAL WORDS
      for(Int_t iPascal=0; iPascal<4; iPascal++){
	for(Int_t iw=0;iw<4;iw++){
	  retcode=fscanf(fil,"%x\n",&word);
	  if(doPrint && iw==2){
	    printf("PASCAL %d ",iPascal);
	    if(word&0xFF000000) printf(" --- ADC full");
	    else printf(" --- ADC 1/2");
	    if(word&0x00FF0000) printf(" --- AM  full");
	    else printf(" --- AM 1/2");
	    printf("\n");
	  }
	} 
      }
    }
  }
}
 DecodeJTAG.C:1
 DecodeJTAG.C:2
 DecodeJTAG.C:3
 DecodeJTAG.C:4
 DecodeJTAG.C:5
 DecodeJTAG.C:6
 DecodeJTAG.C:7
 DecodeJTAG.C:8
 DecodeJTAG.C:9
 DecodeJTAG.C:10
 DecodeJTAG.C:11
 DecodeJTAG.C:12
 DecodeJTAG.C:13
 DecodeJTAG.C:14
 DecodeJTAG.C:15
 DecodeJTAG.C:16
 DecodeJTAG.C:17
 DecodeJTAG.C:18
 DecodeJTAG.C:19
 DecodeJTAG.C:20
 DecodeJTAG.C:21
 DecodeJTAG.C:22
 DecodeJTAG.C:23
 DecodeJTAG.C:24
 DecodeJTAG.C:25
 DecodeJTAG.C:26
 DecodeJTAG.C:27
 DecodeJTAG.C:28
 DecodeJTAG.C:29
 DecodeJTAG.C:30
 DecodeJTAG.C:31
 DecodeJTAG.C:32
 DecodeJTAG.C:33
 DecodeJTAG.C:34
 DecodeJTAG.C:35
 DecodeJTAG.C:36
 DecodeJTAG.C:37
 DecodeJTAG.C:38
 DecodeJTAG.C:39
 DecodeJTAG.C:40
 DecodeJTAG.C:41
 DecodeJTAG.C:42
 DecodeJTAG.C:43
 DecodeJTAG.C:44
 DecodeJTAG.C:45
 DecodeJTAG.C:46
 DecodeJTAG.C:47
 DecodeJTAG.C:48
 DecodeJTAG.C:49
 DecodeJTAG.C:50
 DecodeJTAG.C:51
 DecodeJTAG.C:52
 DecodeJTAG.C:53
 DecodeJTAG.C:54
 DecodeJTAG.C:55
 DecodeJTAG.C:56
 DecodeJTAG.C:57
 DecodeJTAG.C:58
 DecodeJTAG.C:59
 DecodeJTAG.C:60
 DecodeJTAG.C:61
 DecodeJTAG.C:62
 DecodeJTAG.C:63
 DecodeJTAG.C:64
 DecodeJTAG.C:65
 DecodeJTAG.C:66
 DecodeJTAG.C:67
 DecodeJTAG.C:68
 DecodeJTAG.C:69
 DecodeJTAG.C:70
 DecodeJTAG.C:71
 DecodeJTAG.C:72
 DecodeJTAG.C:73
 DecodeJTAG.C:74
 DecodeJTAG.C:75
 DecodeJTAG.C:76
 DecodeJTAG.C:77
 DecodeJTAG.C:78
 DecodeJTAG.C:79
 DecodeJTAG.C:80
 DecodeJTAG.C:81
 DecodeJTAG.C:82
 DecodeJTAG.C:83
 DecodeJTAG.C:84
 DecodeJTAG.C:85
 DecodeJTAG.C:86
 DecodeJTAG.C:87
 DecodeJTAG.C:88
 DecodeJTAG.C:89
 DecodeJTAG.C:90
 DecodeJTAG.C:91
 DecodeJTAG.C:92
 DecodeJTAG.C:93
 DecodeJTAG.C:94
 DecodeJTAG.C:95
 DecodeJTAG.C:96
 DecodeJTAG.C:97
 DecodeJTAG.C:98
 DecodeJTAG.C:99
 DecodeJTAG.C:100
 DecodeJTAG.C:101
 DecodeJTAG.C:102
 DecodeJTAG.C:103
 DecodeJTAG.C:104
 DecodeJTAG.C:105
 DecodeJTAG.C:106
 DecodeJTAG.C:107
 DecodeJTAG.C:108
 DecodeJTAG.C:109
 DecodeJTAG.C:110
 DecodeJTAG.C:111
 DecodeJTAG.C:112