<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, 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.                  *
 **************************************************************************/


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Calibration class for DCS sensors                                        //
//  Authors: <NAME> and <NAME>                              //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include "AliDCSSensorArray.h"

ClassImp(AliDCSSensorArray)

const Int_t  kMinGraph = 10;       // minimum #points of graph to be fitted
const Int_t  kMinPoints = 10;      // minimum number of points per knot in fit
const Int_t  kIter = 10;           // number of iterations for spline fit
const Double_t  kMaxDelta = 0.00;  // precision parameter for spline fit
const Int_t  kFitReq = 2;          // fit requirement, 2 = continuous 2nd derivative

//_____________________________________________________________________________
AliDCSSensorArray::AliDCSSensorArray():TNamed()
{
  //
  // AliDCSSensorArray default constructor
  //
  fSensors = 0;
  fFirstSensor = 0;
  fLastSensor = 0;
  TTimeStamp defTime(2000,1,1,0,0,0);
  fStartTime = defTime;
  fEndTime = defTime;

}
//_____________________________________________________________________________
AliDCSSensorArray::AliDCSSensorArray(Int_t prevRun, const char* dbEntry)
{
  //
  // Read positions etc. from data base entry for previous run
  // Delete all fits and graphs
  //
   AliDCSSensorArray *temp=0;
   AliCDBEntry* entry = 
       AliCDBManager::Instance()->Get(dbEntry,prevRun); 
   if (entry){
     entry->SetOwner(kTRUE);
     temp = (AliDCSSensorArray*)entry->GetObject();
   } 

   TGraph *gr;
   AliSplineFit* fit;

// Delete previous values
   
   Int_t nsensors = temp->fSensors->GetEntries();
   for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     AliDCSSensor *entry = (AliDCSSensor*)temp->fSensors->At(isensor);
     gr = entry->GetGraph();
     if ( gr != 0 ) {
       delete gr;
       gr = 0;
     }
     fit = entry->GetFit();
     if ( fit != 0 ) {
       delete fit;
       fit = 0;
     }
   }    
   
   new (this) AliDCSSensorArray(*temp);
   delete temp;
}



//_____________________________________________________________________________
AliDCSSensorArray::AliDCSSensorArray(const AliDCSSensorArray &c):TNamed(c)
{
  //
  // AliDCSSensorArray copy constructor
  //

  ((AliDCSSensorArray &) c).Copy(*this);

}

///_____________________________________________________________________________
AliDCSSensorArray::~AliDCSSensorArray()
{
  //
  // AliDCSSensorArray destructor
  //
  fSensors->Delete();
  delete fSensors;

}

//_____________________________________________________________________________
AliDCSSensorArray &AliDCSSensorArray::operator=(const AliDCSSensorArray &c)
{
  //
  // Assignment operator
  //

  if (this != &c) ((AliDCSSensorArray &) c).Copy(*this);
  return *this;

}

//_____________________________________________________________________________
void AliDCSSensorArray::Copy(TObject &c) const
{
  //
  // Copy function
  //

  TObject::Copy(c);
}
//_____________________________________________________________________________
void AliDCSSensorArray::SetGraph(TMap *map, const char *amandaString) 
{
  // 
  // Read graphs from DCS maps 
  //
  char dname[100];
  Int_t nsensors = fSensors->GetEntries();
  for ( Int_t isensor=0; isensor<nsensors; isensor++) {
    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
    Int_t dcsSensor=entry->GetIdDCS();
    sprintf(dname,amandaString,dcsSensor);
    TGraph *gr = (TGraph*)map->GetValue(dname);
    entry->SetGraph(gr);
  } 
}  
//_____________________________________________________________________________
void AliDCSSensorArray::MakeSplineFit(TMap *map, const char *amandaString) 
{
  // 
  // Make spline fits from DCS maps 
  //
  char dname[100];
  Int_t nsensors = fSensors->GetEntries();
  for ( Int_t isensor=0; isensor<nsensors; isensor++) {
    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
    Int_t dcsSensor=entry->GetIdDCS();
    sprintf(dname,amandaString,dcsSensor);
    TGraph *gr = (TGraph*)map->GetValue(dname);
    if (gr->GetN() < kMinGraph ) continue;    
    AliSplineFit *fit = new AliSplineFit();
    fit->InitKnots(gr,kMinPoints,kIter,kMaxDelta);
    fit->SplineFit(kFitReq);
    entry->SetStartTime(fStartTime);
    fit->Cleanup();
    entry->SetFit(fit);
  } 
}  

