Package for the SPD FO-uniformity-scan DA.
authormasera <masera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Feb 2009 10:48:41 +0000 (10:48 +0000)
committermasera <masera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Feb 2009 10:48:41 +0000 (10:48 +0000)
It is made up of ITSSPDFOda.cxx and the 5 classes, AliITSOnlineSPDfo,
AliITSOnlineSPDfoChip, AliITSOnlineSPDfoChipConfig, AliITSOnlineSPDfoInfo
and AliITSOnlineSPDfoAnalyzer.

-----------------------------------------------------------------------------
AliITSOnlineSPDfo :
It is a manager class that knows how to store data, how to read them and how to
manage them.

AliITSOnlineSPDfoChip (+AliITSOnlineSPDfoChipConfig):
It is the container class. It stores per each pixel configuration
inside the chip the corresponding FO output.

AliITSOnlineSPDfoInfo:
It stores the how the scan was arranged (number of dacs, their codes, number
of pulses, etc.)

AliITSOnlineSPDfoAnalyzer:
It is the class that analyzes the FO scan data to determine the more suitable
DAC values to have the best FO trigger efficiency.

Annalisa Mastroserio

14 files changed:
ITS/AliITSOnlineSPDfo.cxx [new file with mode: 0644]
ITS/AliITSOnlineSPDfo.h [new file with mode: 0644]
ITS/AliITSOnlineSPDfoAnalyzer.cxx [new file with mode: 0644]
ITS/AliITSOnlineSPDfoAnalyzer.h [new file with mode: 0644]
ITS/AliITSOnlineSPDfoChip.cxx [new file with mode: 0644]
ITS/AliITSOnlineSPDfoChip.h [new file with mode: 0644]
ITS/AliITSOnlineSPDfoChipConfig.cxx [new file with mode: 0644]
ITS/AliITSOnlineSPDfoChipConfig.h [new file with mode: 0644]
ITS/AliITSOnlineSPDfoInfo.cxx [new file with mode: 0644]
ITS/AliITSOnlineSPDfoInfo.h [new file with mode: 0644]
ITS/CMake_libITSrec.txt
ITS/ITSSPDfoda.cxx [new file with mode: 0644]
ITS/ITSrecLinkDef.h
ITS/libITSrec.pkg

