ROOT logo
//*-- AUTHOR Ilse Koenig
//*-- created : 25/06/2009 by Ilse Koenig

//_HADES_CLASS_DESCRIPTION
///////////////////////////////////////////////////////////////////////
//
// HTrb2Correction
//
///////////////////////////////////////////////////////////////////////

using namespace std;
#include "htrb2correction.h"
#include "TBuffer.h"
#include <iostream>
#include <iomanip>
#include <ctype.h>
#include <stdlib.h>

ClassImp(HTrb2Correction)

HTrb2Correction::HTrb2Correction(const Char_t* temperatureSensor)
               : nValuesPerChannel(256) {
  // Default constructor with the temperatureSensor identifying the board
  // Sets the name of the board, but does not create the array for the corrections
  SetName(temperatureSensor);
  nChannels=0;
  highResolutionFlag=-1;
  subeventId=-1;
}

Float_t* HTrb2Correction::makeArray() {
  // Creates the array for the corrections if not existing
  if (boardType.CompareTo("TRB")==0) {
    if (nChannels==0) {
      nChannels=128;
      corrData.Set(nChannels*nValuesPerChannel);
      corrData.Reset();
    }
    return corrData.GetArray();
  } else {
    Error("makeArray","Board %s has not type TRB",GetName());
    return 0;
  }
}

void HTrb2Correction::deleteArray() {
  // Deletes the array for the corrections
  nChannels=0;
  corrData.Set(0);
}

Float_t HTrb2Correction::getCorrection(Int_t c, Int_t i) {
  // Returns the correction value for channel c and bin i
  if (nChannels>0 && c>=0 && c<nChannels && i>=0 && i<nValuesPerChannel) {
    return (corrData.GetArray())[c*nValuesPerChannel+i];
  } else {
    Error("getCorrection","No corrections or invalid address");
    return 0;
  }
}

void HTrb2Correction::setCorrection(Int_t c, Int_t i, Float_t v) {
  // Sets the correction value v for channel c and bin i
  if (nChannels>0 && c>=0 && c<nChannels && i>=0 && i<nValuesPerChannel) {
    corrData[c*nValuesPerChannel+i]=v;
  } else Error("getCorrection","No corrections or invalid address");
}

void HTrb2Correction::clearArray() {
  // Sets all values in the array to 0;
  corrData.Reset();
}

Bool_t HTrb2Correction::fillArray(Float_t* data,Int_t nd) {
  // Creates the array for the corrections, if not existing
  // and copies the data
  makeArray();
  Bool_t rc=kFALSE;
  if (data!=0 && nd==getSize()) {
    memcpy(corrData.GetArray(),data,nd*sizeof(Float_t));
    rc=kTRUE;
  } else {
    Error("fill","Invalid number of data: %i",getSize());
  }
  return rc;
}

void HTrb2Correction::print() {
  Int_t l=0;
  cout<<"temperatureSensor: "<<GetName()<<'\n';
  for(Int_t i=0;i<nChannels;i++) {
    l=0;
    cout<<"  channel: "<<i<<'\n';
    for(Int_t k=0;k<nValuesPerChannel;k++) {
      l++;
      cout<<setw(13)<<right<<fixed<<setprecision(6)<<corrData[i*nValuesPerChannel+k];
      if (l==10) {
        cout<<'\n';
        l=0;
      }
    }
    cout<<endl;
  }
}

void HTrb2Correction::write(fstream& fout) {
  if (nChannels>0) {
    Int_t l=0;
    fout<<"temperatureSensor: "<<GetName()<<'\n';
    for(Int_t i=0;i<nChannels;i++) {
      l=0;
      fout<<"  channel: "<<i<<'\n';
      for(Int_t k=0;k<nValuesPerChannel;k++) {
        l++;
        fout<<setw(13)<<right<<fixed<<setprecision(6)<<corrData[i*nValuesPerChannel+k];
        if (l==10) {
          fout<<'\n';
          l=0;
        }
      }
      fout<<endl;
    }
    fout<<"//----------------------------------------------------------------------------"
        <<endl;
  }
}

