LCOV - code coverage report
Current view: top level - MUON/MUONgraphics - AliMUONTrackerVoltages.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 234 0.4 %
Date: 2016-06-14 17:26:59 Functions: 1 19 5.3 %

          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             : // $Id$
      17             : 
      18             : #include "AliMUONTrackerVoltages.h"
      19             : 
      20             : #include <algorithm>
      21             : #include <map>
      22             : #include <set>
      23             : 
      24             : #include "AliCDBManager.h"
      25             : #include "AliCDBEntry.h"
      26             : #include "AliDCSValue.h"
      27             : #include "AliGRPObject.h"
      28             : #include "AliMpArrayI.h"
      29             : #include "AliMpConstants.h"
      30             : #include "AliMpDCSNamer.h"
      31             : #include "AliMpDEStore.h"
      32             : #include "AliMpDetElement.h"
      33             : #include "AliMUON2DMap.h"
      34             : #include "AliMUONCalibParamND.h"
      35             : #include "AliMUONCalibrationData.h"
      36             : #include "AliMUONCDB.h"
      37             : #include "AliMUONPainterDataRegistry.h"
      38             : #include "AliMUONTrackerData.h"
      39             : #include "AliMUONTrackerDataWrapper.h"
      40             : #include "AliLog.h"
      41             : 
      42             : #include "TCanvas.h"
      43             : #include "TGraph.h"
      44             : #include "TH2.h"
      45             : #include "TLine.h"
      46             : #include "TMap.h"
      47             : #include "TMultiGraph.h"
      48             : #include "TObjArray.h"
      49             : #include "TObjString.h"
      50             : #include "TStyle.h"
      51             : #include "Riostream.h"
      52             : 
      53             : //
      54             : // Base class to inspect the MUON TRACKER HV and LV values
      55             : //
      56             : // With this class you can :
      57             : //
      58             : // - print the values for some (or all) HV channels or LV groups (method Print)
      59             : // - plot the values for some (or all) HV channels or LV groups (method Plot)
      60             : //
      61             : // Note that in this class, all the output (either text or canvas) or the
      62             : // channel *names* used are the same as in the DCS UI at Pt2
      63             : // Specifically the chamber ids start at 1, the slat numbers at 1 and
      64             : // the quad and sect number at 1 also. And not at zero like for the
      65             : // DCS *aliases*. On the contraty, the internal map, coming from the OCDB,
      66             : // only contains aliases, not names. Confusing ? It is.
      67             : //
      68             : 
      69          12 : ClassImp(AliMUONTrackerVoltages)
      70             : 
      71             : //______________________________________________________________________________
      72           0 : AliMUONTrackerVoltages::AliMUONTrackerVoltages(const char* runlist, const char* ocdbPath)
      73           0 : : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
      74           0 : {
      75             :   // ctor from a runlist (txt file)
      76           0 :   SetRunList(runlist);
      77           0 : }
      78             : 
      79             : //______________________________________________________________________________
      80           0 : AliMUONTrackerVoltages::AliMUONTrackerVoltages(Int_t runNumber, const char* ocdbPath)
      81           0 : : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
      82           0 : {
      83             :   // ctor for a single run
      84           0 :   SetRunList(runNumber);
      85           0 : }
      86             : 
      87             : //______________________________________________________________________________
      88             : AliMUONTrackerVoltages::~AliMUONTrackerVoltages()
      89           0 : {
      90             :   // dtor
      91           0 :   delete fDCSNamer;
      92           0 : }
      93             : 
      94             : //____________________________________________________________________________
      95             : TMultiGraph* AliMUONTrackerVoltages::CombineMulti(TObjArray& graphs)
      96             : {
      97             :   // combine multigraphs
      98             : 
      99           0 :   TMultiGraph* rv = new TMultiGraph;
     100             : 
     101           0 :   TIter next(&graphs);
     102             :   TMultiGraph* mg;
     103           0 :   TMultiGraph* ref = static_cast<TMultiGraph*>(next());
     104             : 
     105           0 :   Int_t dref = ref->GetListOfGraphs()->GetEntries();
     106             : 
     107           0 :   while ( ( mg = static_cast<TMultiGraph*>(next())) )
     108             :   {
     109           0 :     TList* list = mg->GetListOfGraphs();
     110           0 :     Int_t d1 = list->GetEntries();
     111             : 
     112           0 :     if (  d1 != dref )
     113             :     {
     114           0 :       AliError(Form("%d vs %d",d1,dref));
     115           0 :       return 0x0;
     116             :     }
     117           0 :   }
     118             : 
     119           0 :   for ( Int_t i = 0; i < dref; ++i )
     120             :   {
     121           0 :     TObjArray graph;
     122           0 :     next.Reset();
     123           0 :     while ( ( mg = static_cast<TMultiGraph*>(next())) )
     124             :     {
     125           0 :       graph.Add(mg->GetListOfGraphs()->At(i));
     126           0 :       TGraph* g = Combine(graph);
     127           0 :       rv->Add(g);
     128             :     }
     129           0 :   }
     130           0 :   return rv;
     131           0 : }
     132             : 
     133             : //____________________________________________________________________________
     134             : TGraph* AliMUONTrackerVoltages::Combine(TObjArray& graphs)
     135             : {
     136             :   // make one graph out of several
     137             :   // x axis is supposed to be time and will end up ordered in the
     138             :   // returned graph
     139             : 
     140           0 :   std::map<int, std::vector<double> > values;
     141           0 :   std::map<int, std::vector<double> >::const_iterator it;
     142             : 
     143           0 :   TIter next(&graphs);
     144             :   TGraph* g;
     145             : 
     146           0 :   while ( ( g = static_cast<TGraph*>(next())) )
     147             :   {
     148           0 :     for ( Int_t i = 0; i < g->GetN(); ++i )
     149             :     {
     150           0 :       std::vector<double> pair;
     151             : 
     152           0 :       pair.push_back(g->GetX()[i]);
     153           0 :       pair.push_back(g->GetY()[i]);
     154             : 
     155           0 :       values.insert( std::make_pair(g->GetX()[i],pair));
     156           0 :     }
     157             :   }
     158             : 
     159             :   TGraph* rv(0x0);
     160             : 
     161           0 :   if ( values.size() )
     162             :   {
     163           0 :     std::vector<double> vx;
     164           0 :     std::vector<double> vy;
     165             : 
     166           0 :     for ( it = values.begin(); it != values.end(); ++it )
     167             :     {
     168           0 :       const std::vector<double>& q = it->second;
     169             : 
     170           0 :       vx.push_back(q[0]);
     171           0 :       vy.push_back(q[1]);
     172             :     }
     173             : 
     174           0 :     rv = new TGraph(values.size(),&vx[0],&vy[0]);
     175           0 :     rv->GetXaxis()->SetNoExponent();
     176             : 
     177           0 :     g = static_cast<TGraph*>(graphs.At(0));
     178             : 
     179           0 :     rv->SetName(g->GetName());
     180           0 :     rv->SetTitle(g->GetTitle());
     181           0 :   }
     182             : 
     183             :   return rv;
     184           0 : }
     185             : 
     186             : //______________________________________________________________________________
     187             : TMap*
     188             : AliMUONTrackerVoltages::CreateMap(Int_t runNumber, Bool_t /*patched*/) const
     189             : {
     190             :   /// Create the map object
     191           0 :   return dynamic_cast<TMap*>(AliMUONCalibrationData::CreateObject(runNumber,fOCDBObjectPath));
     192             : }
     193             : 
     194             : //______________________________________________________________________________
     195             : bool AliMUONTrackerVoltages::IsAlmostEqualRelative(float A, float B, float maxRelDiff) const
     196             : {
     197             :     // Calculate the difference.
     198           0 :     float diff = fabs(A - B);
     199           0 :     A = fabs(A);
     200           0 :     B = fabs(B);
     201             :     // Find the largest
     202           0 :     float largest = (B > A) ? B : A;
     203             : 
     204           0 :     if (diff <= largest * maxRelDiff)
     205           0 :       return true;
     206           0 :     return false;
     207           0 : }
     208             : 
     209             : //______________________________________________________________________________
     210             : TMultiGraph*
     211             : AliMUONTrackerVoltages::Map2Graph(TMap* m, const char* dcsname)
     212             : {
     213             :   // Make a graph of the values matching dcsname
     214           0 :   TIter next(m);
     215             :   TObjString* s;
     216             : 
     217           0 :   TMultiGraph* mg = new TMultiGraph;
     218             : 
     219           0 :   while ( ( s = static_cast<TObjString*>(next()) ) )
     220             :   {
     221           0 :     TString name(DCSNamer()->DCSNameFromAlias(s->String()));
     222             : 
     223           0 :     if ( dcsname && !name.Contains(dcsname)) continue;
     224             : 
     225           0 :     TGraph* g = GraphValues(m,name);
     226             : 
     227           0 :     if ( g )
     228             :     {
     229           0 :       g->SetMarkerSize(1.5);
     230           0 :       g->SetMarkerStyle(2);
     231           0 :       g->SetLineStyle(2);
     232           0 :       mg->Add(g,"lp");
     233           0 :       g->SetTitle(name.Data());
     234             :     }
     235           0 :   }
     236             : 
     237             :   return mg;
     238           0 : }
     239             : 
     240             : //______________________________________________________________________________
     241             : void AliMUONTrackerVoltages::ReadIntegers(const char* filename, std::vector<int>& integers)
     242             : {
     243             :   /// Read integers from filename, where integers are either
     244             :   /// separated by "," or by return carriage
     245           0 :   std::ifstream in(gSystem->ExpandPathName(filename));
     246           0 :   int i;
     247             : 
     248           0 :   std::set<int> runset;
     249             : 
     250           0 :   char line[10000];
     251             : 
     252           0 :   in.getline(line,10000,'\n');
     253             : 
     254           0 :   TString sline(line);
     255             : 
     256           0 :   if (sline.Contains(","))
     257             :   {
     258           0 :     TObjArray* a = sline.Tokenize(",");
     259           0 :     TIter next(a);
     260             :     TObjString* s;
     261           0 :     while ( ( s = static_cast<TObjString*>(next()) ) )
     262             :     {
     263           0 :       runset.insert(s->String().Atoi());
     264             :     }
     265           0 :     delete a;
     266           0 :   }
     267             :   else
     268             :   {
     269           0 :     runset.insert(sline.Atoi());
     270             : 
     271           0 :     while ( in >> i )
     272             :     {
     273           0 :       runset.insert(i);
     274             :     }
     275             :   }
     276             : 
     277           0 :   for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
     278             :   {
     279           0 :     integers.push_back((*it));
     280             :   }
     281             : 
     282           0 :   std::sort(integers.begin(),integers.end());
     283           0 : }
     284             : 
     285             : //______________________________________________________________________________
     286             : AliMpDCSNamer*
     287             : AliMUONTrackerVoltages::DCSNamer() const
     288             : {
     289             :   // return the dcs namer
     290           0 :   if (!fDCSNamer)
     291             :   {
     292           0 :     if (!AliMpDEStore::Instance(false))
     293             :     {
     294           0 :       AliMUONCDB::LoadMapping();
     295           0 :     }
     296           0 :     fDCSNamer = new AliMpDCSNamer("TRACKER");
     297           0 :   }
     298           0 :   return fDCSNamer;
     299           0 : }
     300             : 
     301             : //______________________________________________________________________________
     302             : void AliMUONTrackerVoltages::SetRunList(Int_t runNumber)
     303             : {
     304             :   // Make the runlist be a single run
     305           0 :   fRunList.clear();
     306           0 :   fRunList.push_back(runNumber);
     307           0 : }
     308             : 
     309             : //______________________________________________________________________________
     310             : void
     311             : AliMUONTrackerVoltages::SetRunList(const char* runlist)
     312             : {
     313             :   // Read the runlist from an ASCII file or a comma separated list
     314             :   // or a space separated list
     315             : 
     316           0 :   fRunList.clear();
     317             : 
     318           0 :   if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") )
     319             :   {
     320             :     TObjArray* runs = 0x0;
     321           0 :     if ( TString(runlist).Contains(",") )
     322             :     {
     323           0 :       runs = TString(runlist).Tokenize(",");
     324           0 :     }
     325             :     else
     326             :     {
     327           0 :       runs = TString(runlist).Tokenize(" ");
     328             :     }
     329           0 :     TIter next(runs);
     330             :     TObjString* s;
     331           0 :     std::set<int> runset;
     332             : 
     333           0 :     while ( ( s = static_cast<TObjString*>(next()) ) )
     334             :     {
     335           0 :       runset.insert(s->String().Atoi());
     336             :     }
     337             : 
     338           0 :     for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
     339             :     {
     340           0 :       fRunList.push_back((*it));
     341             :     }
     342             : 
     343           0 :     std::sort(fRunList.begin(),fRunList.end());
     344             : 
     345           0 :     delete runs;
     346           0 :   }
     347             :   else
     348             :   {
     349           0 :     ReadIntegers(runlist,fRunList);
     350             :   }
     351           0 : }
     352             : 
     353             : 
     354             : //______________________________________________________________________________
     355             : TGraph*
     356             : AliMUONTrackerVoltages::GraphValues(TMap* m, const char* dcsname)
     357             : {
     358             :   // make a graph of HV channels' voltage values for a given dcs name (name, not
     359             :   // alias)
     360             : 
     361           0 :   if ( TString(dcsname).Contains("sw") )
     362             :   {
     363             :     // do not graph switches
     364           0 :     return 0x0;
     365             :   }
     366             : 
     367             : 
     368           0 :   AliInfo(dcsname);
     369             : 
     370           0 :   TPair* p = static_cast<TPair*>(m->FindObject(DCSNamer()->DCSAliasFromName(dcsname).Data()));
     371             : 
     372           0 :   if (!p) return 0x0;
     373             : 
     374           0 :   TObjArray* a = static_cast<TObjArray*>(p->Value());
     375             : 
     376           0 :   std::cout << "a for " << p->Key() << " : " << std::endl;
     377             : 
     378           0 :   a->Print();
     379             : 
     380           0 :   TIter n2(a);
     381             :   AliDCSValue* val;
     382             :   Int_t i(0);
     383             : 
     384           0 :   TGraph* g = new TGraph(a->GetEntries());
     385           0 :   while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
     386             :   {
     387           0 :     g->SetPoint(i,val->GetTimeStamp(),val->GetFloat());
     388           0 :     ++i;
     389             :   }
     390           0 :   g->SetName(dcsname);
     391             :   return g;
     392           0 : }
     393             : 
     394             : //______________________________________________________________________________
     395             : void AliMUONTrackerVoltages::TimeAxis(TMultiGraph* g)
     396             : {
     397           0 :   g->GetXaxis()->SetTimeDisplay(1);
     398             : //  g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
     399           0 :   g->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
     400           0 :   g->GetXaxis()->SetTimeOffset(0,"gmt");
     401           0 :   g->GetXaxis()->SetNdivisions(505);
     402           0 : }
     403             : 
     404             : //______________________________________________________________________________
     405             : void
     406             : AliMUONTrackerVoltages::Print(Option_t* dcsname) const
     407             : {
     408             :   /// Print HV values for a given dcs name (or all if dcsname=0)
     409             : 
     410           0 :   AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
     411             : 
     412           0 :   for ( std::vector<int>::size_type iRun = 0; iRun < fRunList.size(); ++iRun )
     413             :   {
     414           0 :     Int_t runNumber = fRunList[iRun];
     415             : 
     416           0 :     AliInfo("---------------------");
     417           0 :     AliInfo(Form("RUN %09d",runNumber));
     418             : 
     419           0 :     AliCDBManager::Instance()->SetRun(runNumber);
     420             : 
     421           0 :     TMap* m = CreateMap(runNumber);
     422           0 :     TIter next(m);
     423             :     TObjString* s;
     424             : 
     425           0 :     while ( ( s = static_cast<TObjString*>(next()) ) )
     426             :     {
     427           0 :       TString name(DCSNamer()->DCSNameFromAlias(s->String()));
     428             : 
     429           0 :       if ( dcsname && !name.Contains(dcsname)) continue;
     430             : 
     431           0 :       TPair* p = static_cast<TPair*>(m->FindObject(s->String()));
     432             : 
     433           0 :       if (!p) continue;
     434             : 
     435           0 :       std::cout << "==== " << s->String() << std::endl;
     436             : 
     437           0 :       TObjArray* a = static_cast<TObjArray*>(p->Value());
     438           0 :       TIter n2(a);
     439             :       AliDCSValue* val;
     440             :       Int_t i(0);
     441             : 
     442           0 :       while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
     443             :       {
     444           0 :         std::cout << Form("i=%5d ",i) << std::endl;
     445           0 :         val->Print("");
     446           0 :         ++i;
     447             :       }
     448           0 :     }
     449           0 :   }
     450           0 : }
     451             : 
     452             : //______________________________________________________________________________
     453             : void
     454             : AliMUONTrackerVoltages::Plot(const char* dcsname, Bool_t withPatch, Bool_t plotIntermediate)
     455             : {
     456             :   /// Show HV values for a given dcs name (or all if dcsname=0)
     457             :   /// Each canvas for each run will go to a separate PDF file
     458             : 
     459           0 :   Ssiz_t ix = fOCDBObjectPath.Last('/');
     460           0 :   TString what = fOCDBObjectPath(ix+1,fOCDBObjectPath.Length()-ix);
     461             : 
     462           0 :   AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
     463           0 :   TObjArray graphs;
     464             : 
     465           0 :   for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
     466             :   {
     467           0 :     Int_t runNumber = fRunList[i];
     468             : 
     469           0 :     AliCDBManager::Instance()->SetRun(runNumber);
     470             : 
     471           0 :     TMap* m = CreateMap(runNumber,withPatch);
     472             : 
     473           0 :     TMultiGraph* mg = Map2Graph(m,dcsname);
     474             : 
     475           0 :     if ( !mg ) continue;
     476             : 
     477           0 :     graphs.Add(mg);
     478             : 
     479           0 :     TString cname(Form("MCH_%s_RUN%09d",what.Data(),runNumber));
     480             : 
     481           0 :     if ( dcsname && strlen(dcsname) > 0 )
     482             :     {
     483           0 :       TString s(dcsname);
     484           0 :       s.ReplaceAll("/","_");
     485           0 :       cname += Form("_dcsname_%s",s.Data());
     486           0 :     }
     487             : 
     488           0 :     AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber);
     489             : 
     490             :     TLine* startRunLine(0);
     491             :     TLine* endRunLine(0);
     492             :     time_t start(0);
     493             :     time_t end(0);
     494             : 
     495           0 :     if ( e )
     496             :     {
     497           0 :       AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());
     498           0 :       if (grp)
     499             :       {
     500           0 :         start = grp->GetTimeStart();
     501           0 :         end = grp->GetTimeEnd();
     502           0 :         TDatime dstart(start);
     503           0 :         TDatime dend(end);
     504             : 
     505           0 :         dstart.Print();
     506           0 :         dend.Print();
     507           0 :       }
     508           0 :     }
     509             : 
     510           0 :     if ( end )
     511             :     {
     512           0 :       TGraph* g = new TGraph(1);
     513           0 :       g->SetPoint(0,end,0);
     514           0 :       mg->Add(g,"");
     515           0 :     }
     516             : 
     517           0 :     if ( plotIntermediate )
     518             :     {
     519           0 :       TCanvas* c = new TCanvas(cname.Data(),cname.Data());
     520             : 
     521           0 :       c->Draw();
     522             : 
     523           0 :       mg->SetTitle(cname.Data());
     524             : 
     525           0 :       mg->Draw("AL");
     526             : 
     527           0 :       TimeAxis(mg);
     528             : 
     529           0 :       if ( start )
     530             :       {
     531           0 :         startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax());
     532           0 :         startRunLine->SetLineColor(2);
     533           0 :         startRunLine->SetLineWidth(4);
     534             :       }
     535           0 :       if  ( end )
     536             :       {
     537           0 :         endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax());
     538           0 :         endRunLine->SetLineColor(2);
     539           0 :         endRunLine->SetLineWidth(4);
     540             :       }
     541             : 
     542           0 :       if ( startRunLine ) startRunLine->Draw();
     543           0 :       if ( endRunLine ) endRunLine->Draw();
     544             : 
     545           0 :       c->SaveAs(Form("%s.pdf",cname.Data()));
     546           0 :     }
     547           0 :   }
     548             : 
     549           0 :   new TCanvas;
     550             : 
     551           0 :   TMultiGraph* g = CombineMulti(graphs);
     552             : 
     553           0 :   TIter next(g->GetListOfGraphs());
     554             :   TGraph* gi;
     555             : 
     556           0 :   while ( ( gi = static_cast<TGraph*>(next())))
     557             :   {
     558           0 :     gi->SetMarkerStyle(kPlus);
     559             :   }
     560           0 :   g->Draw("alp");
     561           0 :   TimeAxis(g);
     562           0 : }

Generated by: LCOV version 1.11