]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/Macros/AliTRDcheckConfig.C
Changes in order to modify also ITSonly tracks
[u/mrichter/AliRoot.git] / TRD / Macros / AliTRDcheckConfig.C
1 //===================================================================================
2 // This is a macro to analyze TRD/Calib/DCS OCDB objects either
3 // from the grid for a given run number or from a local object.
4 // If you want to analyze data from the grid, please don't forget to
5 // have a valid alien token initialized and the file /tmp/gclient_env_$UID source'd.
6 //
7 // Arguments:
8 // The first argument is the runnumber (this is ignored in case of a local file),
9 // the second is a string that needs to contain either "grid" or "local". Further
10 // you can add either verbose or quiet to that string. If you don't, you'll be asked
11 // for all stuff individually wether you want to see it or not
12 // the thrid argument is the number of the ROC you (eventually) want to dump its data
13 // member of.
14 // The fourth one is the path and name of the local file you might want to look at.
15 //
16 // So the simplest way to use this macro is if you want to check the output of a given
17 // run from the OCDB:
18 // .x AliTRDcheckConfig.C(60111)
19 //
20 // An example for quickly checking a local file:
21 // .x AliTRDcheckConfig.C(0, "local quiet", 533, "$ALICE_ROOT/TRD/Calib/DCS/Run0_999999999_v0_s0.root")
22 //
23 // Please contact Frederick Kramer in case of problems
24 //===================================================================================
25
26 // This is the path one needs to change if the year is no longer 2009 
27 // and the runnumber cannot be found
28 //TString alienOcdbPath("alien://folder=/alice/data/2009/OCDB/");
29 TString alienOcdbPath("alien://folder=/alice/data/2010/OCDB/");
30
31 // Do not make changes below here unless you know what your doing
32
33 const Int_t nROC = 540;
34 const Int_t nROB = 8;
35 const Int_t nMCM = 18;
36 const Int_t cArraySize = 1000;
37
38 Bool_t errors = false;
39
40 Int_t AnalyzeArray(Int_t states[cArraySize], Int_t occur[cArraySize]) {
41   long long srtIndx[cArraySize] = 0;
42   
43   TMath::Sort(cArraySize, occur, srtIndx);
44
45   Int_t totalSum = 0, subSum = 0, iIndex = 0;
46   for (Int_t i=0; i<cArraySize; i++) totalSum += occur[i];
47   
48   cout << "    The majority ("<< occur[srtIndx[0]] << " of " 
49        << totalSum <<") is: " << states[srtIndx[0]] << endl;
50   subSum = occur[srtIndx[0]];
51   while (totalSum != subSum) {
52     if (++iIndex > 999) {
53       cout << "E : out of bounds." << endl;
54       break;
55     }
56     Printf("    Next: %7d (%d)", states[srtIndx[iIndex]], occur[srtIndx[iIndex]]);
57     subSum += occur[srtIndx[iIndex]];
58   }
59   return states[srtIndx[0]];
60 }
61
62
63
64 void FillItemInArray(Int_t states[cArraySize], Int_t occur[cArraySize], Int_t item, Bool_t allowNeg) {
65   for (Int_t iArrPos=0; iArrPos<cArraySize; iArrPos++) {
66     // if allowNeg is set then we change the number indicating that the item ws not set from -1 to -100
67     // so that small negitive numbers can be sorted too
68     if ((allowNeg && item == -100000) || (!allowNeg && item == -1)) break; // value not set
69     if (states[iArrPos] == item) {
70       occur[iArrPos]++;
71       break;
72     } else if (occur[iArrPos] == 0) {
73       states[iArrPos] = item;
74       occur[iArrPos]++;
75       break;
76     }
77   }
78 }
79
80 void GetMajoritys(AliTRDCalDCS* calDCSObj) {
81   
82   Int_t gsmStates[cArraySize] = {0}, gsmOccur[cArraySize] = {0};
83   Int_t nimStates[cArraySize] = {0}, nimOccur[cArraySize] = {0};
84   Int_t nevStates[cArraySize] = {0}, nevOccur[cArraySize] = {0};
85   Int_t nptStates[cArraySize] = {0}, nptOccur[cArraySize] = {0};
86   
87   for (Int_t i=0; i<cArraySize; i++) {
88     gsmStates[i] = 0; gsmOccur[i]  = 0;
89     nimStates[i] = 0; nimOccur[i]  = 0;
90     nevStates[i] = 0; nevOccur[i]  = 0;
91     nptStates[i] = 0; nptOccur[i]  = 0;  
92   }
93   
94   for (Int_t i=0; i<nROC && i<calDCSObj->GetFEEArr()->GetSize(); i++) {
95     AliTRDCalDCSFEE *idcsfee = calDCSObj->GetCalDCSFEEObj(i);
96     if ((idcsfee == NULL) || (idcsfee->GetStatusBit() != 0)) continue;
97     for (Int_t j=0; j<nROB; j++) {
98       for (Int_t k=0; k<nMCM; k++) {
99         Int_t igsm = idcsfee->GetMCMGlobalState(j,k);
100         Int_t inim = idcsfee->GetMCMStateNI(j,k);
101         Int_t inev = idcsfee->GetMCMEventCnt(j,k);
102         Int_t inpt = idcsfee->GetMCMPtCnt(j,k);
103         
104         FillItemInArray(gsmStates, gsmOccur, igsm, false); 
105         FillItemInArray(nimStates, nimOccur, inim, false); 
106         FillItemInArray(nevStates, nevOccur, inev, false); 
107         FillItemInArray(nptStates, nptOccur, inpt, false); 
108       }
109     }
110   }
111   
112   cout << "I : Global MCM state statistics:" << endl;
113   AnalyzeArray(gsmStates, gsmOccur);
114   cout << "I : Network interface state statistics:" << endl;
115   AnalyzeArray(nimStates, nimOccur);
116   cout << "I : MCM Event counter reading statistics:" << endl;
117   AnalyzeArray(nevStates, nevOccur);
118   cout << "I : MCM PreTrigger counter reading statistics:" << endl;
119   AnalyzeArray(nptStates, nptOccur);
120   
121   return;
122 }
123
124
125
126 void GetMajorityDifferences(AliTRDCalDCS* calDCSObj, AliTRDCalDCS* calDCSObj2) {
127   
128   Int_t gsmStates[cArraySize] = {0}, gsmOccur[cArraySize] = {0};
129   Int_t nimStates[cArraySize] = {0}, nimOccur[cArraySize] = {0};
130   Int_t nevStates[cArraySize] = {0}, nevOccur[cArraySize] = {0};
131   Int_t nptStates[cArraySize] = {0}, nptOccur[cArraySize] = {0};
132   
133   for (Int_t i=0; i<cArraySize; i++) {
134     gsmStates[i] = 0; gsmOccur[i]  = 0;
135     nimStates[i] = 0; nimOccur[i]  = 0;
136     nevStates[i] = 0; nevOccur[i]  = 0;
137     nptStates[i] = 0; nptOccur[i]  = 0;  
138   }
139   
140   for (Int_t i=0; i<nROC && i<calDCSObj->GetFEEArr()->GetSize() && i<calDCSObj2->GetFEEArr()->GetSize(); i++) {
141     AliTRDCalDCSFEE *idcsfee = calDCSObj->GetCalDCSFEEObj(i);
142     AliTRDCalDCSFEE *idcsfee2 = calDCSObj2->GetCalDCSFEEObj(i);
143     if ((idcsfee == NULL) || (idcsfee2 == NULL) || 
144       (idcsfee->GetStatusBit() != 0) /*|| (idcsfee2->GetStatusBit() != 0)*/) continue;
145     for (Int_t j=0; j<nROB; j++) {
146       for (Int_t k=0; k<nMCM; k++) {
147         Int_t igsm = idcsfee->GetMCMGlobalState(j,k) - idcsfee2->GetMCMGlobalState(j,k);
148         Int_t inim = idcsfee->GetMCMStateNI(j,k)     - idcsfee2->GetMCMStateNI(j,k);
149         Int_t inev = idcsfee2->GetMCMEventCnt(j,k)   - idcsfee->GetMCMEventCnt(j,k);
150         Int_t inpt = idcsfee2->GetMCMPtCnt(j,k)      - idcsfee->GetMCMPtCnt(j,k);
151         
152         // if they were set to -1, it means they were not actauuly set
153         // change -1 to -100 to mean they werent set since the above 
154         // can give negitives
155         if (idcsfee->GetMCMGlobalState(j,k) == -1 && igsm == 0) igsm =-100000;
156         if (idcsfee->GetMCMStateNI(j,k) == -1 && inim == 0)     inim =-100000;
157         if (idcsfee->GetMCMEventCnt(j,k) == -1 && inev == 0)    inev =-100000;
158         if (idcsfee->GetMCMPtCnt(j,k) == -1 && inpt == 0)       inpt =-100000;
159         
160         FillItemInArray(gsmStates, gsmOccur, igsm, true); 
161         FillItemInArray(nimStates, nimOccur, inim, true); 
162         FillItemInArray(nevStates, nevOccur, inev, true); 
163         FillItemInArray(nptStates, nptOccur, inpt, true); 
164       }
165     }
166   }
167   
168   cout << "I : Global MCM state difference statistics:" << endl;
169   AnalyzeArray(gsmStates, gsmOccur);
170   cout << "I : Network interface state difference statistics:" << endl;
171   AnalyzeArray(nimStates, nimOccur);
172   cout << "I : MCM Event counter difference statistics:" << endl;
173   if (AnalyzeArray(nevStates, nevOccur) < 1) {
174     cout << "E : There should have been some events recorded, but there weren't" << endl;
175     errors = true;
176   }
177   cout << "I : MCM PreTrigger counter difference statistics:" << endl;
178   if (AnalyzeArray(nptStates, nptOccur) < 1) {
179     cout << "E : There should have been some events recorded, but there weren't" << endl;
180     errors = true;
181   }
182   
183   return;
184 }
185
186
187 void AliTRDcheckConfig(Int_t runNr=0, char *pathfile="nopathgiven"){
188
189   AliCDBEntry *entry=0;
190   TString pathfilets(pathfile);
191
192   // get the source
193   if(pathfilets.Contains("nopathgiven")) {
194     cout << "I : Accessing grid storage for run number " << runNr << endl;
195     cout << "I : Get CDBManager instance." << endl;
196     AliCDBManager *man = AliCDBManager::Instance();
197     cout << "I : SetDefaultStorage." << endl;
198     man->SetDefaultStorage(alienOcdbPath);
199     cout << "I : Get OCDB Entry." << endl;
200     entry = man->Get("TRD/Calib/DCS", runNr);
201     if (entry == NULL) {
202       cout << endl << "ERROR: Unable to get the AliTRDCalDCS object from the OCDB for run number " << runNr << endl << endl;
203       cout << "If the run number is correct, it could be that the year is no longer 2009 and" << endl;
204       cout << "the path where the objects is stored has changed, check the top of this macro " << endl;
205       cout << "to change the path." << endl;
206       return;
207     }
208   } else {
209     cout << "I : Accessing local storage" << endl;
210     TFile *f = new TFile(pathfile);
211     if(f != NULL) {
212       entry = (AliCDBEntry*) f->Get("AliCDBEntry");
213     }
214     else {
215       cout << "E : Cannot open file" << endl;
216       return;
217     }
218   }
219   
220   TObject *objectCDB = (TObject*)entry->GetObject();
221   if (objectCDB->IsA()->InheritsFrom("TObjArray")) {
222     TObjArray *objArrayCDB = (TObjArray*)entry->GetObject();
223   }
224   
225   // the CalDCS object
226   AliTRDCalDCS *caldcs;
227   AliTRDCalDCS *caldcs2;
228
229   Bool_t sorandeor = true;
230
231   caldcs = (AliTRDCalDCS*) objArrayCDB->At(0);
232   caldcs2 = (AliTRDCalDCS*) objArrayCDB->At(1);
233
234   if (caldcs == NULL && caldcs2 == NULL) {
235     cout << "E : Niether the start or end of run files were in the root file.";
236     return;
237   } else if (caldcs != NULL && caldcs2 == NULL) {
238     cout << "E : The EOR file was not in the root file.";
239     errors = true;
240     sorandeor = false;
241   } else if (caldcs == NULL && caldcs2 != NULL) {
242     cout << "E : The SOR file was not in the root file.";
243     errors = true;
244     sorandeor = false;
245     caldcs = caldcs2;
246   }
247
248   cout << endl << "============ Non responding ROC Summary: ============" << endl;
249   TString bitfivestr = " ROCs with status bit 5. These havn't responded to communication\nattempts over DIM. Most probably they just were off this is ok.\n    DCS IDs: ";
250   Int_t lengthfive = bitfivestr.Length();
251   TString bitfourstr = " ROCs with status bit 4! BAD! This might be due to a communication problem between fxsproxy and the feeserver(s) \n    DCS IDs: ";
252   Int_t lengthfour = bitfourstr.Length();
253   TString bitthreestr = " ROCs with status bit 3! BAD! data from fee server was old or corrupt.\n    DCS IDs: ";
254   Int_t lengththree = bitthreestr.Length();
255   TString bittwostr = " ROCs with status bit 2. These have been in states in which they cannot be read out, e.g. Standby.\n    DCS IDs: ";
256   Int_t lengthtwo = bittwostr.Length();
257   TString bitonestr = " ROCs with status bit 1! BAD! This means the chamber(s) didn't respont even though is should have been in a good state.\n    DCS IDs: ";
258   Int_t lengthone = bitonestr.Length();
259
260   Int_t nSB1=0, nSB2=0, nSB3=0, nSB4=0, nSB5=0, nTot=0;
261   for (Int_t i=0; i<nROC && i<caldcs->GetFEEArr()->GetSize(); i++) {
262     AliTRDCalDCSFEE *idcsfee;
263     idcsfee = caldcs->GetCalDCSFEEObj(i);
264     if (idcsfee != NULL) {
265       Int_t sb = idcsfee->GetStatusBit();
266       if (sb == 5) { bitfivestr  += i; bitfivestr  += "  "; nSB5++; }
267       if (sb == 4) { bitfourstr  += i; bitfourstr  += "  "; nSB4++; errors = true; }
268       if (sb == 3) { bitthreestr += i; bitthreestr += "  "; nSB3++; errors = true; }
269       if (sb == 2) { bittwostr   += i; bittwostr   += "  "; nSB2++; }
270       if (sb == 1) { bitonestr   += i; bitonestr   += "  "; nSB1++; errors = true; }
271       nTot += 1;
272     }
273   }
274
275   if (lengthfive < bitfivestr.Length()) cout << nSB5 << bitfivestr.Data() << endl << endl;
276   if (lengthfour < bitfourstr.Length()) cout << nSB4 << bitfourstr.Data() << endl << endl;
277   if (lengththree < bitthreestr.Length()) cout << nSB3 << bitthreestr.Data() << endl << endl;
278   if (lengthtwo < bittwostr.Length()) cout << nSB2 << bittwostr.Data() << endl << endl;
279   if (lengthone < bitonestr.Length()) cout << nSB1 << bitonestr.Data() << endl << endl;
280   
281   cout << "The remaining " << nTot-(nSB1+nSB2+nSB3+nSB4+nSB5) << " ROCs responded correctly in the start of run."<<endl;
282
283   Int_t nChanged=0, nTot=0;
284   for (Int_t i=0; i<nROC && i<caldcs->GetFEEArr()->GetSize(); i++) {
285     AliTRDCalDCSFEE *idcsfee;
286     idcsfee = caldcs->GetCalDCSFEEObj(i);
287     idcsfee2 = caldcs2->GetCalDCSFEEObj(i);
288     if (idcsfee != NULL && idcsfee2 != NULL) {
289       Int_t sbd = idcsfee->GetStatusBit() - idcsfee2->GetStatusBit();
290       if (sbd != 0) { 
291         cout << "ROC " << i << " changed from state " << idcsfee->GetStatusBit() << " at start of the run to "  << idcsfee2->GetStatusBit() << " at the end of the run." << endl;
292         nChanged++; 
293       }
294       nTot += 1;
295     }
296   }
297   
298   if (nChanged == 0) {
299     cout << "No ROCs changed state between the start and end of the run" << endl;
300   } else {
301     cout << "E : " << nChanged << " out of " << nTot << " ROCs changed state during the run" << endl;
302     errors = true; 
303   }
304
305   cout << endl << "============ Statistics from RSTATE: ============" << endl;
306   cout<<"I : The majority entry is given as well as all other values," << endl;
307   cout<<"    sorted according to their occurrence." << endl << endl;
308   GetMajoritys(caldcs);
309   if (sorandeor) GetMajorityDifferences(caldcs,caldcs2);
310
311   cout << endl << "============ Global Configuraton: ============" << endl;
312   cout<<"I : Anything not listed is not set, mixed numbers are indicated with a" << endl;
313   cout<<"    value of -2 and strings are set to 'mixed' if they're mixed." << endl << endl;
314   if (caldcs->GetGlobalNumberOfTimeBins() != -1)
315     cout<<"Global number of time bins.........................: "<<caldcs->GetGlobalNumberOfTimeBins() << endl;
316   if (caldcs->GetGlobalConfigTag() != -1)
317     cout<<"Global configuration tag...........................: "<<caldcs->GetGlobalConfigTag() << endl;
318   if (caldcs->GetGlobalSingleHitThres() != -1)
319     cout<<"Global single hit threshold........................: "<<caldcs->GetGlobalSingleHitThres() << endl;
320   if (caldcs->GetGlobalThreePadClustThres() != -1)
321     cout<<"Global three pad cluster threshold.................: "<<caldcs->GetGlobalThreePadClustThres()<<endl;
322   if (caldcs->GetGlobalSelectiveNoZS() != -1)
323     cout<<"Global selective ZS (every i'th event).............: "<<caldcs->GetGlobalSelectiveNoZS() << endl;
324   if (caldcs->GetGlobalTCFilterWeight() != -1)
325     cout<<"Global tail cancellation filter weight.............: "<<caldcs->GetGlobalTCFilterWeight() << endl;
326   if (caldcs->GetGlobalTCFilterShortDecPar() != -1)
327     cout<<"Global tail cancellat. filter short decay parameter: "<<caldcs->GetGlobalTCFilterShortDecPar()<<endl;
328   if (caldcs->GetGlobalTCFilterLongDecPar() != -1)
329     cout<<"Global tail cancellation filt. long decay parameter: "<<caldcs->GetGlobalTCFilterLongDecPar()<<endl;
330   if (caldcs->GetGlobalModeFastStatNoise() != -1)
331     cout<<"Global fast statistics mode?.......................: "<<caldcs->GetGlobalModeFastStatNoise() << endl;
332   if (caldcs->GetGlobalConfigVersion() != "")
333     cout<<"Global configuration tag version...................: "<<caldcs->GetGlobalConfigVersion() << endl;
334   if (caldcs->GetGlobalConfigName() != "")
335     cout<<"Global configuration tag name......................: "<<caldcs->GetGlobalConfigName() << endl;
336   if (caldcs->GetGlobalFilterType() != "")
337     cout<<"Global filter type.................................: "<<caldcs->GetGlobalFilterType() << endl;
338   if (caldcs->GetGlobalReadoutParam() != "")
339     cout<<"Global readout parameter...........................: "<<caldcs->GetGlobalReadoutParam() << endl;
340   if (caldcs->GetGlobalTestPattern() != "")
341     cout<<"Global test pattern................................: "<<caldcs->GetGlobalTestPattern() << endl;
342   if (caldcs->GetGlobalTrackletMode() != "")
343     cout<<"Global tracklet mode...............................: "<<caldcs->GetGlobalTrackletMode() << endl;
344   if (caldcs->GetGlobalTrackletDef() != "")
345     cout<<"Global tracklet definition.........................: "<<caldcs->GetGlobalTrackletDef() << endl;
346   if (caldcs->GetGlobalTriggerSetup() != "")
347     cout<<"Global trigger setup...............................: "<<caldcs->GetGlobalTriggerSetup() << endl;
348   if (caldcs->GetGlobalAddOptions() != "")
349     cout<<"Global additional options..........................: "<<caldcs->GetGlobalAddOptions() << endl;
350   
351   cout << endl << "============ Error Summary: ============" << endl;
352   if (errors) {
353     cout<<"    I noticed some errors, please see above for the specifics." << endl;
354   } else {
355     cout<<"    I didn't notice any errors, but that doesn't mean there weren't any!" << endl;
356   }
357   
358
359 }