AliRoot Core  edcc906 (edcc906)
CheckTriggerDCS.C
Go to the documentation of this file.
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 
22 
23 
24 #if !defined(__CINT__) || defined(__MAKECINT__)
25 
26 #include <Riostream.h>
27 
28 // ROOT includes
29 #include "TGraph.h"
30 #include "TString.h"
31 #include "TSystem.h"
32 #include "TCanvas.h"
33 #include "TLegend.h"
34 #include "TGrid.h"
35 #include "TMap.h"
36 #include "TObjArray.h"
37 #include "THashList.h"
38 #include "TAxis.h"
39 #include "TTimeStamp.h"
40 #include "TObjString.h"
41 
42 // STEER includes
43 #include "AliCDBManager.h"
44 #include "AliDCSValue.h"
45 
46 // MUON includes
47 #include "AliMUONCalibrationData.h"
48 #include "AliMpDEIterator.h"
49 #include "AliMpDEManager.h"
50 #include "AliMpDCSNamer.h"
51 #include "AliMpCDB.h"
52 #include "AliMUONCDB.h"
53 
54 #endif
55 
56 enum {kDcsHV, kDcsI};
57 
58 //________________________________________________
59 TGraph* GetGraph ( Int_t imeas, Int_t ich, Int_t irpc, TList* graphList )
60 {
61  TString graphName = Form("%s_RPC%i_ch%i",imeas == kDcsI ? "I" : "HV", irpc, ich+1);
62  TGraph* graph = static_cast<TGraph*>(graphList->FindObject(graphName.Data()));
63  if ( ! graph ) {
64  graph = new TGraph();
65  graph->SetName(graphName.Data());
66  graph->GetXaxis()->SetTitle("Time");
67  graph->GetXaxis()->SetTimeDisplay(1);
68  graph->GetYaxis()->SetTitle(imeas == kDcsI ? "RPC Currents (#muA)" : "RPC HV (V)");
69  graphList->Add(graph);
70  }
71  return graph;
72 }
73 
74 
75 //________________________________________________
77 {
78  printf("Missing points can be obtained in the correct format by querying the amanda server asking for the advanced options:\n");
79  printf("Identification: alias; Time: Epoch\n");
80  printf("Identification: alias; Time: Epoch\n");
81 }
82 
83 
84 //________________________________________________
85 Bool_t UpdateMap ( TMap* triggerDcsMap, TString recoveredPointsFilename, UInt_t startTime, UInt_t stopTime, THashList& missingAliases )
86 {
88  if ( gSystem->AccessPathName(recoveredPointsFilename.Data()) ) {
89  printf("Error: cannot open file %s\n",recoveredPointsFilename.Data());
90  return kFALSE;
91  }
92 
93  TString currLine = "";
94  ifstream inFile(recoveredPointsFilename.Data());
95  while ( ! inFile.eof() ) {
96  currLine.ReadLine(inFile);
97  if ( ! currLine.Contains(";") ) continue;
98  TObjArray* arr = currLine.Tokenize(";");
99  if ( arr->GetEntries() == 3 ) {
100  Double_t timeStampFloat = static_cast<TObjString*>(arr->At(0))->String().Atof();
101  UInt_t timeStamp = (UInt_t)timeStampFloat;
102  TString alias = static_cast<TObjString*>(arr->At(1))->GetString();
103  Float_t value = static_cast<TObjString*>(arr->At(2))->String().Atof();
104  delete arr;
105  if ( ! missingAliases.FindObject(alias.Data()) ) {
106  printf("Warning: alias %s is not in the list of missing points\n",alias.Data());
107  continue;
108  }
109  if ( timeStamp < startTime || timeStamp > stopTime ) {
110  printf("Warning: the point %s %u is not in the time range (%u, %u)\n",alias.Data(),timeStamp,startTime,stopTime);
111  continue;
112  }
113  TObjArray* values = static_cast<TObjArray*>(triggerDcsMap->GetValue(alias.Data()));
114  if ( ! values ) {
115  values = new TObjArray();
116  triggerDcsMap->Add(new TObjString(alias),values);
117  }
118  AliDCSValue* val = new AliDCSValue(value,timeStamp);
119  values->Add(val);
120  }
121  else {
122  printf("Warning: ill formed point: %s\n",currLine.Data());
124  delete arr;
125  }
126  }
127  inFile.close();
128 
129  return kTRUE;
130 }
131 
132 
133 //________________________________________________
134 void CompareDCSvalues ( Int_t runNumber, const char* cdb1, const char* cdb2 )
135 {
137  TString cdb[2] = {cdb1, cdb2};
138  TMap* maps[2] = {0x0,0x0};
140  for ( Int_t icdb=0; icdb<2; icdb++ ) {
141  mgr->SetDefaultStorage(cdb[icdb]);
142  mgr->SetRun(runNumber);
143  AliMUONCalibrationData calibrationData(runNumber);
144  TMap* triggerDcsMap = calibrationData.TriggerDCS();
145  if ( ! triggerDcsMap ) {
146  printf("Error: cannot find TriggerDCS in %s",cdb[icdb].Data());
147  return;
148  }
149  maps[icdb] = static_cast<TMap*>(triggerDcsMap->Clone());
150  }
151 
152  printf("\n\n Checking for differences between %s and %s :\n\n",cdb[0].Data(),cdb[1].Data());
153 
154  TIter next(maps[0]);
155  TObjString* key = 0x0;
156  while ( (key = static_cast<TObjString*>(next())) ) {
157  TObjArray* values1 = static_cast<TObjArray*>(maps[0]->GetValue(key->GetName()));
158  TObjArray* values2 = static_cast<TObjArray*>(maps[1]->GetValue(key->GetName()));
159  if ( ! values2 ) {
160  printf("Alias %s only in %s\n",key->GetName(),cdb[0].Data());
161  continue;
162  }
163  if ( values1->GetEntriesFast() == values2->GetEntriesFast() ) {
164  for ( Int_t ival=0; ival<values1->GetEntries(); ival++ ) {
165  AliDCSValue* val1 = static_cast<AliDCSValue*>(values1->UncheckedAt(ival));
166  AliDCSValue* val2 = static_cast<AliDCSValue*>(values2->UncheckedAt(ival));
167  if ( val1->GetTimeStamp() != val2->GetTimeStamp() ) {
168  printf("Alias %s: value %i. Timestamps %u != %u\n",key->GetName(),ival,val1->GetTimeStamp(), val2->GetTimeStamp());
169  }
170  if ( val1->GetFloat() != val2->GetFloat() ) {
171  printf("Alias %s: value %i. Float %g != %g\n",key->GetName(),ival,val1->GetFloat(), val2->GetFloat());
172  }
173  }
174  }
175  else {
176  printf("Alias %s. Number of points: %i != %i\n",key->GetName(),values1->GetEntriesFast(),values2->GetEntriesFast());
177  }
178  maps[1]->DeleteEntry(static_cast<TPair*>(maps[1]->FindObject(key->GetName()))->Key());
179  }
180 
181  TIter next1(maps[1]);
182  while ( (key = static_cast<TObjString*>(next1())) ) {
183  printf("Alias %s only in %s\n",key->GetName(),cdb[1].Data());
184  maps[1]->GetValue(key->GetName())->Print();
185  }
186 
187  for ( Int_t icdb=0; icdb<2; icdb++ ) delete maps[icdb
188  ];
189 }
190 
191 
192 
193 //________________________________________________
194 void CheckTriggerDCS ( Int_t runNumber, TString ocdbPath="raw://", TString recoveredPointsFilename = "", TString outDirRecovery = "CDB" )
195 {
197 
198  THashList graphList;
199 
200  if (ocdbPath.Contains("alien")) TGrid::Connect("alien://");
201 
203  mgr->SetDefaultStorage(ocdbPath.Data());
204  mgr->SetRun(runNumber);
205  mgr->SetSpecificStorage("MUON/Calib/MappingData","local://$ALICE_ROOT/OCDB"); // SAVE TIME
206 
208 
209  AliMUONCalibrationData calibrationData(AliCDBManager::Instance()->GetRun());
210 
211  TMap* triggerDcsMap = calibrationData.TriggerDCS();
212 
213  if ( ! triggerDcsMap ) {
214  printf("Cannot fill DCS histos, as triggerDcsMap is NULL\n");
215  return;
216  }
217 
218  AliMpDCSNamer triggerDcsNamer("TRIGGER");
219 
220  UInt_t minTimeStamp = 0xFFFFFFFF;
221 
222  UInt_t maxTimeStamp = 0;
223 
224  THashList missingPoints;
225  missingPoints.SetOwner();
226 
227  AliMpDEIterator deIt;
228  deIt.First();
229  while ( !deIt.IsDone() )
230  {
231  Int_t detElemId = deIt.CurrentDEId();
232 
234 
235  Int_t ich = AliMpDEManager::GetChamberId(detElemId);
236  Int_t irpc = detElemId%100;
237 
238  for ( Int_t imeas=0; imeas<AliMpDCSNamer::kNDCSMeas; imeas++ ){
239  TString currAlias = triggerDcsNamer.DCSAliasName(detElemId, 0, imeas);
240 
241  TObjArray* values = static_cast<TObjArray*>(triggerDcsMap->GetValue(currAlias.Data()));
242  if ( values ) {
243  TIter next(values);
244  AliDCSValue* val = 0x0;
245  Int_t ipoint = 0;
246  while ( ( val = static_cast<AliDCSValue*>(next()) ) ) {
247  Float_t hvi = val->GetFloat();
248  UInt_t timeStamp = val->GetTimeStamp();
249  if ( timeStamp < minTimeStamp ) minTimeStamp = timeStamp;
250  if ( timeStamp > maxTimeStamp ) maxTimeStamp = timeStamp;
251  TGraph* graph = GetGraph(imeas,ich,irpc,&graphList);
252  if ( ipoint == 0 ) {
253  TTimeStamp ts(timeStamp);
254  graph->SetTitle(Form("Date: %u (yyyymmdd)\n",ts.GetDate()));
255  }
256  graph->SetPoint(ipoint++,timeStamp,hvi);
257  } // loop on values
258  }
259  else {
260  printf("Did not find expected alias (%s) for DE %d\n",currAlias.Data(),detElemId);
261  missingPoints.Add(new TObjString(currAlias));
262  }
263  } // loop on measured types (HV and currents)
264  } // if (stationType == kStationTrigger)
265 
266  deIt.Next();
267  }
268 
269  if ( missingPoints.GetEntries() > 0 ) {
270  if ( recoveredPointsFilename.IsNull() ) {
271  printf("\n\nNo values found for the following aliases:\n");
272  TIter next(&missingPoints);
273  TObject* obj = 0x0;
274  while ( (obj = next() ) ) printf("%s\n",obj->GetName());
275  printf("\n");
277  printf("\nIn the time range\n");
278  UInt_t year, month, day, hour, min, sec;
279  for ( Int_t itime=0; itime<2; itime++) {
280  UInt_t timeStamp = ( itime == 0 ) ? minTimeStamp : maxTimeStamp;
281  TTimeStamp ts(timeStamp);
282  ts.GetDate(kTRUE,0,&year,&month,&day);
283  ts.GetTime(kTRUE,0,&hour,&min,&sec);
284  TString usTime = "AM";
285  if ( hour >= 12 ) {
286  hour = hour - 12;
287  usTime = "PM";
288  }
289  if ( hour == 0 ) hour = 12;
290  ts.Print();
291  printf(" Amanda format: %i/%i/%i %i:%i:%i %s\n",month,day,year,hour,min,sec,usTime.Data());
292  }
293  }
294  else {
295  printf("\nRecover missing points with data in %s\n",recoveredPointsFilename.Data());
296 
297  TMap* clonedTriggerDCSmap = static_cast<TMap*>(triggerDcsMap->Clone());
298 
299  if ( UpdateMap(clonedTriggerDCSmap, recoveredPointsFilename, minTimeStamp, maxTimeStamp, missingPoints) ) {
300  TString specStorageDir = "MUON/Calib/TriggerDCS";
301  TString fullDir = Form("%s/%s",outDirRecovery.Data(),specStorageDir.Data());
302  if ( gSystem->AccessPathName(fullDir) ) gSystem->Exec(Form("mkdir -p %s",fullDir.Data()));
303  mgr->UnloadFromCache(specStorageDir.Data());
304  mgr->SetSpecificStorage(specStorageDir.Data(),Form("local://%s",outDirRecovery.Data()));
305  AliMUONCDB::WriteToCDB(clonedTriggerDCSmap, specStorageDir.Data(), runNumber, runNumber, "Recovered MTR DCS values");
306  }
307  }
308  }
309 
310 
311  for ( Int_t imeas=0; imeas<2; imeas++ ){
312  for ( Int_t ich=10; ich<14; ich++ ){
313  TString canName = Form("%s_ch%i",imeas == kDcsI ? "I" : "HV", ich+1);
314  TCanvas* can = new TCanvas(canName.Data(), canName.Data(), 200, 10, 600, 600);
315  TLegend* leg = new TLegend(0.6,0.6,0.9,0.9);
316  leg->SetBorderSize(1);
317  Int_t icolor=0;
318  for ( Int_t irpc = 0; irpc<18; irpc++ ) {
319  TGraph* graph = GetGraph(imeas,ich,irpc,&graphList);
320  if ( graph->GetN() == 0 ) {
321 // printf("No points found for %s\n",graph->GetName());
322  continue;
323  }
324  TString drawOpt = "lp";
325  if ( can->GetListOfPrimitives()->GetEntries() == 0 ) drawOpt.Append("a");
326  if ( irpc<9 ) icolor = irpc+1;
327  else icolor = (irpc-8)*10+1;
328 // icolor++;
329 // if ( icolor == 10 ) icolor++;
330  graph->SetLineColor(icolor);
331  graph->SetMarkerColor(icolor);
332  graph->SetMarkerStyle(20+irpc%10);
333  if ( imeas == kDcsHV ) graph->GetYaxis()->SetRangeUser(9500.,11000.);
334  else graph->GetYaxis()->SetRangeUser(0,10);
335  graph->GetXaxis()->SetTimeDisplay(1);
336  graph->Draw(drawOpt.Data());
337  leg->AddEntry(graph,Form("RPC %i",irpc),"lp");
338  }
339  leg->Draw();
340  }
341  }
342 }
TMap * TriggerDCS() const
Get the Trigger HV and current values.
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
Bool_t UpdateMap(TMap *triggerDcsMap, TString recoveredPointsFilename, UInt_t startTime, UInt_t stopTime, THashList &missingAliases)
The iterator over detection elements.
Int_t year
year for detector configuration
Definition: Config.C:96
#define TObjArray
Bool_t IsDone() const
Collection of methods usefull to DCS handling for MUON TRK and TRG.
Definition: AliMpDCSNamer.h:22
static Bool_t LoadDDLStore(Bool_t warn=false)
Definition: AliMpCDB.cxx:149
Int_t CurrentDEId() const
Float_t GetFloat() const
void Print(const char *method, TStopwatch &timer, Int_t n)
static Int_t GetChamberId(Int_t detElemId, Bool_t warn=true)
void SetSpecificStorage(const char *calibType, const char *dbString, Int_t version=-1, Int_t subVersion=-1)
TGraph * GetGraph(Int_t imeas, Int_t ich, Int_t irpc, TList *graphList)
TTimeStamp startTime(2009, 8, 7, 0, 0, 0)
void CheckTriggerDCS(Int_t runNumber, TString ocdbPath="raw://", TString recoveredPointsFilename="", TString outDirRecovery="CDB")
static AliMp::StationType GetStationType(Int_t detElemId)
void SetRun(Int_t run)
void UnloadFromCache(const char *path)
void SetDefaultStorage(const char *dbString)
void WriteToCDB(const char *calibpath, TObject *object, Int_t startRun, Int_t endRun, const char *filename)
Single entry point to access MUON calibration data.
void PrintQueryOptions()
trigger stations (slats)
Number of measured quantities.
Definition: AliMpDCSNamer.h:86
TTimeStamp stopTime(2009, 12, 31, 0, 0, 0)
UInt_t GetTimeStamp() const
Definition: AliDCSValue.h:55
static Int_t runNumber
Definition: pdc06_config.C:126
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
TString DCSAliasName(Int_t detElemId, Int_t sector=0, Int_t dcsMeasure=0) const
void CompareDCSvalues(Int_t runNumber, const char *cdb1, const char *cdb2)