diff --git a/ITS/AliITSOnlineSPDfo.cxx b/ITS/AliITSOnlineSPDfo.cxx
new file mode 100644 (file)
index 0000000..7ef678e
--- /dev/null
@@ -0,0 +1,364 @@
+/**************************************************************************
+ * Copyright(c) 2008-2010, 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$ */
+
+////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                     // 
+// This class is used within the detector algorithm framework //
+// to write and read FO scan data.                            //
+////////////////////////////////////////////////////////////////
+
+#include <TFile.h>
+#include <Riostream.h>
+#include <TSystem.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TArrayI.h>
+#include <TIterator.h>
+#include <TKey.h>
+#include <TMath.h>
+#include <TList.h>
+#include "AliLog.h"
+#include "AliITSOnlineSPDfoChipConfig.h"
+#include "AliITSOnlineSPDfoChip.h"
+#include "AliITSOnlineSPDfoInfo.h"
+#include "AliITSOnlineSPDfo.h"
+
+
+ClassImp(AliITSOnlineSPDfo)
+//-----------------------------------------------
+AliITSOnlineSPDfo::AliITSOnlineSPDfo():
+fRunNr(0),
+fNdacs(0),
+fFileName(""),
+fFile(0x0),
+fInfo(0x0),
+fDACnames(0x0),
+fArray(0x0),
+fCheckIndex(-1),
+fIndex(-1),
+fInitialConfiguration("")
+{
+// default constructor
+} 
+
+//-------------------------------------------------
+AliITSOnlineSPDfo::AliITSOnlineSPDfo(TString inputfile, Int_t runNr, Int_t eqId):
+fRunNr(runNr),
+fNdacs(0),
+fFileName(""),
+fFile(0x0),
+fInfo(0x0),
+fDACnames(0x0),
+fArray(0x0),
+fCheckIndex(-1),
+fIndex(-1),
+fInitialConfiguration("")
+{
+ //
+ // constructor 
+ //   
+    fFileName=Form("%i_%s%02i.root",runNr,inputfile.Data(),eqId);
+    fFile = TFile::Open(fFileName.Data());
+    fArray = new TObjArray();
+    fDACnames = new THashList();
+}
+//--------------------------------------------------
+AliITSOnlineSPDfo::AliITSOnlineSPDfo(const AliITSOnlineSPDfo &c):
+fRunNr(c.fRunNr),
+fNdacs(c.fNdacs),
+fFileName(c.fFileName),
+fFile(c.fFile),
+fInfo(c.fInfo),
+fDACnames(c.fDACnames),
+fArray(c.fArray),
+fCheckIndex(c.fCheckIndex),
+fIndex(c.fIndex),
+fInitialConfiguration(c.fInitialConfiguration)
+{
+  //
+  //copy constructor
+  //
+}    
+//--------------------------------------------------
+void AliITSOnlineSPDfo::SetFile(TString inputfile)
+{
+  //
+  // open the file where the data are
+  //
+  
+ if(fFile) {
+   fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo");
+   return; 
+ } else {
+   fFile = TFile::Open(inputfile.Data());
+   if(!fFile) {
+     Info("AliITSOnlineSPDfo::SetFile",Form(" %s  not existing.... The scan info are not available....crash is expected \n",inputfile.Data()));
+     return;
+    } else {
+     fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo");
+     fNdacs = fInfo->GetNumDACindex();
+   }
+}
+
+}
+
+//------------------------------------------------------
+void AliITSOnlineSPDfo::CreateOutputFile()
+{
+  //
+  // Create the file (needed only in the DA ), will delete the previous one!
+  //  
+  if(fFile) Info("AliITSOnlineSPDfo::CreateOutputFile","removing previous file....\n");
+   fFile = TFile::Open(fFileName.Data(),"RECREATE"); 
+  
+}
+//------------------------------------------------------
+void AliITSOnlineSPDfo::AddMeasurement(const TArrayS dac, Short_t measure[4], Int_t hs, Int_t chipId)
+{
+  /*
+  // Here a single measurement is added to the chip container. 
+  // A single measurement corresponds to a specific pixel-configuration output
+  // in the Fast-OR chip. If N configurations are considered, then
+  // the data structure is the following:
+  //
+  //                                          -> HS0_CHIP0 -> measure0[4]
+  //                                         /                measure1[4]
+  //                                        /                   ...
+  //  fArray->At(i) =  DAC1-DAC2-DAC3-DAC4                    measureN[4]
+  //                                        \
+  //                                         \ 
+  //                                          -> HS0_CHIP1 -> measure0[4]
+  //                                                          measure1[4]
+  //                                                             ....
+  //                                                          measureN[4]
+  //
+  */
+
+  AliITSOnlineSPDfoChipConfig *counts = new AliITSOnlineSPDfoChipConfig(measure);
+  Int_t arrayelement = CheckDACEntry(dac);
+  
+  if(arrayelement< 0){
+    TString dacname = CreateDACEntry(dac);
+    TObjString *string = new TObjString(dacname.Data());
+    fDACnames->Add(string);
+     
+    TObjArray *array = new TObjArray(60);
+    AliITSOnlineSPDfoChip * chip = new AliITSOnlineSPDfoChip(dac.GetSize());
+    chip->SetActiveHS(hs);
+    chip->SetChipId(chipId); 
+    for(Int_t i=0; i< dac.GetSize() ; i++) chip->SetDACParameter(i,dac.At(i));               
+    chip->AddMeasurement(counts);
+    array->AddAt(chip,hs*10+chipId);  
+    fArray->AddLast(array); 
+     
+  } else {
+    
+    TObjArray *arr = (TObjArray*)fArray->At(arrayelement);  
+    if(!arr->At(hs*10+chipId)){
+      AliITSOnlineSPDfoChip * chip = new AliITSOnlineSPDfoChip(dac.GetSize());
+      chip->SetActiveHS(hs);
+      chip->SetChipId(chipId); 
+      for(Int_t i=0; i< dac.GetSize() ; i++) chip->SetDACParameter(i,dac.At(i));               
+      chip->AddMeasurement(counts);
+      arr->AddAt(chip,hs*10+chipId);     
+      
+      } else {
+      
+      AliITSOnlineSPDfoChip *c = (AliITSOnlineSPDfoChip *)arr->At(hs*10+chipId);
+      if(c)c->AddMeasurement(counts);    
+    }   
+  }
+}
+//---------------------------------------
+Int_t AliITSOnlineSPDfo::CheckDACEntry(const TArrayS dac)
+{
+  //
+  // Check if the set of dacs has been already added to the array
+  // 
+  
+   
+  TString name = CreateDACEntry(dac);
+  
+  if(!fDACnames) {
+    Info("AliITSOnlineSPDfo::CheckDACEntry"," NO DAC name array is present, exiting.... \n");
+    return -1;
+  }
+  
+   Double_t c = 0;
+  for(Int_t i=0; i< fNdacs; i++)  c+=dac.At(i)*TMath::Power(10,3*i);
+  if(c==fCheckIndex) return fIndex;
+   
+  
+   Int_t idx = -1;
+   
+  if(fDACnames->FindObject( name.Data() )) {
+    idx = fDACnames->IndexOf( fDACnames->FindObject( name.Data() )  );
+    fCheckIndex=0;
+    for(Int_t i=0; i< fNdacs; i++) fCheckIndex+=dac.At(i)*TMath::Power(10,3*i);
+    fIndex=idx;
+
+  }
+  return idx;
+
+}
+//_________________________________________________________
+void AliITSOnlineSPDfo::WriteToFile()
+{
+  //
+  //The array of DACS and all its content is written to file.
+  // Here the general info on the FO calibration scan are 
+  // written in the same file
+  
+  if(fDACnames->GetEntries() != fArray->GetEntries()) {
+   printf("mismatch names-array. Exiting....");   
+    return;
+  }
+  
+  for(Int_t i=0; i< fDACnames->GetEntries(); i++){
+  fFile->WriteObject(fArray->At(i),fDACnames->At(i)->GetName());
+  }
+  fFile->WriteTObject(fInfo,"generalinfo"); 
+  fFile->Close();
+  
+}
+//______________________________________________________
+
+TString AliITSOnlineSPDfo::CreateDACEntry(const TArrayS dacs) const
+{
+  //
+  // The string of DACs is build
+  // 
+  
+  TString dacvalues;
+  for(Int_t i=0; i<dacs.GetSize(); i++) dacvalues+=Form("-%i",dacs.At(i));
+  dacvalues.Remove(0,1);
+  return dacvalues;
+}
+//_____________________________________________________
+TArrayI AliITSOnlineSPDfo::GetDACscanParams() const
+{ 
+  //
+  // this method retrieves the DAC value range and its steps
+  //
+  TFile *f =0x0;
+  if(fFile->IsOpen()) f = fFile;
+  else f = TFile::Open(fFileName.Data());
+  
+  TArrayI dacs;
+  if(f->GetNkeys() < 2) return dacs;
+  dacs.Set(fNdacs*3);
+  
+  TArrayI min(fNdacs), max(fNdacs),step(fNdacs), check(fNdacs), refvalues(fNdacs);
+  
+  for(Int_t i=0; i< fNdacs ; i++) {
+    min.AddAt(9999,i);
+    max.AddAt(0,i);
+    step.AddAt(0,i);
+    check.AddAt(0,i);
+  }
+  
+  
+  TKey *key;
+  TIter iter(f->GetListOfKeys());  
+  while ((key = (TKey*)(iter.Next()))) {
+    TString classname = key->GetClassName();
+    if(classname.Contains("OnlineSPD")) break;
+    
+    TString values = key->GetName();
+    Int_t *val = GetDACvalues(values,fNdacs); // the user has to delete it!
+      
+    for(Int_t i=0; i< fNdacs; i++) {
+      if(val[i]<=min.At(i)) min.AddAt(val[i],i);
+      if(val[i] >= max.At(i)) max.AddAt(val[i],i);
+      // procedure to get the step size;
+      if(!check.At(i)) { 
+       refvalues.AddAt(val[i],i);
+       check.AddAt(1,i);
+      }
+      if(step.At(i) ==0 && check.At(i)){
+        if(val[i]!=refvalues.At(i)) step.AddAt(TMath::Abs(refvalues.At(i) - val[i]),i);
+      }  
+      // end procedure to get the step size 
+    }   
+    delete [] val;
+  }
+
+  for(Int_t i=0; i<fNdacs; i++) {
+    dacs.AddAt(min.At(i),3*i);
+    dacs.AddAt(max.At(i),3*i+1);
+    dacs.AddAt(step.At(i),3*i+2); 
+  }
+  
+  return dacs;     
+}
+//___________________________________________________________________
+Int_t* AliITSOnlineSPDfo::GetDACvalues(TString s, const Int_t ndacs) const
+{
+  //
+  // Translates the string of DACS values into an array of integers
+  //
+  
+   Int_t *val = new Int_t[ndacs]; 
+   
+   s.ReplaceAll("-"," ");
+   char *pEnd = Form("%s",s.Data());
+   for(Int_t i=0; i< ndacs; i++) {
+     val[i] = strtol(pEnd,&pEnd,10); // conversion from string to long
+   }  
+   return val;   
+}
+
+//___________________________________________________________________
+Double_t* AliITSOnlineSPDfo::GetDACvaluesD(TString s, const Int_t ndacs) const 
+{  
+  //
+  // Translates the string of DACS values into an array of doubles
+  // (needed to fill the thnsparse)
+  //
+   Double_t *val = new Double_t[ndacs];
+   Int_t *values =  GetDACvalues(s,ndacs);
+   for(Int_t i=0; i< ndacs; i++) val[i] = (Double_t)values[i];
+   delete [] values;
+   
+   return val;   
+}
+//-------------------------------------------------------------------
+TArrayS AliITSOnlineSPDfo::CreateDACArray(const TArrayS dacs, const TArrayS dacId) const
+{
+  //
+  // method to order the data according to the DAC index
+  //
+  
+  TArrayS dacarray(dacs.GetSize());
+  for(Int_t i=0; i<dacs.GetSize(); i++) {
+    if(dacId.At(i)==kIdFOPOL) dacarray.AddAt(dacs.At(i),kFOPOL);
+    else if(dacId.At(i)==kIdCONVPOL) dacarray.AddAt(dacs.At(i),kCONVPOL);
+    else if(dacId.At(i)==kIdCOMPREF) dacarray.AddAt(dacs.At(i),kCOMPREF);
+    else if(dacId.At(i)==kIdPreVTH) dacarray.AddAt(dacs.At(i),kPreVTH);
+    else dacarray.AddAt(dacs.At(i),i);
+    
+  }
+  return dacarray;
+  
+}
+  
+  
diff --git a/ITS/AliITSOnlineSPDfo.h b/ITS/AliITSOnlineSPDfo.h
new file mode 100644 (file)
index 0000000..d126244
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef ALIITSONLINESPDFO_H
+#define ALIITSONLINESPDFO_H  
+/* Copyright(c) 2008-2010, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                     // 
+// This class is used within the detector algorithm framework //
+// to write and read FO scan data.                            //
+////////////////////////////////////////////////////////////////
+
+#include <TString.h>
+#include <THashList.h>
+
+class TFile;
+class TArrayS;
+class AliITSOnlineSPDfoInfo;
+
+class AliITSOnlineSPDfo {
+
+ public:
+  AliITSOnlineSPDfo();//ctor
+  AliITSOnlineSPDfo(TString inputfile, Int_t runNr, Int_t eqId); 
+  AliITSOnlineSPDfo(const AliITSOnlineSPDfo &c);
+  
+  virtual ~AliITSOnlineSPDfo(){ delete fArray; delete fDACnames;} //dctor
+  enum {kFOPOL=0, kCONVPOL=1, kCOMPREF=2, kPreVTH=3, kIdFOPOL=20, kIdCONVPOL=17, kIdCOMPREF=16, kIdPreVTH=39};
+  
+  // GENERAL METHODS
+  void    AddMeasurement(const TArrayS dac, Short_t measure[3], Int_t hs, Int_t chipId);
+  Int_t   CheckDACEntry(const TArrayS dac);
+  TString CreateDACEntry(const TArrayS dacs) const;
+  TArrayS CreateDACArray(const TArrayS dacs, const TArrayS dacId) const;
+  void    CreateOutputFile(); 
+  void    WriteToFile();
+  
+  // SETTER
+ void SetNdacs(UInt_t ndacs) {fNdacs=ndacs;}
+ void SetFOscanParams(AliITSOnlineSPDfoInfo *info) {fInfo=info;}
+ void SetFile(TString inputfile);
+ void SetDACArray(TObjArray *obj) {if(!fArray) fArray = obj; else printf("The fArray is alreay available, no need to set it again.\n");}
+ // GETTER 
+  TFile* GetFile()   const           {return fFile;}
+  UInt_t GetNdacs()  const           {return fNdacs;}
+  
+  TObjArray *GetDACArray() const     {return fArray;}
+  THashList * GetDACnameList() const {return fDACnames;}
+  
+  TArrayI GetDACscanParams() const;                               // retrieves per each DAC the range and the step used in the scan 
+  AliITSOnlineSPDfoInfo * GetFOscanInfo() const {return fInfo;}
+  Int_t *GetDACvalues(TString s, const Int_t ndacs) const;        // translates the string in the corresponding DACS                                                      // the user has to delete the pointer after use!
+  Double_t *GetDACvaluesD(TString s, const Int_t ndacs) const;    // translates the string in the corresponding DACS
+  
+
+ protected:
+ Int_t fRunNr;
+ Int_t fNdacs;
+ TString fFileName;
+ TFile *fFile; 
+ AliITSOnlineSPDfoInfo *fInfo;
+ THashList *fDACnames;
+ TObjArray *fArray;               // array of the 10 chips in the 6 HS per DAC set
+ Double_t fCheckIndex;            // check array index (to speed up)
+ Int_t fIndex; 
+ TString fInitialConfiguration;
+  
+  private:
+  AliITSOnlineSPDfo& operator= (const AliITSOnlineSPDfo& c);
+  
+    ClassDef(AliITSOnlineSPDfo,1)
+  };
+    
+#endif
diff --git a/ITS/AliITSOnlineSPDfoAnalyzer.cxx b/ITS/AliITSOnlineSPDfoAnalyzer.cxx
new file mode 100644 (file)
index 0000000..a8ca392
--- /dev/null
@@ -0,0 +1,567 @@
+/**************************************************************************
+ * Copyright(c) 2008-2010, 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$ */
+
+////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                 //
+// This class is used in the detector algorithm framework //
+// to process the data stored in special container files  //
+// (see AliITSOnlineSPDfo). The "good" set of DAC values  //
+// is extracted.                                          //
+////////////////////////////////////////////////////////////
+
+#include <TFile.h>
+#include <TMath.h>
+#include <TString.h>
+#include <TStyle.h>
+#include <TF1.h>
+#include <TH1D.h>
+#include <TH2D.h>
+#include <TArrayI.h>
+#include <TCanvas.h>
+#include <THnSparse.h>
+#include <TKey.h>
+#include <iostream>
+#include <fstream>
+#include "AliITSOnlineSPDfoChipConfig.h"
+#include "AliITSOnlineSPDfoChip.h"
+#include "AliITSOnlineSPDfoInfo.h"
+#include "AliITSOnlineSPDfo.h"
+#include "AliITSOnlineSPDfoAnalyzer.h"
+#include "AliLog.h"
+
+AliITSOnlineSPDfoAnalyzer::AliITSOnlineSPDfoAnalyzer(const TString fileName, Bool_t readFromGridFile) :
+  fFileName(0),
+  fNdims(0),
+  fNbins(0x0),
+  fXmin(0x0),
+  fXmax(0x0),
+  fFOHandler(0x0),
+  fHighOccupancyCheck(kTRUE)
+{
+  // constructor
+  fFileName = fileName;
+  for(Int_t iqual =0; iqual<kNqualityFlags; iqual++) fGeneralThresholds[iqual]=0;
+  
+  for (UInt_t chipNr=0; chipNr<10; chipNr++) {
+    for (UInt_t hs=0; hs<6; hs++) {
+      for(Int_t i =0; i< kNqualityFlags; i++) fNh[i][hs][chipNr]=NULL;
+    }
+  }
+  
+  Init(readFromGridFile); 
+}
+//-------------------------------------------------------------------
+AliITSOnlineSPDfoAnalyzer::AliITSOnlineSPDfoAnalyzer(const AliITSOnlineSPDfoAnalyzer& foan) :
+  fFileName(foan.fFileName),
+  fNdims(foan.fNdims),
+  fNbins(foan.fNbins),
+  fXmin(foan.fXmin),
+  fXmax(foan.fXmax),
+  fFOHandler(foan.fFOHandler),
+  fHighOccupancyCheck(foan.fHighOccupancyCheck)
+{
+  //
+  // copy constructor, only copies the filename and params (not the processed data
+  //
+  
+  for(Int_t iqual =0; iqual<3; iqual++) fGeneralThresholds[iqual] =foan.fGeneralThresholds[iqual];
+  for (UInt_t chipNr=0; chipNr<11; chipNr++) {
+    for (UInt_t hs=0; hs<6; hs++) {
+      for(Int_t i=0; i<kNqualityFlags;i++) fNh[i][hs][chipNr]=NULL;
+    }
+  }
+  
+  Init();
+}
+//-------------------------------------------------------------------
+AliITSOnlineSPDfoAnalyzer::~AliITSOnlineSPDfoAnalyzer() 
+{
+  //
+  // destructor
+  // 
+  
+  for (UInt_t hs=0; hs<6; hs++) {
+    for (UInt_t chipNr=0; chipNr<11; chipNr++) {
+      for(Int_t i=0; i<kNqualityFlags ; i++ ) if(fNh[i][hs][chipNr]!=NULL) delete fNh[i][hs][chipNr];          
+    }
+  }
+  delete fFOHandler;
+}
+//-------------------------------------------------------------------
+AliITSOnlineSPDfoAnalyzer& AliITSOnlineSPDfoAnalyzer::operator=(const AliITSOnlineSPDfoAnalyzer& foan) 
+{
+  // assignment operator, only copies the filename and params (not the processed data)
+  if (this!=&foan) {
+    for (UInt_t hs=0; hs<6; hs++) {
+      for (UInt_t chipNr=0; chipNr<11; chipNr++) {
+       for(Int_t i=0; i<kNqualityFlags ; i++ ) if(fNh[i][hs][chipNr]!=NULL) delete fNh[i][hs][chipNr];
+      }
+    }
+    
+    fFileName=foan.fFileName;
+    fHighOccupancyCheck=foan.fHighOccupancyCheck;
+    Init();    
+  }
+  return *this;
+}
+//-------------------------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::Init(Bool_t readFromGridFile) 
+{
+  //
+  // first checks type of container and then initializes container obj
+  //
+  if (!readFromGridFile) {
+    TFile* p0 = TFile::Open(fFileName.Data());
+    if (p0 == NULL) {
+      printf("no file open!"); 
+      return;
+    }
+    else { 
+      fFOHandler = new AliITSOnlineSPDfo();
+      fFOHandler->SetFile(fFileName);
+    }
+    p0->Close();   
+  }
+}
+//-------------------------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::SetGeneralThresholds(Float_t thre[3])
+{
+  // here the settings for the 3 quality flags are defined
+  for(Int_t i=0; i< 3; i++) fGeneralThresholds[i]=thre[i];  
+}
+//-------------------------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::SetNdimensions()
+{
+  //
+  // here the axis of the N-dim histograms are setted 
+  // 
+  if(!fFOHandler) {
+    printf("no fo object. Exiting...\n"); 
+    return;
+  }
+  
+  TArrayI array = fFOHandler->GetDACscanParams();
+  fNdims = array.GetSize()/3;
+  fNbins = new Int_t[fNdims];
+  fXmin = new Double_t[fNdims];
+  fXmax = new Double_t[fNdims];
+  for(Int_t i=0; i< fNdims; i++){
+    fXmin[i] = array.At(3*i)-0.25;
+    fXmax[i] = array.At(3*i+1)+0.25;
+    fNbins[i] = (Int_t)((fXmax[i]-fXmin[i])/0.5)+1;//to avoid Int->Double conversion problems when checking results. 
+  } 
+}
+//-------------------------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::BuildTHnSparse(Int_t ihs, Int_t ichip)
+{
+  //
+  // here the N-dim histogram is booked per chip in one HS 
+  //
+  
+  if(!fNdims) SetNdimensions();
+  
+  for(Int_t iqual =0; iqual < 3; iqual++) fNh[iqual][ihs][ichip] = new THnSparseI(Form("h%i_HS%i_C%i",iqual,ihs,ichip), Form("h%i_HS%i_C%i",iqual,ihs,ichip), fNdims, fNbins, fXmin, fXmax);
+}
+//-------------------------------------------------------------------
+Int_t AliITSOnlineSPDfoAnalyzer::Select(const AliITSOnlineSPDfoChip *chip) const
+{
+  //
+  // Selects the DAC values if in the chip: the I configuration corresponds to
+  // 0% efficiency ( no FO response case). All the others shoud be within the 
+  // predefined thresholds
+  
+  if(!fFOHandler->GetFOscanInfo()) {
+    printf("no general information object in the file. Exiting...\n");
+    return -1;
+  }
+  
+  Double_t npulses = (fFOHandler->GetFOscanInfo())->GetNumTriggers();
+  
+  if(npulses == 0. ) {
+    Info("AliITSOnlineSPDfoAnalyzer::Select","no trigger pulses set. Exiting...");
+    return -999;
+  } 
+  
+  TObjArray *array = chip->GetChipConfigInfo();
+  if(!array) {
+    printf("No measurement array found in the chip!!\n");
+    return 0;
+  }
+  
+  Int_t quality = -1;
+  
+  Float_t counts = 0;
+  
+  Int_t processedconfigurations = chip->GetNumberOfChipConfigs();
+  if(fHighOccupancyCheck) processedconfigurations-=1;
+  
+  for(Int_t isteps =0; isteps < processedconfigurations; isteps++){ 
+    
+    Int_t matrixId = ((AliITSOnlineSPDfoChipConfig*)array->At(isteps))->GetChipConfigMatrixId();
+    counts = (Float_t)(((AliITSOnlineSPDfoChipConfig*)array->At(isteps))->GetChipConfigCounter());
+    
+    if(matrixId==0 && counts > 0) return -1;
+    
+    Float_t efficiency = counts/npulses;
+    
+    if(isteps > 0){
+      Int_t response = IsSelected(efficiency);
+      if( response >=0) {
+       if(quality < response) quality = response;
+      }
+      else return -1; 
+    }
+  }
+  return quality;
+}
+//-----------------------------------------------------
+Int_t AliITSOnlineSPDfoAnalyzer::IsSelected(Float_t eff) const
+{
+  //
+  // returns the quality of the selection 
+  //
+  for(Int_t i=0; i<3; i++){   
+    if(eff <= 1.+ fGeneralThresholds[i] && eff >= 1. - fGeneralThresholds[i]  ) return i;
+  }
+  return -1;
+}
+//----------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::Process()
+{ 
+  //
+  // The procedure is the following:
+  // - DAC 4-tuples are checked  
+  // - if the 4-tuple survives the selection, the chip-related histograms are filled.
+  // (- Per each histogram the mean values of each axis are taken)
+  //
+  if(!fFOHandler) { 
+    Warning("AliITSOnlineSPDfoAnalyzer::Process","no fo object. Exiting.. \n");
+    return;
+  } 
+  
+  TKey *key;
+  Double_t *dacvalues;
+  
+  TIter iter((fFOHandler->GetFile())->GetListOfKeys());  
+  while ((key = (TKey*)(iter.Next()))) {
+    TString classname = key->GetClassName();
+    if(classname.Contains("OnlineSPD")) break;
+    
+    TObjArray *array = (TObjArray*)(fFOHandler->GetFile())->Get(key->GetName()); // array of chips corresponding to the DACS (size 1-60)
+    if(!array){
+      printf("no array found! Exiting...");
+      break; 
+    }
+    
+    dacvalues = fFOHandler->GetDACvaluesD(key->GetName(), GetFOHandler()->GetFOscanInfo()->GetNumDACindex());
+    
+    for(Int_t i=0; i< array->GetSize(); i++){
+      AliITSOnlineSPDfoChip *chip = (AliITSOnlineSPDfoChip *)array->At(i);     
+      if(!chip) continue;
+      Int_t hs = chip->GetActiveHS();
+      Int_t chipid = chip->GetChipId();     
+      Int_t quality = Select(chip);
+      if(quality<0) continue; 
+      if(!fNh[quality][hs][chipid]) BuildTHnSparse(hs,chipid);
+      fNh[quality][hs][chipid]->Fill(dacvalues);       
+    } 
+  } 
+}
+//---------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::WriteToFile(TString outputfile)
+{
+  //
+  // The 4-dim histograms are stored into a file
+  //
+  
+  TFile * f = TFile::Open(outputfile.Data(),"recreate");
+  for(Int_t ihs =0; ihs < 6; ihs++) {
+    for(Int_t ichip =0; ichip < 10; ichip++){
+      for(Int_t i=0; i<kNqualityFlags ; i++ ) if(fNh[i][ihs][ichip]) f->WriteObjectAny(fNh[i][ihs][ichip],"THnSparse",Form("h%i_hs%i_chip%i",i,ihs,ichip));
+    }
+  }
+  f->Close();
+}
+//---------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::CheckResults(TString filename, Int_t hs, Int_t ichip, Int_t iqual) const
+{
+  //  
+  //The chip related 4-dim histograms are produced and stored into eps files
+  //    
+  
+  TFile *f = TFile::Open(filename.Data());
+  if(!f) {
+    Info("AliITSOnlineSPDfoAnalyzer::CehckResults","no file open!. Exiting...\n");
+    return; 
+  }
+  
+  THnSparse *hn;
+  TObject *obj;
+  
+  TIter iter(f->GetListOfKeys());
+  while((obj=iter.Next())){
+    TString name = obj->GetName();
+    hn=(THnSparse*)f->Get(name.Data()); 
+    if(name.Contains(Form("hs%i",hs)) && name.Contains(Form("chip%i",ichip)) && name.Contains(Form("h%i",iqual))) GetCanvases(hn,hs,ichip,iqual);
+  } 
+}
+//-----------------------------------------------------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::GetCanvases(const THnSparse *hn,Int_t hs, Int_t chip, Int_t iqual) const
+{
+  //
+  // 1-Dim and 2 Dim Projections of 4-dim histograms are visualized in canvases per quality selection
+  //
+  //
+  
+  if(!hn) {printf("no thnsparse...exiting!"); return;} 
+  
+  gStyle->SetPalette(1);
+  
+  TString dacname[4];
+  
+  if(  (fFOHandler->GetFOscanInfo())->GetDACindex(0) == 20 ) dacname[0] = "FOPOL";
+  else dacname[0] = "possible DAC-name/ DAC-register-number mismatch";  
+  if(  (fFOHandler->GetFOscanInfo())->GetDACindex(1) == 17 ) dacname[1] = "CONVPOL";
+  else dacname[1] = "possible DAC-name/ DAC-register-number mismatch";
+  if(  (fFOHandler->GetFOscanInfo())->GetDACindex(2) == 16 ) dacname[2] = "COMPREF";
+  else dacname[2] = "possible DAC-name/ DAC-register-number mismatch";
+  if(  (fFOHandler->GetFOscanInfo())->GetDACindex(3) == 39 ) dacname[3] = "pre_VTH";
+  else dacname[3] = "possible DAC-name/ DAC-register-number mismatch";
+  
+  TString titles = Form("|eff-1| <= %f   for CHIP %i  in HS  %i",fGeneralThresholds[iqual],hs,chip);
+  TCanvas *c[3];
+  
+  for(Int_t i=0; i<2; i++) {
+    c[i] = new TCanvas(Form("c%i",i+1),Form(" %i DIM plots. %s ",i+1,titles.Data()),1200,800); 
+    c[i]->Divide(2,2);
+  }
+  
+  
+  for(Int_t idim =0; idim<2; idim++){
+    for(Int_t k=1; k<5; k++){
+      c[idim]->cd(k);
+      
+      TH1D *h1 =0x0;
+      TH2D *h2=0x0;       
+      if(idim == 0) {
+        h1 = hn->Projection(k-1);
+        if(!h1) printf("no histogram!!...\n\n\n");
+        h1->SetXTitle(Form("DAC %i  ( %s )",k-1,dacname[k-1].Data()));
+        h1->SetYTitle("entries (eff within thresholds)");
+        h1->Draw();
+      } 
+      
+      if(idim==1) {      
+        if(k<4){
+          h2  = hn->Projection(k-1,k);
+          h2->SetXTitle(Form("DAC %i ( %s )",k,dacname[k].Data())); h2->SetYTitle(Form("DAC %i  ( %s )",k-1,dacname[k-1].Data()));
+          h2->SetTitleOffset(2,"Y"); h2->SetTitleOffset(1.5,"X");
+       } else {
+         h2 = hn->Projection(0,3);
+         h2->SetXTitle(Form("DAC %i ( %s )",3,dacname[3].Data())); h2->SetYTitle(Form("DAC %i  ( %s )",0, dacname[0].Data()));
+         h2->SetTitleOffset(2,"Y"); h2->SetTitleOffset(1.5,"X"); 
+       }    
+       
+        h2->Draw("lego2");
+      }  
+    }// k loop
+    
+    c[idim]->SaveAs(Form("c%iDIM_%i_%i_%i.eps",idim,iqual,hs,chip));   
+  }// idim loop  
+}
+//-----------------------------------------------------
+TArrayI AliITSOnlineSPDfoAnalyzer::ChooseDACValues(Int_t hs, Int_t chip) const
+{
+  //
+  // here the "best" 4 dacs are chosen. The most present are taken. 
+  // If the n-tuple does not correspond to a meaningful entry, the
+  // closest value to the mean point in the n-dimensional histogram
+  // is taken.
+  
+  TH1D *h=0x0; 
+  TArrayI dacs(fNdims+1);
+  
+  for(Int_t i=0; i<fNdims+1; i++) dacs.AddAt(-1,i);
+  
+  for(Int_t iqual =0; iqual < kNqualityFlags; iqual++){
+    if(!fNh[iqual][hs][chip]) continue;    
+    if(fNh[iqual][hs][chip]->GetEntries()==0) continue;
+    for(Int_t idim =0; idim<fNdims; idim++){
+      if(dacs.At(idim)>=0) continue;
+      h = fNh[iqual][hs][chip]->Projection(idim); 
+      dacs.AddAt((Int_t)h->GetBinLowEdge(h->GetMaximumBin()+1),idim);
+      Int_t bin=-1;
+      if(idim == fFOHandler->kPreVTH && CorrectPreVTHChioce(h,bin) ) {
+       dacs.AddAt((Int_t)h->GetBinLowEdge(bin+1),idim);  
+      }     
+      dacs.AddAt(iqual,fNdims);
+    }//idim
+  }//iqual
+  
+  if(!IsExisting(dacs,hs,chip)  && dacs.At(fNdims)>-1) {   
+    TArrayI centraldacs = GetCentralDACS(dacs.At(fNdims),hs,chip,h);
+    dacs = centraldacs;
+  }
+  return dacs; 
+}
+//_____________________________________________________
+Bool_t AliITSOnlineSPDfoAnalyzer::IsExisting(TArrayI dacs,Int_t hs, Int_t chip) const
+{
+  //
+  // check the N-tuple corresponds to a real one
+  //  
+  
+  if(dacs.At(fNdims)<0) return kFALSE;
+  Bool_t isOk = kFALSE;
+  
+  Int_t size = dacs.GetSize()-1;
+  Double_t *entry = new Double_t[size];
+  for(Int_t i=0; i<size; i++) entry[i] = dacs.At(i);
+  Int_t checkbin = fNh[dacs.At(dacs.GetSize()-1)][hs][chip]->GetBin(entry,kFALSE); // kFALSE does not allocate another bin
+  if(checkbin > -1) isOk = kTRUE;
+  delete entry;
+  return isOk; 
+}
+//-----------------------------------------------------------
+TArrayI AliITSOnlineSPDfoAnalyzer::GetCentralDACS(Int_t qualityflag, Int_t hs, Int_t chip, const TH1D *hd) const
+{
+  //
+  // This method gets the DAC values which are closest to the mean point in the N-dim histogram
+  // It is called when the most probable DAC set does not correspond to a real entry in the N-dim
+  // histogram.
+  //
+  TArrayI dacs(fNdims+1);
+   
+  Double_t *mean=new Double_t[fNdims];
+  Int_t *goodbins=new Int_t[fNdims];
+  Double_t distance = 99999;
+  for(Int_t i=0; i<fNdims ;i++){ 
+    mean[i]=hd->GetMean();
+    goodbins[i]=0;
+    dacs.AddAt(-1,i);
+  }
+  
+  Int_t *bins = new Int_t[fNdims];
+  Double_t *val=new Double_t[fNdims];
+  
+  for(Int_t in=0; in< fNh[qualityflag][hs][chip]->GetNbins() ; in++){
+    
+    fNh[qualityflag][hs][chip]->GetBinContent(in,bins);
+    Double_t r2 = 0;  
+    for(Int_t j=0; j<fNdims; j++) {
+      val[j]=hd->GetBinCenter(bins[j]);
+      r2+=TMath::Power(val[j]-mean[j],2);
+    }
+    
+    if(r2<distance) {
+      distance = r2;
+      fNh[qualityflag][hs][chip]->GetBinContent(in,goodbins);
+    }    
+  }
+  
+  for(Int_t k=0; k<fNdims; k++) {
+    Int_t a = (Int_t)( hd->GetBinCenter(goodbins[k]) + 0.5 *hd->GetBinWidth(goodbins[k]) ); 
+    dacs.AddAt(a,k);  
+  }
+  dacs.AddAt(qualityflag,fNdims);
+  
+  delete mean;
+  delete goodbins;
+  delete bins;
+  delete val;
+  return dacs;
+}
+//-------------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::ReadParamsFromLocation(const Char_t *dirName) 
+{
+  //
+  // opens file (default name) in dir dirName and reads parameters from it
+  // The file should be in database
+  //
+  
+  TString paramsFileName = Form("./%s/focalib_params.txt",dirName);
+  
+  ifstream paramsFile;
+  paramsFile.open(paramsFileName, ifstream::in);
+  if (paramsFile.fail()) {
+    printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
+  }
+  else {
+    while(1) {
+      Char_t paramN[50];
+      Char_t paramV[50];
+      paramsFile >> paramN;
+      if (paramsFile.eof()) break;
+      paramsFile >> paramV;
+      SetParam(paramN,paramV);
+      if (paramsFile.eof()) break;
+    }
+    paramsFile.close();
+  }
+}
+//---------------------------------------------------------
+void AliITSOnlineSPDfoAnalyzer::SetParam(const Char_t *pname, const Char_t *pval) 
+{
+  //
+  // sets a single parameter when reading from a file in the database
+  //
+  
+  TString name = pname;
+  TString val = pval;
+  
+  
+  if (name.CompareTo("fGeneralThresholds0")==0) {
+    fGeneralThresholds[0] = val.Atof();
+  }
+  else if (name.CompareTo("fGeneralThresholds1")==0) {
+    fGeneralThresholds[1] = val.Atof();
+  }
+  else if (name.CompareTo("fGeneralThresholds2")==0) {
+    fGeneralThresholds[2] = val.Atof();
+  }
+  else {
+    Error("AliITSOnlineSPDscanAnalyzer::SetParam","Parameter %s in configuration file unknown.",name.Data());
+  }
+}
+//--------------------------------------------------------
+Bool_t AliITSOnlineSPDfoAnalyzer::CorrectPreVTHChioce(const TH1D *h,Int_t &bin) const
+{
+  //
+  // Checks if more maxima of the same height are present in the pre_VTH case
+  //
+  
+  Int_t counts =0;
+  Int_t bins[10]={0,0,0,0,0,0,0,0,0,0};
+  Int_t binindex=0;
+  Bool_t check=kFALSE;
+
+  for(Int_t i=0; i<= h->GetNbinsX(); i++){    
+    if(h->GetBinContent(i) == h->GetMaximum() || h->GetBinContent(i) == h->GetMaximum()-1) {
+      counts++;
+      bins[binindex]=i;
+      binindex++;
+    }
+  }
+  
+  if(counts>1) {
+    bin=bins[binindex-1];
+    check = kTRUE; 
+  }
+  return check; 
+}
+
diff --git a/ITS/AliITSOnlineSPDfoAnalyzer.h b/ITS/AliITSOnlineSPDfoAnalyzer.h
new file mode 100644 (file)
index 0000000..cf129d2
--- /dev/null
@@ -0,0 +1,66 @@
+#ifndef ALIITSONLINESPDFOANALYZER_H
+#define ALIITSONLINESPDFOANALYZER_H
+/* Copyright(c) 2008-2010, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                     // 
+// This class is used within the detector algorithm framework //
+// to analyze FO scan data. It intends to find the best DAC   //
+// values to get the best FO trigger efficiency               //
+////////////////////////////////////////////////////////////////
+
+class THnSparse;
+class TObject;
+class TArrayI;
+class AliITSOnlineSPDfo;
+class AliITSOnlineSPDfoInfo;
+
+class AliITSOnlineSPDfoAnalyzer {
+  
+ public:
+  AliITSOnlineSPDfoAnalyzer(const TString fileName,  Bool_t readFromGridFile=kFALSE);
+  AliITSOnlineSPDfoAnalyzer(const AliITSOnlineSPDfoAnalyzer& foan);
+  ~AliITSOnlineSPDfoAnalyzer();
+  
+  AliITSOnlineSPDfoAnalyzer& operator=(const AliITSOnlineSPDfoAnalyzer& handle);
+  
+  void       Init(Bool_t readFromGridFile=kFALSE);     
+  
+  enum {kNqualityFlags=3};
+  
+  void ReadParamsFromLocation(const Char_t* dirName);
+  Int_t IsSelected(Float_t eff) const;                  // selection quality (0 = best, 1 tight, 2 loose)
+  Int_t Select(const AliITSOnlineSPDfoChip *chip) const;
+  void WriteToFile(TString outputfile);
+  Bool_t IsExisting(TArrayI dacs,Int_t hs, Int_t chip) const;
+  Bool_t CorrectPreVTHChioce(const TH1D *h,Int_t &bin) const;
+  
+  // SETTERS
+  void SetGeneralThresholds(Float_t thre[3]); 
+  void SetParam(const Char_t *pname, const Char_t *pval);
+  void SetNdimensions();
+  void BuildTHnSparse(Int_t ihs, Int_t ichip);
+  void Process();
+  void CheckResults(TString filename, Int_t hs, Int_t ichip, Int_t iqual) const;
+  
+  // GETTERS
+  void GetCanvases(const THnSparse *hn, Int_t ihs, Int_t ichip,Int_t iqual) const;
+  TArrayI ChooseDACValues(Int_t ihs, Int_t ichip) const;
+  TArrayI GetCentralDACS(Int_t qualityflag, Int_t hs, Int_t chip, const TH1D *hd) const;
+  AliITSOnlineSPDfo * GetFOHandler() const {return fFOHandler;}
+  
+ private:
+  TString fFileName;
+  Int_t fNdims; // number of dimensions of the histogram (= #DACs in the scan)
+  Int_t *fNbins; //[fNdims]  
+  Double_t *fXmin; //[fNdims]
+  Double_t *fXmax; //[fNdims]  
+  AliITSOnlineSPDfo *fFOHandler;
+  Float_t fGeneralThresholds[3];
+  THnSparse *fNh[3][6][10];      // N-dim histo per chip per half sector per quality flag [0= exact, 1 = within 0.01, 2 = within 0.05]
+  Bool_t fHighOccupancyCheck;
+};
+
+#endif
diff --git a/ITS/AliITSOnlineSPDfoChip.cxx b/ITS/AliITSOnlineSPDfoChip.cxx
new file mode 100644 (file)
index 0000000..f0e6fdf
--- /dev/null
@@ -0,0 +1,109 @@
+/**************************************************************************
+ * Copyright(c) 2008-2010, 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$ */
+
+/////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                      //
+// This class is used as a container for the FO scan           //
+//                                                             //
+/////////////////////////////////////////////////////////////////
+
+
+#include <TObjArray.h>
+#include "AliITSOnlineSPDfoChipConfig.h"
+#include "AliITSOnlineSPDfoChip.h"
+
+ClassImp(AliITSOnlineSPDfoChip)
+//-----------------------------------------------
+AliITSOnlineSPDfoChip::AliITSOnlineSPDfoChip():
+TObject(),
+fActiveHS(0),
+fChipId(0),
+fNumDACparams(0),
+fNumChipConfigs(0),
+fDACparams(0x0),
+fChipConfigArray(0x0)
+{
+// default constructor
+} 
+
+//-------------------------------------------------
+AliITSOnlineSPDfoChip::AliITSOnlineSPDfoChip(Short_t nparams):
+TObject(),
+fActiveHS(0),
+fChipId(0),
+fNumDACparams(nparams),
+fNumChipConfigs(0),
+fDACparams(0x0),
+fChipConfigArray(0x0)
+{
+ //
+ // constructor 
+ //
+  fDACparams = new Short_t[fNumDACparams];
+  fChipConfigArray = new TObjArray(); //starting with no objects, then adding...
+}
+//--------------------------------------------------
+
+AliITSOnlineSPDfoChip::AliITSOnlineSPDfoChip(const AliITSOnlineSPDfoChip &c):
+TObject(c),
+fActiveHS(c.fActiveHS),
+fChipId(c.fChipId),
+fNumDACparams(c.fNumDACparams),
+fNumChipConfigs(c.fNumChipConfigs),
+fDACparams(0x0),
+fChipConfigArray(0x0)
+{
+  //
+  //copy constructor 
+  // fChipConfigArray is not copied. This method is private
+  //
+
+  for(Int_t iPar =0; iPar < fNumDACparams; iPar++) fDACparams[iPar] = c.fDACparams[iPar]; 
+}    
+//--------------------------------------------------
+AliITSOnlineSPDfoChip::~AliITSOnlineSPDfoChip()
+{
+ // dctor
+  
+   fChipConfigArray->SetOwner(kTRUE);
+   fChipConfigArray->Clear();
+   delete fChipConfigArray;
+   delete [] fDACparams;
+}
+//--------------------------------------------------
+void AliITSOnlineSPDfoChip::AddMeasurement(AliITSOnlineSPDfoChipConfig *confinfo)
+{
+  //
+  //setter for the Chip global measurement
+  //
+  
+  fChipConfigArray->AddLast(confinfo);
+  fNumChipConfigs++;
+}
+//_____________________________________________________
+void AliITSOnlineSPDfoChip::PrintInfo()
+{
+  //
+  // prints container content
+  //
+  printf(" \n ActiveHS %d   ChipId %d",fActiveHS,fChipId);
+  printf(" DAC parameters : %d    %d    %d    %d \n",fDACparams[0],fDACparams[1],fDACparams[2],fDACparams[3]); 
+  for(Int_t i=0; i< fNumChipConfigs; i++) {
+    if(!(AliITSOnlineSPDfoChipConfig*)(GetChipConfigInfo()->At(i)) ) printf("AliISOnlineSPDfoChipConfig pointer null");
+    else ((AliITSOnlineSPDfoChipConfig*)(GetChipConfigInfo()->At(i)))->PrintInfo();   
+  }
+}
diff --git a/ITS/AliITSOnlineSPDfoChip.h b/ITS/AliITSOnlineSPDfoChip.h
new file mode 100644 (file)
index 0000000..dd939f7
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef ALIITSONLINESPDFOCHIP_H
+#define ALIITSONLINESPDFOCHIP_H  
+/* Copyright(c) 2008-2010, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+
+/////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                      //
+// This class is the container for FastOR online calibration.  //
+//                                                             //
+/////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+
+class TObjArray;
+class AliITSOnlineSPDfoChipConfig;
+
+class AliITSOnlineSPDfoChip : public TObject{
+
+ public:
+  AliITSOnlineSPDfoChip();//ctor
+  AliITSOnlineSPDfoChip(Short_t nparams); 
+  
+  virtual ~AliITSOnlineSPDfoChip(); //dctor
+
+  // SETTERS
+  void SetActiveHS(Int_t hs)               {fActiveHS=hs;}
+  void SetChipId(Int_t chipId)             {fChipId=chipId;}
+  void SetDACParameter(Int_t i, UShort_t par) {fDACparams[i] = par;}
+  void AddMeasurement(AliITSOnlineSPDfoChipConfig *ChipConfiginfo);
+
+  // GETTERS
+  Short_t GetActiveHS() const                 {return fActiveHS;}
+  Short_t GetChipId()  const                  {return fChipId;} 
+  Short_t GetNumberOfDACParams() const        {return fNumDACparams;}
+  Short_t GetDACParameters(Int_t ipar)  const {return fDACparams[ipar];}
+  Int_t GetNumberOfChipConfigs() const        {return fNumChipConfigs;} 
+  TObjArray* GetChipConfigInfo() const        {return fChipConfigArray;}
+   
+  void PrintInfo();              // prints the container content
+  
+ protected:
+  Short_t     fActiveHS;         //number of the activated HS
+  Short_t     fChipId;           //id number of the chip
+  Int_t       fNumDACparams;     //number of DAC parameters to be considered 
+  Short_t     fNumChipConfigs;   //number of ChipConfigs used in the chip     
+  Short_t     *fDACparams;       //[fNumDACparams] 
+  TObjArray   *fChipConfigArray; // array of ChipConfigs in the chip
+
+  private:
+  AliITSOnlineSPDfoChip(const AliITSOnlineSPDfoChip &c);
+  AliITSOnlineSPDfoChip& operator= (const AliITSOnlineSPDfoChip& c);
+
+    ClassDef(AliITSOnlineSPDfoChip,1)
+  };
+    
+#endif
diff --git a/ITS/AliITSOnlineSPDfoChipConfig.cxx b/ITS/AliITSOnlineSPDfoChipConfig.cxx
new file mode 100644 (file)
index 0000000..cc0e298
--- /dev/null
@@ -0,0 +1,61 @@
+/**************************************************************************
+ * Copyright(c) 2008-2010, 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$ */
+
+/////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                      //
+// This class is used as a container for the FO scan           //
+//                                                             //
+/////////////////////////////////////////////////////////////////
+
+
+#include <TObjArray.h>
+#include "AliITSOnlineSPDfoChipConfig.h"
+
+ClassImp(AliITSOnlineSPDfoChipConfig)
+
+AliITSOnlineSPDfoChipConfig::AliITSOnlineSPDfoChipConfig():
+ TObject(),
+ fChipConfigRow(0),
+ fChipConfigCol(0),
+ fCounter(0),
+ fMatrixId(-1)
+{
+//constructor  
+}
+//__________________________
+
+AliITSOnlineSPDfoChipConfig::AliITSOnlineSPDfoChipConfig(Short_t measure[4]):
+ TObject(),
+ fChipConfigRow(measure[1]),
+ fChipConfigCol(measure[2]),
+ fCounter(measure[3]),
+ fMatrixId(measure[0])
+{
+//constructor
+}
+//
+AliITSOnlineSPDfoChipConfig::AliITSOnlineSPDfoChipConfig(const AliITSOnlineSPDfoChipConfig &p):
+TObject(p),
+fChipConfigRow(p.fChipConfigRow),
+fChipConfigCol(p.fChipConfigCol),
+fCounter(p.fCounter),
+fMatrixId(p.fMatrixId)
+{
+  //
+  //copy constructor
+  //
+}    
diff --git a/ITS/AliITSOnlineSPDfoChipConfig.h b/ITS/AliITSOnlineSPDfoChipConfig.h
new file mode 100644 (file)
index 0000000..2a0a633
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef ALIITSONLINESPDFOCHIPCONFIG_H
+#define ALIITSONLINESPDFOCHIPCONFIG_H  
+/* Copyright(c) 2008-2010, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+/////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                      //
+// This class is the brick of the container for the FastOR     //
+// online calibration.                                         //
+/////////////////////////////////////////////////////////////////
+
+#include <TObject.h>
+class TObjArray;
+
+class AliITSOnlineSPDfoChipConfig : public TObject{
+  
+ public:
+  AliITSOnlineSPDfoChipConfig(); // ctor
+  AliITSOnlineSPDfoChipConfig(Short_t measure[4]);
+  AliITSOnlineSPDfoChipConfig(const AliITSOnlineSPDfoChipConfig& p);           //  copy constructor
+  
+  virtual ~AliITSOnlineSPDfoChipConfig(){;} //dtor    
+  
+  //SETTERS
+  void SetChipConfigMatrixId(Short_t idMatrix)    {fMatrixId = idMatrix;}
+  void SetChipConfigRow(Short_t pixRow)           {fChipConfigRow = pixRow;}
+  void SetChipConfigCol(Short_t pixCol)           {fChipConfigCol = pixCol;}
+  void SetChipConfigCounter(UShort_t ncounts)     {fCounter = ncounts;}
+  //GETTERS
+  void GetChipConfigId(Int_t pixId[2]) const      {pixId[0] = fChipConfigRow; pixId[1]=fChipConfigCol;}
+  Short_t  GetChipConfigCounter() const           {return fCounter;}
+  Short_t  GetChipConfigMatrixId() const          {return fMatrixId;}
+  
+  void PrintInfo() {printf(" MatrixId %d -  Row %d   Col %d  -  Counts %d \n",fMatrixId,fChipConfigRow,fChipConfigCol,fCounter);}
+  
+ private:
+  Short_t fChipConfigRow; 
+  Short_t fChipConfigCol; 
+  Short_t fCounter;
+  Short_t fMatrixId;
+  AliITSOnlineSPDfoChipConfig &operator=(const AliITSOnlineSPDfoChipConfig& p);
+  
+  ClassDef(AliITSOnlineSPDfoChipConfig,1)
+    
+};
+    
+#endif
diff --git a/ITS/AliITSOnlineSPDfoInfo.cxx b/ITS/AliITSOnlineSPDfoInfo.cxx
new file mode 100644 (file)
index 0000000..32fff62
--- /dev/null
@@ -0,0 +1,58 @@
+/**************************************************************************
+ * Copyright(c) 2008-2010, 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$ */
+
+////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                     // 
+// This class is used within the detector algorithm framework //
+// to collect information on how the scan was arranged.       //
+////////////////////////////////////////////////////////////////
+
+#include "AliITSOnlineSPDfoInfo.h"
+
+ClassImp(AliITSOnlineSPDfoInfo)
+  
+//_____________________________________________________________________
+AliITSOnlineSPDfoInfo::AliITSOnlineSPDfoInfo(): 
+ fRunNumber(0), fRouter(999), fNumTriggers(0),
+ fDBversion(0), fNumDACindex(0), fDACindex(0)
+{}
+//_____________________________________________________________________
+AliITSOnlineSPDfoInfo::~AliITSOnlineSPDfoInfo() 
+{}
+//_____________________________________________________________________
+void AliITSOnlineSPDfoInfo::ClearThis() {
+  // reset all values for this object
+  fRunNumber=0;
+  fRouter=999;
+  fNumTriggers=0;
+  fDBversion=0;
+  fNumDACindex=0;
+  fDACindex.Reset();
+}
+//_____________________________________________________________________
+void AliITSOnlineSPDfoInfo::AddDACindex(Short_t index) {
+  // add a new DAC index, allocate space for TArrayS
+  fNumDACindex++;
+  fDACindex.Set(fNumDACindex);
+  fDACindex.AddAt(index, fNumDACindex-1);
+}
+//_____________________________________________________________________
+Short_t AliITSOnlineSPDfoInfo::GetDACindex(UShort_t id) const {
+  // returns the DAC index at position id of TArrayS
+  if (id>=fNumDACindex) return -1;
+  else                  return fDACindex.At(id);
+}
diff --git a/ITS/AliITSOnlineSPDfoInfo.h b/ITS/AliITSOnlineSPDfoInfo.h
new file mode 100644 (file)
index 0000000..ee3f1ff
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef ALIITSONLINESPDFOINFO_H
+#define ALIITSONLINESPDFOINFO_H
+/* Copyright(c) 2008-2010, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+////////////////////////////////////////////////////////////////
+// Author: A. Mastroserio                                     // 
+// This class is used within the detector algorithm framework //
+// to collect information on how the scan was arranged.       //
+////////////////////////////////////////////////////////////////
+
+
+#include <TObject.h>
+#include <TArrayS.h>
+
+class AliITSOnlineSPDfoInfo :  public TObject {
+
+ public:
+  AliITSOnlineSPDfoInfo();
+  virtual ~AliITSOnlineSPDfoInfo();
+
+  virtual void   ClearThis();
+  virtual void   AddDACindex(Short_t index);
+
+  // SETTERS
+  virtual void SetRunNumber(UInt_t val)  {fRunNumber=val;}
+  virtual void SetRouter(UShort_t val)   {fRouter=val;}
+  virtual void SetNumTriggers(UInt_t val){fNumTriggers=val;}
+  virtual void SetDBversion(Int_t val)   {fDBversion=val;}
+
+  // GETTERS
+  UInt_t   GetRunNumber() const     {return fRunNumber;}
+  UShort_t GetRouter() const        {return fRouter;}
+  UInt_t   GetNumTriggers() const   {return fNumTriggers;}
+  Int_t    GetDBversion() const     {return fDBversion;}
+
+  UShort_t GetNumDACindex() const   {return fNumDACindex;}
+  Short_t  GetDACindex(UShort_t id) const; // returns -1 if ID not present
+
+  TArrayS GetDACIndexArray() const  {return fDACindex;}
+
+ protected:
+  UInt_t   fRunNumber;   // run number
+  UShort_t fRouter;      // router number (should be same as eq number)
+  UInt_t   fNumTriggers; // number of triggers sent for each scan step
+  Int_t    fDBversion;   // global configuration db version
+                        
+  UShort_t fNumDACindex; // number of DAC indices in TArrayI below
+  TArrayS  fDACindex;    // list of DAC indices related to each DAC value
+
+  ClassDef(AliITSOnlineSPDfoInfo,1)
+};
+    
+#endif
index e8dc409..4d5ce8f 100644 (file)
@@ -68,6 +68,11 @@ set(SRCS
                AliITSOnlineSPDphys.cxx 
                AliITSOnlineSPDphysAnalyzer.cxx 
                AliITSOnlineSPDphysInfo.cxx 
+                AliITSOnlineSPDfoChipConfig.cxx 
+                AliITSOnlineSPDfoChip.cxx 
+                AliITSOnlineSPDfo.cxx 
+                AliITSOnlineSPDfoInfo.cxx 
+                AliITSOnlineSPDfoAnalyzer.cxx 
                AliITSBadChannelsAuxSPD.cxx 
                AliITSBadChannelsSPD.cxx  
                AliITSChannelSPD.cxx  
diff --git a/ITS/ITSSPDfoda.cxx b/ITS/ITSSPDfoda.cxx
new file mode 100644 (file)
index 0000000..d2bfd3d
--- /dev/null
@@ -0,0 +1,344 @@
+////////////////////////////////////////////////////////////////////////////////
+// This program can be compiled in two modes.                                 //
+//                                                                            //
+// 1. With the DAQ DA framework on. This is the default operating mode.       //
+// Call this program with the name of the executable followed by the          //
+// data files to process.                                                     //
+//                                                                            //
+// 2. Without the DAQ DA framework on. Define the SPD_DA_OFF environment var. //
+// Call this program with the name of the executable followed by the          //
+// runNr and the data files to process.                                       //
+//                                                                            //
+////////////////////////////////////////////////////////////////////////////////
+
+#ifndef SPD_DA_OFF
+extern "C" {
+#include <daqDA.h>
+}
+#endif
+#include "event.h"
+#include "monitor.h"
+#include "AliRawReaderDate.h"
+#include "AliITSRawStreamSPD.h"
+#include "AliITSOnlineSPDfoChip.h"
+#include "AliITSOnlineSPDfoInfo.h"
+#include "AliITSOnlineSPDfo.h"
+#include "AliITSOnlineSPDfoAnalyzer.h"
+#include "AliLog.h"
+#include <Riostream.h>
+#include <fstream>
+#include <TROOT.h>
+#include <TStopwatch.h>
+#include <TPluginManager.h>
+#include <TObjArray.h>
+#include <TClonesArray.h>
+#include <TObjString.h>
+#include <TString.h>
+#include <TFitter.h>
+#include <TFile.h>
+
+int main(int argc, char **argv) {
+  if (argc<2) {
+    printf("Wrong number of arguments\n");
+    return -1;
+  }
+  
+  
+  TStopwatch timer;
+  timer.Start();
+  
+  // directory structure, hard coded
+  char *saveDirNoisyToFXS    = "./calibResults/ScanNoisyToFXS";     //     may delete content
+  char *saveDirDCSconfigToFXS= "./calibResults/ScanDCSconfigToFXS"; //     may delete content
+  char *configFilesDir       = "./configFiles";                     //     may delete content
+  char *saveDirIdsToFXS      = "./calibResults/IdsToFXS"; 
+  // parameters config files
+  TString thresholdsFileName = Form("%s/focalib_params.txt",configFilesDir); 
+  
+  TFitter *fitter = new TFitter(3);
+  TVirtualFitter::SetFitter(fitter);
+  
+  // This line is needed in case of a stand-alone application w/o
+  // $ROOTSYS/etc/system.rootrc file
+  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
+                                       "*",
+                                       "TStreamerInfo",
+                                       "RIO",
+                                       "TStreamerInfo()");
+  
+  // turn off annoying warning messages
+  new AliLog;
+  AliLog::Instance()->SetGlobalDebugLevel(-20);
+  
+  
+  
+  
+// ********* STEP 0: Get configuration files from db (if there are any) , then read parameters*********  
+  
+  //chip efficiency selection parameters (needed afterwards for the data analysis)
+  Int_t status = 0;
+#ifndef SPD_DA_OFF
+  TString idp = "spd_focalib_params";
+  status=daqDA_DB_getFile(idp.Data(),thresholdsFileName.Data());
+  if (status) {
+    printf("Failed to get config file %s: status=%d. Using default tuning parameters.\n",idp.Data(),status);
+    TString rmCmd = Form("rm -f %s",thresholdsFileName.Data());
+    system(rmCmd.Data());
+  }
+#endif
+   
+  
+  
+  // ********* STEP 1: Produce FO scan container files (Reference Data). ***********************************
+  int startSeg = 1;
+  
+#ifndef SPD_DA_OFF
+  if (getenv("DATE_RUN_NUMBER")==0) {
+    printf("DATE_RUN_NUMBER not properly set.\n");
+    return -1;
+  }
+  int runNr = atoi(getenv("DATE_RUN_NUMBER"));
+#else
+  int runNr = atoi(argv[1]);
+  startSeg = 2;
+#endif
+  
+  Int_t evType =-1;
+  AliITSOnlineSPDfoInfo *info[20]; Int_t ntriggers[20]; Int_t vDB[20]; Bool_t iseq[20];
+  Bool_t infodacs[6] = {kFALSE, kFALSE, kFALSE, kFALSE, kFALSE,kFALSE}; // num of DAC params
+  AliITSOnlineSPDfo *fomanager[20];
+  TString s = "focalib";
+  
+  for(Int_t equip =0; equip < 20; equip++ ) {        
+    info[equip] = new AliITSOnlineSPDfoInfo();
+    info[equip]->SetRunNumber(runNr);
+    info[equip]->SetRouter(equip);
+    ntriggers[equip] = 0;
+    vDB[equip] =0;  
+    iseq[equip]=kFALSE;
+    fomanager[equip] = new AliITSOnlineSPDfo(s,runNr,equip);
+  }
+  
+  
+  // loop over run segments
+  for (int segNr=startSeg; segNr<argc; segNr++) {
+    
+    int status;
+    
+    // define data source : this is argument 1   
+    status=monitorSetDataSource( argv[segNr] );
+    if (status!=0) {
+      printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
+      return -1;
+    }
+    // declare monitoring program 
+    status=monitorDeclareMp("ITS_SPD_CAL");
+    if (status!=0) {
+      printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
+      return -1;
+    }
+    // define wait event timeout - 1s max 
+    monitorSetNowait();
+    monitorSetNoWaitNetworkTimeout(1000);
+    
+    Int_t eventType;
+    UInt_t eventNr=0;
+    Int_t entry=0;    
+    // main loop (infinite) 
+    for(;;) {
+      
+      struct eventHeaderStruct *event;
+      eventTypeType eventT;
+      
+      /* check shutdown condition */
+#ifndef SPD_DA_OFF
+      if (daqDA_checkShutdown()) {break;}
+#endif
+      /* get next event (blocking call until timeout) */
+      status=monitorGetEventDynamic((void **)&event);
+      if (status==MON_ERR_EOF) {
+       printf ("End of File detected\n");
+       break; /* end of monitoring file has been reached */
+      }
+      if (status!=0) {
+       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
+       break;
+      }
+      /* retry if got no event */
+      if (event==NULL) {
+       continue;
+      }
+      
+      eventT=event->eventType;
+      eventType = (Int_t) eventT;
+      
+      if (eventT == PHYSICS_EVENT) {
+       
+       eventNr++;
+       //if(eventNr%5000 == 0 )printf(" eventNr %d\n",eventNr);
+       
+       AliRawReader *reader = new AliRawReaderDate((void*)event);
+       AliITSRawStreamSPD *str = new AliITSRawStreamSPD(reader);
+        
+       for (UInt_t eqId=0; eqId<20; eqId++) {
+         
+         reader->Reset();
+         reader->Select("ITSSPD",eqId,eqId);
+          
+         if (str->ReadCalibHeader()>0) {
+        
+            if(evType<0) evType = str->GetFOHtype();
+               
+            if(!iseq[eqId]){ // create output files           
+             fomanager[eqId]->CreateOutputFile();
+             fomanager[eqId]->SetFOscanParams(info[eqId]);
+             iseq[eqId]=kTRUE;
+            }
+                     
+            if(info[eqId]->GetNumDACindex()<1) {
+              Int_t ind =0;
+              while(str->GetFOHdacIndex(ind)>0) {
+                info[eqId]->AddDACindex(str->GetFOHdacIndex(ind));
+                ind++;
+              }
+            }
+                   
+            if(!ntriggers[eqId]) {
+             ntriggers[eqId] = str->GetFOHtriggers();
+             info[eqId]->SetNumTriggers(str->GetFOHtriggers()); 
+            }
+           if(!vDB[eqId])      {
+             vDB[eqId]       = str->GetFOHglobalDBversion();
+             info[eqId]->SetDBversion(str->GetFOHglobalDBversion());
+           }       
+          
+            if(!fomanager[eqId]->GetNdacs()) fomanager[eqId]->SetNdacs(str->GetFOHnumDacs());
+           
+            TArrayS dacvalues(str->GetFOHnumDacs());
+            for(Int_t n = 0; n<str->GetFOHnumDacs(); n++) dacvalues.AddAt(str->GetFOHdacValue(n),n);
+            
+            TArrayS dacs = fomanager[eqId]->CreateDACArray(dacvalues, info[eqId]->GetDACIndexArray());
+           
+            for(Int_t ihs =0; ihs < 6; ihs++) { // needed in the header to access the HS and ChipId info (in data it is different)
+             for(Int_t ich =0; ich < 10; ich++){
+               if(!str->GetFOHchipPresent(ihs, ich)) continue;
+                 Short_t measure[4] = {str->GetFOHMatrixID(),str->GetFOHpixelRow(), str->GetFOHpixelCol(), str->GetFOHchipCount(ihs,ich)}; 
+                  fomanager[eqId]->AddMeasurement(dacs,measure,ihs,ich);                                            
+             } // chip loop      
+            }// HS loop
+         }// if str->ReadHeader()>0;          
+       }//if eqId      
+       delete str;
+       delete reader;
+      }
+      
+      // free resources 
+      free(event);   
+    }// infinite loop
+    
+    
+    
+#ifndef SPD_DA_OFF
+    daqDA_progressReport((unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 ));
+#else
+    printf("progress: %d\n",(unsigned int)( ((Float_t)(segNr-startSeg+1))/(argc-startSeg)*50 ));
+#endif
+    
+  }// loop over run segments
+  
+   
+     TString id[20], files[20];
+    for(Int_t ifile =0; ifile < 20; ifile++) {
+      if(iseq[ifile]){
+      id[ifile] = Form("SPD_ref_fo%02i",ifile);
+      files[ifile] = fomanager[ifile]->GetFile()->GetName();
+      fomanager[ifile]->WriteToFile();
+    }
+      delete fomanager[ifile];
+    }
+    
+      
+    // ANALYSIS part
+    
+    for(Int_t iff =0; iff<20 ; iff++){
+     if(!iseq[iff]) continue;
+          
+     AliITSOnlineSPDfoAnalyzer * analyzer = new AliITSOnlineSPDfoAnalyzer(Form("%i_%s%02i.root",runNr,s.Data(),iff));      
+     analyzer->ReadParamsFromLocation(configFilesDir);
+     analyzer->Process();
+     
+     TString dcsConfigFileName = Form("%s/dcsConfig_run_%d_eq_%d.txt",saveDirDCSconfigToFXS,runNr,iff);
+     ofstream dcsfile;
+     dcsfile.open(dcsConfigFileName.Data());
+     dcsfile << "[SPD SCAN]\n"; 
+     dcsfile << "RunNumber=" << runNr << "\n";
+     dcsfile << "Type="<< evType <<"\n";
+     dcsfile << "Router=" << iff << "\n";
+     dcsfile << "ActualDetConfiguration=" << vDB[iff]<<"\n\n";
+     dcsfile << "[DACvalues]\n"; 
+     
+       for(Int_t hs =0; hs<6; hs++){
+        for(Int_t ichip =0; ichip < 10; ichip++){
+          TArrayI dacs = analyzer->ChooseDACValues(hs,ichip);
+          
+          if(dacs.GetSize() == 0) continue;
+          for(Int_t idac =0; idac < dacs.GetSize() - 1; idac++) { // -1 (the last one is the quality flag)
+            if(dacs.At(idac) >=0 ) {
+              dcsfile << ((analyzer->GetFOHandler())->GetFOscanInfo())->GetDACindex(idac) << ",";
+              dcsfile << iff << ",";
+              dcsfile << hs << ",";
+              dcsfile << ichip << "=" ;
+              dcsfile << dacs.At(idac) << ",";
+              dcsfile << dacs.At(dacs.GetSize() - 1) << "\n";
+            }
+          }
+        }
+       }
+       dcsfile.close();
+    }
+    
+    
+    printf("Preparing DCS config files\n");
+    // send a tared file of all the dcsConfig text files
+    TString command = Form("cd %s; tar -cf dcsConfig.tar *",saveDirDCSconfigToFXS);
+    //printf("\n\n%s\n\n",command.Data());
+    //system(command.Data());
+    TString fileName = Form("%s/dcsConfig.tar",saveDirDCSconfigToFXS);
+    TString iddcs = "SPD_dcsConfig";
+    
+#ifndef SPD_DA_OFF
+    status = daqDA_FES_storeFile(fileName.Data(),iddcs.Data());
+    if (status!=0) {
+      printf("Failed to export file %s , status %d\n",fileName.Data(),status);
+      return -1;
+    }
+#endif
+    
+    
+    printf("Opening id list file\n");
+    TString idsFXSFileName = Form("%s/FXSids_run_%d.txt",saveDirIdsToFXS,runNr);
+    ofstream idsFXSfile;
+    idsFXSfile.open(idsFXSFileName.Data());
+    
+    // send reference data to FXS
+    for (UInt_t eqId=0; eqId<20; eqId++) {
+      if(!iseq[eqId]) continue;   
+      //printf("Preparing reference data for eq %d\n",eqId);
+      
+      TString idf = Form("SPD_fo_scan_%d",eqId);
+#ifndef SPD_DA_OFF
+      status = daqDA_FES_storeFile(files[eqId].Data(),idf.Data());
+      if (status!=0) {
+       printf("Failed to export file %s , status %d\n",files[eqId].Data(),status);
+       return -1;
+      }
+#endif
+      idsFXSfile << Form("%s\n",idf.Data());   
+    }
+    
+    timer.Stop();
+    timer.Print();   
+    printf("DA finished.\n");
+    return 0;  
+}
index 3ade034..39e8247 100644 (file)
 #pragma link C++ class AliITSOnlineSPDphys+;
 #pragma link C++ class AliITSOnlineSPDphysAnalyzer+;
 #pragma link C++ class AliITSOnlineSPDphysInfo+;
