]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliGRPPreprocessor.cxx
When calculating a*a-b*b the form (a-b)*(a+b) is usually more numerically stable.
[u/mrichter/AliRoot.git] / STEER / AliGRPPreprocessor.cxx
index 14b338141049f8f511bf3b45ba419cc3d4dec075..dcc15131a426986324f86b7186a8c84e5b7338f7 100644 (file)
 #include <TList.h>
 #include <TMap.h>
 #include <TObjString.h>
-#include <TTimeStamp.h>
-#include <TSystem.h>
-#include <TFile.h>
-#include <TParameter.h>
 #include <TGraph.h>
 
 #include "AliGRPPreprocessor.h"
-#include "AliGRPDCS.h"
 #include "AliGRPObject.h"
 #include "AliDCSSensor.h"
 #include "AliSplineFit.h"
@@ -48,9 +43,8 @@
 class AliDCSValue;
 class AliShuttleInterface;
 
-#include <TH1.h>
-
 // needed for ReceivePromptRecoParameters
+
 #include <TSQLServer.h>
 #include <TSQLResult.h>
 #include <TSQLRow.h>
@@ -67,7 +61,7 @@ ClassImp(AliGRPPreprocessor)
 
   const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook
   const Int_t AliGRPPreprocessor::fgknDCSDP = 50;   // number of dcs dps
-  const Int_t AliGRPPreprocessor::fgknDCSDP_HallProbes = 40;   // number of dcs dps
+  const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40;   // number of dcs dps
   const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
                    "LHCState",              // missing in DCS
                    "L3Polarity",
@@ -121,7 +115,7 @@ ClassImp(AliGRPPreprocessor)
                    "SurfaceAtmosPressure"
                  };
 
