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"
19 #include "Riostream.h"
20 #include "TObjArray.h"
21 #include "TObjString.h"
22 #include "AliDCSValue.h"
25 #include "AliMpDCSNamer.h"
28 #include "AliCDBEntry.h"
29 #include "AliCDBManager.h"
34 #include "TMultiGraph.h"
35 #include "AliMUONCDB.h"
37 #include "AliMUONCalibrationData.h"
38 #include "AliGRPObject.h"
40 ClassImp(AliMUONTrackerHV)
42 //______________________________________________________________________________
43 AliMUONTrackerHV::AliMUONTrackerHV(const char* runlist, const char* ocdbPath) : TObject(), fRunList(), fOCDBPath(ocdbPath)
45 // ctor from a runlist (txt file)
49 //______________________________________________________________________________
50 AliMUONTrackerHV::AliMUONTrackerHV(Int_t runNumber, const char* ocdbPath) : TObject(), fRunList(), fOCDBPath(ocdbPath)
52 // ctor for a single run
53 SetRunList(runNumber);
56 //______________________________________________________________________________
57 AliMUONTrackerHV::~AliMUONTrackerHV()
62 //______________________________________________________________________________
63 void AliMUONTrackerHV::ReadIntegers(const char* filename, std::vector<int>& integers)
65 /// Read integers from filename, where integers are either
66 /// separated by "," or by return carriage
67 std::ifstream in(gSystem->ExpandPathName(filename));
74 in.getline(line,10000,'\n');
78 if (sline.Contains(","))
80 TObjArray* a = sline.Tokenize(",");
83 while ( ( s = static_cast<TObjString*>(next()) ) )
85 runset.insert(s->String().Atoi());
91 runset.insert(sline.Atoi());
99 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
101 integers.push_back((*it));
104 std::sort(integers.begin(),integers.end());
108 //______________________________________________________________________________
109 void AliMUONTrackerHV::SetRunList(Int_t runNumber)
111 // Make the runlist be a single run
113 fRunList.push_back(runNumber);
116 //______________________________________________________________________________
118 AliMUONTrackerHV::SetRunList(const char* runlist)
120 // Read the runlist from an ASCII file or a comma separated list
121 // or a space separated list
125 if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") )
127 TObjArray* runs = 0x0;
128 if ( TString(runlist).Contains(",") )
130 runs = TString(runlist).Tokenize(",");
134 runs = TString(runlist).Tokenize(" ");
138 std::set<int> runset;
140 while ( ( s = static_cast<TObjString*>(next()) ) )
142 runset.insert(s->String().Atoi());
145 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
147 fRunList.push_back((*it));
150 std::sort(fRunList.begin(),fRunList.end());
156 ReadIntegers(runlist,fRunList);
161 //______________________________________________________________________________
163 AliMUONTrackerHV::ShowValues(TMap* m, const char* name)
165 // make a graph of HV channels' voltage values for a given dcs alias (name)
171 TPair* p = static_cast<TPair*>(m->FindObject(name));
172 TObjArray* a = static_cast<TObjArray*>(p->Value());
177 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
179 StdoutToAliInfo(std::cout << Form("i=%5d ",i);
184 if ( TString(name).Contains("sw") )
186 // do not graph switches
191 g = new TGraph(a->GetEntries());
193 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
195 g->SetPoint(i,val->GetTimeStamp(),val->GetFloat());
201 //______________________________________________________________________________
203 AliMUONTrackerHV::Scan(Int_t verbose)
205 /// Retrieve HV values from OCDB for a given run list, and check whether
206 /// we have some issues with them...
208 if ( fRunList.empty() )
210 std::cout << "No runs to process..." << std::endl;
214 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
216 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
218 AliMUONCDB::CheckHV(fRunList[i],verbose);
222 //______________________________________________________________________________
223 void AliMUONTrackerHV::HVoff(const char* logfile, const char* outputBaseName)
225 /// Check the number of HV which have problem
226 /// the input is the output of e.g.
227 /// .L MUONTrackerHV.C+
228 /// ScanHV("lhc11de.list");> lhc11de.log
231 gStyle->SetOptStat(0);
235 std::ifstream in(logfile);
236 int run(-1),a,b,c,d,e,f,g,h,z,other;
237 std::map<int,std::string> results;
240 const char* testProblem = "I-AliMUONCDB::CheckHV::CheckHV: Problem at ";
242 while ( in.getline(line,1023,'\n') )
245 if (sline.Contains("SUMMARY"))
249 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)",
250 &r,&a,&b,&c,&d,&e,&f,&g,&h,&z,&other);
255 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
256 AliCDBManager::Instance()->SetRun(r);
257 AliMUONCDB::LoadMapping();
262 results.insert(std::make_pair<int,std::string>(run,message));
269 else if ( sline.Contains(testProblem) )
272 message += sline(strlen(testProblem),sline.Length()-1).Data();
276 results.insert(std::make_pair<int,std::string>(run,message));
278 AliMpDCSNamer hvNamer("TRACKER");
280 TH2* hvoff = new TH2I(outputBaseName,outputBaseName,1,0,1,1,0,1);
282 std::map<int,std::string>::const_iterator it;
284 for ( it = results.begin(); it != results.end(); ++it )
286 AliInfo(Form("%d -> %s",it->first,it->second.c_str()));
287 TObjArray* split = TString(it->second.c_str()).Tokenize("|");
290 while ( ( str = static_cast<TObjString*>(next()) ) )
292 TString s(str->String());
293 TObjArray* parts = s.Tokenize(":");
294 TString alias = (static_cast<TObjString*>(parts->At(0)))->String();
295 TString channel = hvNamer.DCSChannelNameFromAlias(alias.Data());
296 channel.ReplaceAll(".actual.vMon","");
297 hvoff->Fill(Form("%6d",it->first),channel.Data(),1.0);
303 hvoff->LabelsDeflate("x");
304 hvoff->LabelsDeflate("y");
305 hvoff->LabelsOption("x","<");
306 hvoff->LabelsOption("y","<");
308 TCanvas* c1 = new TCanvas;
309 c1->SetLeftMargin(0.35);
311 c1->Print(Form("%s.pdf",outputBaseName));
312 TCanvas* c2 = new TCanvas;
313 TH1* hx = hvoff->ProjectionX("hvoffperrun");
315 c2->Print(Form("%s-perrun.pdf",outputBaseName));
316 TCanvas* c3 = new TCanvas;
317 c3->SetBottomMargin(0.5);
318 TH1* perchannel = hvoff->ProjectionY("hvoffperchannel");
319 perchannel->GetXaxis()->SetBit(TAxis::kLabelsVert);
320 perchannel->GetXaxis()->LabelsOption(">");
322 c3->Print(Form("%s-perchannel.pdf",outputBaseName));
325 //______________________________________________________________________________
326 void AliMUONTrackerHV::TimeAxis(TMultiGraph* g)
328 g->GetXaxis()->SetTimeDisplay(1);
329 // g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
330 g->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
331 g->GetXaxis()->SetTimeOffset(0,"gmt");
332 g->GetXaxis()->SetNdivisions(505);
335 //______________________________________________________________________________
337 AliMUONTrackerHV::ShowHV(TMap* m, const char* dcsname)
341 AliMpDCSNamer hvNamer("TRACKER");
342 TMultiGraph* mg = new TMultiGraph;
344 while ( ( s = static_cast<TObjString*>(next()) ) )
346 TString name(s->String());
348 if ( dcsname && !name.Contains(dcsname)) continue;
350 TGraph* g = ShowValues(m,name);
354 g->SetMarkerSize(1.5);
355 g->SetMarkerStyle(2);
358 g->SetTitle(name.Data());
365 //______________________________________________________________________________
367 AliMUONTrackerHV::Plot(const char* dcsname, Bool_t withPatch)
369 /// Show HV values for a given dcs alias (or all if dcsname=0)
370 /// Each canvas for each run will go to a separate PDF file
372 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
374 messages.SetOwner(kTRUE);
376 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
378 Int_t runNumber = fRunList[i];
382 AliCDBManager::Instance()->SetRun(runNumber);
384 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,withPatch,&messages);
386 TMultiGraph* mg = ShowHV(m,dcsname);
390 TString cname(Form("MCH_HV_RUN%09d",runNumber));
392 if ( strlen(dcsname) > 0 )
395 s.ReplaceAll("/","_");
396 cname += Form("_dcsname_%s",s.Data());
399 AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber);
401 TLine* startRunLine(0);
402 TLine* endRunLine(0);
408 AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());
411 start = grp->GetTimeStart();
412 end = grp->GetTimeEnd();
418 TGraph* g = new TGraph(1);
419 g->SetPoint(0,end,0);
423 TCanvas* c = new TCanvas(cname.Data(),cname.Data());
427 mg->SetTitle(cname.Data());
435 startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax());
436 startRunLine->SetLineColor(2);
437 startRunLine->SetLineWidth(4);
441 endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax());
442 endRunLine->SetLineColor(2);
443 endRunLine->SetLineWidth(4);
446 if ( startRunLine ) startRunLine->Draw();
447 if ( endRunLine ) endRunLine->Draw();
449 c->SaveAs(Form("%s.pdf",cname.Data()));
453 //______________________________________________________________________________
455 AliMUONTrackerHV::ReportTrips()
459 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
462 messages.SetOwner(kTRUE);
465 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
467 Int_t runNumber = fRunList[i];
469 AliInfo("---------------------");
475 AliCDBManager::Instance()->SetRun(runNumber);
477 AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,&messages);
479 TIter next(&messages);
481 while ( ( msg = static_cast<TObjString*>(next())) )
483 if ( msg->String().Contains("TRIP") )
489 AliInfo(Form("RUN %09d - %d trip%c",runNumber,ntrips,(ntrips>1 ? 's':' ')));
493 while ( ( msg = static_cast<TObjString*>(next())) )
495 if ( msg->String().Contains("TRIP") )
497 AliInfo(msg->String().Data());