LCOV - code coverage report
Current view: top level - STEER/CDB - AliDCSSensorArray.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 428 3.5 %
Date: 2016-06-14 17:26:59 Functions: 4 42 9.5 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, 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             : //  Calibration class for DCS sensors                                        //
      20             : //  Authors: Marian Ivanov and Haavard Helstrup                              //
      21             : //                                                                           //
      22             : ///////////////////////////////////////////////////////////////////////////////
      23             : 
      24             : #include "AliDCSSensorArray.h"
      25             : #include "AliLog.h"
      26             : #include <TMath.h>
      27             : #include "AliDCSSensor.h"
      28             : #include "AliNDLocalRegression.h"
      29         128 : ClassImp(AliDCSSensorArray)
      30             : 
      31             : const Double_t kSecInHour = 3600.; // seconds in one hour
      32             : const UInt_t   kMinMapTime = 60;   // don't fit maps shorter than one minute
      33             : 
      34             : //_____________________________________________________________________________
      35          45 : AliDCSSensorArray::AliDCSSensorArray():TNamed(), 
      36          45 :   fMinGraph(10),
      37          45 :   fMinPoints(10),
      38          45 :   fIter(10),
      39          45 :   fMaxDelta(0.0),
      40          45 :   fFitReq(2),
      41          45 :   fValCut(-1),
      42          45 :   fDiffCut(-1),
      43          45 :   fStartTime (2000,1,1,0,0,0),
      44          45 :   fEndTime   (2000,1,1,0,0,0),
      45          45 :   fSensors(0)
      46         143 : {
      47             :   //
      48             :   // AliDCSSensorArray default constructor
      49             :   //
      50             : 
      51          49 : }
      52             : //_____________________________________________________________________________
      53           0 : AliDCSSensorArray::AliDCSSensorArray(TClonesArray *arr):TNamed(),
      54           0 :   fMinGraph(10),
      55           0 :   fMinPoints(10),
      56           0 :   fIter(10),
      57           0 :   fMaxDelta(0.0),
      58           0 :   fFitReq(2),
      59           0 :   fValCut(-1),
      60           0 :   fDiffCut(-1),
      61           0 :   fStartTime (2000,1,1,0,0,0),
      62           0 :   fEndTime   (2000,1,1,0,0,0),
      63           0 :   fSensors(arr)
      64           0 : {
      65             :   //
      66             :   // AliDCSSensorArray special constructor taking TClonesArray from ReadList
      67             :   //
      68             : 
      69           0 : }
      70             : //_____________________________________________________________________________
      71             : AliDCSSensorArray::AliDCSSensorArray(Int_t run, const char* dbEntry) :
      72           0 :   TNamed(),
      73           0 :   fMinGraph(10),
      74           0 :   fMinPoints(10),
      75           0 :   fIter(10),
      76           0 :   fMaxDelta(0.0),
      77           0 :   fFitReq(2),
      78           0 :   fValCut(-1),
      79           0 :   fDiffCut(-1),
      80           0 :   fStartTime (2000,1,1,0,0,0),
      81           0 :   fEndTime   (2000,1,1,0,0,0),
      82           0 :   fSensors(0)
      83           0 : {
      84             :   //
      85             :   // Read configuration from OCDB
      86             :   //
      87             : 
      88           0 :   AliCDBEntry *entry = AliCDBManager::Instance()->Get(dbEntry,run);
      89           0 :   if (entry) {
      90           0 :     TTree *tree = (TTree*) entry->GetObject();
      91           0 :     fSensors = AliDCSSensor::ReadTree(tree);
      92           0 :   } else {
      93           0 :     AliError("Unable to load configuration from CDB!");
      94             :   }
      95           0 : }
      96             : //_____________________________________________________________________________
      97             : AliDCSSensorArray::AliDCSSensorArray(UInt_t startTime, UInt_t endTime,
      98             :                        TTree* confTree) :
      99           0 :   TNamed(),
     100           0 :   fMinGraph(10),
     101           0 :   fMinPoints(10),
     102           0 :   fIter(10),
     103           0 :   fMaxDelta(0.0),
     104           0 :   fFitReq(2),
     105           0 :   fValCut(-1),
     106           0 :   fDiffCut(-1),
     107           0 :   fStartTime (2000,1,1,0,0,0),
     108           0 :   fEndTime   (2000,1,1,0,0,0),
     109           0 :   fSensors(0)
     110             : 
     111           0 : {
     112             :   //
     113             :   // AliDCSSensorArray constructor for Shuttle preprocessor
     114             :   //  (confTree read from OCDB)
     115             :   //
     116           0 :   fSensors = AliDCSSensor::ReadTree(confTree);
     117           0 :   fSensors->BypassStreamer(kFALSE);
     118           0 :   fStartTime = TTimeStamp((time_t)startTime,0);
     119           0 :   fEndTime   = TTimeStamp((time_t)endTime,0);
     120           0 : }
     121             : 
     122             : 
     123             : //_____________________________________________________________________________
     124             : AliDCSSensorArray::AliDCSSensorArray(UInt_t startTime, UInt_t endTime,
     125             :                        TClonesArray *sensors) :
     126           0 :   TNamed(),
     127           0 :   fMinGraph(10),
     128           0 :   fMinPoints(10),
     129           0 :   fIter(10),
     130           0 :   fMaxDelta(0.0),
     131           0 :   fFitReq(2),
     132           0 :   fValCut(-1),
     133           0 :   fDiffCut(-1),
     134           0 :   fStartTime (2000,1,1,0,0,0),
     135           0 :   fEndTime   (2000,1,1,0,0,0),
     136           0 :   fSensors(sensors)
     137             : 
     138           0 : {
     139             :   //
     140             :   // AliDCSSensorArray constructor for Shuttle preprocessor
     141             :   //  (TClonesArray of AliDCSSensor objects)
     142             :   //
     143           0 :   fStartTime = TTimeStamp((time_t)startTime,0);
     144           0 :   fEndTime   = TTimeStamp((time_t)endTime,0);
     145           0 : }
     146             : 
     147             : //_____________________________________________________________________________
     148           0 : AliDCSSensorArray::AliDCSSensorArray(const AliDCSSensorArray &c):TNamed(c),
     149           0 :   fMinGraph(c.fMinGraph),
     150           0 :   fMinPoints(c.fMinPoints),
     151           0 :   fIter(c.fIter),
     152           0 :   fMaxDelta(c.fMaxDelta),
     153           0 :   fFitReq(c.fFitReq),
     154           0 :   fValCut(c.fValCut),
     155           0 :   fDiffCut(c.fDiffCut),
     156           0 :   fStartTime (c.fStartTime),
     157           0 :   fEndTime   (c.fEndTime),
     158           0 :   fSensors(0)
     159             : 
     160           0 : {
     161             :   //
     162             :   // AliDCSSensorArray copy constructor
     163             :   //
     164             : 
     165           0 :   fSensors = (TClonesArray*)c.fSensors->Clone();
     166           0 : }
     167             : 
     168             : ///_____________________________________________________________________________
     169             : AliDCSSensorArray::~AliDCSSensorArray()
     170           0 : {
     171             :   //
     172             :   // AliDCSSensorArray destructor  - we have somehwere double delete - had to be disabled -TO BE FIXED LATER
     173             :   //
     174             :   //fSensors->Delete();
     175             :   //delete fSensors;
     176             : 
     177           6 : }
     178             : 
     179             : //_____________________________________________________________________________
     180             : AliDCSSensorArray &AliDCSSensorArray::operator=(const AliDCSSensorArray &c)
     181             : {
     182             :   //
     183             :   // Assignment operator
     184             :   //
     185           0 :   if (this != &c) {
     186           0 :      fSensors->Delete();
     187           0 :      new (this) AliDCSSensorArray(c);
     188           0 :      fSensors = (TClonesArray*)c.fSensors->Clone();
     189           0 :   }
     190           0 :   return *this;
     191           0 : }
     192             : 
     193             : void AliDCSSensorArray::Print(const Option_t* option) const{
     194             :   //
     195             :   // print function overwriten
     196             :   //
     197           0 :   TString opt = option; opt.ToLower();
     198           0 :   printf("%s:%s\n",GetTitle(), GetName());
     199           0 :   if (!fSensors) return;
     200           0 :   Int_t nsensors=fSensors->GetEntries();
     201           0 :   for (Int_t i=0; i<nsensors; i++){
     202           0 :     printf("Sensor Nr%d\n",i);
     203           0 :     if (fSensors->At(i)) fSensors->At(i)->Print(option);
     204             :   }
     205           0 : }
     206             : 
     207             : //____________________________________________________________________________
     208             : 
     209             : void AliDCSSensorArray::SetGraph(TMap *map)
     210             : {
     211             :   //
     212             :   // Read graphs from DCS maps
     213             :   //
     214           0 :   Int_t nsensors = fSensors->GetEntries();
     215           0 :   for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     216           0 :     AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     217           0 :     TString stringID = entry->GetStringID();
     218           0 :     TGraph *gr = (TGraph*)map->GetValue(stringID.Data());
     219           0 :     if ( gr !=0 ) {
     220           0 :        entry->SetGraph((TGraph*)gr->Clone());
     221           0 :     } else {
     222           0 :        entry->SetGraph(0);
     223             :     }
     224           0 :   }
     225           0 : }
     226             : //_____________________________________________________________________________
     227             : void AliDCSSensorArray::MakeSplineFit(TMap *map, Bool_t keepMap)
     228             : {
     229             :   //
     230             :   // Make spline fits from DCS maps
     231             :   //
     232           0 :   Int_t nsensors = fSensors->GetEntries();
     233           0 :   for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     234           0 :     AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     235           0 :     TString stringID = entry->GetStringID();
     236           0 :     TGraph *gr = (TGraph*)map->GetValue(stringID.Data());
     237           0 :     if (!gr ) {
     238           0 :       entry->SetFit(0);
     239           0 :       entry->SetGraph(0);
     240           0 :       AliWarning(Form("sensor %s: no input graph",stringID.Data()));
     241           0 :       continue;
     242             :     }
     243           0 :     UInt_t timeDiff = entry->GetEndTime() - entry->GetStartTime();
     244           0 :     if ( timeDiff < kMinMapTime ) {
     245           0 :       AliWarning(Form("sensor %s: map length < 60 s, DCS graph kept.",stringID.Data()));
     246           0 :       entry->SetGraph((TGraph*)gr->Clone());
     247           0 :     } else {
     248           0 :       AliSplineFit *fit = new AliSplineFit();
     249           0 :       fit->SetMinPoints(fMinGraph);
     250           0 :       fit->InitKnots(gr,fMinPoints,fIter,fMaxDelta);
     251           0 :       fit->SplineFit(fFitReq);
     252           0 :       fit->Cleanup();
     253           0 :       if (fit->GetKnots()>0) {
     254           0 :         entry->SetFit(fit);
     255           0 :       } else {
     256           0 :         AliWarning(Form("sensor %s: no fit performed, DCS graph kept.",stringID.Data()));
     257           0 :         entry->SetGraph((TGraph*)gr->Clone());
     258             :       }
     259             :     }
     260           0 :     if (keepMap) entry->SetGraph((TGraph*)gr->Clone());
     261           0 :   }
     262           0 : }
     263             : //_____________________________________________________________________________
     264             : void AliDCSSensorArray::MakeSplineFitAddPoints(TMap *map)
     265             : {
     266             :   //
     267             :   // Make spline fits from DCS maps
     268             :   //
     269           0 :   Int_t nsensors = fSensors->GetEntries();
     270           0 :   for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     271           0 :     AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     272             : 
     273             :   // fetch old points from existing graph
     274             : 
     275           0 :     TGraph *gr = entry->GetGraph();
     276           0 :     if (!gr) {
     277           0 :       gr = new TGraph();
     278           0 :       entry->SetGraph(gr);
     279           0 :     } 
     280           0 :     TString stringID = entry->GetStringID();
     281             : 
     282             :   // fetch new points from DCS map
     283             :   
     284           0 :     TGraph *grAdd = (TGraph*)map->GetValue(stringID.Data());
     285           0 :     if (!grAdd ) return;
     286             : 
     287             :   // add new points to end of graph
     288             :   
     289           0 :     Int_t nPointsOld=gr->GetN();
     290           0 :     Int_t nPointsAdd=grAdd->GetN();
     291           0 :     gr->Expand(nPointsOld+nPointsAdd);
     292           0 :     gr->Set(nPointsOld+nPointsAdd);
     293           0 :     Double_t *addX=grAdd->GetX();
     294           0 :     Double_t *addY=grAdd->GetY();
     295           0 :     for (Int_t i=0;i<nPointsAdd;i++) {
     296           0 :       gr->SetPoint(nPointsOld+i,addX[i],addY[i]);
     297             :     }
     298             :  
     299             :    // make fit to complete graph
     300             :    
     301           0 :     AliSplineFit *fit = new AliSplineFit();
     302           0 :     fit->SetMinPoints(fMinGraph);
     303           0 :     fit->InitKnots(gr,fMinPoints,fIter,fMaxDelta);
     304           0 :     fit->SplineFit(fFitReq);
     305           0 :     fit->Cleanup();
     306           0 :     if (fit->GetKnots()>0) {
     307           0 :       AliSplineFit *oldFit = entry->GetFit();
     308           0 :       if (oldFit) delete oldFit;
     309           0 :       entry->SetFit(fit);
     310           0 :     } else {
     311           0 :       AliWarning(Form("sensor %s: no new fit performed. If available, old fit kept.",stringID.Data()));
     312             :     }
     313           0 :   }
     314           0 : }
     315             : 
     316             : //_____________________________________________________________________________
     317             : Int_t AliDCSSensorArray::NumFits() const 
     318             : {
     319             :  //
     320             :  // Return number of sensors where a succesful fit has been made
     321             :  //
     322             :   Int_t nfit=0;
     323           0 :   Int_t nsensors = fSensors->GetEntries();
     324           0 :   for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     325           0 :     AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     326           0 :     if (entry->GetFit()) nfit++;
     327             :   }    
     328           0 :   return nfit;
     329             : }
     330             : //_____________________________________________________________________________
     331             : Double_t AliDCSSensorArray::GetValue(UInt_t timeSec, Int_t sensor) 
     332             : {
     333             :   //
     334             :   // Return sensor value at time timeSec (obtained from fitted function)
     335             :   //  timeSec = time in seconds from start of run
     336             :   //
     337             : 
     338           0 :   AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(sensor);
     339           0 :   return entry->GetValue(TTimeStamp((time_t)fStartTime.GetSec()+timeSec,0));
     340           0 : }
     341             : 
     342             : 
     343             : //_____________________________________________________________________________
     344             : TMap* AliDCSSensorArray::ExtractDCS(TMap *dcsMap, Bool_t keepStart)
     345             : {
     346             :  //
     347             :  // Extract temperature graphs from DCS maps
     348             :  //
     349           0 :  TMap *values = new TMap;
     350             :  TObjArray * valueSet;
     351             :  // Declare ownership of keys and values
     352             :  // added to the TMap, see
     353             :  // https://root.cern.ch/root/html/TMap.html#TMap:_TMap
     354           0 :  values->SetOwner();
     355           0 :  values->SetOwnerValue();
     356             : 
     357             :  //
     358             :  // Keep global start/end times
     359             :  //    to avoid extrapolations, the fits will only be valid from first 
     360             :  //    measured point to last measured point. This is consistent with hardware,
     361             :  //    as there would be a new measured point if the value changed.
     362             :  
     363           0 :  TTimeStamp startTime=fStartTime;
     364           0 :  TTimeStamp endTime=fEndTime;
     365             :  
     366           0 :  Int_t nsensors = fSensors->GetEntries();
     367           0 :  for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     368           0 :    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     369           0 :    TString stringID = entry->GetStringID();
     370           0 :    TPair *pair = (TPair*)dcsMap->FindObject(stringID.Data());
     371           0 :    if ( pair ) {                            // only try to read values
     372             :                                             // if DCS object available
     373           0 :      valueSet = (TObjArray*)pair->Value();
     374           0 :      TGraph *graph = MakeGraph(valueSet,keepStart);   // MakeGraph sets start/end time
     375             :                                             // per sensor
     376           0 :      values->Add(new TObjString(stringID.Data()),graph);
     377           0 :      entry->SetStartTime(fStartTime);
     378           0 :      entry->SetEndTime(fEndTime);
     379           0 :    }
     380           0 :  }
     381             :  // Reset global start/end time 
     382             :  //    ..... yes, I know this won't get a prize for structured programming..:-)
     383             : 
     384           0 :  fStartTime=startTime;
     385           0 :  fEndTime=endTime;
     386             :  return values;
     387           0 : }
     388             : 
     389             : 
     390             : //_____________________________________________________________________________
     391             : TGraph* AliDCSSensorArray::MakeGraph(TObjArray* valueSet, Bool_t keepStart){
     392             :   //
     393             :   // Make graph of temperature values read from DCS map
     394             :   //   (spline fit parameters will subsequently be obtained from this graph) 
     395             :   //
     396           0 :   Int_t nentries = valueSet->GetEntriesFast(); 
     397           0 :   if ( nentries == 0 ) return 0;
     398             :   
     399           0 :   Float_t *x = new Float_t[nentries];
     400           0 :   Float_t *y = new Float_t[nentries];
     401             :   Int_t time0=0, previousTime=0;
     402           0 :   TTimeStamp firstTime(0);
     403           0 :   TTimeStamp lastTime(0);
     404           0 :   if (keepStart) { 
     405           0 :      firstTime = fStartTime;
     406           0 :      time0 = firstTime.GetSec();
     407           0 :   }
     408             :   Int_t out=0;
     409             :   Int_t skipped=0;
     410           0 :   AliDCSValue *val = (AliDCSValue *)valueSet->At(0);
     411           0 :   AliDCSValue::Type type = val->GetType();
     412           0 :   if ( type == AliDCSValue::kInvalid || type == AliDCSValue::kBool ) {
     413           0 :      delete [] x;
     414           0 :      delete [] y;
     415           0 :      return 0;
     416             :   }
     417             :   Float_t value;
     418           0 :   for (Int_t i=0; i<nentries; i++){
     419           0 :     val = (AliDCSValue *)valueSet->At(i);
     420           0 :     if (!val) continue;
     421           0 :     if (time0==0){
     422           0 :       time0=val->GetTimeStamp();
     423           0 :       firstTime= TTimeStamp((time_t)val->GetTimeStamp(),0);
     424           0 :       lastTime=TTimeStamp((time_t)val->GetTimeStamp(),0);
     425           0 :      }
     426           0 :     switch ( type )
     427             :     { 
     428             :       case AliDCSValue::kFloat:
     429           0 :         value = val->GetFloat();
     430           0 :         break;
     431             :       case AliDCSValue::kChar:
     432           0 :         value = static_cast<Float_t>(val->GetChar());
     433           0 :         break;
     434             :       case AliDCSValue::kInt:
     435           0 :         value = static_cast<Float_t>(val->GetInt());
     436           0 :         break;
     437             :       case AliDCSValue::kUInt:
     438           0 :         value = static_cast<Float_t>(val->GetUInt());
     439           0 :         break;
     440             :       default:
     441             :         continue;
     442             :     }
     443           0 :     if (fValCut>0 && TMath::Abs(value)>fValCut) continue;   // refuse values greater than cut
     444           0 :     if (fDiffCut>0 ) {
     445           0 :       if ( out>0 && skipped<10 && TMath::Abs(value-y[out-1])>fDiffCut) {
     446           0 :         skipped++;                               // refuse values changing 
     447           0 :         continue;                                // by > cut  in one time step
     448             :       }                                          
     449             :       skipped=0;
     450           0 :     }                                         
     451           0 :     if (val->GetTimeStamp()-time0>1000000) continue;
     452           0 :     if (val->GetTimeStamp()-previousTime < 1 ) continue;   // refuse duplicate recordings
     453           0 :     previousTime=val->GetTimeStamp();
     454           0 :     lastTime=TTimeStamp((time_t)val->GetTimeStamp(),0);
     455           0 :     x[out] = (val->GetTimeStamp()-time0)/kSecInHour; // give times in fractions of hours 
     456           0 :     y[out] = value;
     457           0 :     out++;    
     458           0 :   }
     459           0 :   if (!keepStart) fStartTime=firstTime;
     460           0 :   fEndTime=lastTime;
     461           0 :   TGraph * graph = new TGraph(out,x,y);
     462           0 :   delete [] x;
     463           0 :   delete [] y;
     464             :   return graph;
     465           0 : }
     466             : 
     467             : //_____________________________________________________________________________
     468             : void AliDCSSensorArray::RemoveGraphDuplicates(Double_t tolerance){
     469             : //
     470             : //   Remove points with same y value as the previous measured point
     471             : //   (to save space for non-fitted graphs -- i.e. last measured point used)
     472             : //
     473           0 :   Int_t nsensors = fSensors->GetEntries();
     474           0 :   for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     475           0 :     AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     476           0 :     TGraph *graph = entry->GetGraph();
     477           0 :     Double_t x=-999.,y=-999., x0=-999.,y0=-999.;
     478           0 :     if (graph) {
     479           0 :       Int_t npoints=graph->GetN();
     480           0 :       if (npoints>1) {
     481           0 :         for (Int_t i=npoints-1;i>0;i--) {
     482           0 :            graph->GetPoint(i,x,y);
     483           0 :            graph->GetPoint(i-1,x0,y0);
     484           0 :            if ( TMath::Abs(y-y0) < TMath::Abs(tolerance*y0) ) graph->RemovePoint(i);
     485             :          }
     486           0 :       }
     487           0 :     }
     488           0 :    }
     489           0 : }    
     490             : 
     491             : //_____________________________________________________________________________
     492             : void AliDCSSensorArray::RemoveAbsBelowThreshold(const Double_t threshold){
     493             :   //
     494             :   //   Remove points with Abs(y) value below threshold
     495             :   //   (to save space for non-fitted graphs)
     496             :   //   Only remove if the two neighboring points are also
     497             :   //   below threshold t.
     498             :   //   See following figure where x = keep, o = remove
     499             :   //   ^
     500             :   //   | x
     501             :   //   |                             x
     502             :   //   |     x                      x
     503             :   //  t . . . . . . . . . . . . . . . .
     504             :   //   |       x o                x
     505             :   //  0 - - - - - - - - - - - - - - - - - >
     506             :   //   |           o    x   x o o
     507             :   // -t . . . . . . . . . . . . . . . .
     508             :   //   |                  x
     509             :   //
     510             :   
     511           0 :   const Int_t nsensors = fSensors->GetEntries();
     512           0 :   for (Int_t isensor=0; isensor<nsensors; isensor++) {
     513           0 :     AliDCSSensor *entry = static_cast<AliDCSSensor*>(fSensors->At(isensor));
     514           0 :     TGraph *graph = entry->GetGraph();
     515           0 :     Double_t xa=-999.,ya=-999.,xb=-999.,yb=-999.,xc=-999.,yc=-999.;
     516           0 :     if (graph) {
     517           0 :       const Int_t npoints=graph->GetN();
     518           0 :       for (Int_t i=npoints-2;i>0;i--) {
     519           0 :         graph->GetPoint(i-1,xa,ya);
     520           0 :         graph->GetPoint(i,xb,yb);
     521           0 :         graph->GetPoint(i+1,xc,yc);
     522           0 :         if ( (TMath::Abs(ya) < threshold) &&
     523           0 :              (TMath::Abs(yb) < threshold) &&
     524           0 :              (TMath::Abs(yc) < threshold) ) {
     525           0 :           graph->RemovePoint(i);
     526           0 :         }
     527             :       }
     528           0 :     }
     529           0 :   }
     530           0 : }
     531             : 
     532             : //_____________________________________________________________________________
     533             : AliDCSSensor* AliDCSSensorArray::GetSensor(Int_t IdDCS) 
     534             : {
     535             :  //
     536             :  //  Return sensor information for sensor specified by IdDCS
     537             :  //
     538           0 :  Int_t nsensors = fSensors->GetEntries();
     539           0 :  for (Int_t isensor=0; isensor<nsensors; isensor++) {
     540           0 :    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     541           0 :    if (entry->GetIdDCS() == IdDCS) return entry;
     542           0 :  }
     543           0 :  return 0;
     544           0 : }
     545             : //_____________________________________________________________________________
     546             : AliDCSSensor* AliDCSSensorArray::GetSensor(const TString& stringID)
     547             : {
     548             :  //
     549             :  //  Return sensor information for sensor specified by stringID
     550             :  //
     551           0 :  Int_t nsensors = fSensors->GetEntries();
     552           0 :  for (Int_t isensor=0; isensor<nsensors; isensor++) {
     553           0 :    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     554           0 :    if (entry->GetStringID() == stringID) return entry;
     555           0 :  }
     556           0 :  return 0;
     557           0 : }
     558             : //_____________________________________________________________________________
     559             : AliDCSSensor* AliDCSSensorArray::GetSensor(Double_t x, Double_t y, Double_t z)
     560             : {
     561             :  //
     562             :  //  Return sensor closest to given position
     563             :  //
     564           0 :  Int_t nsensors = fSensors->GetEntries();
     565             :  Double_t dist2min=1e99;
     566             :  Double_t xs,ys,zs,dist2;
     567             :  Int_t ind=-1;
     568           0 :  for (Int_t isensor=0; isensor<nsensors; isensor++) {
     569           0 :    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     570           0 :    xs = entry->GetX();
     571           0 :    ys = entry->GetY();
     572           0 :    zs = entry->GetZ();
     573           0 :    dist2 = (x-xs)*(x-xs) + (y-ys)*(y-ys) + (z-zs)*(z-zs);
     574           0 :    if (dist2 < dist2min) {
     575             :       ind=isensor;
     576             :       dist2min = dist2;
     577           0 :    }
     578             :  }
     579           0 :  if ( ind >= 0 ) {
     580           0 :     return (AliDCSSensor*)fSensors->At(ind);
     581             :  } else {
     582           0 :     return 0;
     583             :  }
     584           0 : }
     585             : //_____________________________________________________________________________
     586             : AliDCSSensor* AliDCSSensorArray::GetSensorNum(Int_t ind)
     587             : {
     588             :  //
     589             :  //  Return sensor given by array index
     590             :  //
     591           0 :  return (AliDCSSensor*)fSensors->At(ind);
     592             : }
     593             : 
     594             : //_____________________________________________________________________________
     595             : Int_t AliDCSSensorArray::SetSensor(const TString& stringID,
     596             :                           const  AliDCSSensor& sensor)
     597             : {
     598             :  //
     599             :  //  Update sensor information for sensor specified by stringID
     600             :  //
     601           0 :  Int_t nsensors = fSensors->GetEntries();
     602           0 :  for (Int_t isensor=0; isensor<nsensors; isensor++) {
     603           0 :    AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     604           0 :    if (entry->GetStringID() == stringID) 
     605             :      {
     606           0 :       new ((*fSensors)[isensor])AliDCSSensor(sensor);
     607           0 :       return isensor;
     608             :      }
     609           0 :  }
     610           0 :  return -1;
     611           0 : }
     612             : //_____________________________________________________________________________
     613             : void AliDCSSensorArray::SetSensorNum(const Int_t ind, const AliDCSSensor& sensor)
     614             : {
     615             :  //
     616             :  //  Update sensor information for sensor at index ind
     617             :  //
     618           0 :    new ((*fSensors)[ind])AliDCSSensor(sensor);
     619           0 :    return;
     620           0 : }
     621             : //_____________________________________________________________________________
     622             : void AliDCSSensorArray::RemoveSensorNum(Int_t ind)
     623             : {
     624             :  //
     625             :  //  Return sensor given by array index
     626             :  //
     627             : 
     628           0 :   delete fSensors->RemoveAt(ind);
     629           0 :   fSensors->Compress();
     630           0 : }
     631             : //_____________________________________________________________________________
     632             : void AliDCSSensorArray::RemoveSensor(Int_t IdDCS)
     633             : {
     634             :  //
     635             :  //  Deletes Sensor by given IdDCS
     636             :  //
     637             : 
     638           0 :   Int_t nsensors = fSensors->GetEntries();
     639           0 :   for (Int_t isensor=0; isensor<nsensors; isensor++) { // loop over sensors
     640           0 :     AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     641           0 :     if (entry->GetIdDCS()==IdDCS) {
     642           0 :       delete fSensors->RemoveAt(isensor);
     643           0 :       break;
     644             :     }
     645           0 :   }
     646           0 :   fSensors->Compress();
     647           0 : }
     648             : //_____________________________________________________________________________
     649             : TArrayI AliDCSSensorArray::OutsideThreshold(Double_t threshold, UInt_t timeSec, Bool_t below) const
     650             : {
     651             :  //
     652             :  // Return sensors with values outside threshold at time defined by second
     653             :  // parameter
     654             :  // By default sensors with values below threshold are listed, if third
     655             :  // parameter is set to kFALSE sensors with values above threshold are listed
     656             :  //
     657           0 :   Int_t nsensors = fSensors->GetEntries();
     658           0 :   TArrayI array(nsensors);
     659             :   Int_t outside=0;
     660           0 :   for (Int_t isensor=0; isensor<nsensors; isensor++) { // loop over sensors
     661           0 :     AliDCSSensor *entry = (AliDCSSensor*)fSensors->At(isensor);
     662           0 :     Double_t val=entry->GetValue(timeSec);
     663           0 :     if (below) {
     664           0 :       if (val<threshold) array[outside++] = entry->GetIdDCS();
     665             :     } else {
     666           0 :       if (val>threshold) array[outside++] = entry->GetIdDCS();
     667             :     }    
     668             :   }
     669           0 :   array.Set(outside);
     670             :   return array;
     671           0 : }
     672             :  
     673             : //_____________________________________________________________________________
     674             : Int_t AliDCSSensorArray::GetFirstIdDCS() const
     675             : {
     676             :  //
     677             :  //  Return DCS Id of first sensor
     678             :  //
     679           0 :  if ( fSensors != 0 ) {
     680           0 :     return ((AliDCSSensor*)fSensors->At(0))->GetIdDCS();
     681             :  } else {
     682           0 :     return 0;
     683             :  }
     684           0 : }
     685             : 
     686             : //_____________________________________________________________________________
     687             : Int_t AliDCSSensorArray::GetLastIdDCS() const 
     688             : {
     689             :  //
     690             :  //  Return DCS Id of last sensor
     691             :  //
     692           0 :  if ( fSensors != 0 ) {
     693           0 :     Int_t last = fSensors->GetEntries();
     694           0 :     return ((AliDCSSensor*)fSensors->At(last-1))->GetIdDCS();
     695             :  } else {
     696           0 :     return 0;
     697             :  }
     698           0 : }
     699             : //_____________________________________________________________________________
     700             : void AliDCSSensorArray::ClearGraph()
     701             : {
     702             :   //
     703             :   // Delete DCS graphs from all sensors in array
     704             :   //
     705             :    
     706           0 :    Int_t nsensors = fSensors->GetEntries();
     707           0 :    for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     708           0 :      AliDCSSensor *sensor = (AliDCSSensor*)fSensors->At(isensor);
     709           0 :      TGraph *gr = sensor->GetGraph();
     710           0 :      if ( gr != 0 ) {
     711           0 :        delete gr;
     712             :        gr = 0;
     713           0 :      }
     714           0 :      sensor->SetGraph(0);
     715             :    }
     716           0 : }
     717             : //_____________________________________________________________________________
     718             : void AliDCSSensorArray::ClearFit()
     719             : {
     720             :   //
     721             :   // Delete spline fits from all sensors in array
     722             :   //
     723             : 
     724           0 :    Int_t nsensors = fSensors->GetEntries();
     725           0 :    for ( Int_t isensor=0; isensor<nsensors; isensor++) {
     726           0 :      AliDCSSensor *sensor = (AliDCSSensor*)fSensors->At(isensor);
     727           0 :      AliSplineFit *fit = sensor->GetFit();
     728           0 :      if ( fit != 0 ) {
     729           0 :        delete fit;
     730             :        fit = 0;
     731           0 :      }
     732           0 :      sensor->SetFit(0);
     733             :    }
     734           0 : }
     735             : //_____________________________________________________________________________
     736             : void AliDCSSensorArray::AddSensors(AliDCSSensorArray *newSensors)
     737             : {
     738             :   //
     739             :   // add sensors from two sensor arrays
     740             :   //
     741             :   
     742           0 :   Int_t numNew = newSensors->NumSensors();
     743           0 :   Int_t numOld = fSensors->GetEntries();
     744           0 :   fSensors->Expand(numOld+numNew);
     745           0 :   for (Int_t i=0;i<numNew;i++) {
     746           0 :     AliDCSSensor *sens = newSensors->GetSensorNum(i);
     747           0 :     new ((*fSensors)[numOld+i]) AliDCSSensor(*sens);
     748             :   }
     749           0 : }  
     750             : 
     751             : void  AliDCSSensorArray::DumpToTree(const char * fname, Int_t deltaT, Int_t sigmaT){
     752             :   ///
     753             :   /// Dump the content of the DCS sensor array into the tree
     754             :   /// Usage:
     755             :   ///   1.) visualization
     756             :   ///   2.) make a numerical diff (if saved as root file)
     757             :   ///   3.) make a "alphabetic" diff if saved as xml file
     758             :   ///
     759           0 :   Int_t nSensors = fSensors->GetEntries();
     760           0 :   UInt_t nBins=TMath::Nint(Double_t(fEndTime-fStartTime)/deltaT)+1;  
     761           0 :   UInt_t startTime=deltaT*(fStartTime/deltaT);
     762           0 :   TVectorF values(nSensors);
     763           0 :   TVectorF valuesSmooth(nSensors);
     764             : 
     765           0 :   for (Int_t iSensor=0; iSensor<nSensors; iSensor++){
     766           0 :     AliDCSSensor *sensor=  GetSensorNum (iSensor);
     767           0 :     TGraph *gr = sensor->GetGraph();
     768           0 :     if (gr) gr->Sort();
     769             :   }
     770             :   //
     771             :   //
     772           0 :   TTreeSRedirector *pcstream = new TTreeSRedirector(fname,"recreate");
     773           0 :   for (Int_t itime=0; itime<nBins; itime++) {
     774           0 :     UInt_t evalTime=startTime+itime*deltaT;
     775           0 :     TTimeStamp timeStamp(evalTime);
     776           0 :     (*pcstream)<<"sensorDumpTime"<<"evalTime="<<evalTime;
     777           0 :     for (Int_t iSensor=0; iSensor<nSensors; iSensor++){
     778           0 :       AliDCSSensor *sensor=  GetSensorNum (iSensor);
     779           0 :       values[iSensor]=sensor->GetValue(timeStamp);
     780           0 :       TGraph *gr = sensor->GetGraph();
     781           0 :       valuesSmooth[iSensor]=0;
     782           0 :       if (gr){
     783           0 :         valuesSmooth[iSensor]=AliNDLocalRegression::EvalGraphKernel(gr, (timeStamp-sensor->GetStartTime())/3600., sigmaT/3600.,3,0,1);
     784           0 :       }
     785           0 :       (*pcstream)<<"sensorDumpTime"<<TString::Format("%s=",(sensor->GetStringID()).Data())<<values[iSensor];      
     786           0 :       (*pcstream)<<"sensorDumpTime"<<TString::Format("s%s=",(sensor->GetStringID()).Data())<<valuesSmooth[iSensor];      
     787             :     }
     788           0 :     (*pcstream)<<"sensorDumpTime"<<"\n";
     789           0 :   }
     790             : 
     791           0 :   (*pcstream)<<"sensorDumpFull"<<"array.="<<this<<"\n";    
     792           0 :   for (Int_t iSensor=0; iSensor<nSensors; iSensor++){
     793           0 :     AliDCSSensor *sensor=  GetSensorNum (iSensor);
     794           0 :     if (sensor->GetGraph()){
     795           0 :       (*pcstream)<<"sensorDump"<<TString::Format("gr%s.=",(sensor->GetStringID()).Data())<<sensor; 
     796           0 :      }
     797             :   }
     798           0 :   (*pcstream)<<"sensorDump"<<"\n";
     799             :   
     800           0 :   delete pcstream;
     801             : 
     802             : 
     803           0 : }
     804             :   

Generated by: LCOV version 1.11