-  const char* AliGRPPreprocessor::fgkDCSDataPoints_HallProbes[AliGRPPreprocessor::fgknDCSDP_HallProbes] = {
+  const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
                   "L3_BSF17_H1",
                   "L3_BSF17_H2",
                   "L3_BSF17_H3",
@@ -196,6 +190,8 @@ AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
 {
        // constructor - shuttle must be instantiated!
 
+       AddRunType("COSMIC");
+       AddRunType("LASER");
        AddRunType("PHYSICS");
 }
 
@@ -268,8 +264,10 @@ UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
        //=================//
        // DCS data points //
        //=================//
+       Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
        Int_t entries = ProcessDcsDPs( valueMap, grpobj );
-       if( entries < fgknDCSDP-3 ) { // FIXME (!= ) LHState and pressure map are not working yet...
+       Log(Form("entries found = %d",entries));
+       if( entries < fgknDCSDP-7 ) { // FIXME (!= ) LHState and pressure map are not working yet... and removing the 4 values for the missing HP 
                Log(Form("Problem with the DCS data points!!!"));
                error |= 8;
        } else  Log(Form("DCS data points, successful!"));
@@ -493,12 +491,12 @@ UInt_t AliGRPPreprocessor::ProcessDaqFxs()
        
        TString fRawDataFileName = "GRP_Merged.tag.root";
        Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
-       /* temporary, to speed up
+       
        if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
                Log("Error merging raw data files!!!");
                return 3;
        }
-       */
+       
        TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
        Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
        
@@ -523,6 +521,11 @@ UInt_t AliGRPPreprocessor::ProcessDaqFxs()
 //_______________________________________________________________
 UInt_t AliGRPPreprocessor::ProcessDcsFxs()
 {
+
+       // processing the info
+       // stored in the DCS FXS
+       // coming from the trigger
+
        {
                // Get the CTP counters information
                TList* list = GetFileSources(kDCS,"CTP_xcounters");  
@@ -576,7 +579,7 @@ Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
        // processing DCS DPs
        //
 
-       Int_t entries = 0;
+       Int_t entries = 0;  // counting the entries that are in the DCS DB, not taking care whether they have values or not
        Int_t nLHCEntries = 0;
        Int_t nL3Entries = 0;
        Int_t nDipoleEntries = 0;
@@ -595,8 +598,13 @@ Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
 
 //_______________________________________________________________
 
-Int_t AliGRPPreprocessor::ProcessL3DPs(TMap* valueMap, AliGRPObject* grpObj)
+Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
 {
+
+       // processing DPs
+       // related to 
+       // L3 info
+
        Int_t nL3Entries = 0;
        TObjArray *array = 0x0;
        Int_t indexDP = -1;
@@ -608,8 +616,14 @@ Int_t AliGRPPreprocessor::ProcessL3DPs(TMap* valueMap, AliGRPObject* grpObj)
                Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
        } 
        else {
-               Char_t charDCS = ProcessBool(array);
-               grpObj->SetL3Polarity(charDCS);
+               if (array->GetEntries() == 0){
+                       AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
+               }
+               else {
+                       Char_t charDCS = ProcessBool(array);
+                       grpObj->SetL3Polarity(charDCS);
+                       AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
+               }
                nL3Entries++;
        }
 
@@ -622,9 +636,14 @@ Int_t AliGRPPreprocessor::ProcessL3DPs(TMap* valueMap, AliGRPObject* grpObj)
                Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
        } 
        else {
-               Float_t *floatDCS = ProcessFloatAll(array);
-               grpObj->SetL3Current(floatDCS);
-               delete floatDCS;
+               if (array->GetEntries() == 0){
+                       AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
+               }
+               else {
+                       Float_t *floatDCS = ProcessFloatAll(array);
+                       grpObj->SetL3Current(floatDCS);
+                       delete floatDCS;
+               }
                nL3Entries++;
        }
 
@@ -633,23 +652,31 @@ Int_t AliGRPPreprocessor::ProcessL3DPs(TMap* valueMap, AliGRPObject* grpObj)
 }
 //_______________________________________________________________
 
-Int_t AliGRPPreprocessor::ProcessDipoleDPs(TMap* valueMap, AliGRPObject* grpObj)
+Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
 {
+       // processing DPs
+       // related to 
+       // the Dipole info
+
        Int_t nDipoleEntries = 0;
        TObjArray *array = 0x0;
        Int_t indexDP = -1;
 
        AliInfo(Form("==========DipolePolarity==========="));
        indexDP = kDipolePolarity;
-       AliInfo(Form("indexDP = %d",indexDP));
        array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
-       AliInfo(Form("array entries = %d",array->GetEntries()));
        if(!array) {
                Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
        } 
        else {
-               Bool_t charDCS = ProcessBool(array);
-               grpObj->SetDipolePolarity(charDCS);
+               if (array->GetEntries() == 0){
+                       AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
+               }
+               else {
+                       Char_t charDCS = ProcessBool(array);
+                       grpObj->SetDipolePolarity(charDCS);
+                       AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
+               }
                nDipoleEntries++;
        }
 
@@ -662,9 +689,14 @@ Int_t AliGRPPreprocessor::ProcessDipoleDPs(TMap* valueMap, AliGRPObject* grpObj)
                Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
        } 
        else {
-               Float_t *floatDCS = ProcessFloatAll(array);
-               grpObj->SetDipoleCurrent(floatDCS);
-               delete floatDCS;
+               if (array->GetEntries() == 0){
+                       AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
+               }
+               else {
+                       Float_t *floatDCS = ProcessFloatAll(array);
+                       grpObj->SetDipoleCurrent(floatDCS);
+                       delete floatDCS;
+               }
                nDipoleEntries++;
        }
 
@@ -675,6 +707,10 @@ Int_t AliGRPPreprocessor::ProcessDipoleDPs(TMap* valueMap, AliGRPObject* grpObj)
 
 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
 {
+       // processing DPs
+       // related to 
+       // evironment conditions (temperature, pressure) info
+
        Int_t nEnvEntries = 0;
        TObjArray *array = 0x0;
        Int_t indexDP = -1;
@@ -686,8 +722,14 @@ Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
                Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
        } 
        else {
-               Float_t *floatDCS = ProcessFloatAll(array);
-               grpObj->SetCavernTemperature(floatDCS);
+               if (array->GetEntries() == 0){
+                       AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
+               }
+               else {
+                       Float_t *floatDCS = ProcessFloatAll(array);
+                       grpObj->SetCavernTemperature(floatDCS);
+                       delete floatDCS;
+               }
                nEnvEntries++;
        }
 
@@ -696,8 +738,6 @@ Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
        AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
        AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
        dcsSensorArray->Print();
-       AliInfo(Form("fPressure = %p",fPressure));
-       AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
        if( fPressure->NumFits()==0 ) {
                Log("Problem with the pressure sensor values!!!");
        } 
@@ -775,14 +815,18 @@ Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
 }
 //_______________________________________________________________
 
-Int_t AliGRPPreprocessor::ProcessHPDPs(TMap* valueMap, AliGRPObject* grpObj)
+Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
 {
+       // processing DPs
+       // related to 
+       // Hall Probes info
+
        Int_t nHPEntries = 0;
        TObjArray *array = 0x0;
        Int_t indexDP = -1;
 
-       if (fgknDCSDP_HallProbes != AliGRPObject::GetNumberOfHP()){
-               AliError(Form("Number of Hall probes expected in GRP Preprocessor (i.e. %d) different from number of Hall Probes foreseen in GRP object (i.e. %d). Looping on entries from GRP object anyway.", fgknDCSDP_HallProbes, AliGRPObject::GetNumberOfHP()));
+       if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
+               AliError(Form("Number of Hall probes expected in GRP Preprocessor (i.e. %d) different from number of Hall Probes foreseen in GRP object (i.e. %d). Looping on entries from GRP object anyway.", fgknDCSDPHallProbes, AliGRPObject::GetNumberOfHP()));
        }
        for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
                AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
@@ -791,23 +835,29 @@ Int_t AliGRPPreprocessor::ProcessHPDPs(TMap* valueMap, AliGRPObject* grpObj)
                        Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
                } 
                else {
-                       Float_t *floatDCS = ProcessFloatAll(array);
-                       AliDebug(2,Form("value[0] = %f, value[1] = %f, value[2] = %f, value[3] = %f, value[4] = %f",floatDCS[0],floatDCS[1],floatDCS[2],floatDCS[3],floatDCS[4])); 
-                       grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
-                       for (Int_t kk = 0 ; kk< 5; kk++){
-                               AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
+                       if (array->GetEntries() == 0){
+                               AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
+                       }
+                       else {
+                               Float_t *floatDCS = ProcessFloatAll(array);
+                               AliDebug(2,Form("value[0] = %f, value[1] = %f, value[2] = %f, value[3] = %f, value[4] = %f",floatDCS[0],floatDCS[1],floatDCS[2],floatDCS[3],floatDCS[4])); 
+                               grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
+                               for (Int_t kk = 0 ; kk< 5; kk++){
+                                       AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
+                               }
+                               delete floatDCS;
                        }
-                       delete floatDCS;
                        nHPEntries++;
                }
        }
                
-       return 0;
+       Log(Form("Hall Probes = %d ", nHPEntries));
+       return nHPEntries;
 }
 
 //_______________________________________________________________
 
