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. *
15 **************************************************************************/
17 /********************************************************************************
19 * AliLHCData: summary of the LHC related information from LHC DIP. *
20 * Created from the TMap provided by the AliLHCReader with optional beginning *
22 * The data are (wrapped in the AliLHCDipValT): *
23 * made of TimeStamp (double) and array of values *
25 * Multiple entries for each type of data are possible. To obtaine number of *
26 * records (with distinct timestamp) for give type od records use: *
27 * int GetNBunchConfigMeasured(int beam) (with beam=0,1) etc. *
29 * To get i-th entry, use brec= AliLHCDipValI* GetBunchConfigMeasured(bm,i); *
30 * Note: exact type of templated AliLHCDipValT pointer depends on the record *
31 * type, concult getters to know it. *
33 * Then, once the pointer is obtained, details can be accessed: *
34 * int nBunches = brec->GetSize(); *
35 * for (int i=0;i<nBunches;i++) printf("Bunch#%d: %d\n",i,(*brec)[i]); *
38 * Author: ruben.shahoyan@cern.ch *
40 ********************************************************************************/
42 #include "AliLHCData.h"
44 #include "AliDCSArray.h"
45 #include "AliLHCReader.h"
46 #include "AliTriggerBCMask.h"
48 #include <TObjArray.h>
53 const Char_t* AliLHCData::fgkDCSNames[] = {
54 "LHC_IntensityBeam%1d_totalIntensity",
55 "LHC_BeamIntensityPerBunchBeam%1d_averageBeamIntensity",
56 "LHC_BeamIntensityPerBunchBeam%1d_Average_BunchIntensities",
58 "LHC_LumAverageBRANB_4%c2_acqMode",
59 "LHC_LumAverageBRANB_4%c2_meanLuminosity",
60 "LHC_LumAverageBRANB_4%c2_meanLuminosityError",
61 "LHC_BeamLuminosityPerBunchBRANB_4%c2_Average_BunchLuminosity",
62 "LHC_BeamLuminosityPerBunchBRANB_4%c2_BunchLuminosityError",
63 "LHC_LumAverageBRANB_4%c2_meanCrossingAngle",
64 "LHC_LumAverageBRANB_4%c2_meanCrossingAngleError",
65 "LHC_CirculatingBunchConfig_Beam%d",
68 "LHC_BunchLengthBeam%1d_nBunches",
69 "LHC_BunchLengthBeam%1d_bunchesLenghts",
70 "LHC_BunchLengthBeam%1d_filledBuckets",
72 "LHC_RunControl_ActiveInjectionScheme",
73 "LHC_RunControl_BetaStar",
74 "LHC_RunControl_IP2_Xing_Murad",
75 "LHC_RunControl_IP2_ALICE_Murad",
77 "LHC_BeamSizeBeam%1d_acqMode",
78 "LHC_BeamSizeBeam%1d_sigmaH",
79 "LHC_BeamSizeBeam%1d_sigmaV",
80 "LHC_BeamSizeBeam%1d_emittanceH",
81 "LHC_BeamSizeBeam%1d_emittanceV",
82 "LHC_BeamSizeBeam%1d_errorSigmaH",
83 "LHC_BeamSizeBeam%1d_errorSigmaV",
85 "LHC_CollimatorPos_%s_lvdt_%s",
90 const Char_t* AliLHCData::fgkDCSColNames[] = {
96 const Char_t* AliLHCData::fgkDCSColJaws[] = {
97 "gap_downstream","gap_upstream","left_downstream",
98 "left_upstream","right_downstream","right_upstream"};
100 //___________________________________________________________________
101 AliLHCData::AliLHCData(const TMap* dcsMap, double tmin, double tmax)
102 : fTMin(0),fTMax(0),fFillNumber(0),fData(0),fkFile2Process(0),fkMap2Process(0)
104 FillData(dcsMap,tmin,tmax);
107 //___________________________________________________________________
108 AliLHCData::AliLHCData(const Char_t* dcsFile, double tmin, double tmax)
109 : fTMin(0),fTMax(0),fFillNumber(0),fData(0),fkFile2Process(dcsFile),fkMap2Process(0)
111 FillData(dcsFile,tmin,tmax);
114 //___________________________________________________________________
115 Bool_t AliLHCData::FillData(const TMap* dcsMap,double tmin, double tmax)
117 // process DCS map and fill all fields.
119 fkMap2Process = dcsMap;
124 //___________________________________________________________________
125 Bool_t AliLHCData::FillData(const Char_t* dcsFile,double tmin, double tmax)
127 // process DCS file and fill all fields.
129 fkFile2Process = dcsFile;
134 //___________________________________________________________________
135 Bool_t AliLHCData::FillData(double tmin, double tmax)
137 // process DCS map and fill all fields.
138 // Accept only entries with timestamp between tmin and tmax
140 char buff[100],buff1[100];
145 // -------------------------- extract Fill Number
146 int iFirst=0,iLast=0;
147 TObjArray* arr = GetDCSEntry(fgkDCSNames[kFillNum],iFirst,iLast,fTMin,fTMax);
148 if (arr) SetFillNumber( ExtractInt( (AliDCSArray*)arr->At(iFirst), 0) );
149 if (fkFile2Process) delete arr; // array was created on demand
151 for (int ibm=0;ibm<2;ibm++) {
153 snprintf(buff,99,fgkDCSNames[kBunchConf],ibm+1); // ----- declared bunch configuration
154 FillBunchConfig(fBunchConfDecl[ibm], buff);
156 snprintf(buff,99,fgkDCSNames[kBunchLgtFillB],ibm+1); // ----- measured bunch configuration
157 FillBunchConfig(fBunchConfMeas[ibm], buff);
159 snprintf(buff,99,fgkDCSNames[kBunchLgt],ibm+1); // ----- measured bunch lenghts
160 FillBunchInfo(fBunchLengths[ibm],buff,ibm,kFALSE);
162 snprintf(buff,99,fgkDCSNames[kIntBunchAv],ibm+1); // ----- B-by-B intensities
163 FillBunchInfo(fIntensPerBunch[ibm],buff,ibm,kTRUE);
166 snprintf(buff,99,fgkDCSNames[kIntTot],ibm+1); // ----- total intensities for beam 1 and 2
167 FillScalarRecord(fIntensTotal[ibm], buff);
169 snprintf(buff,99,fgkDCSNames[kIntTotAv],ibm+1); // ----- total intensities for beam 1 and 2 from B-by-B average
170 FillScalarRecord(fIntensTotalAv[ibm], buff);
172 snprintf(buff,99,fgkDCSNames[kBeamSzEmittH],ibm+1); // ----- H emittance for beam 1 and 2
173 FillScalarRecord(fEmittanceH[ibm], buff);
175 snprintf(buff,99,fgkDCSNames[kBeamSzEmittV],ibm+1); // ----- V emittance for beam 1 and 2
176 FillScalarRecord(fEmittanceV[ibm], buff);
178 snprintf(buff,99 ,fgkDCSNames[kBeamSzSigH], ibm+1); // ----- H sigmas and errors for beam 1 and 2
179 snprintf(buff1,99,fgkDCSNames[kBeamSzSigHErr],ibm+1);
180 FillScalarRecord(fBeamSigmaH[ibm], buff, buff1);
182 snprintf(buff,99 ,fgkDCSNames[kBeamSzSigV], ibm+1); // ----- V sigmas and errors for beam 1 and 2
183 snprintf(buff1,99,fgkDCSNames[kBeamSzSigVErr],ibm+1);
184 FillScalarRecord(fBeamSigmaV[ibm], buff, buff1);
188 FlagInteractingBunches(fBunchConfMeas[0],fBunchConfMeas[1]);
189 FlagInteractingBunches(fBunchConfDecl[0],fBunchConfDecl[1]);
191 for (int ilr=0;ilr<2;ilr++) {
193 snprintf(buff,99 ,fgkDCSNames[kLumBunch], ilr ? 'R':'L'); // ---- BC-by-BC luminosity at IP2 and its error
194 snprintf(buff1,99,fgkDCSNames[kLumBunchErr], ilr ? 'R':'L');
195 FillBCLuminosities(fLuminPerBC[ilr], buff, buff1, 0); // BRAN L uses beam2 as a reference, BRAN R - beam1
197 snprintf(buff,99 ,fgkDCSNames[kLumTot] , ilr ? 'R':'L'); // ---- total luminosity at IP2 and its error
198 snprintf(buff1,99,fgkDCSNames[kLumTotErr], ilr ? 'R':'L');
199 FillScalarRecord(fLuminTotal[ilr], buff, buff1);
201 snprintf(buff,99 ,fgkDCSNames[kLumAcqMode], ilr ? 'R':'L'); // ---- luminosity acquisition mode
202 FillAcqMode(fLuminAcqMode[ilr], buff);
204 snprintf(buff,99, fgkDCSNames[kLumCrossAng] , ilr ? 'R':'L'); //----- crossing angle at IP2 and its error
205 snprintf(buff1,99,fgkDCSNames[kLumCrossAngErr], ilr ? 'R':'L');
206 FillScalarRecord(fCrossAngle[ilr], buff, buff1);
210 for (int icl=0;icl<kNCollimators;icl++) { // ----- collimators positions
211 for (int jaw=0;jaw<kNJaws;jaw++) {
212 snprintf(buff,99,fgkDCSNames[kCollPos], fgkDCSColNames[icl],fgkDCSColJaws[jaw]);
213 FillScalarRecord(fCollimators[icl][jaw], buff);
219 FillStringRecord(fRCInjScheme, fgkDCSNames[kRCInjSch]); // ---- active injection scheme
220 FillScalarRecord(fRCBeta, fgkDCSNames[kRCBeta]); // ---- target beta
221 FillScalarRecord(fRCAngH, fgkDCSNames[kRCCrossAng]); // ---- horisontal angle
222 FillScalarRecord(fRCAngV,fgkDCSNames[kRCVang] ); // ---- vertical angle
227 //___________________________________________________________________
228 TObjArray* AliLHCData::GetDCSEntry(const char* key,int &entry,int &last,double tmin,double tmax) const
230 // extract array from the DCS map or file and find the first entry within the time limits
234 if (fkMap2Process) arr = (TObjArray*)fkMap2Process->GetValue(key);
235 else if (fkFile2Process) {
237 arr = rd.ReadSingleLHCDP(fkFile2Process,key);
240 AliError("Neither DCS map nor DCS filename are set");
244 if (!arr || !arr->GetEntriesFast()) {
245 AliWarning(Form("No data for %s",key));
246 if (fkMap2Process) delete arr; // created on demand
249 int ntot = arr->GetEntriesFast();
251 // search 1st entry before or at tmin
252 AliDCSArray* ent = 0;
253 Bool_t found = kFALSE;
254 for (entry=0;entry<ntot;entry++) {
255 ent = (AliDCSArray*)arr->At(entry);
256 if (ent->GetTimeStamp()>=tmin-kMarginSOR && ent->GetTimeStamp()<=tmax+kMarginEOR) {
258 if (ent->GetTimeStamp()>tmin) break;
264 str += AliLHCDipValF::TimeAsString(tmin);
266 str += AliLHCDipValF::TimeAsString(tmax);
267 AliWarning(Form("All entries for %s are outside the requested range:\n%s",key,str.Data()));
268 if (fkMap2Process) delete arr; // created on demand
271 if (entry>0) entry--;
273 // search last entry at or after tmin
275 for (last=entry;last<ntot;last++) {
276 ent = (AliDCSArray*)arr->At(last);
277 if (ent->GetTimeStamp()>tmax) break;
279 if (last == ntot) last--;
280 else if (ent->GetTimeStamp()>tmax+kMarginEOR) last--;
285 //___________________________________________________________________
286 Int_t AliLHCData::TimeDifference(double v1,double v2,double tol) const
288 // return 0 if the times are the same within the tolerance
292 if (v1>tol) return 1;
293 if (v1<-tol) return -1;
297 //___________________________________________________________________
298 Bool_t AliLHCData::GoodPairID(int beam) const
300 // check for correct beam identifier
301 if (beam>kBeam2||beam<0) {AliError(Form("BeamID can be 0 or 1, %d requested",beam)); return kFALSE;}
305 //___________________________________________________________________
306 AliLHCDipValI* AliLHCData::GetBunchConfigMeasured(int beam,double tstamp) const
308 // find measured bunch configuration valid for given tstamp
309 if (!GoodPairID(beam)) return 0;
310 return (AliLHCDipValI*)FindRecValidFor(fBunchConfMeas[beam][kStart],fBunchConfMeas[beam][kNStor],tstamp);
313 //___________________________________________________________________
314 AliLHCDipValI* AliLHCData::GetBunchConfigDeclared(int beam,double tstamp) const
316 // find declared bunch configuration valid for given tstamp
317 if (!GoodPairID(beam)) return 0;
318 return (AliLHCDipValI*)FindRecValidFor(fBunchConfDecl[beam][kStart],fBunchConfDecl[beam][kNStor],tstamp);
321 //___________________________________________________________________
322 TObject* AliLHCData::FindRecValidFor(int start,int nrec, double tstamp) const
324 // find record within this limits valid for given tstamp (i.e. the last one before or equal to tstamp)
325 AliLHCDipValI *prevObj = 0;
326 for (int i=0;i<nrec;i++) {
327 AliLHCDipValI* curObj = (AliLHCDipValI*)fData[start+i];
328 if (TimeDifference(tstamp,curObj->GetTimeStamp())<=0) break;
331 if (!prevObj && nrec>0) prevObj = (AliLHCDipValI*)fData[start]; // if no exact match, return the 1st one
335 //___________________________________________________________________
336 Int_t AliLHCData::FillScalarRecord(int refs[2], const char* rec, const char* recErr, Double_t maxAbsVal)
338 // fill record for scalar value, optionally accompanied by measurement error
340 AliInfo(Form("Acquiring record: %s",rec));
342 TObjArray *arr=0,*arrE=0;
343 Int_t iLast=0,iLastE=0,iFirst=0,iFirstE=0;
345 refs[kStart] = fData.GetEntriesFast();
348 if ( !(arr=GetDCSEntry(rec,iFirst,iLast,fTMin,fTMax)) ) return -1;
352 arrE = GetDCSEntry(recErr,iFirstE,iLastE,fTMin,fTMax);
356 // Bool_t last = kFALSE;
357 while (iFirst<=iLast) {
358 AliDCSArray *dcsVal = (AliDCSArray*) arr->At(iFirst++);
359 double tstamp = dcsVal->GetTimeStamp();
361 AliLHCDipValF* curValD = new AliLHCDipValF(dim,tstamp); // start new period
362 double vcheck = ExtractDouble(dcsVal,0); // value
363 if (TMath::Abs(vcheck) > maxAbsVal) {
364 AliError(Form("ANOMALOUS VALUE %e for slot %d of %s: exceeds %e",vcheck, 0, rec, maxAbsVal));
367 (*curValD)[0] = vcheck;
371 while (iFirstE<=iLastE) { // try to find corresponding error
372 AliDCSArray *dcsValE = (AliDCSArray*) arrE->At(iFirstE);
373 double tstampE = dcsValE->GetTimeStamp();
374 int tdif = TimeDifference(tstamp,tstampE);
375 if (!tdif) { // error matches to value
376 errVal = ExtractDouble(dcsVal,0); // value
377 if (TMath::Abs(errVal) > maxAbsVal) {
378 AliError(Form("ANOMALOUS VALUE %e for slot %d of %s: exceeds %e",errVal, 0, recErr, maxAbsVal));
384 else if (tdif>0) iFirstE++; // error time lags behind, read the next one
385 else break; // error time is ahead of value, no error associated
387 (*curValD)[dim-1] = errVal; // error
388 curValD->SetLastSpecial(); // lable the last entry as an error
396 if (fkFile2Process) {
403 //___________________________________________________________________
404 Int_t AliLHCData::FillBunchConfig(int refs[2],const char* rec)
406 // fill record for bunch configuration
408 AliInfo(Form("Acquiring record: %s",rec));
412 refs[kStart] = fData.GetEntriesFast();
415 if ( !(arr=GetDCSEntry(rec,iFirst,iLast,fTMin,fTMax)) ) return -1;
417 AliLHCDipValI* prevRecI=0;
419 while (iFirst<=iLast) {
420 AliDCSArray *dcsVal = (AliDCSArray*) arr->At(iFirst++);
421 double tstamp = dcsVal->GetTimeStamp();
423 int bucket=0, nbunch=0, ndiff=0;
424 int nSlots = dcsVal->GetNEntries(); // count number of actual bunches (non-zeros)
425 int* dcsArr = dcsVal->GetInt();
426 while(nbunch<nSlots && (bucket=dcsArr[nbunch])) {
427 if (prevRecI && prevRecI->GetSize()>nbunch && bucket!=prevRecI->GetValue(nbunch)) ndiff++;
430 if (!nbunch) AliWarning(Form("%s record is present but empty: no beam?",rec));
431 if (prevRecI && !ndiff && nbunch==prevRecI->GetSize()) continue; // record similar to previous one
432 AliLHCDipValI* curValI = new AliLHCDipValI(nbunch,tstamp);
433 for (int i=nbunch;i--;) (*curValI)[i] = dcsArr[i];
439 if (fkFile2Process) delete arr;
443 //___________________________________________________________________
444 Int_t AliLHCData::FillAcqMode(int refs[2],const char* rec)
446 // fill acquisition mode
448 AliInfo(Form("Acquiring record: %s",rec));
452 refs[kStart] = fData.GetEntriesFast();
455 if ( !(arr=GetDCSEntry(rec,iFirst,iLast,fTMin,fTMax)) ) return -1;
457 AliLHCDipValI* prevRecI=0;
458 while (iFirst<=iLast) {
459 AliDCSArray *dcsVal = (AliDCSArray*) arr->At(iFirst++);
460 double tstamp = dcsVal->GetTimeStamp();
462 int nSlots = dcsVal->GetNEntries();
463 if (nSlots<1) continue;
464 int acqMode = dcsVal->GetInt()[0];
465 if (prevRecI && (*prevRecI)[0] == acqMode) continue; // record similar to previous one
466 AliLHCDipValI* curValI = new AliLHCDipValI(1,tstamp);
467 (*curValI)[0] = acqMode;
473 if (fkFile2Process) delete arr;
477 //___________________________________________________________________
478 Int_t AliLHCData::FillStringRecord(int refs[2],const char* rec)
480 // fill record with string value
482 AliInfo(Form("Acquiring record: %s",rec));
487 refs[kStart] = fData.GetEntriesFast();
490 if ( !(arr=GetDCSEntry(rec,iFirst,iLast,fTMin,fTMax)) ) return -1;
492 while (iFirst<=iLast) {
493 AliDCSArray *dcsVal = (AliDCSArray*) arr->At(iFirst++);
494 double tstamp = dcsVal->GetTimeStamp();
496 TString &str = ExtractString(dcsVal);
497 if (!prevRec.IsNull()) {if (str == prevRec) continue;} // skip similar record
500 AliLHCDipValC* curValS = new AliLHCDipValC(1,tstamp);
501 curValS->SetValues(str.Data(),str.Length()+1);
506 if (fkFile2Process) delete arr;
510 //___________________________________________________________________
511 Int_t AliLHCData::FillBunchInfo(int refs[2],const char* rec, int ibm, Bool_t inRealSlots, Double_t maxAbsVal)
513 // fill bunch properties for beam ibm
514 // if inRealSlots = true, then the value is taken from bunchRFbucket/10, otherwise, the value
515 // for the i-th bunch is taken from the i-th element
517 AliInfo(Form("Acquiring record: %s",rec));
521 refs[kStart] = fData.GetEntriesFast();
524 if ( !(arr=GetDCSEntry(rec,iFirst,iLast,fTMin,fTMax)) ) return -1;
526 while (iFirst<=iLast) {
527 AliDCSArray *dcsVal = (AliDCSArray*) arr->At(iFirst++);
528 double tstamp = dcsVal->GetTimeStamp();
530 AliLHCDipValI *bconf = GetBunchConfigMeasured(ibm,tstamp);
532 AliWarning(Form("Mearured bunch configuration for beam %d at t=%.1f is not available, trying declared one",ibm+1,tstamp));
533 bconf = GetBunchConfigDeclared(ibm,tstamp);
536 AliWarning(Form("Declared bunch configuration for beam %d at t=%.1f is not available, skip this record",ibm+1,tstamp));
539 int nSlots = dcsVal->GetNEntries(); // count number of actual bunches (non-zeros)
540 int nbunch = bconf->GetSize();
542 AliWarning(Form("More N bunches than slots in %s at time %.1f",rec,tstamp));
545 double* dcsArr = dcsVal->GetDouble();
546 AliLHCDipValF* curValD = new AliLHCDipValF(nbunch,tstamp);
547 for (int i=nbunch;i--;) {
548 int ind = inRealSlots ? (*bconf)[i]/10 : i;
550 AliError(Form("Bunch %d refers to wrong slot %d, set to -1",i,(*bconf)[i]));
554 double vcheck = dcsArr[ind];
555 if (TMath::Abs(vcheck) > maxAbsVal) {
556 AliError(Form("ANOMALOUS VALUE %e for slot %d of %s: exceeds %e",vcheck, ind, rec, maxAbsVal));
559 (*curValD)[i] = vcheck;
565 if (fkFile2Process) delete arr;
570 //___________________________________________________________________
571 Int_t AliLHCData::FillBCLuminosities(int refs[2],const char* rec, const char* recErr, int useBeam, Double_t maxAbsVal)
573 // fill luminosities per bunch crossing
575 AliInfo(Form("Acquiring record: %s",rec));
576 TObjArray *arr,*arrE=0;
577 Int_t iLast=0,iLastE=0,iFirst=0,iFirstE=0;
579 refs[kStart] = fData.GetEntriesFast();
582 if ( !(arr=GetDCSEntry(rec,iFirst,iLast,fTMin,fTMax)) ) return -1;
584 while (iFirst<=iLast) {
585 AliDCSArray *dcsVal = (AliDCSArray*) arr->At(iFirst++);
586 double tstamp = dcsVal->GetTimeStamp();
588 AliLHCDipValI *bconf;
589 bconf = GetBunchConfigMeasured(useBeam,tstamp); // luminosities are stored according to beam bunches
591 AliWarning(Form("Mearured bunch configuration for beam%d at t=%.1f is not available, trying declared one",useBeam,tstamp));
592 bconf = GetBunchConfigDeclared(useBeam,tstamp);
595 AliWarning(Form("Declared bunch configuration for beam%i at t=%.1f is not available, skip this record",useBeam,tstamp));
598 int nSlots = dcsVal->GetNEntries(); // count number of actual bunches (non-zeros)
599 int nbunch = bconf->GetSize();
600 double* dcsArr = dcsVal->GetDouble();
603 AliWarning(Form("More N bunches than slots in %s at time %.1f",rec,tstamp));
607 if (!bconf->IsProcessed1()) {
608 AliWarning(Form("Bunch conf. for beam%d has no marked interacting bunches, store all luminosity for all filled bunches",useBeam));
611 else { // count number of interacting bunches
612 for (int i=nbunch;i--;) if ((*bconf)[i]<0) dim++;
616 arrE=GetDCSEntry(recErr,iFirstE,iLastE,fTMin,fTMax);
619 AliLHCDipValF* curValD = new AliLHCDipValF(dim,tstamp);
621 for (int i=0;i<nbunch;i++) {
622 int slot = (*bconf)[i];
623 if (bconf->IsProcessed1() && slot>0) continue;
625 int ind = TMath::Abs(slot)/10;
627 AliError(Form("Bunch %d refers to wrong slot %d, set to -1",cnt,slot));
628 (*curValD)[cnt] = -1;
631 double vcheck = dcsArr[ind];
632 if (TMath::Abs(vcheck) > maxAbsVal) {
633 AliError(Form("ANOMALOUS VALUE %e for slot %d of %s: exceeds %e",vcheck, ind, rec, maxAbsVal));
636 (*curValD)[i] = vcheck;
643 while (iFirstE<=iLastE) { // try to find corresponding error
644 AliDCSArray *dcsValE = (AliDCSArray*) arrE->At(iFirstE);
645 double tstamp1 = dcsValE->GetTimeStamp();
646 int tdif = TimeDifference(tstamp,tstamp1);
647 if (!tdif) { // error matches to value
648 errVal = dcsValE->GetDouble()[0];
649 if (TMath::Abs(errVal) > maxAbsVal) {
650 AliError(Form("ANOMALOUS VALUE %e for slot %d of %s: exceeds %e",errVal,0, rec, maxAbsVal));
656 else if (tdif>0) iFirstE++; // error time lags behind, read the next one
657 else break; // error time is ahead of value, no error associated
659 (*curValD)[dim-1] = errVal; // error
660 curValD->SetLastSpecial(); // lable the last entry as an error
666 if (fkFile2Process) {
674 //___________________________________________________________________
675 Int_t AliLHCData::ExtractInt(AliDCSArray* dcsArray,Int_t el) const
677 // extract integer from the dcsArray
680 int sz = dcsArray->GetNEntries();
681 if (sz<=el) return val;
683 if (dcsArray->GetType()==AliDCSArray::kInt) val = dcsArray->GetInt(el);
684 else if (dcsArray->GetType()==AliDCSArray::kString) {
685 TObjString *stro = dcsArray->GetStringArray(el);
686 if (stro) val = stro->GetString().Atoi();
687 else AliError(Form("DCSArray TObjString for element %d is missing",el));
689 else if (dcsArray->GetType()==AliDCSArray::kUInt) val = dcsArray->GetUInt(el);
690 else AliError(Form("Integer requested from DCSArray of type %d",dcsArray->GetType()));
694 //___________________________________________________________________
695 Double_t AliLHCData::ExtractDouble(AliDCSArray* dcsArray,Int_t el) const
697 // extract double from the dcsArray
700 int sz = dcsArray->GetNEntries();
701 if (sz<=el) return val;
703 if (dcsArray->GetType()==AliDCSArray::kDouble) val = dcsArray->GetDouble(el);
704 else if (dcsArray->GetType()==AliDCSArray::kFloat) val = dcsArray->GetFloat(el);
705 else if (dcsArray->GetType()==AliDCSArray::kString) {
706 TObjString *stro = dcsArray->GetStringArray(el);
707 if (stro) val = stro->GetString().Atof();
708 else AliError(Form("DCSArray has TObjString for element %d is missing",el));
710 else if (dcsArray->GetType()==AliDCSArray::kChar) val = dcsArray->GetChar(el);
711 else if (dcsArray->GetType()==AliDCSArray::kInt) val = dcsArray->GetInt(el);
712 else if (dcsArray->GetType()==AliDCSArray::kUInt) val = dcsArray->GetUInt(el);
713 else AliError(Form("Double requested from DCSArray of type %d",dcsArray->GetType()));
717 //___________________________________________________________________
718 TString& AliLHCData::ExtractString(AliDCSArray* dcsArray) const
720 // extract string from the dcsArray
724 int sz = dcsArray->GetNEntries();
725 if (dcsArray->GetType()!=AliDCSArray::kString) {
726 AliError(Form("String requested from DCSArray of type %d",dcsArray->GetType()));
730 for (int i=0;i<sz;i++) {
731 str += dcsArray->GetStringArray(i)->GetString();
732 if (i<sz-1) str += " ";
737 //___________________________________________________________________
738 void AliLHCData::Print(const Option_t* opt) const
743 Bool_t utcTime = opts.Contains("loc") ? kFALSE:kTRUE;
745 if (!opts.Contains("f")) {
746 printf("Use Print(\"f\") to print full info\n");
747 printf("Printing short info:\n<RecordType>(number of records): <TimeStamp, value> for 1st record only\n");
750 TString sdtmn = AliLHCDipValI::TimeAsString(fTMin,utcTime);
751 TString sdtmx = AliLHCDipValI::TimeAsString(fTMax,utcTime);
752 printf("Fill#%6d Validity: %s - %s (%s)\n",fFillNumber,sdtmn.Data(),sdtmx.Data(),utcTime ? "UTC":"LOC");
754 printf("********** SETTINGS FROM RUN CONTROL **********\n");
756 printf("* %-38s","Injection Scheme");
757 PrintAux(full,fRCInjScheme,opts);
759 printf("* %-38s","Beta Star");
760 PrintAux(full,fRCBeta,opts);
762 printf("* %-38s","Horisontal Crossing Angle");
763 PrintAux(full,fRCAngH,opts);
765 printf("* %-38s","Vertical Crossing Angle");
766 PrintAux(full,fRCAngV,opts);
768 for (int ib=0;ib<2;ib++) {
769 printf("* Beam%d filling [- interacts at IR2!] ",ib+1);
770 PrintAux(full,fBunchConfDecl[ib],opts);
773 printf("\n********** MEASURED DATA **********\n");
775 for (int ib=0;ib<2;ib++) {
776 printf("* Beam%d filling [- interacts at IR2!] ",ib+1);
777 PrintAux(full,fBunchConfMeas[ib],opts);
780 for (int ib=0;ib<2;ib++) {
781 printf("* Beam%d total intensity ",ib+1);
782 PrintAux(full,fIntensTotal[ib],opts);
785 for (int ib=0;ib<2;ib++) {
786 printf("* Beam%d total intensity (bunch average) ",ib+1);
787 PrintAux(full,fIntensTotalAv[ib],opts);
790 for (int ib=0;ib<2;ib++) {
791 printf("* Beam%d intensity per bunch ",ib+1);
792 PrintAux(full,fIntensPerBunch[ib],opts);
795 for (int ib=0;ib<2;ib++) {
796 printf("* Beam%d bunch lengths ",ib+1);
797 PrintAux(full,fBunchLengths[ib],opts);
800 for (int ib=0;ib<2;ib++) {
801 printf("* Beam%d Horisontal emittance ",ib+1);
802 PrintAux(full,fEmittanceH[ib],opts);
805 for (int ib=0;ib<2;ib++) {
806 printf("* Beam%d Vertical emittance ",ib+1);
807 PrintAux(full,fEmittanceV[ib],opts);
810 for (int ib=0;ib<2;ib++) {
811 printf("* Beam%d Horisontal sigma ",ib+1);
812 PrintAux(full,fBeamSigmaH[ib],opts);
815 for (int ib=0;ib<2;ib++) {
816 printf("* Beam%d Vertical sigma ",ib+1);
817 PrintAux(full,fBeamSigmaV[ib],opts);
820 for (int lr=0;lr<2;lr++) {
821 printf("* Total luminosity from BRANB_4%c2 ",lr ? 'R':'L');
822 PrintAux(full,fLuminTotal[lr],opts);
825 for (int lr=0;lr<2;lr++) {
826 printf("* Luminosity acq.mode, BRANB_4%c2 ",lr ? 'R':'L');
827 PrintAux(full,fLuminAcqMode[lr],opts+"bit");
830 for (int lr=0;lr<2;lr++) {
831 printf("* Luminosity per BC from BRANB_4%c2 ",lr ? 'R':'L');
832 PrintAux(full,fLuminPerBC[lr],opts);
835 for (int lr=0;lr<2;lr++) {
836 printf("* Crossing angle, side %c ",lr ? 'R':'L');
837 PrintAux(full,fCrossAngle[lr],opts);
840 for (int coll=0;coll<kNCollimators;coll++)
841 for (int jaw=0;jaw<kNJaws;jaw++) {
842 printf("* Collimator %10s:%16s",fgkDCSColNames[coll],fgkDCSColJaws[jaw]);
843 PrintAux(full,fCollimators[coll][jaw],opts);
846 printf("* Alice fill integrated luminosity data: ");
847 PrintAux(full,fLumiAlice,opts);
849 printf("* Alice fill integrated background data ");
850 PrintAux(full,fBckgAlice,opts);
855 //___________________________________________________________________
856 void AliLHCData::PrintAux(Bool_t full, const Int_t refs[2], const Option_t *opt) const
858 // aux method to print the reocrds of the same type
859 int nrec = refs[kNStor];
864 printf(": (%3d):\t",nrec); // number of records
866 int sz = ((AliLHCDipValI*)fData[refs[kStart]])->GetSizeTotal(); // dimension of the record
867 Bool_t isStr = ((AliLHCDipValI*)fData[refs[kStart]])->IsTypeC();
868 if ((!isStr && sz>2) || nrec>1) printf("\n"); // long record, open new line
869 for (int i=0;i<nrec;i++) fData[refs[kStart]+i]->Print(opt);
873 //___________________________________________________________________
874 void AliLHCData::Clear(const Option_t *)
892 for (int icl=kNCollimators;icl--;) for (int jaw=kNJaws;jaw--;) fCollimators[icl][jaw][i]=0;
895 fBunchConfDecl[j][i] = 0;
896 fBunchConfMeas[j][i] = 0;
897 fBunchLengths[j][i] = 0;
898 fIntensTotal[j][i] = 0;
899 fIntensTotalAv[j][i] = 0;
900 fIntensPerBunch[j][i] = 0;
901 fCrossAngle[j][i] = 0;
902 fEmittanceH[j][i] = 0;
903 fEmittanceV[j][i] = 0;
904 fBeamSigmaH[j][i] = 0;
905 fBeamSigmaV[j][i] = 0;
906 fLuminTotal[j][i] = 0;
907 fLuminPerBC[j][i] = 0;
908 fLuminAcqMode[j][i] = 0;
913 //___________________________________________________________________
914 Int_t AliLHCData::GetNInteractingBunchesMeasured(int i) const
916 // get number of interacting bunches at IR2
917 AliLHCDipValI* rec = GetBunchConfigMeasured(kBeam1,i);
918 if (!rec) {AliInfo(Form("No record %d found",i)); return -1;}
919 if (!rec->IsProcessed1()) { AliInfo("Interacting bunches were not marked"); return -1;}
921 for (int j=rec->GetSize();j--;) if ( (*rec)[j]<0 ) n++;
925 //___________________________________________________________________
926 Int_t AliLHCData::GetNInteractingBunchesDeclared(int i) const
928 // get number of interacting bunches at IR2
929 AliLHCDipValI* rec = GetBunchConfigMeasured(kBeam1,i);
930 if (!rec) {AliInfo(Form("No record %d found",i)); return -1;}
931 if (!rec->IsProcessed1()) { AliInfo("Interacting bunches were not marked"); return -1; }
933 for (int j=rec->GetSize();j--;) if ( (*rec)[j]<0 ) n++;
937 //___________________________________________________________________
938 Int_t AliLHCData::IsPilotPresent(int i) const
940 // check in the filling scheme is the pilot bunch is present
941 AliLHCDipValC* rec = GetInjectionScheme();
942 if (!rec) {AliInfo(Form("No record %d found",i)); return -1;}
943 TString scheme = rec->GetValues();
944 return scheme.Contains("wp",TString::kIgnoreCase);
947 //___________________________________________________________________
948 void AliLHCData::FlagInteractingBunches(const Int_t beam1[2],const Int_t beam2[2])
950 // assign - sign to interacting bunches
952 for (int ib1=0;ib1<beam1[kNStor];ib1++) {
953 AliLHCDipValI *bm1 = (AliLHCDipValI*)fData[ beam1[kStart] + ib1];
955 AliLHCDipValI *bm2 = (AliLHCDipValI*)FindRecValidFor(beam2[kStart],beam2[kNStor], bm1->GetTimeStamp());
958 int nb1 = bm1->GetSize();
959 int nb2 = bm2->GetSize();
961 for (i1=0;i1<nb1;i1++) {
962 int bunch2=-1, bunch1 = TMath::Abs((*bm1)[i1]);
963 int slot2 =-1, slot1 = GetBCId(bunch1,0);
964 for (i2=0;i2<nb2;i2++) {
965 bunch2 = TMath::Abs((*bm2)[i2]);
966 slot2 = GetBCId(bunch2,1);
967 if (slot1==slot2) break;
969 if (slot1!=slot2) continue;
970 (*bm1)[i1] = -bunch1;
971 (*bm2)[i2] = -bunch2;
972 bm1->SetProcessed1();
973 bm2->SetProcessed1();
978 //___________________________________________________________________
979 Int_t AliLHCData::GetMeanIntensity(int beamID, Double_t &colliding, Double_t &noncolliding, const TObjArray* bcmasks) const
981 // get average intensity for all, colliding and non-colliding bunches
982 // on success returns number of intensity records used (1 per ~10 min)
983 // If triggered BC masks are provided, calculation is done for Triggered BC only
984 colliding = noncolliding = -1.;
985 if (beamID<0||beamID>1) {
986 AliError(Form("BeamID must be either 0 or 1, %d requested",beamID));
990 AliTriggerBCMask *bcMaskBoth=0,*bcMaskSingle=0;
992 if (bcmasks && (nbcm=bcmasks->GetEntries())) {
993 if (nbcm>1) bcMaskBoth = (AliTriggerBCMask*)bcmasks->At(1);
994 if (nbcm>0 && beamID==kBeam1) bcMaskSingle = (AliTriggerBCMask*)bcmasks->At(0);
995 else if (nbcm>2 && beamID==kBeam2) bcMaskSingle = (AliTriggerBCMask*)bcmasks->At(2);
997 if (!bcMaskSingle) AliError(Form("Only triggered BSs are requested but %c mask is not provided",beamID ? 'C':'A'));
998 if (!bcMaskBoth) AliError("Only triggered BSs are requested but B mask is not provided");
1001 AliWarning("No BC masks are provided");
1004 int nrec = GetNIntensityPerBunch(beamID);
1005 if (nrec<1) return -1;
1006 AliLHCDipValI *conf = GetBunchConfigMeasured(beamID);
1007 if (!conf) conf = GetBunchConfigDeclared(beamID);
1008 if (!conf) return -2;
1009 int nb = conf->GetSize();
1011 for (int irec=0;irec<nrec;irec++) {
1013 AliLHCDipValD* rIntD = 0;
1014 AliLHCDipValF* rIntF = GetIntensityPerBunch(beamID,irec);
1015 // for BWD compatibility of some periods
1016 if (rIntF->IsA() == AliLHCDipValD::Class()) {rIntD=(AliLHCDipValD*)rIntF; rIntF=0;}
1017 if (!rIntF && !rIntD) {
1018 AliError(Form("Failed to get GetIntensityPerBunch(%d,%d)",beamID,irec));
1021 for (int ib=0;ib<nb;ib++) {
1023 if (rIntF) val = rIntF->GetValue(ib);
1024 else if (rIntD) val = rIntD->GetValue(ib);
1025 if (val<0) continue;
1026 int bID = conf->GetValue(ib);
1027 // check if this is a triggered bunch
1028 int bcID = GetBCId(bID, beamID);
1029 if (bID<0) { // interacting
1030 if (bcMaskBoth && bcMaskBoth->GetMask(bcID)) continue; // masked
1034 if (bcMaskSingle && bcMaskSingle->GetMask(bcID)) continue; // masked
1035 noncolliding += val;
1040 noncolliding /= nrec;
1044 //___________________________________________________________________
1045 void AliLHCData::FillLumiAlice(Int_t nrec, Int_t* timeArr, Double_t* valArr)
1047 // Create a record for lumi integrated from the beginning of fill
1048 // We need dedicated method since this info comes from Alice (not LHCDip) as instantaneous values
1049 // and is retrofitted for past runs
1050 fLumiAlice[kStart] = fData.GetEntriesFast();
1051 fLumiAlice[kNStor] = 0;
1052 if (nrec<2 || !timeArr || !valArr) return;
1053 double tprv,period,currTime;
1054 if ((currTime=double(UInt_t(timeArr[0])))>fTMin) {
1055 AliError(Form("TimeStamp of 1st record: %s > TimeStamp of SOR: %s, STOP",
1056 AliLHCDipValI::TimeAsString(currTime),AliLHCDipValI::TimeAsString(fTMin)));
1060 if ((tprv=double(UInt_t(timeArr[nrec-1])))<fTMax) {
1061 AliWarning(Form("TimeStamp of last (%d) record: %s < TimeStamp of EOR: %s, Data will be truncated",nrec-1,
1062 AliLHCDipValI::TimeAsString(tprv),AliLHCDipValI::TimeAsString(fTMax)));
1065 // init the average time step
1066 period = (tprv - currTime)/(nrec-1);
1069 for (int i=0;i<nrec;i++) {
1071 currTime = double(UInt_t(timeArr[i]));
1072 if (i>0) period = currTime - tprv;
1073 if (currTime-period>fTMax) continue;
1074 lumiInt += valArr[i]*period;
1075 // printf("%d %.2f V:%f Int:%f\n",i,period,valArr[i],lumiInt);
1076 if (currTime+period<fTMin) continue;
1077 AliLHCDipValF* curValF = new AliLHCDipValF(1,currTime);
1078 (*curValF)[0] = lumiInt;
1080 fLumiAlice[kNStor]++;
1083 printf("Stored %d Alice Integrated luminosity records out of %d provided\n",fLumiAlice[kNStor],nrec);
1086 //___________________________________________________________________
1087 void AliLHCData::FillBckgAlice(Int_t nrec, Int_t* timeArr, Double_t* valArr)
1089 // Create a record for lumi integrated from the beginning of fill
1090 // We need dedicated method since this info comes from Alice (not LHCDip) as instantaneous values
1091 // and is retrofitted for past runs
1092 fBckgAlice[kStart] = fData.GetEntriesFast();
1093 fBckgAlice[kNStor] = 0;
1094 if (nrec<2 || !timeArr || !valArr) return;
1095 double tprv,period,currTime;
1096 if ((currTime=double(UInt_t(timeArr[0])))>fTMin) {
1097 AliError(Form("TimeStamp of 1st record: %s > TimeStamp of SOR: %s, STOP",
1098 AliLHCDipValI::TimeAsString(currTime),AliLHCDipValI::TimeAsString(fTMin)));
1102 if ((tprv=double(UInt_t(timeArr[nrec-1])))<fTMax) {
1103 AliWarning(Form("TimeStamp of last (%d) record: %s < TimeStamp of EOR: %s, Data will be truncated",nrec-1,
1104 AliLHCDipValI::TimeAsString(tprv),AliLHCDipValI::TimeAsString(fTMax)));
1107 // init the average time step
1108 period = (tprv - currTime)/(nrec-1);
1111 for (int i=0;i<nrec;i++) {
1113 currTime = double(UInt_t(timeArr[i]));
1114 if (i>0) period = currTime - tprv;
1115 if (currTime-period>fTMax) continue;
1116 bckgInt += valArr[i]*period;
1117 if (currTime+period<fTMin) continue;
1118 AliLHCDipValF* curValF = new AliLHCDipValF(1,currTime);
1119 (*curValF)[0] = bckgInt;
1121 fBckgAlice[kNStor]++;
1124 printf("Stored %d Alice Integrated Background records out of %d provided\n",fBckgAlice[kNStor],nrec);
1127 //_____________________________________________________________________________
1128 Float_t AliLHCData::GetLumiInstAlice(Double_t tStamp) const
1130 // get closest in time value on inst luminosity
1131 int idx = FindEntryValidFor(fLumiAlice[kStart],fLumiAlice[kNStor],tStamp);
1132 if (idx<0) return -1;
1133 AliLHCDipValF *rec=GetLumiAliceRecord(idx),*rec1=GetLumiAliceRecord(idx>0 ? idx-1:idx+1);
1134 if (!rec || !rec1) return -1;
1135 double dt = rec->GetTimeStamp() - rec1->GetTimeStamp();
1136 return TMath::Abs(dt)>1e-6 ? (rec->GetValue()-rec1->GetValue())/dt : -1;
1139 //_____________________________________________________________________________
1140 Float_t AliLHCData::GetBckgInstAlice(Double_t tStamp) const
1142 // get closest in time value on inst luminosity
1143 int idx = FindEntryValidFor(fBckgAlice[kStart],fBckgAlice[kNStor],tStamp);
1144 if (idx<0) return -1;
1145 AliLHCDipValF *rec=GetBckgAliceRecord(idx),*rec1=GetBckgAliceRecord(idx>0 ? idx-1:idx+1);
1146 if (!rec || !rec1) return -1;
1147 double dt = rec->GetTimeStamp() - rec1->GetTimeStamp();
1148 return TMath::Abs(dt)>1e-6 ? (rec->GetValue()-rec1->GetValue())/dt : -1;
1151 //_____________________________________________________________________________
1152 TGraph* AliLHCData::ExportGraph(Int_t *coord, Int_t elID) const
1154 // export time/values to graph:
1155 // coord: int[2] array with 1st entry and number of entries stored, obtained via GetOffs... method
1156 // elID - element of the AliLHCDipValT array to extract
1157 if (!coord || coord[1]<1) return 0;
1158 TGraph* gr = new TGraph(coord[1]);
1159 for (int i=0;i<coord[1];i++) {
1160 TObject* obj = fData.At(coord[0]+i);
1162 AliError(Form("Entry %d does not exist",i));
1165 if (obj->IsA()==AliLHCDipValD::Class()) {
1166 AliLHCDipValD* objD = (AliLHCDipValD*)obj;
1167 gr->SetPoint(i,objD->GetTimeStamp(),objD->GetValue(elID));
1169 else if (obj->IsA()==AliLHCDipValF::Class()) {
1170 AliLHCDipValF* objF = (AliLHCDipValF*)obj;
1171 gr->SetPoint(i,objF->GetTimeStamp(),objF->GetValue(elID));
1173 else if (obj->IsA()==AliLHCDipValI::Class()) {
1174 AliLHCDipValI* objI = (AliLHCDipValI*)obj;
1175 gr->SetPoint(i,objI->GetTimeStamp(),objI->GetValue(elID));
1177 else if (obj->IsA()==AliLHCDipValC::Class()) {
1178 AliLHCDipValC* objC = (AliLHCDipValC*)obj;
1179 gr->SetPoint(i,objC->GetTimeStamp(),objC->GetValue(elID));
1182 AliError(Form("Graph cannot be exported for records of type %s",obj->IsA()->GetName()));