//_____________________________________________________________________________
Double_t AliDCSSensorArray::GetValue(UInt_t timeSec, Int_t sensor) 
{
  // 
  // Return sensor value at time timeSec (obtained from fitted function)
  //  timeSec = time in seconds from start of run
  //
  AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(sensor);
  return entry->GetValue(timeSec);
}
    

//_____________________________________________________________________________
TMap* AliDCSSensorArray::ExtractDCS(TMap *dcsMap, const char *amandaString) 
{
 //
 // Extract temperature graphs from DCS maps
 //
 TMap *values = new TMap;
 TObjArray * valueSet;
 for (Int_t dcsSensor = fFirstSensor; dcsSensor<=fLastSensor; dcsSensor++)
 {
   TString DPname = Form (amandaString,dcsSensor);
   valueSet = (TObjArray*)dcsMap->FindObject(DPname.Data());
   TGraph *graph = MakeGraph(valueSet);
   values->Add(new TObjString(DPname.Data()),graph);
 }
 return values;
}<commit_msg>Update to correctly read DCS maps from FXS: ExtractDCS (Haavard)<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, 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.                  *
 **************************************************************************/


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Calibration class for DCS sensors                                        //
//  Authors: <NAME> and <NAME>                              //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include "AliDCSSensorArray.h"

ClassImp(AliDCSSensorArray)

const Int_t  kMinGraph = 10;       // minimum #points of graph to be fitted
const Int_t  kMinPoints = 10;      // minimum number of points per knot in fit
const Int_t  kIter = 10;           // number of iterations for spline fit
const Double_t  kMaxDelta = 0.00;  // precision parameter for spline fit
const Int_t  kFitReq = 2;          // fit requirement, 2 = continuous 2nd derivative

//_____________________________________________________________________________
AliDCSSensorArray::AliDCSSensorArray():TNamed(), 
  fFirstSensor(0),
  fLastSensor(0),
  fStartTime (2000,1,1,0,0,0),
  fEndTime   (2000,1,1,0,0,0),
  fSensors(0)
{
  //
  // AliDCSSensorArray default constructor
  //

}
//_____________________________________________________________________________
AliDCSSensorArray::AliDCSSensorArray(Int_t prevRun, const char* dbEntry) : 
  TNamed(),
  fFirstSensor(0),
  fLastSensor(0),
  fStartTime (2000,1,1,0,0,0),
  fEndTime   (2000,1,1,0,0,0),
  fSensors(0)
{
  //
  // Read positions etc. from data base entry for previous run
  // Delete all fits and graphs
  //
   AliDCSSensorArray *temp=0;
   AliCDBEntry* entry = 
       AliCDBManager::Instance()->Get(dbEntry,prevRun); 
   if (entry){
     entry->SetOwner(kTRUE);
     temp = (AliDCSSensorArray*)entry->GetObject();
   } 

   TGraph *gr;
   AliSplineFit* fit;

// Delete previous values
   
   Int_t nsensors = temp->fSensors->GetEntries();
   for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     AliDCSSensor *entry = (AliDCSSensor*)temp->fSensors->At(isensor);
     gr = entry->GetGraph();
     if ( gr != 0 ) {
       delete gr;
       gr = 0;
     }
     fit = entry->GetFit();
     if ( fit != 0 ) {
       delete fit;
       fit = 0;
     }
   }    
   
   new (this) AliDCSSensorArray(*temp);
   delete temp;
}



