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 "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"
47 #include "TMultiGraph.h"
48 #include "TObjArray.h"
49 #include "TObjString.h"
51 #include "Riostream.h"
54 // Class to inspect the MUON TRACKER HV values
56 // With this class you can :
58 // a) get a list of trips (method ReportTrips)
59 // b) print the values for some (or all) HV channels (method Print)
60 // c) plot the values for some (or all) HV channels (method Plot)
61 // d) get a list of HV channels that are "OFF" (methods Scan and HVoff)
63 // Note that in this class, all the output (either text or canvas) or the
64 // channel *names* used are the same as in the DCS UI at Pt2
65 // Specifically the chamber ids start at 1, the slat numbers at 1 and
66 // the quad and sect number at 1 also. And not at zero like for the
67 // DCS *aliases*. On the contraty, the internal map, coming from the OCDB,
68 // only contains aliases, not names. Confusing ? It is.
71 ClassImp(AliMUONTrackerHV)
73 //______________________________________________________________________________
74 AliMUONTrackerHV::AliMUONTrackerHV(const char* runlist, const char* ocdbPath)
75 : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
77 // ctor from a runlist (txt file)
81 //______________________________________________________________________________
82 AliMUONTrackerHV::AliMUONTrackerHV(Int_t runNumber, const char* ocdbPath)
83 : TObject(), fRunList(), fOCDBPath(ocdbPath), fDCSNamer(0x0)
85 // ctor for a single run
86 SetRunList(runNumber);
89 //______________________________________________________________________________
90 AliMUONTrackerHV::~AliMUONTrackerHV()
96 //______________________________________________________________________________
97 void AliMUONTrackerHV::ReadIntegers(const char* filename, std::vector<int>& integers)
99 /// Read integers from filename, where integers are either
100 /// separated by "," or by return carriage
101 std::ifstream in(gSystem->ExpandPathName(filename));
104 std::set<int> runset;
108 in.getline(line,10000,'\n');
112 if (sline.Contains(","))
114 TObjArray* a = sline.Tokenize(",");
117 while ( ( s = static_cast<TObjString*>(next()) ) )
119 runset.insert(s->String().Atoi());
125 runset.insert(sline.Atoi());
133 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
135 integers.push_back((*it));
138 std::sort(integers.begin(),integers.end());
141 //______________________________________________________________________________
143 AliMUONTrackerHV::DCSNamer() const
145 // return the dcs namer
148 if (!AliMpDEStore::Instance(false))
150 AliMUONCDB::LoadMapping();
152 fDCSNamer = new AliMpDCSNamer("TRACKER");
157 //______________________________________________________________________________
158 void AliMUONTrackerHV::SetRunList(Int_t runNumber)
160 // Make the runlist be a single run
162 fRunList.push_back(runNumber);
165 //______________________________________________________________________________
167 AliMUONTrackerHV::SetRunList(const char* runlist)
169 // Read the runlist from an ASCII file or a comma separated list
170 // or a space separated list
174 if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") )
176 TObjArray* runs = 0x0;
177 if ( TString(runlist).Contains(",") )
179 runs = TString(runlist).Tokenize(",");
183 runs = TString(runlist).Tokenize(" ");
187 std::set<int> runset;
189 while ( ( s = static_cast<TObjString*>(next()) ) )
191 runset.insert(s->String().Atoi());
194 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
196 fRunList.push_back((*it));
199 std::sort(fRunList.begin(),fRunList.end());
205 ReadIntegers(runlist,fRunList);
210 //______________________________________________________________________________
212 AliMUONTrackerHV::GraphValues(TMap* m, const char* dcsname)
214 // make a graph of HV channels' voltage values for a given dcs name (name, not
217 if ( TString(dcsname).Contains("sw") )
219 // do not graph switches
226 TPair* p = static_cast<TPair*>(m->FindObject(DCSNamer()->DCSAliasFromName(dcsname).Data()));
230 TObjArray* a = static_cast<TObjArray*>(p->Value());
235 TGraph* g = new TGraph(a->GetEntries());
236 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
238 g->SetPoint(i,val->GetTimeStamp(),val->GetFloat());
244 //______________________________________________________________________________
246 AliMUONTrackerHV::Scan(Int_t verbose)
248 /// Retrieve HV values from OCDB for a given run list, and check whether
249 /// we have some issues with them...
250 /// If you pipe the results of this into a text file, you can then
251 /// feed it to the HVoff method for further investigations.
254 if ( fRunList.empty() )
256 AliError("No runs to process...");
260 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
262 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
264 AliMUONCDB::CheckHV(fRunList[i],verbose);
268 //______________________________________________________________________________
269 void AliMUONTrackerHV::HVoff(const char* logfile, const char* outputBaseName)
271 /// Check the number of HV which have problem
272 /// the input is the output of e.g.
273 /// .L MUONTrackerHV.C+
274 /// ScanHV("lhc11de.list");> lhc11de.log
277 gStyle->SetOptStat(0);
281 std::ifstream in(logfile);
282 int run(-1),a,b,c,d,e,f,g,h,z,other;
283 std::map<int,std::string> results;
286 const char* testProblem = "I-AliMUONCDB::CheckHV::CheckHV: Problem at ";
288 while ( in.getline(line,1023,'\n') )
291 if (sline.Contains("SUMMARY"))
295 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)",
296 &r,&a,&b,&c,&d,&e,&f,&g,&h,&z,&other);
301 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
302 AliCDBManager::Instance()->SetRun(r);
303 AliMUONCDB::LoadMapping();
308 results.insert(std::make_pair<int,std::string>(run,message));
315 else if ( sline.Contains(testProblem) )
318 message += sline(strlen(testProblem),sline.Length()-1).Data();
322 results.insert(std::make_pair<int,std::string>(run,message));
324 TH2* hvoff = new TH2I(outputBaseName,outputBaseName,1,0,1,1,0,1);
326 std::map<int,std::string>::const_iterator it;
328 for ( it = results.begin(); it != results.end(); ++it )
330 AliInfo(Form("%d -> %s",it->first,it->second.c_str()));
331 TObjArray* split = TString(it->second.c_str()).Tokenize("|");
334 while ( ( str = static_cast<TObjString*>(next()) ) )
336 TString s(str->String());
337 TObjArray* parts = s.Tokenize(":");
338 TString alias = (static_cast<TObjString*>(parts->At(0)))->String();
339 TString channel = DCSNamer()->DCSNameFromAlias(alias.Data());
340 channel.ReplaceAll(".actual.vMon","");
341 hvoff->Fill(Form("%6d",it->first),channel.Data(),1.0);
347 hvoff->LabelsDeflate("x");
348 hvoff->LabelsDeflate("y");
349 hvoff->LabelsOption("x","<");
350 hvoff->LabelsOption("y","<");
352 TCanvas* c1 = new TCanvas;
353 c1->SetLeftMargin(0.35);
355 c1->Print(Form("%s.pdf",outputBaseName));
356 TCanvas* c2 = new TCanvas;
357 TH1* hx = hvoff->ProjectionX("hvoffperrun");
359 c2->Print(Form("%s-perrun.pdf",outputBaseName));
360 TCanvas* c3 = new TCanvas;
361 c3->SetBottomMargin(0.5);
362 TH1* perchannel = hvoff->ProjectionY("hvoffperchannel");
363 perchannel->GetXaxis()->SetBit(TAxis::kLabelsVert);
364 perchannel->GetXaxis()->LabelsOption(">");
366 c3->Print(Form("%s-perchannel.pdf",outputBaseName));
369 //______________________________________________________________________________
370 void AliMUONTrackerHV::TimeAxis(TMultiGraph* g)
372 g->GetXaxis()->SetTimeDisplay(1);
373 // g->GetXaxis()->SetTimeFormat("%d/%m %H:%M%F2010-12-31 24:00:00");
374 g->GetXaxis()->SetTimeFormat("%d/%m %H:%M");
375 g->GetXaxis()->SetTimeOffset(0,"gmt");
376 g->GetXaxis()->SetNdivisions(505);
379 //______________________________________________________________________________
381 AliMUONTrackerHV::GraphHV(TMap* m, const char* dcsname)
383 // Make a graph of the values matching dcsname
387 TMultiGraph* mg = new TMultiGraph;
389 while ( ( s = static_cast<TObjString*>(next()) ) )
391 TString name(DCSNamer()->DCSNameFromAlias(s->String()));
393 if ( dcsname && !name.Contains(dcsname)) continue;
395 TGraph* g = GraphValues(m,name);
399 g->SetMarkerSize(1.5);
400 g->SetMarkerStyle(2);
403 g->SetTitle(name.Data());
410 //______________________________________________________________________________
412 AliMUONTrackerHV::Print(Option_t* dcsname) const
414 /// Print HV values for a given dcs name (or all if dcsname=0)
416 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
418 messages.SetOwner(kTRUE);
420 for ( std::vector<int>::size_type iRun = 0; iRun < fRunList.size(); ++iRun )
422 Int_t runNumber = fRunList[iRun];
424 AliInfo("---------------------");
425 AliInfo(Form("RUN %09d",runNumber));
429 AliCDBManager::Instance()->SetRun(runNumber);
431 Bool_t patchValues(kFALSE);
432 Bool_t dryRun(kTRUE);
434 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,patchValues,&messages,dryRun);
439 while ( ( s = static_cast<TObjString*>(next()) ) )
441 TString name(DCSNamer()->DCSNameFromAlias(s->String()));
443 if ( dcsname && !name.Contains(dcsname)) continue;
445 TPair* p = static_cast<TPair*>(m->FindObject(DCSNamer()->DCSAliasFromName(dcsname).Data()));
449 TObjArray* a = static_cast<TObjArray*>(p->Value());
454 while ( ( val = static_cast<AliDCSValue*>(n2()) ) )
456 std::cout << Form("i=%5d ",i) << std::endl;
464 //______________________________________________________________________________
466 AliMUONTrackerHV::Plot(const char* dcsname, Bool_t withPatch)
468 /// Show HV values for a given dcs name (or all if dcsname=0)
469 /// Each canvas for each run will go to a separate PDF file
471 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
473 messages.SetOwner(kTRUE);
475 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
477 Int_t runNumber = fRunList[i];
481 AliCDBManager::Instance()->SetRun(runNumber);
483 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,withPatch,&messages,kTRUE);
485 TMultiGraph* mg = GraphHV(m,dcsname);
489 TString cname(Form("MCH_HV_RUN%09d",runNumber));
491 if ( strlen(dcsname) > 0 )
494 s.ReplaceAll("/","_");
495 cname += Form("_dcsname_%s",s.Data());
498 AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber);
500 TLine* startRunLine(0);
501 TLine* endRunLine(0);
507 AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());
510 start = grp->GetTimeStart();
511 end = grp->GetTimeEnd();
517 TGraph* g = new TGraph(1);
518 g->SetPoint(0,end,0);
522 TCanvas* c = new TCanvas(cname.Data(),cname.Data());
526 mg->SetTitle(cname.Data());
534 startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax());
535 startRunLine->SetLineColor(2);
536 startRunLine->SetLineWidth(4);
540 endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax());
541 endRunLine->SetLineColor(2);
542 endRunLine->SetLineWidth(4);
545 if ( startRunLine ) startRunLine->Draw();
546 if ( endRunLine ) endRunLine->Draw();
548 c->SaveAs(Form("%s.pdf",cname.Data()));
552 //______________________________________________________________________________
554 AliMUONTrackerHV::ReportTrips(Bool_t includeLowOnes)
557 /// if includeLowOnes is kTRUE we'll report also the trips which starts from non-operational voltage values
559 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
562 messages.SetOwner(kTRUE);
565 std::map<std::string,int> channels;
567 for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i )
569 Int_t runNumber = fRunList[i];
571 AliInfo("---------------------");
577 AliCDBManager::Instance()->SetRun(runNumber);
579 AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,&messages,kTRUE);
581 if (!AliMpDEStore::Instance(false))
583 AliMUONCDB::LoadMapping();
586 TIter next(&messages);
588 while ( ( msg = static_cast<TObjString*>(next())) )
590 if ( msg->String().Contains("TRIP") && ( includeLowOnes || !msg->String().Contains("LOWTRIP") ) )
596 AliInfo(Form("RUN %09d - %d trip%c",runNumber,ntrips,(ntrips>1 ? 's':' ')));
599 std::map<int,std::string> report;
601 while ( ( msg = static_cast<TObjString*>(next())) )
603 if ( msg->String().Contains("TRIP") )
605 TObjArray* parts = msg->String().Tokenize(" ");
606 TString channelName(static_cast<TObjString*>(parts->At(0))->String());
608 for ( Int_t ip = 0; ip <= parts->GetLast(); ++ip)
610 TString p(static_cast<TObjString*>(parts->At(ip))->String());
612 if ( p.Contains("TRIP") )
614 if ( includeLowOnes || !p.Contains("LOWTRIP") )
616 TString ts(static_cast<TObjString*>(parts->At(ip+2))->String());
620 Int_t index = ts.Index("TS:");
622 UInt_t timeStamp = TString(ts(index+strlen("TS:"),ts.Length()-index)).Atoi();
624 TString tmp(msg->String());
625 tmp.ReplaceAll(channelName.Data(),DCSNamer()->DCSNameFromAlias(channelName.Data()));
626 report[timeStamp] = tmp.Data();
627 channels[channelName.Data()]++;
635 for ( std::map<int,std::string>::const_iterator it = report.begin(); it != report.end(); ++it )
637 AliInfo(Form("%s %s",TTimeStamp(it->first).AsString("s"),it->second.c_str()));
641 AliInfo("--------------------------------------------------------------------");
642 AliInfo("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
645 AliMUON2DMap tripMap(kTRUE);
646 Int_t nofChannels(AliMpConstants::ManuNofChannels());
648 for ( std::map<std::string,int>::const_iterator it = channels.begin(); it != channels.end(); ++it )
650 AliInfo(Form("%40s %3d",DCSNamer()->DCSNameFromAlias(it->first.c_str()).Data(),it->second));
651 totalTrips += it->second;
653 Int_t detElemId = DCSNamer()->DetElemIdFromDCSAlias(it->first.c_str());
655 AliMpDetElement* de = AliMpDEStore::Instance()->GetDetElement(detElemId);
657 // build the list of manuIds for this channel
658 AliMpArrayI manuArray;
660 manuArray.SetSize(300);
662 Int_t index = DCSNamer()->DCSIndexFromDCSAlias(it->first.c_str());
663 Int_t firstIndex(index);
664 Int_t lastIndex(index);
668 // it's a slat, must loop over PCBs
670 lastIndex = DCSNamer()->NumberOfPCBs(detElemId)-1;
673 for ( int i = firstIndex; i <= lastIndex ; ++i )
675 const AliMpArrayI* ma = de->ManusForHV(i);
678 AliError(Form("Could not get ma for de %d index %d",detElemId,i));
681 for ( int j = 0; j < ma->GetSize(); ++j )
683 manuArray.Add(ma->GetValue(j),kFALSE);
687 for ( Int_t iManu = 0; iManu < manuArray.GetSize(); ++iManu )
689 Int_t manuId = manuArray.GetValue(iManu);
691 AliMUONVCalibParam* tripRate = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
693 tripMap.Add(tripRate);
695 for ( Int_t j = 0 ; j < nofChannels; ++j )
697 tripRate->SetValueAsDouble(j,0,it->second*1.0);
702 AliInfo("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
703 AliInfo(Form("Total of %3d trips for %4ld runs",totalTrips,fRunList.size()));
705 AliMUONTrackerData* data = new AliMUONTrackerData("tripcount","Number of trips",1);
707 data->SetDimensionName(0,"ntrips");
709 AliMUONVTrackerDataMaker* dw = new AliMUONTrackerDataWrapper(data);
711 AliMUONPainterDataRegistry::Instance()->Register(dw);