ROOT logo
// $Id$
// $MpId: testMotifTypeIterators.C,v 1.11 2005/09/26 16:05:25 ivana Exp $
//
// Test macro for reading motif type data and iterate over them.

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

#include "AliMpStation12Type.h"
#include "AliMpPlaneType.h"
#include "AliMpDataProcessor.h"
#include "AliMpDataMap.h"
#include "AliMpDataStreams.h"
#include "AliMpMotifReader.h"
#include "AliMpMotifType.h"
#include "AliMpMotifTypePadIterator.h"
#include "AliMpEncodePair.h"

#include <Riostream.h>
#include <TCanvas.h>
#include <TMarker.h>
#include <TH2.h>

#include <vector>

#endif

TCanvas* CreateTCanvas(const TString& name, const TString& title,
                       AliMq::Station12Type station, AliMp::PlaneType plane)
{
  TString newName(name);
  TString newTitle(title);
  TString unique = AliMq::Station12TypeName(station) + AliMp::PlaneTypeName(plane);
  newName += unique;
  newTitle += unique;
  return new TCanvas(newName.Data(), newTitle.Data());
}                     

void testMotifTypeIterators(AliMq::Station12Type station, AliMp::PlaneType plane)
{
  TString names;
  TString names2;
  Int_t nv =0;
  if ( station == AliMq::kStation1 ) {
    if ( plane == AliMp::kBendingPlane ) 
      names ="ABCDEFGHI";
    else
      names = "ABCDEFGHIJKLMN";
  }    
  else if ( station == AliMq::kStation2 ) {
    if ( plane == AliMp::kBendingPlane ) {
      names ="ABCDEFGHIJKLMNOPQRSTUVWXY";
      names2 ="abcdefghimnptuvvvvv";
      nv = 5;
    }  
    else {
      names = "ABCEFGHIJKLMN";
      names2 ="abcdefgijklmnopqrstuwvvvvv";
      nv = 5;
    }  
  }  
  Int_t nofMotifs = names.Length() + names2.Length(); 
  // cout << " nofMotifs: " << nofMotifs << endl;   
    
  std::vector<TH2C*> histos;
  std::vector<TCanvas*> cvs;
  Int_t i;
  for (i=0;i<1+(nofMotifs-1)/4;++i){
    TString cname("canv"); cname += i;
    TCanvas* canv = CreateTCanvas(cname.Data(),"Iterator viewing...", station, plane);
    canv->Divide(2,2); 
    cvs.push_back(canv);
  }
    
  AliMpDataProcessor mp;
  AliMpDataMap* dataMap = mp.CreateDataMap("data");
  AliMpDataStreams dataStreams(dataMap);

  AliMpMotifReader r(dataStreams, AliMp::kStation12, station, plane);
  //r.SetVerboseLevel(2);

  for (i=0;i<nofMotifs;++i){

    // Get motif name
    TString mname;
    if (i<names.Length())
      mname = names(i, 1);
    else {
      mname = names2(i-names.Length(), 1); 
      if (mname == "v")
        mname += i - names.Length() - (names2.Length()-nv-1);
      else 	   
        mname += "1";
    }	
    //if (i==36) continue;  
        // break for these motifs (St2, BP) - to be investigated
   
    AliMpMotifType *mt = r.BuildMotifType(mname);

    cvs[i/4]->cd(1+ (i%4));
    //histos[i] = new TH2C(Form("h%d",i),Form("Motif type %c",names[i]),
    //                     mt->GetNofPadsX(),-0.5,mt->GetNofPadsX()-0.5,
    //                     mt->GetNofPadsY(),-0.5,mt->GetNofPadsY()-0.5);
               // CINT limitation on DEC

    TString hname("h"); hname += i;

    TH2C* histo = new TH2C(hname.Data(), mname.Data(),
                         mt->GetNofPadsX(),-0.5,mt->GetNofPadsX()-0.5,
                         mt->GetNofPadsY(),-0.5,mt->GetNofPadsY()-0.5);
    histos.push_back(histo);                         

    cout<<"Motif Type "<<mt->GetID()<<endl;
    cout<<"--------------------------------"<<endl;
    Int_t num=0;

    AliMpMotifTypePadIterator it = AliMpMotifTypePadIterator(mt);

    for (it.First(); ! it.IsDone(); it.Next()) {
      cout << "Iterator " << num << ' ';
      AliMp::PairPut(cout, it.CurrentItem().GetIndices()) << endl;
      ++num;
      histo->Fill(it.CurrentItem().GetIx(), it.CurrentItem().GetIy(),num);
    }

    //delete mt;
    histo->Draw("text");
    cvs[i/4]->Update();
  }
}
void testSt12MotifTypeIterators()
{
  AliMq::Station12Type  station[2] = { AliMq::kStation1, AliMq::kStation2 }; 
  AliMp::PlaneType      plane[2]   = { AliMp::kBendingPlane, AliMp::kNonBendingPlane };
  
  for ( Int_t is = 0; is < 2; is++ ) {
    for ( Int_t ip = 0; ip < 2; ip++ ) {
    
      cout << "Running testMotifTypeIterators for " 
           << AliMq::Station12TypeName(station[is]) << "  "
           << AliMp::PlaneTypeName(plane[ip])  << " ... " << endl;
       
      testMotifTypeIterators(station[is], plane[ip]);
    
      cout << "... end running " << endl << endl;
    }  
  }   
}  
  
 testSt12MotifTypeIterators.C:1
 testSt12MotifTypeIterators.C:2
 testSt12MotifTypeIterators.C:3
 testSt12MotifTypeIterators.C:4
 testSt12MotifTypeIterators.C:5
 testSt12MotifTypeIterators.C:6
 testSt12MotifTypeIterators.C:7
 testSt12MotifTypeIterators.C:8
 testSt12MotifTypeIterators.C:9
 testSt12MotifTypeIterators.C:10
 testSt12MotifTypeIterators.C:11
 testSt12MotifTypeIterators.C:12
 testSt12MotifTypeIterators.C:13
 testSt12MotifTypeIterators.C:14
 testSt12MotifTypeIterators.C:15
 testSt12MotifTypeIterators.C:16
 testSt12MotifTypeIterators.C:17
 testSt12MotifTypeIterators.C:18
 testSt12MotifTypeIterators.C:19
 testSt12MotifTypeIterators.C:20
 testSt12MotifTypeIterators.C:21
 testSt12MotifTypeIterators.C:22
 testSt12MotifTypeIterators.C:23
 testSt12MotifTypeIterators.C:24
 testSt12MotifTypeIterators.C:25
 testSt12MotifTypeIterators.C:26
 testSt12MotifTypeIterators.C:27
 testSt12MotifTypeIterators.C:28
 testSt12MotifTypeIterators.C:29
 testSt12MotifTypeIterators.C:30
 testSt12MotifTypeIterators.C:31
 testSt12MotifTypeIterators.C:32
 testSt12MotifTypeIterators.C:33
 testSt12MotifTypeIterators.C:34
 testSt12MotifTypeIterators.C:35
 testSt12MotifTypeIterators.C:36
 testSt12MotifTypeIterators.C:37
 testSt12MotifTypeIterators.C:38
 testSt12MotifTypeIterators.C:39
 testSt12MotifTypeIterators.C:40
 testSt12MotifTypeIterators.C:41
 testSt12MotifTypeIterators.C:42
 testSt12MotifTypeIterators.C:43
 testSt12MotifTypeIterators.C:44
 testSt12MotifTypeIterators.C:45
 testSt12MotifTypeIterators.C:46
 testSt12MotifTypeIterators.C:47
 testSt12MotifTypeIterators.C:48
 testSt12MotifTypeIterators.C:49
 testSt12MotifTypeIterators.C:50
 testSt12MotifTypeIterators.C:51
 testSt12MotifTypeIterators.C:52
 testSt12MotifTypeIterators.C:53
 testSt12MotifTypeIterators.C:54
 testSt12MotifTypeIterators.C:55
 testSt12MotifTypeIterators.C:56
 testSt12MotifTypeIterators.C:57
 testSt12MotifTypeIterators.C:58
 testSt12MotifTypeIterators.C:59
 testSt12MotifTypeIterators.C:60
 testSt12MotifTypeIterators.C:61
 testSt12MotifTypeIterators.C:62
 testSt12MotifTypeIterators.C:63
 testSt12MotifTypeIterators.C:64
 testSt12MotifTypeIterators.C:65
 testSt12MotifTypeIterators.C:66
 testSt12MotifTypeIterators.C:67
 testSt12MotifTypeIterators.C:68
 testSt12MotifTypeIterators.C:69
 testSt12MotifTypeIterators.C:70
 testSt12MotifTypeIterators.C:71
 testSt12MotifTypeIterators.C:72
 testSt12MotifTypeIterators.C:73
 testSt12MotifTypeIterators.C:74
 testSt12MotifTypeIterators.C:75
 testSt12MotifTypeIterators.C:76
 testSt12MotifTypeIterators.C:77
 testSt12MotifTypeIterators.C:78
 testSt12MotifTypeIterators.C:79
 testSt12MotifTypeIterators.C:80
 testSt12MotifTypeIterators.C:81
 testSt12MotifTypeIterators.C:82
 testSt12MotifTypeIterators.C:83
 testSt12MotifTypeIterators.C:84
 testSt12MotifTypeIterators.C:85
 testSt12MotifTypeIterators.C:86
 testSt12MotifTypeIterators.C:87
 testSt12MotifTypeIterators.C:88
 testSt12MotifTypeIterators.C:89
 testSt12MotifTypeIterators.C:90
 testSt12MotifTypeIterators.C:91
 testSt12MotifTypeIterators.C:92
 testSt12MotifTypeIterators.C:93
 testSt12MotifTypeIterators.C:94
 testSt12MotifTypeIterators.C:95
 testSt12MotifTypeIterators.C:96
 testSt12MotifTypeIterators.C:97
 testSt12MotifTypeIterators.C:98
 testSt12MotifTypeIterators.C:99
 testSt12MotifTypeIterators.C:100
 testSt12MotifTypeIterators.C:101
 testSt12MotifTypeIterators.C:102
 testSt12MotifTypeIterators.C:103
 testSt12MotifTypeIterators.C:104
 testSt12MotifTypeIterators.C:105
 testSt12MotifTypeIterators.C:106
 testSt12MotifTypeIterators.C:107
 testSt12MotifTypeIterators.C:108
 testSt12MotifTypeIterators.C:109
 testSt12MotifTypeIterators.C:110
 testSt12MotifTypeIterators.C:111
 testSt12MotifTypeIterators.C:112
 testSt12MotifTypeIterators.C:113
 testSt12MotifTypeIterators.C:114
 testSt12MotifTypeIterators.C:115
 testSt12MotifTypeIterators.C:116
 testSt12MotifTypeIterators.C:117
 testSt12MotifTypeIterators.C:118
 testSt12MotifTypeIterators.C:119
 testSt12MotifTypeIterators.C:120
 testSt12MotifTypeIterators.C:121
 testSt12MotifTypeIterators.C:122
 testSt12MotifTypeIterators.C:123
 testSt12MotifTypeIterators.C:124
 testSt12MotifTypeIterators.C:125
 testSt12MotifTypeIterators.C:126
 testSt12MotifTypeIterators.C:127
 testSt12MotifTypeIterators.C:128
 testSt12MotifTypeIterators.C:129
 testSt12MotifTypeIterators.C:130
 testSt12MotifTypeIterators.C:131
 testSt12MotifTypeIterators.C:132
 testSt12MotifTypeIterators.C:133
 testSt12MotifTypeIterators.C:134
 testSt12MotifTypeIterators.C:135
 testSt12MotifTypeIterators.C:136
 testSt12MotifTypeIterators.C:137
 testSt12MotifTypeIterators.C:138
 testSt12MotifTypeIterators.C:139
 testSt12MotifTypeIterators.C:140
 testSt12MotifTypeIterators.C:141
 testSt12MotifTypeIterators.C:142
 testSt12MotifTypeIterators.C:143
 testSt12MotifTypeIterators.C:144
 testSt12MotifTypeIterators.C:145
 testSt12MotifTypeIterators.C:146
 testSt12MotifTypeIterators.C:147
 testSt12MotifTypeIterators.C:148
 testSt12MotifTypeIterators.C:149