-Int_t AliGRPPreprocessor::ProcessLHCDPs(TMap* valueMap, AliGRPObject* grpObj)
+Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
 {
 
        //
@@ -828,29 +878,34 @@ Int_t AliGRPPreprocessor::ProcessLHCDPs(TMap* valueMap, AliGRPObject* grpObj)
                Log(Form("%s not found in the map!!!",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 (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());
+                               } 
                        }
-                       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]));
+                       else {
+                               Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
                                grpObj->SetLHCState(AliGRPObject::GetInvalidString());
-                       } 
+                       }         
                }
-               else {
-                       Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
-                       grpObj->SetLHCState(AliGRPObject::GetInvalidString());
-               }         
                nLHCEntries++;
        }
        
@@ -863,13 +918,17 @@ Int_t AliGRPPreprocessor::ProcessLHCDPs(TMap* valueMap, AliGRPObject* grpObj)
                Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
        } 
        else {
-               Float_t *floatDCS = ProcessFloatAll(array);
-               grpObj->SetLHCLuminosity(floatDCS);
-               delete floatDCS;
-               nLHCEntries++;
-               AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
-               grpObj->SetLHCLuminositySplineFit(splfit);
-               //              delete splfit;
+               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);
+                       grpObj->SetLHCLuminosity(floatDCS);
+                       delete floatDCS;
+                       AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
+                       grpObj->SetLHCLuminositySplineFit(splfit);
+                       //              delete splfit;
+               }
                nLHCEntries++;
        }
 
