+
+Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
+{
+
+ //
+ // processing of LHC related DCS DPs, i.e.:
+ // LHCState
+ // LHCLuminosity
+ // BeamIntensity
+ //
+
+ Int_t nLHCEntries = 0;
+ TObjArray *array = 0x0;
+ Int_t indexDP = -1;
+
+ AliInfo(Form("==========LHCState==========="));
+ indexDP = kLHCState;
+ array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
+ if(!array) {
+ Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
+ }
+ else {
+ if (array->GetEntries() == 0){
+ AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
+ }
+ else {
+ TString stringDCS = ProcessChar(array);
+ if (stringDCS.Length()!=0) {
+ Bool_t found = kFALSE;
+ for( Int_t i=0; i<20; i+=2 ) {
+ if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
+ stringDCS = fgkLHCState[i+1];
+ found = kTRUE;
+ break;
+ }
+ }
+ if (found){
+ Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
+ grpObj->SetLHCState(stringDCS);
+ }
+ else{
+ Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
+ grpObj->SetLHCState(AliGRPObject::GetInvalidString());
+ }
+ }
+ else {
+ Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
+ grpObj->SetLHCState(AliGRPObject::GetInvalidString());
+ }
+ }
+ ffailedDPs->RemoveAt(indexDP);
+ nLHCEntries++;
+ }
+
+ if (array) array = 0x0;
+
+ AliInfo(Form("==========LHCLuminosity==========="));
+ Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
+ indexDP = kLHCLuminosity;
+ array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
+ if(!array) {
+ Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
+ }
+ else {
+ if (array->GetEntries() == 0){
+ AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
+ }
+ else {
+ Float_t *floatDCS = ProcessFloatAll(array);
+ if (floatDCS != NULL){
+ grpObj->SetLHCLuminosity(floatDCS);
+ AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
+ grpObj->SetLHCLuminositySplineFit(splfit);
+ // delete splfit;
+ }
+ else {
+ outOfRange = kTRUE;
+ }
+ if (floatDCS){
+ delete[] floatDCS;
+ floatDCS = 0x0;
+ }
+ }
+ if (!outOfRange) {
+ ffailedDPs->RemoveAt(indexDP);
+ nLHCEntries++;
+ }
+ }
+
+ if (array) array = 0x0;
+
+ AliInfo(Form("==========BeamIntensity==========="));
+ if (outOfRange) outOfRange = kFALSE; // resetting outOfRange if needed
+ indexDP = kBeamIntensity;
+ array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
+ if(!array) {
+ Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
+ }
+ else {
+ if (array->GetEntries() == 0){
+ AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
+ }
+ else {
+ Float_t *floatDCS = ProcessFloatAll(array);
+ if (floatDCS != NULL){
+ grpObj->SetBeamIntensity(floatDCS);
+ AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
+ grpObj->SetBeamIntensitySplineFit(splfit1);
+ //delete splfit;
+ }
+ else{
+ outOfRange = kTRUE;
+ }
+ if (floatDCS){
+ delete[] floatDCS;
+ floatDCS = 0x0;
+ }
+ }
+ if (!outOfRange) {
+ nLHCEntries++;
+ ffailedDPs->RemoveAt(indexDP);
+ }
+ }
+
+ return nLHCEntries;
+}
+//_________________________________________________________________________
+
+AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
+
+
+ //
+ // returning Spline Fit
+ //
+
+ Int_t entriesarray = array->GetEntries();
+ Float_t* value = new Float_t[entriesarray];
+ Float_t* time = new Float_t[entriesarray];
+ AliDCSValue* v = 0x0;
+ for (Int_t iarray = 0; iarray < entriesarray; iarray++){
+ v = (AliDCSValue*)array->At(iarray);
+ value[iarray] = v->GetFloat();
+ time[iarray] = v->GetTimeStamp();
+ AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
+ }
+ TGraph* gr = new TGraph(entriesarray,value,time);
+ if (!gr ) {
+ AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
+ return NULL;
+ }
+ AliSplineFit *fit = new AliSplineFit();
+ fit->SetMinPoints(10);
+ fit->InitKnots(gr,10,10,0.0);
+ fit->SplineFit(2);
+ fit->Cleanup();
+ if (!fit) {
+ AliWarning(Form("%s: no fit performed",stringID.Data()));
+ return NULL;
+ }
+ return fit;
+}
+
+//_________________________________________________________________________
+
+TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
+{
+
+ //
+ // processing char
+ //
+
+ TString aDCSString="";
+
+ AliDCSValue *v = 0x0;
+ for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
+ v = (AliDCSValue *)array->At(iCount);
+ if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
+ AliError(Form("DCS values for the parameter outside the queried interval"));
+ continue;
+ }
+ if (iCount > 0) {
+ if (aDCSString != v->GetChar())
+ AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
+ }
+ aDCSString = (TString)v->GetChar(); // keeping always last value in the array
+ }
+ return aDCSString;
+}
+
+//__________________________________________________________________________________________________________________
+
+Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
+{
+ //
+ // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
+ //
+ // parameters[0] = mean
+ // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
+ // parameters[2] = median
+ // parameters[3] = standard deviation wrt mean
+ // parameters[4] = standard deviation wrt median
+ //
+
+ TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
+ TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
+ if (timeStartString.IsNull() || timeStartString.IsNull()){
+ if (timeStartString.IsNull()){
+ AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
+ }
+ else if (timeStartString.IsNull()){
+ AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
+ }
+ fdaqStartEndTimeOk = kFALSE;
+ return 0;
+ }
+
+ Int_t timeStart = (Int_t)(timeStartString.Atoi());
+ Int_t timeEnd = (Int_t)(timeEndString.Atoi());
+ Float_t* parameters = new Float_t[5];
+ Int_t iCounts = 0;
+ Int_t iCountsRun = 0;
+ Int_t nCounts = array->GetEntries();
+ Float_t valueBeforeSOR = 0;
+ Float_t valueAfterEOR = 0;
+ Int_t timestampBeforeSOR = -1;
+ Int_t timestampAfterEOR = -1;
+ Int_t ientrySOR = -1;
+ Int_t ientryEOR = -1;
+ Float_t* arrayValues = 0x0;
+ Double_t* arrayWeights = 0x0;
+ Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
+ Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
+
+ for(Int_t i = 0; i < nCounts; i++) {
+ AliDCSValue *v = (AliDCSValue *)array->At(i);
+ if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
+ AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
+ if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
+ if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
+ return NULL;
+ }
+ if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
+ AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
+ iCounts += 1;
+ // look for the last value before SOR and the first value before EOR
+ if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
+ timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
+ AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
+ valueBeforeSOR = v->GetFloat();
+ }
+ else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
+ timestampAfterEOR = (Int_t)(v->GetTimeStamp());
+ valueAfterEOR = v->GetFloat();
+ AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
+ }
+ // check if there are DPs between DAQ_time_start and DAQ_time_end
+ if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
+ if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
+ if (ientryEOR < i) ientryEOR = i; // last entry before EOR
+ AliDebug(2,Form("entry between SOR and EOR"));
+ iCountsRun += 1;
+ }
+ }
+ else {
+ AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
+ }
+ }
+
+ if (timestampBeforeSOR == -1){
+ AliWarning("No value found before SOR");
+ }
+ if (timestampAfterEOR == -1){
+ AliWarning("No value found after EOR");
+ }
+
+ AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
+ AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
+ AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
+ AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
+ AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
+ AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
+
+ Int_t nentriesUsed = 0;
+ if (iCountsRun > 1){
+ AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
+ AliDebug(2,"Calculating (weighted) Mean and Median");
+ arrayValues = new Float_t[iCountsRun];
+ arrayWeights = new Double_t[iCountsRun];
+ nentriesUsed = iCountsRun;
+ for (Int_t i = ientrySOR; i <= ientryEOR; i++){
+ AliDCSValue *v = (AliDCSValue *)array->At(i);
+ Int_t timestamp2 = 0;
+ if (i < ientryEOR){
+ AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
+ timestamp2 = (Int_t)v1->GetTimeStamp();
+ }
+ else {
+ timestamp2 = timeEnd+1;
+ }
+ arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
+ arrayValues[i-ientrySOR] = v->GetFloat();
+ }
+ parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
+ parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
+ }
+ else if (iCountsRun == 1){
+ AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
+ nentriesUsed = 2;
+ if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
+ AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR. Truncated mean won't be calculated.");
+ arrayValues = new Float_t[2];
+ arrayWeights = new Double_t[2];
+ arrayValues[0] = valueBeforeSOR;
+ arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
+ arrayValues[1] = v->GetFloat();
+ arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
+ AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
+ AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
+ parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
+ parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
+ truncMeanFlag = kFALSE;
+ }
+ else{
+ AliError("Cannot calculate mean, truncated mean, median, SD wrt mean, SD wrt median for current DP - only one value collected during the run, but no value before with which to calculate the statistical quantities");
+ parameters[0] = AliGRPObject::GetInvalidFloat();
+ parameters[1] = AliGRPObject::GetInvalidFloat();
+ parameters[2] = AliGRPObject::GetInvalidFloat();
+ parameters[3] = AliGRPObject::GetInvalidFloat();
+ parameters[4] = AliGRPObject::GetInvalidFloat();
+ return parameters;
+ }
+ }
+ else { // iCountsRun == 0, using only the point immediately before SOR
+ if (timestampBeforeSOR == -1){
+ AliError("Cannot set mean, truncated mean, median, SD wrt mean, SD wrt median for current DP - no points during the run collected, and point before SOR missing");
+ parameters[0] = AliGRPObject::GetInvalidFloat();
+ parameters[1] = AliGRPObject::GetInvalidFloat();
+ parameters[2] = AliGRPObject::GetInvalidFloat();
+ parameters[3] = AliGRPObject::GetInvalidFloat();
+ parameters[4] = AliGRPObject::GetInvalidFloat();
+ return parameters;
+ }
+ else {
+ AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
+ AliDebug(2,Form("value = %f",valueBeforeSOR));
+ parameters[0] = valueBeforeSOR;
+ parameters[2] = valueBeforeSOR;
+ truncMeanFlag = kFALSE;
+ sdFlag = kFALSE;
+ }
+ }
+
+ Float_t temp = 0;
+ Float_t temp1 = 0;
+ Float_t sumweights = 0;
+ Int_t entriesTruncMean = 0;
+ Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
+ Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
+
+ // calculating SD wrt Mean and Median
+ AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
+ if (sdFlag){
+ for (Int_t i =0; i< nentriesUsed; i++){
+ AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
+ temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
+ temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
+ sumweights += arrayWeights[i];
+ }
+ // setting SD wrt Mean
+ if (sumweights != 0 ){
+ parameters[3] = TMath::Sqrt(temp1/sumweights);
+ }
+ else {
+ AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
+ parameters[3] = AliGRPObject::GetInvalidFloat();
+ }
+ // setting SD wrt Median
+ if (nentriesUsed != 0){
+ parameters[4] = TMath::Sqrt(temp/nentriesUsed);
+ }
+ else{
+ AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
+ parameters[4] = AliGRPObject::GetInvalidFloat();
+ }
+ }
+ else {
+ parameters[3] = AliGRPObject::GetInvalidFloat();
+ parameters[4] = AliGRPObject::GetInvalidFloat();
+ }
+
+ // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
+ if (truncMeanFlag){
+ AliDebug(2,"Calculating Truncated Mean");
+ for (Int_t i =0; i< nentriesUsed; i++){
+ AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
+ if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
+ arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
+ arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
+ AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
+ entriesTruncMean++;
+ }
+ else{
+ AliDebug(2,"Discarding entry");
+ }
+ }
+ // setting truncated mean
+ if (entriesTruncMean >1){
+ AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
+ parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
+ }
+ else{
+ AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
+ parameters[1] = AliGRPObject::GetInvalidFloat();
+ }
+ }
+ else{
+ parameters[1] = AliGRPObject::GetInvalidFloat();
+ }
+
+ AliInfo(Form("(weighted) mean = %f ",parameters[0]));
+ AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
+ AliInfo(Form("median = %f ",parameters[2]));
+ AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
+ AliInfo(Form("standard deviation with median = %f ",parameters[4]));
+
+ return parameters;
+}
+
+//__________________________________________________________________________________________________________________
+
+Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
+{
+ //
+ // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
+ // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
+ // the flag is set according to the L3/Dipole current value
+ // current threshold for L3 = 350 A (value provided by DCS)
+ // current threshold for Dipole = 450 A (value provided by DCS)
+ //
+ // parameters[0] = mean
+ // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
+ // parameters[2] = median
+ // parameters[3] = standard deviation wrt mean
+ // parameters[4] = standard deviation wrt median
+ //
+
+ AliInfo(Form("indexDP = %d",indexDP));
+
+ Int_t nCounts = array->GetEntries();
+ for(Int_t i = 0; i < nCounts; i++) {
+ AliDCSValue *v = (AliDCSValue *)array->At(i);
+ if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
+ AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
+ if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
+ if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
+ return NULL;
+ }
+ if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
+ AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
+ if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
+ if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
+ }
+ else {
+ AliError(Form("DCS values for the parameter outside the queried interval"));
+ }
+ }
+
+ return ProcessFloatAll(array);
+}
+
+
+//_______________________________________________________________
+
+Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
+{
+ //
+ // processing Boolean values
+ //
+
+ Bool_t aDCSBool = kTRUE;
+
+ AliDCSValue *v = 0x0;
+
+ for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
+ v = (AliDCSValue *)array->At(iCount);
+ if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
+ AliError(Form("DCS values for the parameter outside the queried interval"));
+ continue;
+ }
+ if (iCount > 0) {
+ if (aDCSBool != v->GetBool()) {
+ AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
+ change = kTRUE;
+ }
+ }
+ aDCSBool = v->GetBool(); // always keeping last value
+ AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
+ }
+
+ Char_t caDCSBool = (Char_t) aDCSBool;
+ return caDCSBool;
+
+}
+
+//_______________________________________________________________
+
+Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
+{
+ //
+ // processing Int values, returning mean
+ // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
+ // are outside the queried time interval or their value is out of range
+ //
+
+ TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
+ TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
+ if (timeStartString.IsNull() || timeStartString.IsNull()){
+ if (timeStartString.IsNull()){
+ AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
+ }
+ else if (timeStartString.IsNull()){
+ AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
+ }
+ return 0;
+ }
+
+ Int_t timeStart = (Int_t)(timeStartString.Atoi());
+ Int_t timeEnd = (Int_t)(timeEndString.Atoi());
+ Float_t aDCSArrayMean = 0.0;
+ Int_t iCounts = 0;
+ Float_t valueBeforeSOR = 0;
+ Float_t valueAfterEOR = 0;
+ Int_t timestampBeforeSOR = -1;
+ Int_t timestampAfterEOR = -1;
+ Int_t ientrySOR = -1;
+ Int_t ientryEOR = -1;
+ Float_t* arrayValues = 0x0;
+ Double_t* arrayWeights = 0x0;
+ Int_t iCountsRun = 0;
+ Int_t nCounts = array->GetEntries();
+
+ for(Int_t i = 0; i < nCounts; i++) {
+ AliDCSValue* v = (AliDCSValue *)array->At(i);
+ if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
+ AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
+ return AliGRPObject::GetInvalidFloat();
+ }
+ if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
+ AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
+ iCounts += 1;
+ // look for the last value before SOR and the first value before EOR
+ if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
+ timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
+ AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
+ valueBeforeSOR = (Float_t) v->GetInt();
+ }
+ else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
+ timestampAfterEOR = (Int_t)(v->GetTimeStamp());
+ valueAfterEOR = (Float_t) v->GetInt();
+ AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
+ }
+ // check if there are DPs between DAQ_time_start and DAQ_time_end
+ if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
+ if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
+ if (ientryEOR < i) ientryEOR = i; // last entry before EOR
+ AliDebug(2,Form("entry between SOR and EOR"));
+ iCountsRun += 1;
+ }
+ }
+ else {
+ AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
+ }
+ }
+
+ if (timestampBeforeSOR == -1){
+ AliWarning("No value found before SOR!");
+ }
+ if (timestampAfterEOR == -1){
+ AliWarning("No value found after EOR!");
+ }
+
+ AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
+ AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
+ AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
+ AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
+ AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
+ AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
+
+ Int_t nentriesUsed = 0;
+ if (iCountsRun > 1){
+ AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
+ AliDebug(2,"Calculating (weighted) Mean");
+ arrayValues = new Float_t[iCountsRun];
+ arrayWeights = new Double_t[iCountsRun];
+ nentriesUsed = iCountsRun;
+ for (Int_t i = ientrySOR; i <= ientryEOR; i++){
+ AliDCSValue *v = (AliDCSValue *)array->At(i);
+ Int_t timestamp2 = 0;
+ if (i < ientryEOR){
+ AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
+ timestamp2 = (Int_t)v1->GetTimeStamp();
+ }
+ else {
+ timestamp2 = timeEnd+1;
+ }
+ arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
+ arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
+ }
+ aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
+ }
+ else if (iCountsRun == 1){
+ AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
+ nentriesUsed = 2;
+ if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
+ AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
+ arrayValues = new Float_t[2];
+ arrayWeights = new Double_t[2];
+ arrayValues[0] = valueBeforeSOR;
+ arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
+ arrayValues[1] = (Float_t)v->GetInt();
+ arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
+ AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
+ AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
+ aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
+ }
+ else{
+ AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
+ return AliGRPObject::GetInvalidFloat();
+ }
+ }
+ else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
+ if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
+ if (timestampBeforeSOR == -1){
+ AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
+ }
+ if (timestampAfterEOR == -1){
+ AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
+ }
+ return AliGRPObject::GetInvalidFloat();
+ }
+ else {
+ AliWarning("Using last entry before SOR and first entry after EOR.");
+ nentriesUsed = 2;
+ arrayValues = new Float_t[2];
+ arrayWeights = new Double_t[2];
+ arrayValues[0] = valueBeforeSOR;
+ arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
+ arrayValues[1] = valueAfterEOR;
+ arrayWeights[1] = 1.;
+ AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
+ AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
+ aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
+ }
+ }
+
+ AliInfo(Form("mean = %f ", aDCSArrayMean));
+ return aDCSArrayMean;
+
+}
+//_______________________________________________________________
+
+Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
+{
+ //
+ // processing Int values, returning mean
+ // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
+ // are outside the queried time interval or their value is out of range
+ //
+
+ TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
+ TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
+ if (timeStartString.IsNull() || timeStartString.IsNull()){
+ if (timeStartString.IsNull()){
+ AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
+ }
+ else if (timeStartString.IsNull()){
+ AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
+ }
+ return 0;
+ }
+
+ Int_t timeStart = (Int_t)(timeStartString.Atoi());
+ Int_t timeEnd = (Int_t)(timeEndString.Atoi());
+ Float_t aDCSArrayMean = 0.0;
+ Int_t iCounts = 0;
+ Float_t valueBeforeSOR = 0;
+ Float_t valueAfterEOR = 0;
+ Int_t timestampBeforeSOR = -1;
+ Int_t timestampAfterEOR = -1;
+ Int_t ientrySOR = -1;
+ Int_t ientryEOR = -1;
+ Float_t* arrayValues = 0x0;
+ Double_t* arrayWeights = 0x0;
+ Int_t iCountsRun = 0;
+ Int_t nCounts = array->GetEntries();
+
+ for(Int_t i = 0; i < nCounts; i++) {
+ AliDCSValue* v = (AliDCSValue *)array->At(i);
+ if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
+ AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
+ return AliGRPObject::GetInvalidFloat();
+ }
+ if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
+ AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
+ iCounts += 1;
+ // look for the last value before SOR and the first value before EOR
+ if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
+ timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
+ AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
+ valueBeforeSOR = (Float_t)v->GetUInt();
+ }
+ else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
+ timestampAfterEOR = (Int_t)(v->GetTimeStamp());
+ valueAfterEOR = (Float_t)v->GetUInt();
+ AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
+ }
+ // check if there are DPs between DAQ_time_start and DAQ_time_end
+ if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
+ if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
+ if (ientryEOR < i) ientryEOR = i; // last entry before EOR
+ AliDebug(2,Form("entry between SOR and EOR"));
+ iCountsRun += 1;
+ }
+ }
+ else {
+ AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
+ }
+ }
+
+ if (timestampBeforeSOR == -1){
+ AliWarning("No value found before SOR!");
+ }
+ if (timestampAfterEOR == -1){
+ AliWarning("No value found after EOR!");
+ }
+
+ AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
+ AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
+ AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
+ AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
+ AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
+ AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
+
+ Int_t nentriesUsed = 0;
+ if (iCountsRun > 1){
+ AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
+ AliDebug(2,"Calculating (weighted) Mean");
+ arrayValues = new Float_t[iCountsRun];
+ arrayWeights = new Double_t[iCountsRun];
+ nentriesUsed = iCountsRun;
+ for (Int_t i = ientrySOR; i <= ientryEOR; i++){
+ AliDCSValue *v = (AliDCSValue *)array->At(i);
+ Int_t timestamp2 = 0;
+ if (i < ientryEOR){
+ AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
+ timestamp2 = (Int_t)v1->GetTimeStamp();
+ }
+ else {
+ timestamp2 = timeEnd+1;
+ }
+ arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
+ arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
+ }
+ aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
+ }
+ else if (iCountsRun == 1){
+ AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
+ nentriesUsed = 2;
+ if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
+ AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
+ arrayValues = new Float_t[2];
+ arrayWeights = new Double_t[2];
+ arrayValues[0] = valueBeforeSOR;
+ arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
+ arrayValues[1] = (Float_t)v->GetUInt();
+ arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
+ AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
+ AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
+ aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
+ }
+ else{
+ AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
+ return AliGRPObject::GetInvalidFloat();
+ }
+ }
+ else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
+ if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
+ if (timestampBeforeSOR == -1){
+ AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
+ }
+ if (timestampAfterEOR == -1){
+ AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
+ }
+ return AliGRPObject::GetInvalidFloat();
+ }
+ else {
+ AliWarning("Using last entry before SOR and first entry after EOR.");
+ nentriesUsed = 2;
+ arrayValues = new Float_t[2];
+ arrayWeights = new Double_t[2];
+ arrayValues[0] = valueBeforeSOR;
+ arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
+ arrayValues[1] = valueAfterEOR;
+ arrayWeights[1] = 1.;
+ AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
+ AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
+ aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
+ }
+ }
+
+ AliInfo(Form("mean = %f ",aDCSArrayMean));
+ return aDCSArrayMean;
+
+}
+
+
+//_______________________________________________________________
+
+AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
+{
+ // extract DCS pressure maps. Perform fits to save space
+
+ TMap *map = fPressure->ExtractDCS(dcsAliasMap);
+ if (map) {
+ AliDebug(2,Form("Map has %d entries",map->GetEntries()));
+ fPressure->MakeSplineFit(map);
+ Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
+ if (fitFraction > kFitFraction ) {
+ AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
+ } else {
+ AliInfo("Too few pressure maps fitted!!!");
+ }
+ } else {
+ AliInfo("no atmospheric pressure map extracted!!!");
+ }
+ delete map;
+
+ return fPressure;
+}
+
+