ROOT logo
#if !defined(__CINT__) || defined(__MAKECINT__)
  #include <TStopwatch.h>
  #include <TGrid.h>
  #include <TString.h>
  #include <TMath.h>

  #include "AliRawReader.h"
  #include "AliCaloRawStreamV3.h"
  #include "AliLog.h"
  #include "AliPHOSRawFitterv1.h"
  #include "AliCentralTrigger.h"
  #include "AliTriggerConfiguration.h"
  #include "AliTriggerClass.h"
  #include "AliCDBManager.h"
#endif

//-----------------------------------------------------------------------------
static Bool_t              firstEvent = kTRUE;
static Int_t               runNum;
static UInt_t              period;
static UInt_t              orbitID;
static UInt_t              bcID;
static AliRawReader       *reader;
TString GetTriggerClass(ULong64_t);

//-----------------------------------------------------------------------------
void ReadRawCaloTrigger(const TString fileName = "./", const TString calo="PHOS")
{

  if (fileName.BeginsWith("alien://")) {
    TGrid::Connect("alien://");
  }

  AliCDBManager *man = AliCDBManager::Instance();
  man->SetDefaultStorage("raw://");

  reader = AliRawReader::Create(fileName);
  reader ->Reset();
  AliCaloRawStreamV3 *stream = new AliCaloRawStreamV3(reader,calo);

  Int_t iev = 0;

  TStopwatch stopwatch;
  stopwatch.Start();
  Int_t    module,cellX,cellZ,caloFlag;

  while (reader->NextEvent()) {
    if (firstEvent) {
      firstEvent = kFALSE;
      runNum = reader->GetRunNumber();
      man = AliCDBManager::Instance();
      man ->SetRun(runNum);
    }
    ULong64_t triggerMask  = reader->GetClassMask();
    TString trclasses = GetTriggerClass(triggerMask);
    
    period  = reader->GetPeriod();
    orbitID = reader->GetOrbitID();
    bcID    = reader->GetBCID();
    iev++;
    if (!trclasses.Contains("CPHI1-B-NOPF-ALLNOTRD")) continue;

    AliInfoGeneral("",Form("Reading event %d of type %d, time %d, trig.class \"%s\"",
			   iev,reader->GetType(), reader->GetTimestamp(), trclasses.Data()));

    while (stream->NextDDL()) {
      while (stream->NextChannel()) {
	// Get geometry of the channel
	module   = stream->GetModule();
	cellX    = stream->GetCellX();
	cellZ    = stream->GetCellZ();
	caloFlag = stream->GetCaloFlag();

	Int_t nBunches = 0;
	while (stream->NextBunch()) {
	  const UShort_t *sig = stream->GetSignals();
	  Int_t sigLength = stream->GetBunchLength();
	  Int_t maxAmp  = 0;
	  for (Int_t i = 0; i < sigLength; i++) {
	    if (sig[i] >  maxAmp) {
	      maxAmp = sig[i];
	    }
	  }
	  printf("(m,x,z,c)=(%d,%2d,%2d,%d), bunch=%d, amplutide=%d\n",
		 module,cellX,cellZ,caloFlag,nBunches,maxAmp);
	  nBunches++;
	}
      }
    }
    stream->Reset();
  }
  stopwatch.Print();

}
//-----------------------------------------------------------------------------

