ROOT logo
/// $Id$
///
/// Generate, for a given slat type, the list of translators and their buspatch
///
/// It's the equivalent of the St#_Nappes-crocus-v#.#.pdf files found in 
/// https://twiki.cern.ch/twiki/bin/view/ALICE/St345CrocusFlatCables
/// but sorted by slat type, and not by crocus.
///
/// \author Laurent Aphecetche, Subatech
///

#include "TString.h"
#include <map>
#include <string>
#include <fstream>
#include <iostream>
#include "Riostream.h"
#include "TSystem.h"
#include <vector>
#include <utility>
#include "AliMpDetElement.h"
#include "AliMpDDLStore.h"
#include "AliMpCDB.h"
#include "AliMpDataProcessor.h"
#include "AliMpDataMap.h"
#include "AliMpDataStreams.h"
#include "AliMpDDLStore.h"
#include "AliMpManuStore.h"
#include "AliMpBusPatch.h"
#include <algorithm>

void LoadMapping(Bool_t fromFile)
{
  if ( fromFile ) 
  {
    AliMpDataProcessor mp;
    {
      AliMpDataMap* datamap = mp.CreateDataMap("data");
      AliMpDataStreams dataStreams(datamap);
      AliMpDDLStore::ReadData(dataStreams);
    }
    {
      AliMpDataMap* datamap = mp.CreateDataMap("data_run");
      AliMpDataStreams dataStreams(datamap);
      AliMpManuStore::ReadData(dataStreams);
    }    
  }
  else
  {
    AliMpCDB::LoadAll2();
  }
}

void SlatTranslatorToBusPatches(const char* whichSlat="112200NR2")
{
  LoadMapping(kTRUE);
  
  TString file(gSystem->ExpandPathName("$ALICE_ROOT/MUON/mapping/data/station345/DetElemIdToSlatType.dat"));
  
  ifstream in(file);
  if (in.bad()) return;
  
  int detElemId;
  char s[80];
  char slatType[80];
  std::map<std::string,std::vector<int> > slats;
  
  while ( in.getline(s,80,'\n') )
  {
    if ( s[0] != '#' && strlen(s) > 2 )
    {
      sscanf(s,"%d %s",&detElemId,slatType);
      
      slats[slatType].push_back(detElemId);
    }
  }
  
  std::map<std::string,std::vector<int> >::const_iterator it;
  
  std::vector<int> v = slats[whichSlat];
  
  cout << "----------------------" << endl;
  cout << whichSlat << endl;
  cout << "----------------------" << endl;
  AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(v[0]);
  Int_t nofManus(0);
  Int_t nofChannels(0);
  
  for ( Int_t b = 0; b < de->GetNofBusPatches(); ++b ) 
  {
    Int_t busPatchId = de->GetBusPatchId(b);
    AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
    nofManus += bp->GetNofManus();
    cout << bp->GetTranslatorLabel() << " : " << bp->GetNofManus() << " manus" << endl;
    for ( Int_t im = 0; im < bp->GetNofManus(); ++im )
    {
      Int_t manuId = bp->GetManuId(im);
      nofChannels += de->NofChannelsInManu(manuId);
    }
  }

  cout << "Number of bus patches = " << de->GetNofBusPatches() << endl;
  cout << "Number of manus = " << nofManus << endl;
  cout << "Number of channels = " << nofChannels << endl;
  cout << "----------------------" << endl;

  std::sort(v.begin(),v.end());
  
  for ( size_t i = 0; i < v.size(); ++i ) 
  {
    Int_t detElemId = v[i];
    
    cout << Form("%04d ",detElemId) << endl;

    AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
    for ( Int_t b = 0; b < de->GetNofBusPatches(); ++b ) 
    {
      Int_t busPatchId = de->GetBusPatchId(b);
      AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
      bp->Print();
    }
  }
  cout << endl;

  in.close();
}



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