LCOV - code coverage report
Current view: top level - ITS/ITSrec - AliITSOnlineSPDfo.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 160 0.6 %
Date: 2016-06-14 17:26:59 Functions: 1 17 5.9 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 2008-2010, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : ////////////////////////////////////////////////////////////////
      19             : // Author: A. Mastroserio                                     // 
      20             : // This class is used within the detector algorithm framework //
      21             : // to write and read FO scan data.                            //
      22             : ////////////////////////////////////////////////////////////////
      23             : 
      24             : #include <TFile.h>
      25             : #include <Riostream.h>
      26             : #include <TSystem.h>
      27             : #include <TObjArray.h>
      28             : #include <TObjString.h>
      29             : #include <TArrayI.h>
      30             : #include <TIterator.h>
      31             : #include <TKey.h>
      32             : #include <TMath.h>
      33             : #include <TList.h>
      34             : #include "AliLog.h"
      35             : #include "AliITSOnlineSPDfoChipConfig.h"
      36             : #include "AliITSOnlineSPDfoChip.h"
      37             : #include "AliITSOnlineSPDfoInfo.h"
      38             : #include "AliITSOnlineSPDfo.h"
      39             : 
      40             : 
      41         116 : ClassImp(AliITSOnlineSPDfo)
      42             : //-----------------------------------------------
      43             : AliITSOnlineSPDfo::AliITSOnlineSPDfo():
      44           0 : fRunNr(0),
      45           0 : fNdacs(0),
      46           0 : fFileName(""),
      47           0 : fFile(0x0),
      48           0 : fInfo(0x0),
      49           0 : fDACnames(0x0),
      50           0 : fArray(0x0),
      51           0 : fCheckIndex(-1),
      52           0 : fIndex(-1),
      53           0 : fInitialConfiguration("")
      54           0 : {
      55             : // default constructor
      56           0 : } 
      57             : 
      58             : //-------------------------------------------------
      59             : AliITSOnlineSPDfo::AliITSOnlineSPDfo(TString inputfile, Int_t runNr, Int_t eqId):
      60           0 : fRunNr(runNr),
      61           0 : fNdacs(0),
      62           0 : fFileName(""),
      63           0 : fFile(0x0),
      64           0 : fInfo(0x0),
      65           0 : fDACnames(0x0),
      66           0 : fArray(0x0),
      67           0 : fCheckIndex(-1),
      68           0 : fIndex(-1),
      69           0 : fInitialConfiguration("")
      70           0 : {
      71             :  //
      72             :  // constructor 
      73             :  //   
      74           0 :     fFileName=Form("%i_%s%02i.root",runNr,inputfile.Data(),eqId);
      75           0 :     fFile = TFile::Open(fFileName.Data());
      76           0 :     fArray = new TObjArray();
      77           0 :     fDACnames = new THashList();
      78           0 : }
      79             : //--------------------------------------------------
      80             : AliITSOnlineSPDfo::AliITSOnlineSPDfo(const AliITSOnlineSPDfo &c):
      81           0 : fRunNr(c.fRunNr),
      82           0 : fNdacs(c.fNdacs),
      83           0 : fFileName(c.fFileName),
      84           0 : fFile(c.fFile),
      85           0 : fInfo(c.fInfo),
      86           0 : fDACnames(c.fDACnames),
      87           0 : fArray(c.fArray),
      88           0 : fCheckIndex(c.fCheckIndex),
      89           0 : fIndex(c.fIndex),
      90           0 : fInitialConfiguration(c.fInitialConfiguration)
      91           0 : {
      92             :   //
      93             :   //copy constructor
      94             :   //
      95           0 : }    
      96             : //--------------------------------------------------
      97             : void AliITSOnlineSPDfo::SetFile(TString inputfile)
      98             : {
      99             :   //
     100             :   // open the file where the data are
     101             :   //
     102             :   
     103           0 :  if(fFile) {
     104           0 :    fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo");
     105           0 :    return; 
     106             :  } else {
     107           0 :    fFile = TFile::Open(inputfile.Data());
     108           0 :    if(!fFile) {
     109           0 :      Info("AliITSOnlineSPDfo::SetFile"," %s  not existing.... The scan info are not available....crash is expected \n",inputfile.Data());
     110           0 :      return;
     111             :     } else {
     112           0 :      fInfo = (AliITSOnlineSPDfoInfo *)fFile->Get("generalinfo");
     113           0 :      fNdacs = fInfo->GetNumDACindex();
     114             :    }
     115             : }
     116             : 
     117           0 : }
     118             : 
     119             : //------------------------------------------------------
     120             : void AliITSOnlineSPDfo::CreateOutputFile()
     121             : {
     122             :   //
     123             :   // Create the file (needed only in the DA ), will delete the previous one!
     124             :   //  
     125           0 :   if(fFile) Info("AliITSOnlineSPDfo::CreateOutputFile","removing previous file....\n");
     126           0 :    fFile = TFile::Open(fFileName.Data(),"RECREATE"); 
     127             :   
     128           0 : }
     129             : //------------------------------------------------------
     130             : void AliITSOnlineSPDfo::AddMeasurement(const TArrayS dac, Short_t measure[4], Int_t hs, Int_t chipId)
     131             : {
     132             :   /*
     133             :   // Here a single measurement is added to the chip container. 
     134             :   // A single measurement corresponds to a specific pixel-configuration output
     135             :   // in the Fast-OR chip. If N configurations are considered, then
     136             :   // the data structure is the following:
     137             :   //
     138             :   //                                          -> HS0_CHIP0 -> measure0[4]
     139             :   //                                         /                measure1[4]
     140             :   //                                        /                   ...
     141             :   //  fArray->At(i) =  DAC1-DAC2-DAC3-DAC4                    measureN[4]
     142             :   //                                        \
     143             :   //                                         \ 
     144             :   //                                          -> HS0_CHIP1 -> measure0[4]
     145             :   //                                                          measure1[4]
     146             :   //                                                             ....
     147             :   //                                                          measureN[4]
     148             :   //
     149             :   */
     150             : 
     151           0 :   AliITSOnlineSPDfoChipConfig *counts = new AliITSOnlineSPDfoChipConfig(measure);
     152           0 :   Int_t arrayelement = CheckDACEntry(dac);
     153             :   
     154           0 :   if(arrayelement< 0){
     155           0 :     TString dacname = CreateDACEntry(dac);
     156           0 :     TObjString *string = new TObjString(dacname.Data());
     157           0 :     fDACnames->Add(string);
     158             :      
     159           0 :     TObjArray *array = new TObjArray(60);
     160           0 :     AliITSOnlineSPDfoChip * chip = new AliITSOnlineSPDfoChip(dac.GetSize());
     161           0 :     chip->SetActiveHS(hs);
     162           0 :     chip->SetChipId(chipId); 
     163           0 :     for(Int_t i=0; i< dac.GetSize() ; i++) chip->SetDACParameter(i,dac.At(i));               
     164           0 :     chip->AddMeasurement(counts);
     165           0 :     array->AddAt(chip,hs*10+chipId);  
     166           0 :     fArray->AddLast(array); 
     167             :      
     168           0 :   } else {
     169             :     
     170           0 :     TObjArray *arr = (TObjArray*)fArray->At(arrayelement);  
     171           0 :     if(!arr->At(hs*10+chipId)){
     172           0 :       AliITSOnlineSPDfoChip * chip = new AliITSOnlineSPDfoChip(dac.GetSize());
     173           0 :       chip->SetActiveHS(hs);
     174           0 :       chip->SetChipId(chipId); 
     175           0 :       for(Int_t i=0; i< dac.GetSize() ; i++) chip->SetDACParameter(i,dac.At(i));               
     176           0 :       chip->AddMeasurement(counts);
     177           0 :       arr->AddAt(chip,hs*10+chipId);     
     178             :       
     179           0 :       } else {
     180             :       
     181           0 :       AliITSOnlineSPDfoChip *c = (AliITSOnlineSPDfoChip *)arr->At(hs*10+chipId);
     182           0 :       if(c)c->AddMeasurement(counts);    
     183             :     }   
     184             :   }
     185           0 : }
     186             : //---------------------------------------
     187             : Int_t AliITSOnlineSPDfo::CheckDACEntry(const TArrayS dac)
     188             : {
     189             :   //
     190             :   // Check if the set of dacs has been already added to the array
     191             :   // 
     192             :   
     193             :    
     194           0 :   TString name = CreateDACEntry(dac);
     195             :   
     196           0 :   if(!fDACnames) {
     197           0 :     Info("AliITSOnlineSPDfo::CheckDACEntry"," NO DAC name array is present, exiting.... \n");
     198           0 :     return -1;
     199             :   }
     200             :   
     201             :    Double_t c = 0;
     202           0 :   for(Int_t i=0; i< fNdacs; i++)  c+=dac.At(i)*TMath::Power(10,3*i);
     203           0 :   if(c==fCheckIndex) return fIndex;
     204             :    
     205             :   
     206             :  
     207             :    Int_t idx = -1;
     208             :    
     209           0 :   if(fDACnames->FindObject( name.Data() )) {
     210           0 :     idx = fDACnames->IndexOf( fDACnames->FindObject( name.Data() )  );
     211           0 :     fCheckIndex=0;
     212           0 :     for(Int_t i=0; i< fNdacs; i++) fCheckIndex+=dac.At(i)*TMath::Power(10,3*i);
     213           0 :     fIndex=idx;
     214             : 
     215           0 :   }
     216             :   return idx;
     217             : 
     218           0 : }
     219             : //_________________________________________________________
     220             : void AliITSOnlineSPDfo::WriteToFile()
     221             : {
     222             :   //
     223             :   //The array of DACS and all its content is written to file.
     224             :   // Here the general info on the FO calibration scan are 
     225             :   // written in the same file
     226             :   
     227           0 :   if(fDACnames->GetEntries() != fArray->GetEntries()) {
     228           0 :    printf("mismatch names-array. Exiting....");   
     229           0 :     return;
     230             :   }
     231             :   
     232           0 :   for(Int_t i=0; i< fDACnames->GetEntries(); i++){
     233           0 :   fFile->WriteObject(fArray->At(i),fDACnames->At(i)->GetName());
     234             :   }
     235           0 :   fFile->WriteTObject(fInfo,"generalinfo"); 
     236           0 :   fFile->Close();
     237             :   
     238           0 : }
     239             : //______________________________________________________
     240             : 
     241             : TString AliITSOnlineSPDfo::CreateDACEntry(const TArrayS dacs) const
     242             : {
     243             :   //
     244             :   // The string of DACs is build
     245             :   // 
     246             :   
     247           0 :   TString dacvalues;
     248           0 :   for(Int_t i=0; i<dacs.GetSize(); i++) dacvalues+=Form("-%i",dacs.At(i));
     249           0 :   dacvalues.Remove(0,1);
     250             :   return dacvalues;
     251             :  
     252           0 : }
     253             : //_____________________________________________________
     254             : TArrayI AliITSOnlineSPDfo::GetDACscanParams() const
     255             : { 
     256             :   //
     257             :   // this method retrieves the DAC value range and its steps
     258             :   //
     259             :   TFile *f =0x0;
     260           0 :   if(fFile->IsOpen()) f = fFile;
     261           0 :   else f = TFile::Open(fFileName.Data());
     262             :   
     263           0 :   TArrayI dacs;
     264           0 :   if(f->GetNkeys() < 2) return dacs;
     265           0 :   dacs.Set(fNdacs*3);
     266             :   
     267           0 :   TArrayI min(fNdacs), max(fNdacs),step(fNdacs), check(fNdacs), refvalues(fNdacs);
     268             :   
     269           0 :   for(Int_t i=0; i< fNdacs ; i++) {
     270           0 :     min.AddAt(9999,i);
     271           0 :     max.AddAt(0,i);
     272           0 :     step.AddAt(0,i);
     273           0 :     check.AddAt(0,i);
     274             :   }
     275             :   
     276             :   
     277             :   TKey *key;
     278           0 :   TIter iter(f->GetListOfKeys());  
     279           0 :   while ((key = (TKey*)(iter.Next()))) {
     280           0 :     TString classname = key->GetClassName();
     281           0 :     if(classname.Contains("OnlineSPD")) break;
     282             :     
     283           0 :     TString values = key->GetName();
     284           0 :     Int_t *val = GetDACvalues(values,fNdacs); // the user has to delete it!
     285             :       
     286           0 :     for(Int_t i=0; i< fNdacs; i++) {
     287           0 :       if(val[i]<=min.At(i)) min.AddAt(val[i],i);
     288           0 :       if(val[i] >= max.At(i)) max.AddAt(val[i],i);
     289             :       // procedure to get the step size;
     290           0 :       if(!check.At(i)) { 
     291           0 :         refvalues.AddAt(val[i],i);
     292           0 :         check.AddAt(1,i);
     293             :       }
     294           0 :       if(step.At(i) ==0 && check.At(i)){
     295           0 :         if(val[i]!=refvalues.At(i)) step.AddAt(TMath::Abs(refvalues.At(i) - val[i]),i);
     296             :       }  
     297             :       // end procedure to get the step size 
     298             :     }   
     299           0 :     delete [] val;
     300           0 :   }
     301             : 
     302             :  
     303             :  
     304           0 :   for(Int_t i=0; i<fNdacs; i++) {
     305           0 :     dacs.AddAt(min.At(i),3*i);    
     306           0 :     dacs.AddAt(max.At(i),3*i+1); 
     307           0 :     dacs.AddAt(step.At(i),3*i+2); 
     308             :   }
     309             :  
     310             :   
     311             :   return dacs;     
     312           0 : }
     313             : //___________________________________________________________________
     314             : Int_t* AliITSOnlineSPDfo::GetDACvalues(TString s, const Int_t ndacs) const
     315             : {
     316             :   //
     317             :   // Translates the string of DACS values into an array of integers
     318             :   //
     319             :   
     320           0 :    Int_t *val = new Int_t[ndacs]; 
     321             :    
     322           0 :    s.ReplaceAll("-"," ");
     323           0 :    char *pEnd = Form("%s",s.Data());
     324           0 :    for(Int_t i=0; i< ndacs; i++) {
     325           0 :      val[i] = strtol(pEnd,&pEnd,10); // conversion from string to long
     326             :    }  
     327           0 :    return val;   
     328           0 : }
     329             : 
     330             : //___________________________________________________________________
     331             : Double_t* AliITSOnlineSPDfo::GetDACvaluesD(TString s, const Int_t ndacs) const 
     332             : {  
     333             :   //
     334             :   // Translates the string of DACS values into an array of doubles
     335             :   // (needed to fill the thnsparse)
     336             :   //
     337           0 :    Double_t *val = new Double_t[ndacs];
     338           0 :    Int_t *values =  GetDACvalues(s,ndacs);
     339           0 :    for(Int_t i=0; i< ndacs; i++) val[i] = (Double_t)values[i];
     340           0 :    delete [] values;
     341             :    
     342           0 :    return val;   
     343           0 : }
     344             : //-------------------------------------------------------------------
     345             : TArrayS AliITSOnlineSPDfo::CreateDACArray(const TArrayS dacs, const TArrayS dacId) const
     346             : {
     347             :   //
     348             :   // method to order the data according to the DAC index
     349             :   //
     350             :   
     351           0 :   TArrayS dacarray(dacs.GetSize());
     352           0 :   for(Int_t i=0; i<dacs.GetSize(); i++) {
     353           0 :     if(dacId.At(i)==kIdFOPOL) dacarray.AddAt(dacs.At(i),kFOPOL);
     354           0 :     else if(dacId.At(i)==kIdCONVPOL) dacarray.AddAt(dacs.At(i),kCONVPOL);
     355           0 :     else if(dacId.At(i)==kIdCOMPREF) dacarray.AddAt(dacs.At(i),kCOMPREF);
     356           0 :     else if(dacId.At(i)==kIdPreVTH) dacarray.AddAt(dacs.At(i),kPreVTH);
     357           0 :     else if(dacId.At(i)==kIdCGPOL) dacarray.AddAt(dacs.At(i),kCGPOL);
     358           0 :     else printf("new DAC included in the scan??\n");
     359             :     
     360             :   }
     361             :  
     362             :   return dacarray;
     363             :   
     364           0 : }
     365             :   
     366             :   

Generated by: LCOV version 1.11