1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONTrackerHV.h"
24 #include "AliCDBManager.h"
25 #include "AliCDBEntry.h"
26 #include "AliDCSValue.h"
27 #include "AliGRPObject.h"
28 #include "AliMpDCSNamer.h"
29 #include "AliMpDEStore.h"
30 #include "AliMUONCalibrationData.h"
31 #include "AliMUONCDB.h"
39 #include "TMultiGraph.h"
40 #include "TObjArray.h"
41 #include "TObjString.h"
43 #include "Riostream.h"
46 // Class to inspect the MUON TRACKER HV values
48 // With this class you can :
50 // a) get a list of trips (method ReportTrips)
51 // b) print the values for some (or all) HV channels (method Print)
52 // c) plot the values for some (or all) HV channels (method Plot)
53 // d) get a list of HV channels that are "OFF" (methods Scan and HVoff)
55 // Note that in this class, all the output (either text or canvas) or the
56 // channel *names* used are the same as in the DCS UI at Pt2
57 // Specifically the chamber ids start at 1, the slat numbers at 1 and
58 // the quad and sect number at 1 also. And not at zero like for the
59 // DCS *aliases*. On the contraty, the internal map, coming from the OCDB,
60 // only contains aliases, not names. Confusing ? It is.
63 ClassImp(AliMUONTrackerHV)
65 //______________________________________________________________________________
66 AliMUONTrackerHV::AliMUONTrackerHV(const char* runlist, const char* ocdbPath)
67 : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
69 // ctor from a runlist (txt file)
73 //______________________________________________________________________________
74 AliMUONTrackerHV::AliMUONTrackerHV(Int_t runNumber, const char* ocdbPath)
75 : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
77 // ctor for a single run
78 SetRunList(runNumber);
81 //______________________________________________________________________________
82 AliMUONTrackerHV::~AliMUONTrackerHV()
88 //______________________________________________________________________________
89 void AliMUONTrackerHV::ReadIntegers(const char* filename, std::vector<int>& integers)
91 /// Read integers from filename, where integers are either
92 /// separated by "," or by return carriage
93 std::ifstream in(gSystem->ExpandPathName(filename));
100 in.getline(line,10000,'\n');
104 if (sline.Contains(","))
106 TObjArray* a = sline.Tokenize(",");
109 while ( ( s = static_cast<TObjString*>(next()) ) )
111 runset.insert(s->String().Atoi());
117 runset.insert(sline.Atoi());
125 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
127 integers.push_back((*it));
130 std::sort(integers.begin(),integers.end());
133 //______________________________________________________________________________
135 AliMUONTrackerHV::DCSNamer() const
137 // return the dcs namer
140 if (!AliMpDEStore::Instance(false))
142 AliMUONCDB::LoadMapping();
144 fDCSNamer = new AliMpDCSNamer("TRACKER");
149 //______________________________________________________________________________
150 void AliMUONTrackerHV::SetRunList(Int_t runNumber)
152 // Make the runlist be a single run
154 fRunList.push_back(runNumber);
157 //______________________________________________________________________________
159 AliMUONTrackerHV::SetRunList(const char* runlist)
161 // Read the runlist from an ASCII file or a comma separated list
162 // or a space separated list
166 if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") )
168 TObjArray* runs = 0x0;
169 if ( TString(runlist).Contains(",") )
171 runs = TString(runlist).Tokenize(",");
175 runs = TString(runlist).Tokenize(" ");
179 std::set<int> runset;
181 while ( ( s = static_cast<TObjString*>(next()) ) )
183 runset.insert(s->String().Atoi());
186 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
188 fRunList.push_back((*it));
191 std::sort(fRunList.begin(),fRunList.end());
197 ReadIntegers(runlist,fRunList);
202 //______________________________________________________________________________
204 AliMUONTrackerHV::GraphValues(TMap* m, const char* dcsname)
206 // make a graph of HV channels' voltage values for a given dcs name (name, not
209 if ( TString(dcsname).Contains("sw") )
211 // do not graph switches
218 TPair* p = static_cast<TPair*>(m->FindObject(DCSNamer()->DCSAliasFromName(dcsname).Data()));
222 TObjArray* a = static_cast<TObjArray*>(p->Value());
227 TGraph* g = new TGraph(a->GetEntries());
228 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
230 g->SetPoint(i,val->GetTimeStamp(),val->GetFloat());
236 //______________________________________________________________________________
238 AliMUONTrackerHV::Scan(Int_t verbose)
240 /// Retrieve HV values from OCDB for a given run list, and check whether
241 /// we have some issues with them...
242 /// If you pipe the results of this into a text file, you can then
243 /// feed it to the HVoff method for further investigations.
246 if ( fRunList.empty() )
248 AliError("No runs to process...");
252 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
254 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
256 AliMUONCDB::CheckHV(fRunList[i],verbose);
260 //______________________________________________________________________________
261 void AliMUONTrackerHV::HVoff(const char* logfile, const char* outputBaseName)
263 /// Check the number of HV which have problem
264 /// the input is the output of e.g.
265 /// .L MUONTrackerHV.C+
266 /// ScanHV("lhc11de.list");> lhc11de.log
269 gStyle->SetOptStat(0);
273 std::ifstream in(logfile);
274 int run(-1),a,b,c,d,e,f,g,h,z,other;
275 std::map<int,std::string> results;
278 const char* testProblem = "I-AliMUONCDB::CheckHV::CheckHV: Problem at ";
280 while ( in.getline(line,1023,'\n') )
283 if (sline.Contains("SUMMARY"))
287 sscanf(line,"I-AliMUONCDB::CheckHV::CheckHV: RUN %09d HVchannel SUMMARY : # of cases A(%3d) B(%3d) C(%3d) D(%3d) E(%3d) F(%3d) G(%3d) H(%3d) Z(%3d) OTHER(%3d)",
288 &r,&a,&b,&c,&d,&e,&f,&g,&h,&z,&other);
293 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
294 AliCDBManager::Instance()->SetRun(r);
295 AliMUONCDB::LoadMapping();
300 results.insert(std::make_pair<int,std::string>(run,message));
307 else if ( sline.Contains(testProblem) )
310 message += sline(strlen(testProblem),sline.Length()-1).Data();
314 results.insert(std::make_pair<int,std::string>(run,message));
316 TH2* hvoff = new TH2I(outputBaseName,outputBaseName,1,0,1,1,0,1);
318 std::map<int,std::string>::const_iterator it;
320 for ( it = results.begin(); it != results.end(); ++it )
322 AliInfo(Form("%d -> %s",it->first,it->second.c_str()));
323 TObjArray* split = TString(it->second.c_str()).Tokenize("|");
326 while ( ( str = static_cast<TObjString*>(next()) ) )
328 TString s(str->String());
329 TObjArray* parts = s.Tokenize(":");
330 TString alias = (static_cast<TObjString*>(parts->At(0)))->String();
331 TString channel = DCSNamer()->DCSNameFromAlias(alias.Data());
332 channel.ReplaceAll(".actual.vMon","");
333 hvoff->Fill(Form("%6d",it->first),channel.Data(),1.0);
339 hvoff->LabelsDeflate("x");
340 hvoff->LabelsDeflate("y");
341 hvoff->LabelsOption("x","<");
342 hvoff->LabelsOption("y","<");
344 TCanvas* c1 = new TCanvas;
345 c1->SetLeftMargin(0.35);
347 c1->Print(Form("%s.pdf",outputBaseName));
348 TCanvas* c2 = new TCanvas;
349 TH1* hx = hvoff->ProjectionX("hvoffperrun");
351 c2->Print(Form("%s-perrun.pdf",outputBaseName));
352 TCanvas* c3 = new TCanvas;
353 c3->SetBottomMargin(0.5);
354 TH1* perchannel = hvoff->ProjectionY("hvoffperchannel");
355 perchannel->GetXaxis()->SetBit(TAxis::kLabelsVert);
356 perchannel->GetXaxis()->LabelsOption(">");
358 c3->Print(Form("%s-perchannel.pdf",outputBaseName));
361 //______________________________________________________________________________
362 void AliMUONTrackerHV::TimeAxis(TMultiGraph* g)
364 g->GetXaxis()->SetTimeDisplay(1);
365 // g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
366 g->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
367 g->GetXaxis()->SetTimeOffset(0,"gmt");
368 g->GetXaxis()->SetNdivisions(505);
371 //______________________________________________________________________________
373 AliMUONTrackerHV::GraphHV(TMap* m, const char* dcsname)
375 // Make a graph of the values matching dcsname
379 TMultiGraph* mg = new TMultiGraph;
381 while ( ( s = static_cast<TObjString*>(next()) ) )
383 TString name(DCSNamer()->DCSNameFromAlias(s->String()));
385 if ( dcsname && !name.Contains(dcsname)) continue;
387 TGraph* g = GraphValues(m,name);
391 g->SetMarkerSize(1.5);
392 g->SetMarkerStyle(2);
395 g->SetTitle(name.Data());
402 //______________________________________________________________________________
404 AliMUONTrackerHV::Print(Option_t* dcsname) const
406 /// Print HV values for a given dcs name (or all if dcsname=0)
408 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
410 messages.SetOwner(kTRUE);
412 for ( std::vector<int>::size_type iRun = 0; iRun < fRunList.size(); ++iRun )
414 Int_t runNumber = fRunList[iRun];
416 AliInfo("---------------------");
417 AliInfo(Form("RUN %09d",runNumber));
421 AliCDBManager::Instance()->SetRun(runNumber);
423 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,kFALSE,&messages,kTRUE);
428 while ( ( s = static_cast<TObjString*>(next()) ) )
430 TString name(DCSNamer()->DCSNameFromAlias(s->String()));
432 if ( dcsname && !name.Contains(dcsname)) continue;
434 TPair* p = static_cast<TPair*>(m->FindObject(DCSNamer()->DCSAliasFromName(dcsname).Data()));
438 TObjArray* a = static_cast<TObjArray*>(p->Value());
443 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
445 std::cout << Form("i=%5d ",i) << std::endl;
453 //______________________________________________________________________________
455 AliMUONTrackerHV::Plot(const char* dcsname, Bool_t withPatch)
457 /// Show HV values for a given dcs name (or all if dcsname=0)
458 /// Each canvas for each run will go to a separate PDF file
460 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
462 messages.SetOwner(kTRUE);
464 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
466 Int_t runNumber = fRunList[i];
470 AliCDBManager::Instance()->SetRun(runNumber);
472 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,withPatch,&messages,kTRUE);
474 TMultiGraph* mg = GraphHV(m,dcsname);
478 TString cname(Form("MCH_HV_RUN%09d",runNumber));
480 if ( strlen(dcsname) > 0 )
483 s.ReplaceAll("/","_");
484 cname += Form("_dcsname_%s",s.Data());
487 AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber);
489 TLine* startRunLine(0);
490 TLine* endRunLine(0);
496 AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());
499 start = grp->GetTimeStart();
500 end = grp->GetTimeEnd();
506 TGraph* g = new TGraph(1);
507 g->SetPoint(0,end,0);
511 TCanvas* c = new TCanvas(cname.Data(),cname.Data());
515 mg->SetTitle(cname.Data());
523 startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax());
524 startRunLine->SetLineColor(2);
525 startRunLine->SetLineWidth(4);
529 endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax());
530 endRunLine->SetLineColor(2);
531 endRunLine->SetLineWidth(4);
534 if ( startRunLine ) startRunLine->Draw();
535 if ( endRunLine ) endRunLine->Draw();
537 c->SaveAs(Form("%s.pdf",cname.Data()));
541 //______________________________________________________________________________
543 AliMUONTrackerHV::ReportTrips(Bool_t includeLowOnes)
546 /// if includeLowOnes is kTRUE we'll report also the trips which starts from non-operational voltage values
548 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
551 messages.SetOwner(kTRUE);
554 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
556 Int_t runNumber = fRunList[i];
558 AliInfo("---------------------");
564 AliCDBManager::Instance()->SetRun(runNumber);
566 AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,&messages,kTRUE);
568 if (!AliMpDEStore::Instance(false))
570 AliMUONCDB::LoadMapping();
573 TIter next(&messages);
575 while ( ( msg = static_cast<TObjString*>(next())) )
577 if ( msg->String().Contains("TRIP") && ( includeLowOnes || !msg->String().Contains("LOWTRIP") ) )
583 AliInfo(Form("RUN %09d - %d trip%c",runNumber,ntrips,(ntrips>1 ? 's':' ')));
586 std::map<int,std::string> report;
588 while ( ( msg = static_cast<TObjString*>(next())) )
590 if ( msg->String().Contains("TRIP") )
592 TObjArray* parts = msg->String().Tokenize(" ");
593 TString channelName(static_cast<TObjString*>(parts->At(0))->String());
595 for ( Int_t ip = 0; ip <= parts->GetLast(); ++ip)
597 TString p(static_cast<TObjString*>(parts->At(ip))->String());
599 if ( p.Contains("TRIP") )
601 if ( includeLowOnes || !p.Contains("LOWTRIP") )
603 TString ts(static_cast<TObjString*>(parts->At(ip+2))->String());
607 Int_t index = ts.Index("TS:");
609 UInt_t timeStamp = TString(ts(index+strlen("TS:"),ts.Length()-index)).Atoi();
611 TString tmp(msg->String());
612 tmp.ReplaceAll(channelName.Data(),DCSNamer()->DCSNameFromAlias(channelName.Data()));
613 report[timeStamp] = tmp.Data();
621 for ( std::map<int,std::string>::const_iterator it = report.begin(); it != report.end(); ++it )
623 AliInfo(Form("%s %s",TTimeStamp(it->first).AsString("s"),it->second.c_str()));