]>
Commit | Line | Data |
---|---|---|
084cc733 | 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 "AliMUONTrackerHV.h" | |
19 | #include "Riostream.h" | |
20 | #include "TObjArray.h" | |
21 | #include "TObjString.h" | |
22 | #include "AliDCSValue.h" | |
23 | #include "TMap.h" | |
24 | #include <map> | |
25 | #include "AliMpDCSNamer.h" | |
26 | #include "TH2.h" | |
27 | #include "TStyle.h" | |
28 | #include "AliCDBEntry.h" | |
29 | #include "AliCDBManager.h" | |
30 | #include "TLine.h" | |
31 | #include <set> | |
32 | #include "AliLog.h" | |
33 | #include "TGraph.h" | |
34 | #include "TMultiGraph.h" | |
35 | #include "AliMUONCDB.h" | |
36 | #include "TCanvas.h" | |
37 | #include "AliMUONCalibrationData.h" | |
38 | #include "AliGRPObject.h" | |
39 | ||
40 | ClassImp(AliMUONTrackerHV) | |
41 | ||
42 | //______________________________________________________________________________ | |
43 | AliMUONTrackerHV::AliMUONTrackerHV(const char* runlist, const char* ocdbPath) : TObject(), fRunList(), fOCDBPath(ocdbPath) | |
44 | { | |
45 | // ctor from a runlist (txt file) | |
46 | SetRunList(runlist); | |
47 | } | |
48 | ||
49 | //______________________________________________________________________________ | |
50 | AliMUONTrackerHV::AliMUONTrackerHV(Int_t runNumber, const char* ocdbPath) : TObject(), fRunList(), fOCDBPath(ocdbPath) | |
51 | { | |
52 | // ctor for a single run | |
53 | SetRunList(runNumber); | |
54 | } | |
55 | ||
56 | //______________________________________________________________________________ | |
57 | AliMUONTrackerHV::~AliMUONTrackerHV() | |
58 | { | |
59 | // dtor | |
60 | } | |
61 | ||
62 | //______________________________________________________________________________ | |
63 | void AliMUONTrackerHV::ReadIntegers(const char* filename, std::vector<int>& integers) | |
64 | { | |
65 | /// Read integers from filename, where integers are either | |
66 | /// separated by "," or by return carriage | |
67 | std::ifstream in(gSystem->ExpandPathName(filename)); | |
68 | int i; | |
69 | ||
70 | std::set<int> runset; | |
71 | ||
72 | char line[10000]; | |
73 | ||
74 | in.getline(line,10000,'\n'); | |
75 | ||
76 | TString sline(line); | |
77 | ||
78 | if (sline.Contains(",")) | |
79 | { | |
80 | TObjArray* a = sline.Tokenize(","); | |
81 | TIter next(a); | |
82 | TObjString* s; | |
83 | while ( ( s = static_cast<TObjString*>(next()) ) ) | |
84 | { | |
85 | runset.insert(s->String().Atoi()); | |
86 | } | |
87 | delete a; | |
88 | } | |
89 | else | |
90 | { | |
91 | runset.insert(sline.Atoi()); | |
92 | ||
93 | while ( in >> i ) | |
94 | { | |
95 | runset.insert(i); | |
96 | } | |
97 | } | |
98 | ||
99 | for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it ) | |
100 | { | |
101 | integers.push_back((*it)); | |
102 | } | |
103 | ||
104 | std::sort(integers.begin(),integers.end()); | |
105 | } | |
106 | ||
107 | ||
108 | //______________________________________________________________________________ | |
109 | void AliMUONTrackerHV::SetRunList(Int_t runNumber) | |
110 | { | |
111 | // Make the runlist be a single run | |
112 | fRunList.clear(); | |
113 | fRunList.push_back(runNumber); | |
114 | } | |
115 | ||
116 | //______________________________________________________________________________ | |
117 | void | |
118 | AliMUONTrackerHV::SetRunList(const char* runlist) | |
119 | { | |
120 | // Read the runlist from an ASCII file or a comma separated list | |
121 | // or a space separated list | |
122 | ||
123 | fRunList.clear(); | |
124 | ||
125 | if ( TString(runlist).Contains(",") || TString(runlist).Contains(" ") ) | |
126 | { | |
127 | TObjArray* runs = 0x0; | |
128 | if ( TString(runlist).Contains(",") ) | |
129 | { | |
130 | runs = TString(runlist).Tokenize(","); | |
131 | } | |
132 | else | |
133 | { | |
134 | runs = TString(runlist).Tokenize(" "); | |
135 | } | |
136 | TIter next(runs); | |
137 | TObjString* s; | |
138 | std::set<int> runset; | |
139 | ||
140 | while ( ( s = static_cast<TObjString*>(next()) ) ) | |
141 | { | |
142 | runset.insert(s->String().Atoi()); | |
143 | } | |
144 | ||
145 | for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it ) | |
146 | { | |
147 | fRunList.push_back((*it)); | |
148 | } | |
149 | ||
150 | std::sort(fRunList.begin(),fRunList.end()); | |
151 | ||
152 | delete runs; | |
153 | } | |
154 | else | |
155 | { | |
156 | ReadIntegers(runlist,fRunList); | |
157 | } | |
158 | } | |
159 | ||
160 | ||
161 | //______________________________________________________________________________ | |
162 | TGraph* | |
163 | AliMUONTrackerHV::ShowValues(TMap* m, const char* name) | |
164 | { | |
165 | // make a graph of HV channels' voltage values for a given dcs alias (name) | |
166 | ||
167 | TGraph* g(0x0); | |
168 | ||
169 | AliInfo(name); | |
170 | ||
171 | TPair* p = static_cast<TPair*>(m->FindObject(name)); | |
172 | TObjArray* a = static_cast<TObjArray*>(p->Value()); | |
173 | TIter n2(a); | |
174 | AliDCSValue* val; | |
175 | Int_t i(0); | |
176 | ||
177 | while ( ( val = static_cast<AliDCSValue*>(n2()) ) ) | |
178 | { | |
179 | StdoutToAliInfo(std::cout << Form("i=%5d ",i); | |
180 | val->Print("");); | |
181 | ++i; | |
182 | } | |
183 | ||
184 | if ( TString(name).Contains("sw") ) | |
185 | { | |
186 | // do not graph switches | |
187 | return 0x0; | |
188 | } | |
189 | ||
190 | n2.Reset(); | |
191 | g = new TGraph(a->GetEntries()); | |
192 | i = 0; | |
193 | while ( ( val = static_cast<AliDCSValue*>(n2()) ) ) | |
194 | { | |
195 | g->SetPoint(i,val->GetTimeStamp(),val->GetFloat()); | |
196 | ++i; | |
197 | } | |
198 | return g; | |
199 | } | |
200 | ||
201 | //______________________________________________________________________________ | |
202 | void | |
203 | AliMUONTrackerHV::ScanHV(Int_t verbose) | |
204 | { | |
205 | /// Retrieve HV values from OCDB for a given run list, and check whether | |
206 | /// we have some issues with them... | |
207 | ||
208 | if ( fRunList.empty() ) | |
209 | { | |
210 | std::cout << "No runs to process..." << std::endl; | |
211 | return; | |
212 | } | |
213 | ||
214 | AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data()); | |
215 | ||
216 | for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i ) | |
217 | { | |
218 | AliMUONCDB::CheckHV(fRunList[i],verbose); | |
219 | } | |
220 | } | |
221 | ||
222 | //______________________________________________________________________________ | |
223 | void AliMUONTrackerHV::HVoff(const char* logfile, const char* outputBaseName) | |
224 | { | |
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 | |
229 | /// | |
230 | ||
231 | gStyle->SetOptStat(0); | |
232 | ||
233 | char line[1024]; | |
234 | ||
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; | |
238 | ||
239 | std::string message; | |
240 | const char* testProblem = "I-AliMUONCDB::CheckHV::CheckHV: Problem at "; | |
241 | ||
242 | while ( in.getline(line,1023,'\n') ) | |
243 | { | |
244 | TString sline(line); | |
245 | if (sline.Contains("SUMMARY")) | |
246 | { | |
247 | AliInfo(line); | |
248 | int r; | |
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); | |
251 | if ( r != run ) | |
252 | { | |
253 | if ( run == -1 ) | |
254 | { | |
255 | AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data()); | |
256 | AliCDBManager::Instance()->SetRun(r); | |
257 | AliMUONCDB::LoadMapping(); | |
258 | } | |
259 | ||
260 | if ( run > 0 ) | |
261 | { | |
262 | results.insert(std::make_pair<int,std::string>(run,message)); | |
263 | ||
264 | } | |
265 | message = ""; | |
266 | run = r; | |
267 | } | |
268 | } | |
269 | else if ( sline.Contains(testProblem) ) | |
270 | { | |
271 | message += "|"; | |
272 | message += sline(strlen(testProblem),sline.Length()-1).Data(); | |
273 | } | |
274 | } | |
275 | ||
276 | results.insert(std::make_pair<int,std::string>(run,message)); | |
277 | ||
278 | AliMpDCSNamer hvNamer("TRACKER"); | |
279 | ||
280 | TH2* hvoff = new TH2I(outputBaseName,outputBaseName,1,0,1,1,0,1); | |
281 | ||
282 | std::map<int,std::string>::const_iterator it; | |
283 | ||
284 | for ( it = results.begin(); it != results.end(); ++it ) | |
285 | { | |
286 | AliInfo(Form("%d -> %s",it->first,it->second.c_str())); | |
287 | TObjArray* split = TString(it->second.c_str()).Tokenize("|"); | |
288 | TIter next(split); | |
289 | TObjString* str; | |
290 | while ( ( str = static_cast<TObjString*>(next()) ) ) | |
291 | { | |
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); | |
298 | delete parts; | |
299 | } | |
300 | delete split; | |
301 | } | |
302 | ||
303 | hvoff->LabelsDeflate("x"); | |
304 | hvoff->LabelsDeflate("y"); | |
305 | hvoff->LabelsOption("x","<"); | |
306 | hvoff->LabelsOption("y","<"); | |
307 | ||
308 | TCanvas* c1 = new TCanvas; | |
309 | c1->SetLeftMargin(0.35); | |
310 | hvoff->Draw("text"); | |
311 | c1->Print(Form("%s.pdf",outputBaseName)); | |
312 | TCanvas* c2 = new TCanvas; | |
313 | TH1* hx = hvoff->ProjectionX("hvoffperrun"); | |
314 | hx->Draw(); | |
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(">"); | |
321 | perchannel->Draw(); | |
322 | c3->Print(Form("%s-perchannel.pdf",outputBaseName)); | |
323 | } | |
324 | ||
325 | //______________________________________________________________________________ | |
326 | void AliMUONTrackerHV::TimeAxis(TMultiGraph* g) | |
327 | { | |
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); | |
333 | } | |
334 | ||
335 | //______________________________________________________________________________ | |
336 | TMultiGraph* | |
337 | AliMUONTrackerHV::ShowHV(TMap* m, const char* dcsname) | |
338 | { | |
339 | TIter next(m); | |
340 | TObjString* s; | |
341 | AliMpDCSNamer hvNamer("TRACKER"); | |
342 | TMultiGraph* mg = new TMultiGraph; | |
343 | ||
344 | while ( ( s = static_cast<TObjString*>(next()) ) ) | |
345 | { | |
346 | TString name(s->String()); | |
347 | ||
348 | if ( dcsname && !name.Contains(dcsname)) continue; | |
349 | ||
350 | TGraph* g = ShowValues(m,name); | |
351 | ||
352 | if ( g ) | |
353 | { | |
354 | g->SetMarkerSize(1.5); | |
355 | g->SetMarkerStyle(2); | |
356 | g->SetLineStyle(2); | |
357 | mg->Add(g,"lp"); | |
358 | g->SetTitle(name.Data()); | |
359 | } | |
360 | } | |
361 | ||
362 | return mg; | |
363 | } | |
364 | ||
365 | //______________________________________________________________________________ | |
366 | void | |
367 | AliMUONTrackerHV::Plot(const char* dcsname, Bool_t withPatch) | |
368 | { | |
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 | |
371 | ||
372 | AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data()); | |
373 | TList messages; | |
374 | messages.SetOwner(kTRUE); | |
375 | ||
376 | for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i ) | |
377 | { | |
378 | Int_t runNumber = fRunList[i]; | |
379 | ||
380 | messages.Delete(); | |
381 | ||
382 | AliCDBManager::Instance()->SetRun(runNumber); | |
383 | ||
384 | TMap* m = AliMUONCalibrationData::CreateHV(runNumber,0x0,withPatch,&messages); | |
385 | ||
386 | TMultiGraph* mg = ShowHV(m,dcsname); | |
387 | ||
388 | if ( !mg ) continue; | |
389 | ||
390 | TString cname(Form("MCH_HV_RUN%09d",runNumber)); | |
391 | ||
392 | if ( strlen(dcsname) > 0 ) | |
393 | { | |
394 | TString s(dcsname); | |
395 | s.ReplaceAll("/","_"); | |
396 | cname += Form("_dcsname_%s",s.Data()); | |
397 | } | |
398 | ||
399 | AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data",runNumber); | |
400 | ||
401 | TLine* startRunLine(0); | |
402 | TLine* endRunLine(0); | |
403 | time_t start(0); | |
404 | time_t end(0); | |
405 | ||
406 | if ( e ) | |
407 | { | |
408 | AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject()); | |
409 | if (grp) | |
410 | { | |
411 | start = grp->GetTimeStart(); | |
412 | end = grp->GetTimeEnd(); | |
413 | } | |
414 | } | |
415 | ||
416 | if ( end ) | |
417 | { | |
418 | TGraph* g = new TGraph(1); | |
419 | g->SetPoint(0,end,0); | |
420 | mg->Add(g,""); | |
421 | } | |
422 | ||
423 | TCanvas* c = new TCanvas(cname.Data(),cname.Data()); | |
424 | ||
425 | c->Draw(); | |
426 | ||
427 | mg->SetTitle(cname.Data()); | |
428 | ||
429 | mg->Draw("AL"); | |
430 | ||
431 | TimeAxis(mg); | |
432 | ||
433 | if ( start ) | |
434 | { | |
435 | startRunLine = new TLine(start,mg->GetYaxis()->GetXmin(),start,mg->GetYaxis()->GetXmax()); | |
436 | startRunLine->SetLineColor(2); | |
437 | startRunLine->SetLineWidth(4); | |
438 | } | |
439 | if ( end ) | |
440 | { | |
441 | endRunLine = new TLine(end,mg->GetYaxis()->GetXmin(),end,mg->GetYaxis()->GetXmax()); | |
442 | endRunLine->SetLineColor(2); | |
443 | endRunLine->SetLineWidth(4); | |
444 | } | |
445 | ||
446 | if ( startRunLine ) startRunLine->Draw(); | |
447 | if ( endRunLine ) endRunLine->Draw(); | |
448 | ||
449 | c->SaveAs(Form("%s.pdf",cname.Data())); | |
450 | } | |
451 | } | |
452 | ||
453 | //______________________________________________________________________________ | |
454 | void | |
455 | AliMUONTrackerHV::ReportTrips() | |
456 | { | |
457 | /// Report trips | |
458 | ||
459 | AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data()); | |
460 | ||
461 | TList messages; | |
462 | messages.SetOwner(kTRUE); | |
463 | TObjString* msg(0); | |
464 | ||
465 | for ( std::vector<int>::size_type i = 0; i < fRunList.size(); ++i ) | |
466 | { | |
467 | Int_t runNumber = fRunList[i]; | |
468 | ||
469 | AliInfo("---------------------"); | |
470 | ||
471 | Int_t ntrips(0); | |
472 | ||
473 | messages.Delete(); | |
474 | ||
475 | AliCDBManager::Instance()->SetRun(runNumber); | |
476 | ||
477 | AliMUONCalibrationData::CreateHV(runNumber,0x0,kTRUE,&messages); | |
478 | ||
479 | TIter next(&messages); | |
480 | ||
481 | while ( ( msg = static_cast<TObjString*>(next())) ) | |
482 | { | |
483 | if ( msg->String().Contains("TRIP") ) | |
484 | { | |
485 | ++ntrips; | |
486 | } | |
487 | } | |
488 | ||
489 | AliInfo(Form("RUN %09d - %d trip%c",runNumber,ntrips,(ntrips>1 ? 's':' '))); | |
490 | ||
491 | next.Reset(); | |
492 | ||
493 | while ( ( msg = static_cast<TObjString*>(next())) ) | |
494 | { | |
495 | if ( msg->String().Contains("TRIP") ) | |
496 | { | |
497 | AliInfo(msg->String().Data()); | |
498 | } | |
499 | } | |
500 | } | |
501 | } | |
502 |