//_____________________________________________________________________________
AliDCSSensorArray::AliDCSSensorArray(const AliDCSSensorArray &c):TNamed(c),
  fFirstSensor(c.fFirstSensor),
  fLastSensor(c.fLastSensor),
  fStartTime (c.fStartTime),
  fEndTime   (c.fEndTime),
  fSensors(0)

{
  //
  // AliDCSSensorArray copy constructor
  //

  ((AliDCSSensorArray &) c).Copy(*this);

}

///_____________________________________________________________________________
AliDCSSensorArray::~AliDCSSensorArray()
{
  //
  // AliDCSSensorArray destructor
  //
  fSensors->Delete();
  delete fSensors;

}

//_____________________________________________________________________________
AliDCSSensorArray &AliDCSSensorArray::operator=(const AliDCSSensorArray &c)
{
  //
  // Assignment operator
  //

  if (this != &c) ((AliDCSSensorArray &) c).Copy(*this);
  return *this;

}

//_____________________________________________________________________________
void AliDCSSensorArray::Copy(TObject &c) const
{
  //
  // Copy function
  //

  TObject::Copy(c);
}
//_____________________________________________________________________________
void AliDCSSensorArray::SetGraph(TMap *map, const char *amandaString) 
{
  // 
  // Read graphs from DCS maps 
  //
  char dname[100];
  Int_t nsensors = fSensors->GetEntries();
  for ( Int_t isensor=0; isensor<nsensors; isensor++) {
    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
    Int_t dcsSensor=entry->GetIdDCS();
    sprintf(dname,amandaString,dcsSensor);
    TGraph *gr = (TGraph*)map->GetValue(dname);
    entry->SetGraph(gr);
  } 
}  
//_____________________________________________________________________________
void AliDCSSensorArray::MakeSplineFit(TMap *map, const char *amandaString) 
{
  // 
  // Make spline fits from DCS maps 
  //
  char dname[100];
  Int_t nsensors = fSensors->GetEntries();
  for ( Int_t isensor=0; isensor<nsensors; isensor++) {
    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
    Int_t dcsSensor=entry->GetIdDCS();
    sprintf(dname,amandaString,dcsSensor);
    TGraph *gr = (TGraph*)map->GetValue(dname);
    if (gr->GetN() < kMinGraph ) continue;    
    AliSplineFit *fit = new AliSplineFit();
    fit->InitKnots(gr,kMinPoints,kIter,kMaxDelta);
    fit->SplineFit(kFitReq);
    entry->SetStartTime(fStartTime);
    fit->Cleanup();
    entry->SetFit(fit);
  } 
}  

//_____________________________________________________________________________
Double_t AliDCSSensorArray::GetValue(UInt_t timeSec, Int_t sensor) 
{
  // 
  // Return sensor value at time timeSec (obtained from fitted function)
  //  timeSec = time in seconds from start of run
  //
  AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(sensor);
  return entry->GetValue(timeSec);
}
    

//_____________________________________________________________________________
TMap* AliDCSSensorArray::ExtractDCS(TMap *dcsMap, const char *amandaString) 
{
 //
 // Extract temperature graphs from DCS maps
 //
 TMap *values = new TMap;
 TObjArray * valueSet;
 Int_t nsensors = fSensors->GetEntries();
 for ( Int_t isensor=0; isensor<nsensors; isensor++) {
   AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
   Int_t dcsSensor=entry->GetIdDCS();
   TString DPname = Form (amandaString,dcsSensor);
   TPair *pair = (TPair*)dcsMap->FindObject(DPname.Data());
   valueSet = (TObjArray*)pair->Value();
   TGraph *graph = MakeGraph(valueSet);
   values->Add(new TObjString(DPname.Data()),graph);
 }
 return values;
}
{'fraction_non_alphanumeric': 0.14807106221660596, 'fraction_numerical': 0.009217274957258603, 'mean_word_length': 2.7486765115631093, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6058847', 'n_tokens_mistral': 3834, 'n_tokens_neox': 3695, 'n_words': 865}