Float_t HTrb2Correction::compare(HTrb2Correction& b) {
  // compares two data sets (used by Oracle interface)
  Float_t diff=0.F;
  if (b.getHighResolutionFlag()!=highResolutionFlag) {
    diff=999999.F;
  } else {
    Float_t* arr=b.getCorrections();
    for (Int_t i=0;i<getSize();i++) {
      Float_t d=TMath::Abs(corrData[i]-arr[i]);
      if (d>diff) diff=d;
    }
  }
  return diff;
}
 htrb2correction.cc:1
 htrb2correction.cc:2
 htrb2correction.cc:3
 htrb2correction.cc:4
 htrb2correction.cc:5
 htrb2correction.cc:6
 htrb2correction.cc:7
 htrb2correction.cc:8
 htrb2correction.cc:9
 htrb2correction.cc:10
 htrb2correction.cc:11
 htrb2correction.cc:12
 htrb2correction.cc:13
 htrb2correction.cc:14
 htrb2correction.cc:15
 htrb2correction.cc:16
 htrb2correction.cc:17
 htrb2correction.cc:18
 htrb2correction.cc:19
 htrb2correction.cc:20
 htrb2correction.cc:21
 htrb2correction.cc:22
 htrb2correction.cc:23
 htrb2correction.cc:24
 htrb2correction.cc:25
 htrb2correction.cc:26
 htrb2correction.cc:27
 htrb2correction.cc:28
 htrb2correction.cc:29
 htrb2correction.cc:30
 htrb2correction.cc:31
 htrb2correction.cc:32
 htrb2correction.cc:33
 htrb2correction.cc:34
 htrb2correction.cc:35
 htrb2correction.cc:36
 htrb2correction.cc:37
 htrb2correction.cc:38
 htrb2correction.cc:39
 htrb2correction.cc:40
 htrb2correction.cc:41
 htrb2correction.cc:42
 htrb2correction.cc:43
 htrb2correction.cc:44
 htrb2correction.cc:45
 htrb2correction.cc:46
 htrb2correction.cc:47
 htrb2correction.cc:48
 htrb2correction.cc:49
 htrb2correction.cc:50
 htrb2correction.cc:51
 htrb2correction.cc:52
 htrb2correction.cc:53
 htrb2correction.cc:54
 htrb2correction.cc:55
 htrb2correction.cc:56
 htrb2correction.cc:57
 htrb2correction.cc:58
 htrb2correction.cc:59
 htrb2correction.cc:60
 htrb2correction.cc:61
 htrb2correction.cc:62
 htrb2correction.cc:63
 htrb2correction.cc:64
 htrb2correction.cc:65
 htrb2correction.cc:66
 htrb2correction.cc:67
 htrb2correction.cc:68
 htrb2correction.cc:69
 htrb2correction.cc:70
 htrb2correction.cc:71
 htrb2correction.cc:72
 htrb2correction.cc:73
 htrb2correction.cc:74
 htrb2correction.cc:75
 htrb2correction.cc:76
 htrb2correction.cc:77
 htrb2correction.cc:78
 htrb2correction.cc:79
 htrb2correction.cc:80
 htrb2correction.cc:81
 htrb2correction.cc:82
 htrb2correction.cc:83
 htrb2correction.cc:84
 htrb2correction.cc:85
 htrb2correction.cc:86
 htrb2correction.cc:87
 htrb2correction.cc:88
 htrb2correction.cc:89
 htrb2correction.cc:90
 htrb2correction.cc:91
 htrb2correction.cc:92
 htrb2correction.cc:93
 htrb2correction.cc:94
 htrb2correction.cc:95
 htrb2correction.cc:96
 htrb2correction.cc:97
 htrb2correction.cc:98
 htrb2correction.cc:99
 htrb2correction.cc:100
 htrb2correction.cc:101
 htrb2correction.cc:102
 htrb2correction.cc:103
 htrb2correction.cc:104
 htrb2correction.cc:105
 htrb2correction.cc:106
 htrb2correction.cc:107
 htrb2correction.cc:108
 htrb2correction.cc:109
 htrb2correction.cc:110
 htrb2correction.cc:111
 htrb2correction.cc:112
 htrb2correction.cc:113
 htrb2correction.cc:114
 htrb2correction.cc:115
 htrb2correction.cc:116
 htrb2correction.cc:117
 htrb2correction.cc:118
 htrb2correction.cc:119
 htrb2correction.cc:120
 htrb2correction.cc:121
 htrb2correction.cc:122
 htrb2correction.cc:123
 htrb2correction.cc:124
 htrb2correction.cc:125
 htrb2correction.cc:126
 htrb2correction.cc:127
 htrb2correction.cc:128
 htrb2correction.cc:129
 htrb2correction.cc:130
 htrb2correction.cc:131
 htrb2correction.cc:132
 htrb2correction.cc:133
 htrb2correction.cc:134
 htrb2correction.cc:135
 htrb2correction.cc:136
 htrb2correction.cc:137
 htrb2correction.cc:138
 htrb2correction.cc:139
 htrb2correction.cc:140
 htrb2correction.cc:141