LCOV - code coverage report
Current view: top level - STEER/CDB - AliDCSSensor.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 153 11.8 %
Date: 2016-06-14 17:26:59 Functions: 4 18 22.2 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 2006-07, 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             : 
      17             : ////////////////////////////////////////////////////////////////////////////////
      18             : //                                                                            //
      19             : // Class describing time dependent values read from DCS sensors               //  
      20             : // (including pointers to graphs/fits)                                        //
      21             : // Authors: Marian Ivanov, Haavard Helstrup and Martin Siska                  //
      22             : //                                                                            //
      23             : ////////////////////////////////////////////////////////////////////////////////
      24             : 
      25             : 
      26             : #include "AliDCSSensor.h"
      27             : #include "TDatime.h"
      28             : #include "TCanvas.h"
      29         128 : ClassImp(AliDCSSensor)
      30             : 
      31             : const Double_t kSecInHour = 3600.; // seconds in one hour
      32             : 
      33             : 
      34             : 
      35        8163 : AliDCSSensor::AliDCSSensor():
      36        8163 :   fId(),
      37        8163 :   fIdDCS(0),
      38        8163 :   fStringID(),
      39        8163 :   fStartTime(0),
      40        8163 :   fEndTime(0),
      41        8163 :   fGraph(0),
      42        8163 :   fFit(0),
      43        8163 :   fX(0),
      44        8163 :   fY(0),
      45        8163 :   fZ(0)
      46       25317 : {
      47             :   //
      48             :   //  Standard constructor
      49             :   //
      50        8577 : }
      51             : 
      52             : AliDCSSensor::AliDCSSensor(const AliDCSSensor& source) :
      53           0 :    TNamed(source),
      54           0 :    fId(source.fId),
      55           0 :    fIdDCS(source.fIdDCS),
      56           0 :    fStringID(source.fStringID),
      57           0 :    fStartTime(source.fStartTime),
      58           0 :    fEndTime(source.fEndTime),
      59           0 :    fGraph(0),
      60           0 :    fFit(0),
      61           0 :    fX(source.fX),
      62           0 :    fY(source.fY),
      63           0 :    fZ(source.fZ)
      64             : //
      65             : //  Copy constructor
      66             : //
      67           0 : { 
      68           0 :    if (source.fGraph) fGraph = (TGraph*)source.fGraph->Clone();
      69           0 :    if (source.fFit) fFit = (AliSplineFit*)source.fFit->Clone();
      70           0 : }
      71             : 
      72           4 : AliDCSSensor::~AliDCSSensor(){
      73             :   //
      74             :   // Destructor
      75             :   //
      76           2 :   if(fGraph)
      77           0 :     delete fGraph;
      78           2 :   fGraph=0;
      79             : 
      80           2 : }
      81             : 
      82             : AliDCSSensor& AliDCSSensor::operator=(const AliDCSSensor& source){
      83             : //
      84             : // assignment operator
      85             : //
      86           0 :   if (&source == this) return *this;
      87           0 :   new (this) AliDCSSensor(source);
      88             : 
      89           0 :   return *this;
      90           0 : }
      91             : 
      92             : 
      93             : void AliDCSSensor::Print(const Option_t* option) const{
      94             :   //
      95             :   // print function
      96             :   //  
      97           0 :   TString opt = option; opt.ToLower();
      98           0 :   printf("%s:%s\n",GetTitle(), GetName());
      99           0 :   printf("%s\n",fStringID.Data());
     100             : 
     101           0 : }
     102             : 
     103             : void AliDCSSensor::Draw(Option_t* option) {
     104             :   //
     105             :   // draw function - to viusalize sensor
     106             :   // Unfortuantelly - it  make a memory leak as function Draw does not return the object pointer
     107             :   //
     108           0 :   TCanvas * canvas = new TCanvas((fStringID+option).Data(), (fStringID+option).Data()); 
     109           0 :   if (fGraph){
     110             :     // transform points to time in s
     111           0 :     Int_t npoints = fGraph->GetN();
     112           0 :     for (Int_t i=0; i<npoints; i++){
     113           0 :       fGraph->GetX()[i]=fGraph->GetX()[i]*3600+fStartTime;
     114             :     }
     115           0 :     fGraph->Draw("alp");
     116             :     return;
     117             :   }
     118           0 :   canvas->cd();
     119           0 :   TGraph * graph = MakeGraph(100);  // memory leak - we can not modify the content - const method
     120           0 :   if (graph){
     121           0 :     graph->Draw(option);              // 
     122           0 :   }
     123           0 : }
     124             : 
     125             : 
     126             : 
     127             : //_____________________________________________________________________________
     128             : Double_t AliDCSSensor::GetValue(UInt_t timeSec)
     129             : {
     130             :  // 
     131             :  // Get DCS value for actual sensor
     132             :  //  timeSec given as offset from start-of-map measured in seconds
     133             :  //  *NOTE* In the current TPC setup, start-of-map is defined as the 
     134             :  //         first measured point for each sensor. This will be different
     135             :  //         for each sensor in the array. If you want to get a value at the 
     136             :  //         same absolute time, use AliDCSSensor::GetValue(TTimeStamp time)
     137             :  //         or AliDCSSensorArray::GetValue (UInt_t timeSec, Int_t sensor)
     138             :  //         which measure offsets with respect to the (global) start-of-run
     139             :  //
     140           0 :  Bool_t inside=kTRUE;
     141           0 :  return Eval(TTimeStamp((time_t)(fStartTime+timeSec),0),inside);
     142           0 : }
     143             : //_____________________________________________________________________________
     144             : Double_t AliDCSSensor::GetValue(TTimeStamp time) 
     145             : {
     146             :  // Get DCS value for actual sensor
     147             :  //  time given as absolute TTimeStamp
     148             :  //
     149           0 :  Bool_t inside=kTRUE;
     150           0 :  return Eval(time, inside);
     151           0 : }
     152             : 
     153             : //_____________________________________________________________________________
     154             : 
     155             : Double_t AliDCSSensor::Eval(const TTimeStamp& time, Bool_t& inside) const
     156             : {
     157             :   // 
     158             :   // Return DCS value at given time
     159             :   //  The value is calculated from the AliSplineFit, if a fit is not available 
     160             :   //    the most recent reading from the Graph of DCS points is returned (if 
     161             :   //    the graph is present)
     162             :   //  If time < start of map  return value at start of map, inside = false
     163             :   //  If time > end of map    return value at end of map, inside = false
     164             :   
     165           0 :   UInt_t timeSec = time.GetSec();
     166           0 :   UInt_t diff = timeSec-fStartTime;
     167           0 :   inside = true;
     168             :   
     169           0 :   if ( timeSec < fStartTime ) { 
     170           0 :      inside=false;
     171             :      diff=0;
     172           0 :   }
     173           0 :   if ( timeSec > fEndTime ) {
     174           0 :      inside=false;
     175           0 :      diff = fEndTime-fStartTime;
     176           0 :   }
     177             :  
     178           0 :   Double_t timeHour = diff/kSecInHour;
     179           0 :   if ( fFit ) {
     180           0 :      return fFit->Eval(timeHour); 
     181             :   } else {
     182           0 :      if ( fGraph ) {
     183           0 :        return EvalGraph(timeHour);
     184             :      } else {  
     185           0 :        return -99;
     186             :      }
     187             :   }
     188           0 : }
     189             : //_____________________________________________________________________________
     190             : 
     191             : Double_t AliDCSSensor::EvalGraph(const TTimeStamp& time, Bool_t& inside) const
     192             : {
     193             :   // 
     194             :   // Return DCS value from graph of DCS points (i.e return last reading before
     195             :   //  the time specified by TTimeStamp
     196             :   //  If time < start of map  return value at start of map, inside = false
     197             :   //  If time > end of map    return value at end of map, inside = false
     198             :   
     199           0 :   UInt_t timeSec = time.GetSec();
     200           0 :   UInt_t diff = timeSec-fStartTime;
     201           0 :   inside = true;
     202             :   
     203           0 :   if ( timeSec < fStartTime ) { 
     204           0 :      inside=false;
     205             :      diff=0;
     206           0 :   }
     207           0 :   if ( timeSec > fEndTime ) {
     208           0 :      inside=false;
     209           0 :      diff = fEndTime-fStartTime;
     210           0 :   }
     211             :  
     212           0 :   Double_t timeHour = diff/kSecInHour;
     213           0 :   if ( fGraph ) {
     214           0 :      return EvalGraph(timeHour);
     215             :   } else {  
     216           0 :      return -99;
     217             :   }  
     218           0 : }
     219             : //_____________________________________________________________________________
     220             : Double_t AliDCSSensor::EvalGraph(const Double_t& timeHour) const 
     221             : {
     222             :   //
     223             :   // Extract last value in graph observed before time given by timeHour
     224             :   //
     225             : 
     226             :   // return -99 if point specified is before beginning of graph
     227           0 :   Double_t x=0; Double_t y=0;
     228           0 :   fGraph->GetPoint(0,x,y);
     229           0 :   if ( timeHour < x ) return -99;
     230             :   
     231             :   // return previous point when first time > timeHour is observed
     232             :   
     233           0 :   Int_t npoints = fGraph->GetN();
     234           0 :   for (Int_t i=1; i<npoints; i++) {
     235           0 :      fGraph->GetPoint(i,x,y);
     236           0 :      if ( timeHour < x ) {
     237           0 :        fGraph->GetPoint(i-1,x,y);
     238           0 :        return y;
     239             :      }
     240             :   }
     241             :   
     242             :   // return last point if all times are < timeHour
     243           0 :   return y;
     244           0 : } 
     245             :         
     246             : 
     247             : //_____________________________________________________________________________
     248             : TGraph* AliDCSSensor::MakeGraph(Int_t nPoints, Bool_t debug) const
     249             : {
     250             :   //
     251             :   // Make graph from start time to end time of DCS values 
     252             :   //
     253             : 
     254             :  
     255             : 
     256           0 :   UInt_t stepTime = (fEndTime-fStartTime)/nPoints;
     257             :   
     258           0 :   if (debug==kTRUE) {
     259           0 :      printf ("Start time %d, End time %d, step time %d\n",
     260             :      fStartTime,fEndTime,stepTime);
     261           0 :      TTimeStamp t((time_t)fStartTime,0); t.Print();
     262           0 :      TTimeStamp t2((time_t)fEndTime,0); t2.Print();
     263           0 :   }     
     264             :   
     265           0 :   if ( !fFit ) return 0;
     266             : 
     267           0 :   Double_t *x = new Double_t[nPoints+1];
     268           0 :   Double_t *y = new Double_t[nPoints+1];
     269           0 :   for (Int_t ip=0; ip<nPoints; ip++) {
     270           0 :     x[ip] = (time_t)(fStartTime+ip*stepTime);
     271           0 :     y[ip] = fFit->Eval(ip*stepTime/kSecInHour);
     272           0 :     if (debug==kTRUE) {
     273           0 :      TTimeStamp t3((time_t)x[ip],0); 
     274           0 :      printf ("x=%f, y=%f  ",x[ip],y[ip]);
     275           0 :      t3.Print();
     276           0 :     }
     277             :   }
     278             :   
     279           0 :   TGraph *graph = new TGraph(nPoints,x,y);
     280           0 :   delete [] x;
     281           0 :   delete [] y;
     282             :   
     283           0 :   graph->GetXaxis()->SetTimeDisplay(1);
     284           0 :   graph->GetXaxis()->SetLabelOffset(0.02);
     285           0 :   graph->GetXaxis()->SetTimeFormat("#splitline{%d/%m}{%H:%M}");
     286             : 
     287             :   return graph;
     288           0 : }
     289             : 
     290             : //_____________________________________________________________________________
     291             : 
     292             : TClonesArray * AliDCSSensor::ReadTree(TTree* tree) {
     293             :   //
     294             :   // read values from ascii file
     295             :   //
     296             : 
     297           0 :   Int_t nentries = tree->GetEntries();
     298             : 
     299           0 :   char stringId[100];
     300           0 :   Int_t num=0;
     301           0 :   Int_t idDCS=0;
     302           0 :   Double_t x=0;
     303           0 :   Double_t y=0;
     304           0 :   Double_t z=0;
     305             : 
     306           0 :   tree->SetBranchAddress("StringID",&stringId);
     307           0 :   tree->SetBranchAddress("IdDCS",&idDCS);
     308           0 :   tree->SetBranchAddress("Num",&num);
     309           0 :   tree->SetBranchAddress("X",&x);
     310           0 :   tree->SetBranchAddress("Y",&y);
     311           0 :   tree->SetBranchAddress("Z",&z);
     312             : 
     313             :   // firstSensor = (Int_t)tree->GetMinimum("ECha");
     314             :   // lastSensor = (Int_t)tree->GetMaximum("ECha");
     315             : 
     316           0 :   TClonesArray * array = new TClonesArray("AliDCSSensor",nentries);
     317           0 :    printf ("nentries = %d\n",nentries);
     318             : 
     319           0 :   for (Int_t isensor=0; isensor<nentries; isensor++){
     320           0 :     AliDCSSensor * sens = new ((*array)[isensor])AliDCSSensor;
     321           0 :     tree->GetEntry(isensor);
     322           0 :     sens->SetId(isensor);
     323           0 :     sens->SetIdDCS(idDCS);
     324           0 :     sens->SetStringID(TString(stringId));
     325           0 :     sens->SetX(x);
     326           0 :     sens->SetY(y);
     327           0 :     sens->SetZ(z);
     328             : 
     329             :   }
     330           0 :   return array;
     331           0 : }
     332             : 

Generated by: LCOV version 1.11