+#pragma link C++ class AliITSOnlineSPDfoChipConfig+;
+#pragma link C++ class AliITSOnlineSPDfoChip+;
+#pragma link C++ class AliITSOnlineSPDfo+;
+#pragma link C++ class AliITSOnlineSPDfoInfo+;
+#pragma link C++ class AliITSOnlineSPDfoAnalyzer+;
 #pragma link C++ class AliITSPreprocessorSDD+;
 #pragma link C++ class AliITSOnlineSDD+;
 #pragma link C++ class AliITSOnlineSDDBase+;
index f35a609..78e776b 100644 (file)
@@ -67,6 +67,11 @@ SRCS =       AliITSDetTypeRec.cxx \
                AliITSOnlineSPDphys.cxx \
                AliITSOnlineSPDphysAnalyzer.cxx \
                AliITSOnlineSPDphysInfo.cxx \
+                AliITSOnlineSPDfoChipConfig.cxx \
+                AliITSOnlineSPDfoChip.cxx \
+                AliITSOnlineSPDfo.cxx \
+                AliITSOnlineSPDfoInfo.cxx \
+                AliITSOnlineSPDfoAnalyzer.cxx \
                AliITSBadChannelsAuxSPD.cxx \
                AliITSBadChannelsSPD.cxx  \
                AliITSChannelSPD.cxx  \