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"
42 ClassImp(AliMUONTrackerHV)
44 //______________________________________________________________________________
45 AliMUONTrackerHV::AliMUONTrackerHV(const char* runlist, const char* ocdbPath) : TObject(), fRunList(), fOCDBPath(ocdbPath)
47 // ctor from a runlist (txt file)
51 //______________________________________________________________________________
52 AliMUONTrackerHV::AliMUONTrackerHV(Int_t runNumber, const char* ocdbPath) : TObject(), fRunList(), fOCDBPath(ocdbPath)
54 // ctor for a single run
55 SetRunList(runNumber);
58 //______________________________________________________________________________
59 AliMUONTrackerHV::~AliMUONTrackerHV()
64 //______________________________________________________________________________
65 void AliMUONTrackerHV::ReadIntegers(const char* filename, std::vector<int>& integers)
67 /// Read integers from filename, where integers are either
68 /// separated by "," or by return carriage
69 std::ifstream in(gSystem->ExpandPathName(filename));
76 in.getline(line,10000,'\n');
80 if (sline.Contains(","))
82 TObjArray* a = sline.Tokenize(",");
85 while ( ( s = static_cast<TObjString*>(next()) ) )
87 runset.insert(s->String().Atoi());
93 runset.insert(sline.Atoi());
101 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
103 integers.push_back((*it));
106 std::sort(integers.begin(),integers.end());
110 //______________________________________________________________________________
111 void AliMUONTrackerHV::SetRunList(Int_t runNumber)
113 // Make the runlist be a single run
115 fRunList.push_back(runNumber);
118 //______________________________________________________________________________
120 AliMUONTrackerHV::SetRunList(const char* runlist)
122 // Read the runlist from an ASCII file or a comma separated list
123 // or a space separated list
127 if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") )
129 TObjArray* runs = 0x0;
130 if ( TString(runlist).Contains(",") )
132 runs = TString(runlist).Tokenize(",");
136 runs = TString(runlist).Tokenize(" ");
140 std::set<int> runset;
142 while ( ( s = static_cast<TObjString*>(next()) ) )
144 runset.insert(s->String().Atoi());
147 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
149 fRunList.push_back((*it));
152 std::sort(fRunList.begin(),fRunList.end());
158 ReadIntegers(runlist,fRunList);
163 //______________________________________________________________________________
165 AliMUONTrackerHV::ShowValues(TMap* m, const char* name)
167 // make a graph of HV channels' voltage values for a given dcs alias (name)
173 TPair* p = static_cast<TPair*>(m->FindObject(name));
174 TObjArray* a = static_cast<TObjArray*>(p->Value());
179 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
181 StdoutToAliInfo(std::cout << Form("i=%5d ",i);
186 if ( TString(name).Contains("sw") )
188 // do not graph switches
193 g = new TGraph(a->GetEntries());
195 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
197 g->SetPoint(i,val->GetTimeStamp(),val->GetFloat());
203 //______________________________________________________________________________
205 AliMUONTrackerHV::Scan(Int_t verbose)
207 /// Retrieve HV values from OCDB for a given run list, and check whether
208 /// we have some issues with them...
210 if ( fRunList.empty() )
212 std::cout << "No runs to process..." << std::endl;
216 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
218 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
220 AliMUONCDB::CheckHV(fRunList[i],verbose);
224 //______________________________________________________________________________
225 void AliMUONTrackerHV::HVoff(const char* logfile, const char* outputBaseName)
227 /// Check the number of HV which have problem
228 /// the input is the output of e.g.
229 /// .L MUONTrackerHV.C+
230 /// ScanHV("lhc11de.list");> lhc11de.log
233 gStyle->SetOptStat(0);
237 std::ifstream in(logfile);
238 int run(-1),a,b,c,d,e,f,g,h,z,other;
239 std::map<int,std::string> results;
242 const char* testProblem = "I-AliMUONCDB::CheckHV::CheckHV: Problem at ";
244 while ( in.getline(line,1023,'\n') )
247 if (sline.Contains("SUMMARY"))
251 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)",
252 &r,&a,&b,&c,&d,&e,&f,&g,&h,&z,&other);
257 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
258 AliCDBManager::Instance()->SetRun(r);
259 AliMUONCDB::LoadMapping();
264 results.insert(std::make_pair<int,std::string>(run,message));
271 else if ( sline.Contains(testProblem) )
274 message += sline(strlen(testProblem),sline.Length()-1).Data();
278 results.insert(std::make_pair<int,std::string>(run,message));
280 AliMpDCSNamer hvNamer("TRACKER");
282 TH2* hvoff = new TH2I(outputBaseName,outputBaseName,1,0,1,1,0,1);
284 std::map<int,std::string>::const_iterator it;
286 for ( it = results.begin(); it != results.end(); ++it )
288 AliInfo(Form("%d -> %s",it->first,it->second.c_str()));
289 TObjArray* split = TString(it->second.c_str()).Tokenize("|");
292 while ( ( str = static_cast<TObjString*>(next()) ) )
294 TString s(str->String());
295 TObjArray* parts = s.Tokenize(":");
296 TString alias = (static_cast<TObjString*>(parts->At(0)))->String();
297 TString channel = hvNamer.DCSChannelNameFromAlias(alias.Data());
298 channel.ReplaceAll(".actual.vMon","");
299 hvoff->Fill(Form("%6d",it->first),channel.Data(),1.0);
305 hvoff->LabelsDeflate("x");
306 hvoff->LabelsDeflate("y");
307 hvoff->LabelsOption("x","<");
308 hvoff->LabelsOption("y","<");
310 TCanvas* c1 = new TCanvas;
311 c1->SetLeftMargin(0.35);
313 c1->Print(Form("%s.pdf",outputBaseName));
314 TCanvas* c2 = new TCanvas;
315 TH1* hx = hvoff->ProjectionX("hvoffperrun");
317 c2->Print(Form("%s-perrun.pdf",outputBaseName));
318 TCanvas* c3 = new TCanvas;
319 c3->SetBottomMargin(0.5);
320 TH1* perchannel = hvoff->ProjectionY("hvoffperchannel");
321 perchannel->GetXaxis()->SetBit(TAxis::kLabelsVert);
322 perchannel->GetXaxis()->LabelsOption(">");
324 c3->Print(Form("%s-perchannel.pdf",outputBaseName));
327 //______________________________________________________________________________
328 void AliMUONTrackerHV::TimeAxis(TMultiGraph* g)
330 g->GetXaxis()->SetTimeDisplay(1);
331 // g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
332 g->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
333 g->GetXaxis()->SetTimeOffset(0,"gmt");
334 g->GetXaxis()->SetNdivisions(505);
337 //______________________________________________________________________________
339 AliMUONTrackerHV::ShowHV(TMap* m, const char* dcsname)
343 AliMpDCSNamer hvNamer("TRACKER");
344 TMultiGraph* mg = new TMultiGraph;
346 while ( ( s = static_cast<TObjString*>(next()) ) )
348 TString name(s->String());
350 if ( dcsname && !name.Contains(dcsname)) continue;
352 TGraph* g = ShowValues(m,name);
356 g->SetMarkerSize(1.5);
357 g->SetMarkerStyle(2);
360 g->SetTitle(name.Data());
367 //______________________________________________________________________________
369 AliMUONTrackerHV::Plot(const char* dcsname, Bool_t withPatch)
371 /// Show HV values for a given dcs alias (or all if dcsname=0)
372 /// Each canvas for each run will go to a separate PDF file
374 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
376 messages.SetOwner(kTRUE);
378 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
380 Int_t runNumber = fRunList[i];
384 AliCDBManager::Instance()->SetRun(runNumber);
386 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,withPatch,&messages);
388 TMultiGraph* mg = ShowHV(m,dcsname);
392 TString cname(Form("MCH_HV_RUN%09d",runNumber));
394 if ( strlen(dcsname) > 0 )
397 s.ReplaceAll("/","_");
398 cname += Form("_dcsname_%s",s.Data());
401 AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber);
403 TLine* startRunLine(0);
404 TLine* endRunLine(0);
410 AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());
413 start = grp->GetTimeStart();
414 end = grp->GetTimeEnd();
420 TGraph* g = new TGraph(1);
421 g->SetPoint(0,end,0);
425 TCanvas* c = new TCanvas(cname.Data(),cname.Data());
429 mg->SetTitle(cname.Data());
437 startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax());
438 startRunLine->SetLineColor(2);
439 startRunLine->SetLineWidth(4);
443 endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax());
444 endRunLine->SetLineColor(2);
445 endRunLine->SetLineWidth(4);
448 if ( startRunLine ) startRunLine->Draw();
449 if ( endRunLine ) endRunLine->Draw();
451 c->SaveAs(Form("%s.pdf",cname.Data()));
455 //______________________________________________________________________________
457 AliMUONTrackerHV::ReportTrips()
461 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
464 messages.SetOwner(kTRUE);
467 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
469 Int_t runNumber = fRunList[i];
471 AliInfo("---------------------");
477 AliCDBManager::Instance()->SetRun(runNumber);
479 AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,&messages);
481 TIter next(&messages);
483 while ( ( msg = static_cast<TObjString*>(next())) )
485 if ( msg->String().Contains("TRIP") )
491 AliInfo(Form("RUN %09d - %d trip%c",runNumber,ntrips,(ntrips>1 ? 's':' ')));
494 std::map<int,std::string> report;
496 while ( ( msg = static_cast<TObjString*>(next())) )
498 if ( msg->String().Contains("TRIP") )
500 Int_t index = msg->String().Index("TS:");
501 UInt_t timeStamp = TString(msg->String()(index+strlen("TS:"),msg->String().Length()-index)).Atoi();
502 report[timeStamp] = msg->String().Data();
506 for ( std::map<int,std::string>::const_iterator it = report.begin(); it != report.end(); ++it )
508 AliInfo(Form("%s %s",TTimeStamp(it->first).AsString("s"),it->second.c_str()));