@@ -882,13 +941,17 @@ Int_t AliGRPPreprocessor::ProcessLHCDPs(TMap* valueMap, AliGRPObject* grpObj)
                Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
        } 
        else {
-               Float_t *floatDCS = ProcessFloatAll(array);
-               grpObj->SetBeamIntensity(floatDCS);
-               delete floatDCS;
-               nLHCEntries++;
-               AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
-               grpObj->SetBeamIntensitySplineFit(splfit1);
-               //delete splfit;
+               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);
+                       grpObj->SetBeamIntensity(floatDCS);
+                       delete floatDCS;
+                       AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
+                       grpObj->SetBeamIntensitySplineFit(splfit1);
+                       //delete splfit;
+               }
                nLHCEntries++;
        }
 
@@ -896,7 +959,12 @@ Int_t AliGRPPreprocessor::ProcessLHCDPs(TMap* valueMap, AliGRPObject* grpObj)
 }
 //_________________________________________________________________________
 
-AliSplineFit* AliGRPPreprocessor::GetSplineFit(TObjArray *array, const TString& stringID){
+AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
+
+
+       // 
+       // returning Spline Fit 
+       // 
 
        Int_t entriesarray = array->GetEntries();
        Float_t* value = new Float_t[entriesarray];
@@ -927,7 +995,7 @@ AliSplineFit* AliGRPPreprocessor::GetSplineFit(TObjArray *array, const TString&
 
 //_________________________________________________________________________
 
-TString AliGRPPreprocessor::ProcessChar(TObjArray *array)
+TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
 {
 
        // 
@@ -939,12 +1007,12 @@ TString AliGRPPreprocessor::ProcessChar(TObjArray *array)
        AliDCSValue *v = 0x0;
        for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
                v = (AliDCSValue *)array->At(iCount);
-               if ((v->GetTimeStamp() < fStartTime) || (v->GetTimeStamp() > fEndTime)) {
+               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());
+                       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
@@ -954,7 +1022,7 @@ TString AliGRPPreprocessor::ProcessChar(TObjArray *array)
 
 //__________________________________________________________________________________________________________________
 
-Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
+Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
 {
        // 
        // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median 
@@ -966,7 +1034,7 @@ Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
        // parameters[4] = standard deviation wrt median
        //
 
-       Float_t* parameters = new Float_t[4];
+       Float_t* parameters = new Float_t[5];
        Double_t aDCSArrayMean = 0;     // Mean
        Double_t aDCSArrayTruncMean = 0;// Truncated Mean
        Double_t aDCSArrayMedian = 0;   // Median
@@ -981,7 +1049,7 @@ Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
        Float_t *tempArray = new Float_t[nCounts];
        for(Int_t i = 0; i < nCounts; i++) {
                AliDCSValue *v = (AliDCSValue *)array->At(i);
-               if((v->GetTimeStamp() >= fStartTime) &&(v->GetTimeStamp() <= fEndTime)) {
+               if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
                        aDCSArraySum += v->GetFloat();
                        tempArray[i] = v->GetFloat();
                        AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
@@ -989,29 +1057,37 @@ Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
                }
        }
 
+       AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
        if(iCounts != 0) {
-               aDCSArrayMean = TMath::Mean(nCounts,tempArray);
-               aDCSArrayMedian = TMath::Median(nCounts,tempArray);
-               aDCSArraySDMean = TMath::RMS(nCounts,tempArray);
+               aDCSArrayMean = TMath::Mean(iCounts,tempArray);
+               aDCSArrayMedian = TMath::Median(iCounts,tempArray);
+               aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
+               AliDebug(2,Form("SD = %f",aDCSArraySDMean));
                // computing standard deviation wrt median
                AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
                for (Int_t i = 0; i < iCounts; i++){
                        AliDCSValue *v = (AliDCSValue *)array->At(i);
                        AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
                        AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat())); 
-                       if ((v->GetFloat()<aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>aDCSArrayMean-3*aDCSArraySDMean)){
+                       if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
                                temp1+=v->GetFloat();
                                iCounts1++;
-                               AliDebug(2,Form("temp1 = %f, iCounts = %i",temp1,iCounts1));
+                               AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
                        }
                        temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
                }
+               AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
                temp/=iCounts;
+               AliDebug(3,Form("temp after the ratio = %f", temp));
                if (temp>0) {
                        aDCSArraySDMedian = TMath::Sqrt(temp);
                }
+               else if (temp==0) {
+                       AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
+                       aDCSArraySDMedian = 0;
+               }
                else{
-                       AliError(Form("Radical <= 0 in computing standard deviation! Setting it to -99999...."));
+                       AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
                        aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
                }
        }
@@ -1020,6 +1096,7 @@ Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
                aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
                aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
        }
+       AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
        if (iCounts1 > 0) {
                aDCSArrayTruncMean = temp1/iCounts1;
        }
@@ -1029,11 +1106,11 @@ Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
        
        
        
-       AliDebug(2,Form("mean within %d counts = %f ",nCounts,aDCSArrayMean));
-       AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",nCounts,aDCSArrayTruncMean,iCounts1));
-       AliDebug(2,Form("median within %d counts = %f ",nCounts,aDCSArrayMedian));
-       AliDebug(2,Form("standard deviation with mean within %d counts = %f ",nCounts,aDCSArraySDMean));
-       AliDebug(2,Form("standard deviation with median within %d counts = %f ",nCounts,aDCSArraySDMedian));
+       AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
+       AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
+       AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
+       AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
+       AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
        
        parameters[0] = aDCSArrayMean;
        parameters[1] = aDCSArrayTruncMean;
@@ -1041,7 +1118,8 @@ Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
        parameters[3] = aDCSArraySDMean;
        parameters[4] = aDCSArraySDMedian;
 
-       AliDebug(2,Form("parameters[0] = %f, parameters[1] = %f, parameters[2] = %f, parameters[3] = %f, parameters[4] = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4]));
+       //      AliDebug(2,Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4]));
+       AliInfo(Form("mean = %f, truncated mean = %f, median = %f, SD wrt mean = %f, SD wrt median = %f ",parameters[0],parameters[1],parameters[2],parameters[3],parameters[4]));
 
        return parameters;
 }
@@ -1049,7 +1127,7 @@ Float_t* AliGRPPreprocessor::ProcessFloatAll(TObjArray* array)
 
 //_______________________________________________________________
 
-Char_t AliGRPPreprocessor::ProcessBool(TObjArray* array)
+Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
 {
        // 
        // processing Boolean values
@@ -1058,28 +1136,29 @@ Char_t AliGRPPreprocessor::ProcessBool(TObjArray* array)
        Bool_t aDCSBool = kTRUE;
 
        AliDCSValue *v = 0x0;
-       
+
        for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
                v = (AliDCSValue *)array->At(iCount);
-               if ((v->GetTimeStamp() < fStartTime) || (v->GetTimeStamp() > fEndTime)) {
+               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());
+                       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()));
                }
                aDCSBool = v->GetBool(); // always keeping last value