TString GetTriggerClass(ULong64_t triggerMask)
{
  // Convert a trigger mask to a trigger class
  
  AliCentralTrigger aCTP;
  TString configstr("");
  TString trclasses;
  if (!aCTP.LoadConfiguration(configstr)) { // Load CTP config from OCDB
    AliInfoGeneral("","No trigger configuration found in OCDB! The trigger configuration information will not be used!");
    return trclasses;
  }
  aCTP.SetClassMask(triggerMask);
  AliTriggerConfiguration *config = aCTP.GetConfiguration();
  const TObjArray& classesArray = config->GetClasses();
  Int_t nclasses = classesArray.GetEntriesFast();
  for( Int_t iclass=0; iclass < nclasses; iclass++ ) {
    AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
    if (trclass && trclass->GetMask()>0) {
      Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
      reader->LoadTriggerClass(trclass->GetName(),trindex);
      if (triggerMask & (1ull << trindex)) {
	trclasses += " ";
	trclasses += trclass->GetName();
	trclasses += " ";
      }
    }
  }
  return trclasses;
}
 ReadRawCaloTrigger.C:1
 ReadRawCaloTrigger.C:2
 ReadRawCaloTrigger.C:3
 ReadRawCaloTrigger.C:4
 ReadRawCaloTrigger.C:5
 ReadRawCaloTrigger.C:6
 ReadRawCaloTrigger.C:7
 ReadRawCaloTrigger.C:8
 ReadRawCaloTrigger.C:9
 ReadRawCaloTrigger.C:10
 ReadRawCaloTrigger.C:11
 ReadRawCaloTrigger.C:12
 ReadRawCaloTrigger.C:13
 ReadRawCaloTrigger.C:14
 ReadRawCaloTrigger.C:15
 ReadRawCaloTrigger.C:16
 ReadRawCaloTrigger.C:17
 ReadRawCaloTrigger.C:18
 ReadRawCaloTrigger.C:19
 ReadRawCaloTrigger.C:20
 ReadRawCaloTrigger.C:21
 ReadRawCaloTrigger.C:22
 ReadRawCaloTrigger.C:23
 ReadRawCaloTrigger.C:24
 ReadRawCaloTrigger.C:25
 ReadRawCaloTrigger.C:26
 ReadRawCaloTrigger.C:27
 ReadRawCaloTrigger.C:28
 ReadRawCaloTrigger.C:29
 ReadRawCaloTrigger.C:30
 ReadRawCaloTrigger.C:31
 ReadRawCaloTrigger.C:32
 ReadRawCaloTrigger.C:33
 ReadRawCaloTrigger.C:34
 ReadRawCaloTrigger.C:35
 ReadRawCaloTrigger.C:36
 ReadRawCaloTrigger.C:37
 ReadRawCaloTrigger.C:38
 ReadRawCaloTrigger.C:39
 ReadRawCaloTrigger.C:40
 ReadRawCaloTrigger.C:41
 ReadRawCaloTrigger.C:42
 ReadRawCaloTrigger.C:43
 ReadRawCaloTrigger.C:44
 ReadRawCaloTrigger.C:45
 ReadRawCaloTrigger.C:46
 ReadRawCaloTrigger.C:47
 ReadRawCaloTrigger.C:48
 ReadRawCaloTrigger.C:49
 ReadRawCaloTrigger.C:50
 ReadRawCaloTrigger.C:51
 ReadRawCaloTrigger.C:52
 ReadRawCaloTrigger.C:53
 ReadRawCaloTrigger.C:54
 ReadRawCaloTrigger.C:55
 ReadRawCaloTrigger.C:56
 ReadRawCaloTrigger.C:57
 ReadRawCaloTrigger.C:58
 ReadRawCaloTrigger.C:59
 ReadRawCaloTrigger.C:60
 ReadRawCaloTrigger.C:61
 ReadRawCaloTrigger.C:62
 ReadRawCaloTrigger.C:63
 ReadRawCaloTrigger.C:64
 ReadRawCaloTrigger.C:65
 ReadRawCaloTrigger.C:66
 ReadRawCaloTrigger.C:67
 ReadRawCaloTrigger.C:68
 ReadRawCaloTrigger.C:69
 ReadRawCaloTrigger.C:70
 ReadRawCaloTrigger.C:71
 ReadRawCaloTrigger.C:72
 ReadRawCaloTrigger.C:73
 ReadRawCaloTrigger.C:74
 ReadRawCaloTrigger.C:75
 ReadRawCaloTrigger.C:76
 ReadRawCaloTrigger.C:77
 ReadRawCaloTrigger.C:78
 ReadRawCaloTrigger.C:79
 ReadRawCaloTrigger.C:80
 ReadRawCaloTrigger.C:81
 ReadRawCaloTrigger.C:82
 ReadRawCaloTrigger.C:83
 ReadRawCaloTrigger.C:84
 ReadRawCaloTrigger.C:85
 ReadRawCaloTrigger.C:86
 ReadRawCaloTrigger.C:87
 ReadRawCaloTrigger.C:88
 ReadRawCaloTrigger.C:89
 ReadRawCaloTrigger.C:90
 ReadRawCaloTrigger.C:91
 ReadRawCaloTrigger.C:92
 ReadRawCaloTrigger.C:93
 ReadRawCaloTrigger.C:94
 ReadRawCaloTrigger.C:95
 ReadRawCaloTrigger.C:96
 ReadRawCaloTrigger.C:97
 ReadRawCaloTrigger.C:98
 ReadRawCaloTrigger.C:99
 ReadRawCaloTrigger.C:100
 ReadRawCaloTrigger.C:101
 ReadRawCaloTrigger.C:102
 ReadRawCaloTrigger.C:103
 ReadRawCaloTrigger.C:104
 ReadRawCaloTrigger.C:105
 ReadRawCaloTrigger.C:106
 ReadRawCaloTrigger.C:107
 ReadRawCaloTrigger.C:108
 ReadRawCaloTrigger.C:109
 ReadRawCaloTrigger.C:110
 ReadRawCaloTrigger.C:111
 ReadRawCaloTrigger.C:112
 ReadRawCaloTrigger.C:113
 ReadRawCaloTrigger.C:114
 ReadRawCaloTrigger.C:115
 ReadRawCaloTrigger.C:116
 ReadRawCaloTrigger.C:117
 ReadRawCaloTrigger.C:118
 ReadRawCaloTrigger.C:119
 ReadRawCaloTrigger.C:120
 ReadRawCaloTrigger.C:121
 ReadRawCaloTrigger.C:122
 ReadRawCaloTrigger.C:123
 ReadRawCaloTrigger.C:124
 ReadRawCaloTrigger.C:125
 ReadRawCaloTrigger.C:126