+               AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
        }
        
-       Char_t caDCSBool = (Char_t)aDCSBool;
+       Char_t caDCSBool = (Char_t) aDCSBool;
        return caDCSBool;
        
 }
 
 //_______________________________________________________________
 
-Float_t AliGRPPreprocessor::ProcessInt(TObjArray* array)
+Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
 {
        // 
        // processing Int values, returning mean
@@ -1092,7 +1171,7 @@ Float_t AliGRPPreprocessor::ProcessInt(TObjArray* array)
 
        for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
                v = (AliDCSValue *)array->At(iCount);
-               if((v->GetTimeStamp() >= fStartTime) &&(v->GetTimeStamp() <= fEndTime)) {
+               if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
                        aDCSArraySum += v->GetInt();
                        iCounts += 1;
                }
@@ -1106,7 +1185,7 @@ Float_t AliGRPPreprocessor::ProcessInt(TObjArray* array)
 }
 //_______________________________________________________________
 
-Float_t AliGRPPreprocessor::ProcessUInt(TObjArray* array)
+Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
 {
        // 
        // processing Int values, returning mean
@@ -1119,7 +1198,7 @@ Float_t AliGRPPreprocessor::ProcessUInt(TObjArray* array)
 
        for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
                v = (AliDCSValue *)array->At(iCount);
-               if((v->GetTimeStamp() >= fStartTime) &&(v->GetTimeStamp() <= fEndTime)) {
+               if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
                        aDCSArraySum += v->GetUInt();
                        iCounts += 1;
                }
@@ -1139,7 +1218,6 @@ AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
 {
        // extract DCS pressure maps. Perform fits to save space
        
-       AliInfo ("here ok");
        TMap *map = fPressure->ExtractDCS(dcsAliasMap);
        if (map) {
                fPressure->MakeSplineFit(map);
@@ -1198,7 +1276,7 @@ Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* db
        
        // main logbook
        TString sqlQuery;
-       sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask FROM logbook WHERE run = %d", run);
+       sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
        TSQLResult* result = server->Query(sqlQuery);
        if (!result)
                {
@@ -1221,13 +1299,23 @@ Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* db
                        return -4;
                }
        
+       TString timeStartString(row->GetField(0));
        TString runType(row->GetField(1));
-       
-       TMap grpData;
-       grpData.Add(new TObjString("DAQ_time_start"), new TObjString(row->GetField(0)));
-       grpData.Add(new TObjString("run_type"), new TObjString(runType));
-       grpData.Add(new TObjString("detectorMask"), new TObjString(row->GetField(2)));
-       
+       TString detectorMaskString(row->GetField(2));
+       TString l3CurrentString(row->GetField(3));
+       TString dipoleCurrentString(row->GetField(4));
+       time_t timeStart = (time_t)(timeStartString.Atoi());
+       UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
+       Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
+       Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
+       
+       AliGRPObject * grpObj = new AliGRPObject();
+       grpObj->SetTimeStart(timeStart); 
+       grpObj->SetRunType((TString)(row->GetField(1)));
+       grpObj->SetDetectorMask(detectorMask);
+       grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
+       grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
+
        delete row;
        row = 0;
        
@@ -1235,16 +1323,16 @@ Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* db
        result = 0;
        
        Printf("Storing GRP/GRP/Data object with the following content");
-       grpData.Print();
+       grpObj->Dump();
        
        AliCDBMetaData metadata;
-       metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus");
+       metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
        metadata.SetComment("GRP Output parameters received during online running");
        
        AliCDBId id("GRP/GRP/Data", run, run);
-       Bool_t success = cdb->Put(&grpData, id, &metadata);
+       Bool_t success = cdb->Put(grpObj, id, &metadata);
        
-       grpData.DeleteAll();
+       delete grpObj;
        
        if (!success)
                {