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. *
14 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Class AliGRPPreprocessor
20 // Global Run Parameters (GRP) preprocessor
21 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
22 // Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN
23 // Modified: Chiara.Zampolli@cern.ch CERN
24 //-------------------------------------------------------------------------
29 #include <TObjString.h>
30 #include <TObjArray.h>
37 #include "AliGRPPreprocessor.h"
38 #include "AliGRPObject.h"
39 #include "AliDCSSensor.h"
40 #include "AliSplineFit.h"
41 #include "AliDCSSensorArray.h"
42 #include "AliRawEventHeaderVersions.h"
44 #include "AliTriggerConfiguration.h"
45 #include "AliTriggerRunScalers.h"
47 #include "AliCDBMetaData.h"
49 #include "AliESDVertex.h"
52 class AliShuttleInterface;
54 // needed for ReceivePromptRecoParameters
56 #include <TSQLServer.h>
57 #include <TSQLResult.h>
59 #include <AliCDBManager.h>
60 #include <AliCDBMetaData.h>
62 #include <AliTriggerConfiguration.h>
63 #include <AliCTPTimeParams.h>
65 const Double_t kFitFraction = -1.; // Fraction of DCS sensor fits required
67 ClassImp(AliGRPPreprocessor)
69 //_______________________________________________________________
71 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook for PHYSICS runs, when beamType from DAQ logbook == NULL
72 const Int_t AliGRPPreprocessor::fgknDAQLbParReduced = 7; // num parameters in the logbook for the other cases
73 const Int_t AliGRPPreprocessor::fgknDCSDP = 51; // number of dcs dps
74 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
75 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
76 "LHCState", // missing in DCS
79 "LHCLuminosity", // missing in DCS
80 "BeamIntensity", // missing in DCS
86 "L3_BSF17_Temperature",
90 "L3_BSF4_Temperature",
94 "L3_BKF17_Temperature",
98 "L3_BKF4_Temperature",
102 "L3_BSF13_Temperature",
106 "L3_BSF8_Temperature",
110 "L3_BKF13_Temperature",
114 "L3_BKF8_Temperature",
118 "Dipole_Inside_Temperature",
122 "Dipole_Outside_Temperature",
124 "CavernAtmosPressure",
125 "SurfaceAtmosPressure",
126 "CavernAtmosPressure2"
129 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
133 "L3_BSF17_Temperature",
137 "L3_BSF4_Temperature",
141 "L3_BKF17_Temperature",
145 "L3_BKF4_Temperature",
149 "L3_BSF13_Temperature",
153 "L3_BSF8_Temperature",
157 "L3_BKF13_Temperature",
161 "L3_BKF8_Temperature",
165 "Dipole_Inside_Temperature",
169 "Dipole_Outside_Temperature"
172 const Short_t kSensors = 48; // start index position of sensor in DCS DPs
173 const Short_t kNumSensors = 3; // Number of sensors in DCS DPs (CavernAtmosPressure, SurfaceAtmosPressure, CavernAtmosPressure2)
176 const char* AliGRPPreprocessor::fgkLHCState[20] = {
182 "U", "UNSTABLE BEAMS",
189 const char* kppError[] = {
191 "(DAQ logbook ERROR)",
193 "(Trigger Scalers not found in DCS FXS - ERROR)",
194 "(DCS data points ERROR)",
195 "(Trigger Configuration ERROR)",
196 "(DAQ logbook ERROR determining partition of the run)",
197 "(CTP timing ERROR)",
198 "(SPD Mean Vertex ERROR)"
201 //_______________________________________________________________
203 AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
204 AliPreprocessor("GRP",shuttle), fPressure(0), fmaxFloat(0), fminFloat(0),fmaxDouble(0), fminDouble(0), fmaxInt(0), fminInt(0), fmaxUInt(0), fminUInt(0),fdaqStartEndTimeOk(kTRUE),ffailedDPs(new TObjArray(fgknDCSDP))
206 // constructor - shuttle must be instantiated!
208 AddRunType("COSMIC");
210 AddRunType("PHYSICS");
211 AddRunType("CALIBRATION_BC");
212 AddRunType("CALIBRATION_CENTRAL");
213 AddRunType("CALIBRATION_EMD");
214 AddRunType("CALIBRATION_MB");
215 AddRunType("CALIBRATION_SEMICENTRAL");
216 AddRunType("CALIBRATION");
217 AddRunType("PEDESTAL");
218 AddRunType("STANDALONE");
221 AddRunType("PULSER");
222 AddRunType("STANDALONE_PULSER");
223 AddRunType("STANDALONE_BC");
226 fminFloat = -FLT_MAX;
227 fmaxDouble = DBL_MAX;
228 fminDouble = -DBL_MAX;
234 AliInfo(Form("Max allowed float = %6.5e",fmaxFloat));
235 AliInfo(Form("Min allowed float = %6.5e",fminFloat));
236 AliInfo(Form("Max allowed double = %6.5e",fmaxDouble));
237 AliInfo(Form("Min allowed double = %6.5e",fminDouble));
238 AliInfo(Form("Max allowed integer = %d",fmaxInt));
239 AliInfo(Form("Min allowed integer = %d",fminInt));
240 AliInfo(Form("Max allowed unsigned integer = %u",(Int_t)fmaxUInt));
241 AliInfo(Form("Min allowed unsigned integer = %u",(Int_t)fminUInt));
243 ffailedDPs->SetOwner(kTRUE);
246 //_______________________________________________________________
248 AliGRPPreprocessor::~AliGRPPreprocessor()
257 //_______________________________________________________________
259 void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
261 // Initialize preprocessor
263 AliPreprocessor::Initialize(run, startTime, endTime);
265 AliInfo("Initialization of the GRP preprocessor.");
266 AliInfo(Form("Start Time DCS = %d",GetStartTimeDCSQuery()));
267 AliInfo(Form("End Time DCS = %d",GetEndTimeDCSQuery()));
268 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
269 for(Int_t j = 0; j < kNumSensors; j++) {
270 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
271 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
273 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
275 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
277 for (Int_t iDP=0; iDP < fgknDCSDP; iDP++){
278 TObjString* dp = new TObjString(fgkDCSDataPoints[iDP]);
279 ffailedDPs->AddAt(dp,iDP);
284 //_______________________________________________________________
286 UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
288 // process data retrieved by the Shuttle
290 // retrieving "partition" and "detector" fields from DAQ logbook to
291 // determine the partition in which the run was taken
292 // the partition is used to decide how to react in case of errors for CTP
294 TString partition = (TString)GetRunParameter("partition");
295 TString detector = (TString)GetRunParameter("detector");
297 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
298 grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
299 //=================//
301 //=================//
304 Int_t iDaqLB = ProcessDaqLB(grpobj);
305 TString runType = (TString)GetRunType();
306 TString beamType = (TString)GetRunParameter("beamType");
307 //if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && beamType!="Cosmics") || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType=="Cosmics") || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
308 if((runType == "PHYSICS" && iDaqLB == fgknDAQLbPar && !beamType.IsNull()) || (runType == "PHYSICS" && iDaqLB == fgknDAQLbParReduced && beamType.IsNull()) || (runType != "PHYSICS" && iDaqLB == fgknDAQLbParReduced)) {
309 Log(Form("DAQ Logbook, successful!"));
311 Log(Form("DAQ Logbook, could not get all expected entries!!!"));
315 //=================//
317 //=================//
318 UInt_t iDaqFxs = ProcessDaqFxs();
320 Log(Form("DAQ FXS, successful!"));
322 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
326 //=================//
328 //=================//
329 UInt_t iDcsFxs = ProcessDcsFxs(partition, detector);
331 Log(Form("DCS FXS, successful!"));
332 } else if (iDcsFxs ==1) {
333 Log(Form("DCS FXS, Could not store CTP scalers!!!"));
336 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without CTP scalers...",partition.Data(),detector.Data()));
340 //=================//
341 // DCS data points //
342 //=================//
343 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
344 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
345 Log(Form("entries found = %d (should be %d)",entries, fgknDCSDP-4));
346 if (fdaqStartEndTimeOk){
347 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, L3_BSF4_H3 are not working yet...
348 Log(Form("Problem with the DCS data points!!! Only %d/%d entries found",entries,fgknDCSDP-4));
349 Log(Form("The DPs giving problems were:"));
350 for (Int_t iDP = 0; iDP < fgknDCSDP; iDP++){
351 TObjString *dpString = (TObjString*)ffailedDPs->At(iDP);
353 TString name = dpString->String();
354 if (name != "LHCState" && name != "LHCLuminosity" && name != "BeamIntensity" && name != "L3_BSF4_H3"){
355 Log(Form("******** %s ******** not present, but foreseen --> causing an ERROR",name.Data()));
358 Log(Form(" %s is not present, but was not generating any error since it is not ready in DCS - check the other DPs in this list!",name.Data()));
364 else Log(Form("DCS data points, successful!"));
366 else Log(Form("Statistical values for DCS DPs could not be computed due to missing DAQ_time_start and DAQ_time_end fields in DAQ logbook"));
368 //=======================//
369 // Trigger Configuration //
370 //=======================//
372 const char * triggerConf = GetTriggerConfiguration();
374 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
375 Log("STANDALONE partition for current run, using Trigger Configuration dummy value");
376 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyConfig");
378 Log(Form("No dummy CTP configuration entry found, going into error..."));
382 AliTriggerConfiguration *runcfg = (AliTriggerConfiguration*)cdbEntry->GetObject();
384 Log(Form("dummy CTP config not found in OCDB entry, going into error..."));
388 TString titleCTPcfg = Form("CTP cfg for run %i from Dummy entry in OCDB",fRun);
389 runcfg->SetTitle(titleCTPcfg);
390 AliCDBMetaData metaData;
391 metaData.SetResponsible("Roman Lietava");
392 metaData.SetComment("CTP run configuration from dummy entry in OCDB");
393 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
394 Log("Unable to store the dummy CTP run configuration object to OCDB!");
401 else if (!partition.IsNull() && detector.IsNull()){ // global partition
402 Log("GLOBAL partition for current run, using Trigger Configuration from DAQ Logbook");
403 if (triggerConf!= NULL) {
404 Log("Found trigger configuration in DAQ logbook");
405 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
407 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
411 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
412 runcfg->SetTitle(titleCTPcfg);
413 AliCDBMetaData metaData;
414 metaData.SetBeamPeriod(0);
415 metaData.SetResponsible("Roman Lietava");
416 metaData.SetComment("CTP run configuration from DAQ logbook");
417 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
418 Log("Unable to store the CTP run configuration object to OCDB!");
425 Log("Trigger configuration NULL in DAQ logbook");
431 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger configuration...",partition.Data(),detector.Data()));
435 //===========================//
436 // Trigger Timing Parameters //
437 //===========================//
440 const char * triggerCTPtiming = GetCTPTimeParams();
442 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
443 Log("STANDALONE partition for current run, using CTP timing params dummy value");
444 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyCTPtime");
446 Log(Form("No dummy CTP timing parameters entry found, going into error..."));
450 AliCTPTimeParams *runCTPtiming = (AliCTPTimeParams*)cdbEntry->GetObject();
452 Log(Form("dummy CTP timing parameters not found in OCDB entry, going into error..."));
456 TString titleCTPtiming = Form("CTP timing params for run %i from Dummy entry in OCDB",fRun);
457 runCTPtiming->SetTitle(titleCTPtiming);
458 AliCDBMetaData metadata;
459 metadata.SetResponsible("Roman Lietava");
460 metadata.SetComment("CTP run timing parameters from dummy entry in OCDB");
461 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
462 Log("Unable to store the dummy CTP timing params object to OCDB!");
469 else if (!partition.IsNull() && detector.IsNull()){ // global partition
470 Log("GLOBAL partition for current run, using Trigger Timing Parameters from DAQ Logbook");
471 if (triggerCTPtiming!= NULL) {
472 Log("Found trigger timing params in DAQ logbook");
473 AliDebug(2,Form("%s",triggerCTPtiming));
474 AliCTPTimeParams *runCTPtiming = AliCTPTimeParams::LoadCTPTimeParamsFromString(triggerCTPtiming);
476 Log("Bad CTP trigger timing params file from DAQ logbook! The corresponding CDB entry will not be filled!");
480 TString titleCTPtiming = Form("CTP timing params for run %i from DAQ",fRun);
481 runCTPtiming->SetTitle(titleCTPtiming);
482 AliCDBMetaData metadata;
483 metadata.SetBeamPeriod(0);
484 metadata.SetResponsible("Roman Lietava");
485 metadata.SetComment("CTP timing params from DAQ logbook");
486 if (!Store("CTP","CTPtiming", runCTPtiming, &metadata, 0, 0)) {
487 Log("Unable to store the CTP timing params object to OCDB!");
494 Log("Trigger timing params NULL in DAQ logbook");
500 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error without trigger timing parameters...",partition.Data(),detector.Data()));
503 // storing AliGRPObject in OCDB
506 md.SetResponsible("Chiara Zampolli");
507 md.SetComment("Output parameters from the GRP preprocessor.");
509 Bool_t result = kTRUE;
510 result = Store("GRP", "Data", grpobj, &md);
513 //==================//
514 // SPD Mean Vertex //
515 //==================//
516 UInt_t iSPDMeanVertex = ProcessSPDMeanVertex();
517 if( iSPDMeanVertex == 1 ) {
518 Log(Form("SPD Mean Vertex, successful!"));
520 Log(Form("SPD Mean Vertex failed!!!"));
524 if (result && !error ) {
525 Log("GRP Preprocessor Success");
528 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s%s%s%s",
529 kppError[(error&1)?1:0],
530 kppError[(error&2)?2:0],
531 kppError[(error&4)?3:0],
532 kppError[(error&8)?4:0],
533 kppError[(error&16)?5:0],
534 kppError[(error&32)?6:0],
535 kppError[(error&64)?7:0],
536 kppError[(error&128)?8:0]
542 //_______________________________________________________________
544 UInt_t AliGRPPreprocessor::ProcessSPDMeanVertex()
546 //Getting the SPD Mean Vertex
547 TList* list = GetForeignFileSources("SPD", kDAQ, "VertexDiamond");
548 Bool_t storeResult = kTRUE;
549 if (list !=0x0 && list->GetEntries()!=0)
551 AliInfo("The following sources produced files with the id VertexDiamond from SPD");
553 for (Int_t jj=0;jj<list->GetEntries();jj++){
554 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
555 AliInfo(Form("found source %s", str->String().Data()));
556 TString fileNameRun = GetForeignFile("SPD", kDAQ, "VertexDiamond", str->GetName());
557 if (fileNameRun.Length()>0){
558 AliInfo(Form("Got the file %s", fileNameRun.Data()));
559 TFile daqFile(fileNameRun.Data(),"READ");
560 if (daqFile.IsOpen()) {
561 AliESDVertex* meanVtx = dynamic_cast<AliESDVertex*>(daqFile.Get("MeanVertexPos"));
564 // storing in the OCDB
566 md.SetResponsible("Cvetan Cheshkov");
567 md.SetComment("SPD Mean Vertex");
568 storeResult = Store("GRP", "MeanVertexSPD", meanVtx, &md);
571 AliWarning("No SPD Mean Vertex object found in file");
575 AliError("Can't open file");
576 storeResult = kFALSE;
580 AliWarning("No file found for current source for SPD Mean Vertex");
585 AliWarning("No list found for SPD Mean Vertex");
588 if (list) delete list;
594 //_______________________________________________________________
596 Int_t AliGRPPreprocessor::ProcessDaqLB(AliGRPObject* grpObj)
598 //Getting the DAQ lb information
600 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
601 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
602 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
603 TString beamType = (TString)GetRunParameter("beamType");
604 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
605 UInt_t detectorMask = (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
606 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
607 TString runType = (TString)GetRunType();
609 UInt_t nparameter = 0;
611 grpObj->SetTimeStart(timeStart);
612 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
616 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
620 grpObj->SetTimeEnd(timeEnd);
621 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
625 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
628 if (beamEnergy != 0){
629 grpObj->SetBeamEnergy(beamEnergy);
630 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
631 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
632 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
633 nparameter++; // increasing nparameters only in case we're in PHYSICS runs with beamType != NULL
637 //if ((runType == "PHYSICS" && beamType!="Cosmics")){
638 if ((runType == "PHYSICS" && !beamType.IsNull())){ // if beamType is NOT Null, then we're not in a Cosmics run
639 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, and producing an error (beamType = %s, runType = %s)",beamType.Data(), runType.Data()));
642 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry, but not producing any error (beamType = NULL, runType = %s)", runType.Data()));
647 if (beamType.Length() != 0){
648 grpObj->SetBeamType(beamType);
649 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
653 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry! Not producing any error, considering this as a Cosmics run"));
657 if (numberOfDetectors != 0){
658 grpObj->SetNumberOfDetectors(numberOfDetectors);
659 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
663 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
666 if (detectorMask != 0){
667 grpObj->SetDetectorMask(detectorMask);
668 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
672 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
675 if (lhcPeriod.Length() != 0) {
676 grpObj->SetLHCPeriod(lhcPeriod);
677 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
681 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
683 if (runType.Length() != 0) {
684 grpObj->SetRunType(runType);
685 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
689 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
695 //_______________________________________________________________
697 UInt_t AliGRPPreprocessor::ProcessDaqFxs()
699 //======DAQ FXS======//
701 AliRawEventHeaderV3_9::Class()->IgnoreTObjectStreamer(); // to avoid trying reading TObject store in AliRawEventHeaderV3_9 - temporary fix
702 TList* list = GetFileSources(kDAQ);
704 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
708 if (list->GetEntries() == 0) {
709 Log("no raw data tags in this run: nothing to merge!");
714 TChain *fRawTagChain = new TChain("T");
716 TIterator* iter = list->MakeIterator();
718 while ((obj = iter->Next())) {
719 TObjString* objStr = dynamic_cast<TObjString*> (obj);
721 Log(Form("Found source %s", objStr->String().Data()));
722 TList* list2 = GetFileIDs(kDAQ, objStr->String());
724 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
725 delete fRawTagChain; fRawTagChain=0;
728 Log(Form("Number of ids: %d",list2->GetEntries()));
729 for(Int_t i = 0; i < list2->GetEntries(); i++) {
730 TObjString *idStr = (TObjString *)list2->At(i);
731 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
732 if (fileName.Length() > 0) {
733 Log(Form("Adding file in the chain: %s",fileName.Data()));
734 fRawTagChain->Add(fileName.Data());
737 Log(Form("Could not retrieve file with id %s from source %s: "
738 "connection problems with DAQ FXS!",
739 idStr->String().Data(), objStr->String().Data()));
741 delete list2; list2=0;
742 delete fRawTagChain; fRawTagChain=0;
750 TString fRawDataFileName = "GRP_Merged.tag.root";
751 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
753 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
754 Log("Error merging raw data files!!!");
758 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
759 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
762 Log("Problem storing raw data tags in local file!!!");
764 Log("Raw data tags merged successfully!!");
769 delete fRawTagChain; fRawTagChain=0;
771 if (result == kFALSE) {
779 //_______________________________________________________________
780 UInt_t AliGRPPreprocessor::ProcessDcsFxs(TString partition, TString detector)
783 // processing the info
784 // stored in the DCS FXS
785 // coming from the trigger
787 // Get the CTP counters information
789 if (partition.IsNull() && !detector.IsNull()){ // standalone partition
790 Log("STANDALONE partition for current run, using Trigger Scalers dummy value");
791 AliCDBEntry *cdbEntry = GetFromOCDB("CTP","DummyScalers");
793 Log(Form("No dummy CTP scalers entry found, going into error..."));
797 AliTriggerRunScalers *scalers = (AliTriggerRunScalers*)cdbEntry->GetObject();
799 Log(Form("CTP dummy scalers not found in OCDB entry, going into error..."));
803 AliCDBMetaData metaData;
804 metaData.SetResponsible("Roman Lietava");
805 metaData.SetComment("CTP scalers from dummy entry in OCDB");
806 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
807 Log("Unable to store the dummy CTP scalers object to OCDB!");
814 else if (!partition.IsNull() && detector.IsNull()){ // global partition
815 Log("GLOBAL partition for current run, using CTP scalers from DCS FXS");
816 TString countersfile = GetFile(kDCS, "CTP_xcounters","");
817 if (countersfile.IsNull()) {
818 Log("No CTP counters files has been found: empty source!");
822 Log(Form("File with Id CTP_xcounters found in DCS FXS! Copied to %s",countersfile.Data()));
823 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
825 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
829 AliCDBMetaData metaData;
830 metaData.SetBeamPeriod(0);
831 metaData.SetResponsible("Roman Lietava");
832 metaData.SetComment("CTP scalers");
833 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
834 Log("Unable to store the CTP scalers object to OCDB!");
843 Log(Form("Incorrect field in DAQ logbook for partition = %s and detector = %s, going into error...",partition.Data(),detector.Data()));
850 //_______________________________________________________________
852 Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
856 // processing DCS DPs
859 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
860 Int_t nLHCEntries = 0;
861 Int_t nL3Entries = 0;
862 Int_t nDipoleEntries = 0;
863 Int_t nEnvEntries = 0;
864 Int_t nHallProbesEntries = 0;
865 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
866 nL3Entries = ProcessL3DPs(valueMap, grpObj);
867 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
868 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
869 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
870 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
871 Log(Form("nLHCEntries = %d, L3Entries = %d, nDipoleEntries =%d, nEnvEntries = %d, nHallProbesEntries = %d", nLHCEntries, nL3Entries, nDipoleEntries, nEnvEntries, nHallProbesEntries));
872 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
877 //_______________________________________________________________
879 Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
886 Int_t nL3Entries = 0;
888 TObjArray *array = 0x0;
890 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
892 AliInfo(Form("==========L3Current==========="));
893 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
894 indexDP = kL3Current;
895 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
897 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
900 if (array->GetEntries() == 0){
901 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
904 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
905 if (floatDCS != NULL){
906 grpObj->SetL3Current(floatDCS);
918 ffailedDPs->RemoveAt(indexDP);
922 if (array) array = 0x0;
924 AliInfo(Form("==========L3Polarity==========="));
925 indexDP = kL3Polarity;
926 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
928 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
931 if (array->GetEntries() == 0){
932 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
935 Bool_t change = kFALSE;
936 Char_t charDCS = ProcessBool(array,change);
937 if (change == kFALSE){
938 grpObj->SetL3Polarity(charDCS);
939 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
940 ffailedDPs->RemoveAt(indexDP);
944 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
945 ffailedDPs->RemoveAt(indexDP);
949 AliError(Form("%s value changed within the run, while the magnet was ON (according to the current), setting it to invalid and considering the DP as wrong",fgkDCSDataPoints[indexDP]));
957 //_______________________________________________________________
959 Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
965 Int_t nDipoleEntries = 0;
966 TObjArray *array = 0x0;
968 Bool_t isZero = kTRUE; // flag to monitor L3Current. If set to true, the magnet is OFF, and the polarity can change
970 AliInfo(Form("==========DipoleCurrent==========="));
971 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
972 indexDP = kDipoleCurrent;
973 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
975 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
978 if (array->GetEntries() == 0){
979 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
982 Float_t *floatDCS = ProcessFloatAllMagnet(array, indexDP, isZero);
983 if (floatDCS != NULL){
984 grpObj->SetDipoleCurrent(floatDCS);
996 ffailedDPs->RemoveAt(indexDP);
1000 if (array) array = 0x0;
1002 AliInfo(Form("==========DipolePolarity==========="));
1003 indexDP = kDipolePolarity;
1004 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1006 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1009 if (array->GetEntries() == 0){
1010 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1013 Bool_t change = kFALSE;
1014 Char_t charDCS = ProcessBool(array,change);
1016 grpObj->SetDipolePolarity(charDCS);
1017 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
1018 ffailedDPs->RemoveAt(indexDP);
1022 AliInfo(Form("%s set to invalid, but magnet was OFF (according to the current), DP not considered wrong",fgkDCSDataPoints[indexDP]));
1023 ffailedDPs->RemoveAt(indexDP);
1027 AliError(Form("%s value changed within the run while the magnet was ON (according to the current), setting it to invalid and considering the DP as wrong", fgkDCSDataPoints[indexDP]));
1032 return nDipoleEntries;
1035 //_______________________________________________________________
1037 Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
1041 // evironment conditions (temperature, pressure) info
1043 Int_t nEnvEntries = 0;
1044 TObjArray *array = 0x0;
1047 AliInfo(Form("==========CavernTemperature==========="));
1048 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1049 indexDP = kCavernTemperature;
1050 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1052 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1055 if (array->GetEntries() == 0){
1056 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1059 Float_t *floatDCS = ProcessFloatAll(array);
1060 if (floatDCS != NULL){
1061 grpObj->SetCavernTemperature(floatDCS);
1072 ffailedDPs->RemoveAt(indexDP);
1077 if (array) array = 0x0;
1079 AliInfo(Form("========== AtmosPressures (Cavern + Surface + Cavern2) ==========="));
1080 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
1081 //dcsSensorArray->Print();
1082 if( fPressure->NumFits()<kNumSensors ) {
1083 Log(Form("Check the pressure sensor values! Not all the %d pressure sensors have been fit",kNumSensors));
1085 Log(Form("Number of fits performed = %d",fPressure->NumFits()));
1087 AliInfo(Form("==========CavernAtmosPressure==========="));
1088 indexDP = kCavernAtmosPressure;
1089 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1090 TGraph* graph = sensorCavernP2->GetGraph();
1091 AliDebug(3,Form("index = %d",indexDP));
1092 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1093 AliDebug(2,Form("graph = %p",graph));
1094 AliDebug(3,Form("sensorCavernP2 = %p", sensorCavernP2));
1095 if(sensorCavernP2->GetFit() || graph) {
1096 if (sensorCavernP2->GetFit()){
1097 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1100 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1102 grpObj->SetCavernAtmosPressure(sensorCavernP2);
1103 ffailedDPs->RemoveAt(indexDP);
1106 //if (sensorP2) delete sensorP2;
1108 Log(Form("ERROR!!! Neither graph nor fit found for sensor %s - this will not increase the number of found DCS DPs and will cause an error", fgkDCSDataPoints[indexDP] ));
1111 AliInfo(Form("==========SurfaceAtmosPressure==========="));
1112 indexDP = kSurfaceAtmosPressure;
1113 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1114 graph = sensorP2->GetGraph();
1115 AliDebug(3,Form("index = %d",indexDP));
1116 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1117 AliDebug(2,Form("graph = %p",graph));
1118 AliDebug(3,Form("sensorP2 = %p", sensorP2));
1119 if(sensorP2->GetFit() || graph) {
1120 if (sensorP2->GetFit()){
1121 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1124 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1126 grpObj->SetSurfaceAtmosPressure(sensorP2);
1127 ffailedDPs->RemoveAt(indexDP);
1130 //if (sensorP2) delete sensorP2;
1132 Log(Form("ERROR!!! Neither graph nor fit found for sensor %s - this will not increase the number of found DCS DPs and will cause an error", fgkDCSDataPoints[indexDP] ));
1135 AliInfo(Form("==========CavernAtmosPressure2==========="));
1136 indexDP = kCavernAtmosPressure2;
1137 AliDCSSensor* sensorCavernP22 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
1138 graph = sensorCavernP22->GetGraph();
1139 AliDebug(3,Form("index = %d",indexDP));
1140 AliDebug(3,Form("name = %s",fgkDCSDataPoints[indexDP]));
1141 AliDebug(2,Form("graph = %p",graph));
1142 AliDebug(3,Form("sensorCavernP2_2 = %p", sensorCavernP22));
1143 if(sensorCavernP22->GetFit() || graph) {
1144 if (sensorCavernP22->GetFit()){
1145 Log(Form("Fit for sensor %s found",fgkDCSDataPoints[indexDP]));
1148 Log(Form("Fit for sensor %s not found, but the graph is there - NOT going into error",fgkDCSDataPoints[indexDP]));
1150 grpObj->SetCavernAtmosPressure2(sensorCavernP22);
1151 ffailedDPs->RemoveAt(indexDP);
1154 //if (sensorP2) delete sensorP2;
1156 Log(Form("ERROR!!! Neither graph nor fit found for sensor %s - this will not increase the number of found DCS DPs and will cause an error", fgkDCSDataPoints[indexDP] ));
1162 //_______________________________________________________________
1164 Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
1170 Int_t nHPEntries = 0;
1171 TObjArray *array = 0x0;
1173 Bool_t outOfRange; // flag to monitor if any value collected by DCS is out of range
1175 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
1176 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()));
1178 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
1179 outOfRange = kFALSE; // resetting outOfRange flag at each HP
1180 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
1181 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
1183 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
1186 if (array->GetEntries() == 0){
1187 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
1190 Float_t *floatDCS = ProcessFloatAll(array);
1191 if (floatDCS != NULL){
1192 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]));
1193 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
1194 for (Int_t kk = 0 ; kk< 5; kk++){
1195 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
1207 ffailedDPs->RemoveAt(indexDP + 7); // 7 = shift in the complete list of DPs to get to the Hall Probes
1213 Log(Form("Hall Probes = %d ", nHPEntries));
1217 //_______________________________________________________________
1219 Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
1223 // processing of LHC related DCS DPs, i.e.:
1229 Int_t nLHCEntries = 0;
1230 TObjArray *array = 0x0;
1233 AliInfo(Form("==========LHCState==========="));
1234 indexDP = kLHCState;
1235 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1237 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1240 if (array->GetEntries() == 0){
1241 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
1244 TString stringDCS = ProcessChar(array);
1245 if (stringDCS.Length()!=0) {
1246 Bool_t found = kFALSE;
1247 for( Int_t i=0; i<20; i+=2 ) {
1248 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
1249 stringDCS = fgkLHCState[i+1];
1255 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
1256 grpObj->SetLHCState(stringDCS);
1259 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
1260 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1264 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
1265 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
1268 ffailedDPs->RemoveAt(indexDP);
1272 if (array) array = 0x0;
1274 AliInfo(Form("==========LHCLuminosity==========="));
1275 Bool_t outOfRange = kFALSE; // flag to monitor if any value collected by DCS is out of range
1276 indexDP = kLHCLuminosity;
1277 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1279 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1282 if (array->GetEntries() == 0){
1283 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1286 Float_t *floatDCS = ProcessFloatAll(array);
1287 if (floatDCS != NULL){
1288 grpObj->SetLHCLuminosity(floatDCS);
1289 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1290 grpObj->SetLHCLuminositySplineFit(splfit);
1302 ffailedDPs->RemoveAt(indexDP);
1307 if (array) array = 0x0;
1309 AliInfo(Form("==========BeamIntensity==========="));
1310 if (outOfRange) outOfRange = kFALSE; // resetting outOfRange if needed
1311 indexDP = kBeamIntensity;
1312 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
1314 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
1317 if (array->GetEntries() == 0){
1318 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
1321 Float_t *floatDCS = ProcessFloatAll(array);
1322 if (floatDCS != NULL){
1323 grpObj->SetBeamIntensity(floatDCS);
1324 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
1325 grpObj->SetBeamIntensitySplineFit(splfit1);
1338 ffailedDPs->RemoveAt(indexDP);
1344 //_________________________________________________________________________
1346 AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
1350 // returning Spline Fit
1353 Int_t entriesarray = array->GetEntries();
1354 Float_t* value = new Float_t[entriesarray];
1355 Float_t* time = new Float_t[entriesarray];
1356 AliDCSValue* v = 0x0;
1357 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
1358 v = (AliDCSValue*)array->At(iarray);
1359 value[iarray] = v->GetFloat();
1360 time[iarray] = v->GetTimeStamp();
1361 AliDebug(2,Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
1363 TGraph* gr = new TGraph(entriesarray,value,time);
1365 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
1368 AliSplineFit *fit = new AliSplineFit();
1369 fit->SetMinPoints(10);
1370 fit->InitKnots(gr,10,10,0.0);
1374 AliWarning(Form("%s: no fit performed",stringID.Data()));
1380 //_________________________________________________________________________
1382 TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
1389 TString aDCSString="";
1391 AliDCSValue *v = 0x0;
1392 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1393 v = (AliDCSValue *)array->At(iCount);
1394 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1395 AliError(Form("DCS values for the parameter outside the queried interval"));
1399 if (aDCSString != v->GetChar())
1400 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1402 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1407 //__________________________________________________________________________________________________________________
1409 Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
1412 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1414 // parameters[0] = mean
1415 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1416 // parameters[2] = median
1417 // parameters[3] = standard deviation wrt mean
1418 // parameters[4] = standard deviation wrt median
1421 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1422 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1423 if (timeStartString.IsNull() || timeStartString.IsNull()){
1424 if (timeStartString.IsNull()){
1425 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1427 else if (timeStartString.IsNull()){
1428 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1430 fdaqStartEndTimeOk = kFALSE;
1434 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1435 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1436 Float_t* parameters = new Float_t[5];
1438 Int_t iCountsRun = 0;
1439 Int_t nCounts = array->GetEntries();
1440 Float_t valueBeforeSOR = 0;
1441 Float_t valueAfterEOR = 0;
1442 Int_t timestampBeforeSOR = -1;
1443 Int_t timestampAfterEOR = -1;
1444 Int_t ientrySOR = -1;
1445 Int_t ientryEOR = -1;
1446 Float_t* arrayValues = 0x0;
1447 Double_t* arrayWeights = 0x0;
1448 Bool_t truncMeanFlag = kTRUE; // flag to indicate whether Truncated Mean should be calculated or not
1449 Bool_t sdFlag = kTRUE; // flag to indicate whether SD (wrt Mean/Median) should be calculated or not
1451 for(Int_t i = 0; i < nCounts; i++) {
1452 AliDCSValue *v = (AliDCSValue *)array->At(i);
1453 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1454 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1455 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1456 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1459 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1460 AliDebug(2,Form("%d-th entry = %f at timestamp %i",i,v->GetFloat(),v->GetTimeStamp()));
1462 // look for the last value before SOR and the first value before EOR
1463 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1464 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1465 AliDebug(2,Form("timestamp of last value before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1466 valueBeforeSOR = v->GetFloat();
1468 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1469 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1470 valueAfterEOR = v->GetFloat();
1471 AliDebug(2,Form("timestamp of first value after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1473 // check if there are DPs between DAQ_time_start and DAQ_time_end
1474 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1475 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1476 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1477 AliDebug(2,Form("entry between SOR and EOR"));
1482 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1486 if (timestampBeforeSOR == -1){
1487 AliWarning("No value found before SOR");
1489 if (timestampAfterEOR == -1){
1490 AliWarning("No value found after EOR");
1493 AliDebug(2,Form("Number of valid entries (within DCS query interval) = %i, from a total amount of %i entries",iCounts,nCounts));
1494 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1495 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1496 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1497 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1498 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1500 Int_t nentriesUsed = 0;
1501 if (iCountsRun > 1){
1502 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1503 AliDebug(2,"Calculating (weighted) Mean and Median");
1504 arrayValues = new Float_t[iCountsRun];
1505 arrayWeights = new Double_t[iCountsRun];
1506 nentriesUsed = iCountsRun;
1507 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1508 AliDCSValue *v = (AliDCSValue *)array->At(i);
1509 Int_t timestamp2 = 0;
1511 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1512 timestamp2 = (Int_t)v1->GetTimeStamp();
1515 timestamp2 = timeEnd+1;
1517 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1518 arrayValues[i-ientrySOR] = v->GetFloat();
1520 parameters[0] = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1521 parameters[2] = TMath::Median(iCountsRun,arrayValues,arrayWeights);
1523 else if (iCountsRun == 1){
1524 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1526 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1527 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.");
1528 arrayValues = new Float_t[2];
1529 arrayWeights = new Double_t[2];
1530 arrayValues[0] = valueBeforeSOR;
1531 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1532 arrayValues[1] = v->GetFloat();
1533 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1534 AliDebug(2, Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1535 AliDebug(2, Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1536 parameters[0] = TMath::Mean(2,arrayValues,arrayWeights);
1537 parameters[2] = TMath::Median(2,arrayValues,arrayWeights);
1538 truncMeanFlag = kFALSE;
1541 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");
1542 parameters[0] = AliGRPObject::GetInvalidFloat();
1543 parameters[1] = AliGRPObject::GetInvalidFloat();
1544 parameters[2] = AliGRPObject::GetInvalidFloat();
1545 parameters[3] = AliGRPObject::GetInvalidFloat();
1546 parameters[4] = AliGRPObject::GetInvalidFloat();
1550 else { // iCountsRun == 0, using only the point immediately before SOR
1551 if (timestampBeforeSOR == -1){
1552 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");
1553 parameters[0] = AliGRPObject::GetInvalidFloat();
1554 parameters[1] = AliGRPObject::GetInvalidFloat();
1555 parameters[2] = AliGRPObject::GetInvalidFloat();
1556 parameters[3] = AliGRPObject::GetInvalidFloat();
1557 parameters[4] = AliGRPObject::GetInvalidFloat();
1561 AliWarning("Using only last entry before SOR. Truncated mean and Standard deviations (wrt mean/median) won't be calculated.");
1562 AliDebug(2,Form("value = %f",valueBeforeSOR));
1563 parameters[0] = valueBeforeSOR;
1564 parameters[2] = valueBeforeSOR;
1565 truncMeanFlag = kFALSE;
1572 Float_t sumweights = 0;
1573 Int_t entriesTruncMean = 0;
1574 Float_t* arrayValuesTruncMean = new Float_t[nentriesUsed];
1575 Double_t* arrayWeightsTruncMean = new Double_t[nentriesUsed];
1577 // calculating SD wrt Mean and Median
1578 AliDebug(2,"Calculating SD wrt Mean and SD wrt Median");
1580 for (Int_t i =0; i< nentriesUsed; i++){
1581 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1582 temp += (arrayValues[i]-parameters[2])*(arrayValues[i]-parameters[2]);
1583 temp1 += arrayWeights[i]*(arrayValues[i]-parameters[0])*(arrayValues[i]-parameters[0]);
1584 sumweights += arrayWeights[i];
1586 // setting SD wrt Mean
1587 if (sumweights != 0 ){
1588 parameters[3] = TMath::Sqrt(temp1/sumweights);
1591 AliError("Sum of weights to calculate Standard Deviation (wrt mean) <= 0, setting the SD to invalid");
1592 parameters[3] = AliGRPObject::GetInvalidFloat();
1594 // setting SD wrt Median
1595 if (nentriesUsed != 0){
1596 parameters[4] = TMath::Sqrt(temp/nentriesUsed);
1599 AliError("Number of entries used to calculate Standard Deviation (wrt median) <= 0, setting the SD to invalid");
1600 parameters[4] = AliGRPObject::GetInvalidFloat();
1604 parameters[3] = AliGRPObject::GetInvalidFloat();
1605 parameters[4] = AliGRPObject::GetInvalidFloat();
1608 // calculating truncated mean (this comes afterwards since you need the SD wrt Mean)
1610 AliDebug(2,"Calculating Truncated Mean");
1611 for (Int_t i =0; i< nentriesUsed; i++){
1612 AliDebug(2,Form("Entry %d: value = %f, weight = %f",i,arrayValues[i],arrayWeights[i]));
1613 if ((arrayValues[i]<=parameters[0]+3*parameters[3]) && (arrayValues[i]>=parameters[0]-3*parameters[3])){
1614 arrayValuesTruncMean[entriesTruncMean]=arrayValues[i];
1615 arrayWeightsTruncMean[entriesTruncMean]=arrayWeights[i];
1616 AliDebug(2,Form("For Truncated Mean: Entry %d: value = %f, weight = %f",entriesTruncMean,arrayValuesTruncMean[entriesTruncMean],arrayWeightsTruncMean[entriesTruncMean]));
1620 AliDebug(2,"Discarding entry");
1623 // setting truncated mean
1624 if (entriesTruncMean >1){
1625 AliDebug(2,Form("%d entries used for truncated mean",entriesTruncMean));
1626 parameters[1] = TMath::Mean(entriesTruncMean,arrayValuesTruncMean,arrayWeightsTruncMean);
1629 AliDebug(2,Form("Too few entries (%d) to calculate truncated mean",entriesTruncMean));
1630 parameters[1] = AliGRPObject::GetInvalidFloat();
1634 parameters[1] = AliGRPObject::GetInvalidFloat();
1637 AliInfo(Form("(weighted) mean = %f ",parameters[0]));
1638 AliInfo(Form("(weighted) truncated mean = %f ",parameters[1]));
1639 AliInfo(Form("median = %f ",parameters[2]));
1640 AliInfo(Form("(weighted) standard deviation with (weighted) mean = %f ",parameters[3]));
1641 AliInfo(Form("standard deviation with median = %f ",parameters[4]));
1646 //__________________________________________________________________________________________________________________
1648 Float_t* AliGRPPreprocessor::ProcessFloatAllMagnet(const TObjArray* array, Int_t indexDP, Bool_t &isZero)
1651 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1652 // used for L3 and Dipole magnets, using isZero flag to decide whther the magnet was OFF/ON
1653 // the flag is set according to the L3/Dipole current value
1654 // current threshold for L3 = 350 A (value provided by DCS)
1655 // current threshold for Dipole = 450 A (value provided by DCS)
1657 // parameters[0] = mean
1658 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1659 // parameters[2] = median
1660 // parameters[3] = standard deviation wrt mean
1661 // parameters[4] = standard deviation wrt median
1664 AliInfo(Form("indexDP = %d",indexDP));
1666 Int_t nCounts = array->GetEntries();
1667 for(Int_t i = 0; i < nCounts; i++) {
1668 AliDCSValue *v = (AliDCSValue *)array->At(i);
1669 if ((v->GetFloat() <= fminFloat) || (v->GetFloat() >= fmaxFloat)) {
1670 AliError(Form("Error! Float value found in DCS map at %d-th entry is OUT OF RANGE: value = %6.5e",i,v->GetFloat()));
1671 if (v->GetFloat() < fminFloat) AliInfo(Form("The value is smaller than %6.5e",fminFloat));
1672 if (v->GetFloat() > fmaxFloat) AliInfo(Form("The value is greater than %6.5e",fmaxFloat));
1675 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1676 AliDebug(2,Form("%d-th entry = %f",i,v->GetFloat()));
1677 if (indexDP == kL3Current && v->GetFloat() > 350 && isZero == kTRUE) isZero=kFALSE;
1678 if (indexDP == kDipoleCurrent && v->GetFloat() > 450 && isZero == kTRUE) isZero=kFALSE;
1681 AliError(Form("DCS values for the parameter outside the queried interval"));
1685 return ProcessFloatAll(array);
1689 //_______________________________________________________________
1691 Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array, Bool_t &change)
1694 // processing Boolean values
1697 Bool_t aDCSBool = kTRUE;
1699 AliDCSValue *v = 0x0;
1701 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1702 v = (AliDCSValue *)array->At(iCount);
1703 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
1704 AliError(Form("DCS values for the parameter outside the queried interval"));
1708 if (aDCSBool != v->GetBool()) {
1709 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1713 aDCSBool = v->GetBool(); // always keeping last value
1714 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
1717 Char_t caDCSBool = (Char_t) aDCSBool;
1722 //_______________________________________________________________
1724 Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
1727 // processing Int values, returning mean
1728 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1729 // are outside the queried time interval or their value is out of range
1732 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1733 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1734 if (timeStartString.IsNull() || timeStartString.IsNull()){
1735 if (timeStartString.IsNull()){
1736 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1738 else if (timeStartString.IsNull()){
1739 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1744 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1745 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1746 Float_t aDCSArrayMean = 0.0;
1748 Float_t valueBeforeSOR = 0;
1749 Float_t valueAfterEOR = 0;
1750 Int_t timestampBeforeSOR = -1;
1751 Int_t timestampAfterEOR = -1;
1752 Int_t ientrySOR = -1;
1753 Int_t ientryEOR = -1;
1754 Float_t* arrayValues = 0x0;
1755 Double_t* arrayWeights = 0x0;
1756 Int_t iCountsRun = 0;
1757 Int_t nCounts = array->GetEntries();
1759 for(Int_t i = 0; i < nCounts; i++) {
1760 AliDCSValue* v = (AliDCSValue *)array->At(i);
1761 if ((v->GetInt() < fminInt) || (v->GetInt() > fmaxInt)) {
1762 AliError(Form("Error! Int value found in DCS map at %d-th entry is OUT OF RANGE: value = %d",i, v->GetInt()));
1763 return AliGRPObject::GetInvalidFloat();
1765 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1766 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetInt(),v->GetTimeStamp()));
1768 // look for the last value before SOR and the first value before EOR
1769 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1770 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1771 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1772 valueBeforeSOR = (Float_t) v->GetInt();
1774 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1775 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1776 valueAfterEOR = (Float_t) v->GetInt();
1777 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1779 // check if there are DPs between DAQ_time_start and DAQ_time_end
1780 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1781 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1782 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1783 AliDebug(2,Form("entry between SOR and EOR"));
1788 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1792 if (timestampBeforeSOR == -1){
1793 AliWarning("No value found before SOR!");
1795 if (timestampAfterEOR == -1){
1796 AliWarning("No value found after EOR!");
1799 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1800 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1801 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1802 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1803 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1804 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1806 Int_t nentriesUsed = 0;
1807 if (iCountsRun > 1){
1808 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1809 AliDebug(2,"Calculating (weighted) Mean");
1810 arrayValues = new Float_t[iCountsRun];
1811 arrayWeights = new Double_t[iCountsRun];
1812 nentriesUsed = iCountsRun;
1813 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1814 AliDCSValue *v = (AliDCSValue *)array->At(i);
1815 Int_t timestamp2 = 0;
1817 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1818 timestamp2 = (Int_t)v1->GetTimeStamp();
1821 timestamp2 = timeEnd+1;
1823 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1824 arrayValues[i-ientrySOR] = (Float_t)v->GetInt();
1826 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1828 else if (iCountsRun == 1){
1829 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1831 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1832 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1833 arrayValues = new Float_t[2];
1834 arrayWeights = new Double_t[2];
1835 arrayValues[0] = valueBeforeSOR;
1836 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1837 arrayValues[1] = (Float_t)v->GetInt();
1838 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1839 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1840 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1841 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1844 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
1845 return AliGRPObject::GetInvalidFloat();
1848 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
1849 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
1850 if (timestampBeforeSOR == -1){
1851 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
1853 if (timestampAfterEOR == -1){
1854 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
1856 return AliGRPObject::GetInvalidFloat();
1859 AliWarning("Using last entry before SOR and first entry after EOR.");
1861 arrayValues = new Float_t[2];
1862 arrayWeights = new Double_t[2];
1863 arrayValues[0] = valueBeforeSOR;
1864 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
1865 arrayValues[1] = valueAfterEOR;
1866 arrayWeights[1] = 1.;
1867 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1868 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1869 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
1873 AliInfo(Form("mean = %f ", aDCSArrayMean));
1874 return aDCSArrayMean;
1877 //_______________________________________________________________
1879 Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
1882 // processing Int values, returning mean
1883 // AliGRPObject::GetInvalidFloat() is returned if any of the DCS values
1884 // are outside the queried time interval or their value is out of range
1887 TString timeStartString = (TString)GetRunParameter("DAQ_time_start");
1888 TString timeEndString = (TString)GetRunParameter("DAQ_time_end");
1889 if (timeStartString.IsNull() || timeStartString.IsNull()){
1890 if (timeStartString.IsNull()){
1891 AliError("DAQ_time_start not set in logbook! Setting statistical values for current DP to invalid");
1893 else if (timeStartString.IsNull()){
1894 AliError("DAQ_time_end not set in logbook! Setting statistical values for current DP to invalid");
1899 Int_t timeStart = (Int_t)(timeStartString.Atoi());
1900 Int_t timeEnd = (Int_t)(timeEndString.Atoi());
1901 Float_t aDCSArrayMean = 0.0;
1903 Float_t valueBeforeSOR = 0;
1904 Float_t valueAfterEOR = 0;
1905 Int_t timestampBeforeSOR = -1;
1906 Int_t timestampAfterEOR = -1;
1907 Int_t ientrySOR = -1;
1908 Int_t ientryEOR = -1;
1909 Float_t* arrayValues = 0x0;
1910 Double_t* arrayWeights = 0x0;
1911 Int_t iCountsRun = 0;
1912 Int_t nCounts = array->GetEntries();
1914 for(Int_t i = 0; i < nCounts; i++) {
1915 AliDCSValue* v = (AliDCSValue *)array->At(i);
1916 if ((v->GetUInt() < fminUInt) || (v->GetUInt() > fmaxUInt)) {
1917 AliError(Form("Error! UInt value found in DCS map at %d-th entry is OUT OF RANGE: value = %u",i,v->GetUInt()));
1918 return AliGRPObject::GetInvalidFloat();
1920 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
1921 AliDebug(2,Form("%d-th entry = %d at timestamp %i",i,v->GetUInt(),v->GetTimeStamp()));
1923 // look for the last value before SOR and the first value before EOR
1924 if (((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) && (Int_t)(v->GetTimeStamp()) < timeStart) {
1925 timestampBeforeSOR = (Int_t)(v->GetTimeStamp());
1926 AliDebug(2,Form("timestamp of last entry before SOR = %d, with DAQ_time_start = %d",timestampBeforeSOR,timeStart));
1927 valueBeforeSOR = (Float_t)v->GetUInt();
1929 else if ((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery() && (Int_t)(v->GetTimeStamp()) > timeEnd && timestampAfterEOR == -1){
1930 timestampAfterEOR = (Int_t)(v->GetTimeStamp());
1931 valueAfterEOR = (Float_t)v->GetUInt();
1932 AliDebug(2,Form("timestamp of first entry after EOR = %d, with DAQ_time_end = %d",timestampAfterEOR,timeEnd));
1934 // check if there are DPs between DAQ_time_start and DAQ_time_end
1935 if(((Int_t)(v->GetTimeStamp()) >= timeStart) &&((Int_t)(v->GetTimeStamp()) <= timeEnd)) {
1936 if (ientrySOR == -1) ientrySOR = i; // first entry after SOR
1937 if (ientryEOR < i) ientryEOR = i; // last entry before EOR
1938 AliDebug(2,Form("entry between SOR and EOR"));
1943 AliError(Form("DCS values for the parameter outside the queried interval: timestamp = %d",v->GetTimeStamp()));
1947 if (timestampBeforeSOR == -1){
1948 AliWarning("No value found before SOR!");
1950 if (timestampAfterEOR == -1){
1951 AliWarning("No value found after EOR!");
1954 AliDebug(2,Form("Number of valid entries (within query interval) = %i, starting from %i entries",iCounts,nCounts));
1955 AliDebug(2,Form("Last value before DAQ_time_start (SOR) = %f at timestamp = %d",valueBeforeSOR,timestampBeforeSOR));
1956 AliDebug(2,Form("First value after DAQ_time_end (EOR) = %f at timestamp = %d",valueAfterEOR,timestampAfterEOR));
1957 AliInfo(Form("Found %d entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)",iCountsRun));
1958 AliDebug(2,Form("Index of first entry after DAQ_time_start (SOR) = %d ",ientrySOR));
1959 AliDebug(2,Form("Index of first entry before DAQ_time_end (EOR) = %d ",ientryEOR));
1961 Int_t nentriesUsed = 0;
1962 if (iCountsRun > 1){
1963 AliInfo("Using entries between DAQ_time_start (SOR) and DAQ_time_end (EOR)");
1964 AliDebug(2,"Calculating (weighted) Mean");
1965 arrayValues = new Float_t[iCountsRun];
1966 arrayWeights = new Double_t[iCountsRun];
1967 nentriesUsed = iCountsRun;
1968 for (Int_t i = ientrySOR; i <= ientryEOR; i++){
1969 AliDCSValue *v = (AliDCSValue *)array->At(i);
1970 Int_t timestamp2 = 0;
1972 AliDCSValue *v1 = (AliDCSValue *)array->At(i+1);
1973 timestamp2 = (Int_t)v1->GetTimeStamp();
1976 timestamp2 = timeEnd+1;
1978 arrayWeights[i-ientrySOR] = (Double_t)(timestamp2 - (Int_t)v->GetTimeStamp());
1979 arrayValues[i-ientrySOR] = (Float_t)v->GetUInt();
1981 aDCSArrayMean = TMath::Mean(iCountsRun,arrayValues,arrayWeights);
1983 else if (iCountsRun == 1){
1984 AliDCSValue* v = (AliDCSValue *)array->At(ientrySOR);
1986 if (timestampBeforeSOR != -1 && timestampBeforeSOR != (Int_t)v->GetTimeStamp()){
1987 AliWarning("Using single entry between DAQ_time_start (SOR) and DAQ_time_end (EOR) and last entry before SOR.");
1988 arrayValues = new Float_t[2];
1989 arrayWeights = new Double_t[2];
1990 arrayValues[0] = valueBeforeSOR;
1991 arrayWeights[0] = (Double_t)((Int_t)v->GetTimeStamp()-timestampBeforeSOR);
1992 arrayValues[1] = (Float_t)v->GetUInt();
1993 arrayWeights[1] = (Double_t)(timeEnd+1-(Int_t)v->GetTimeStamp());
1994 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
1995 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
1996 aDCSArrayMean = TMath::Mean(2,arrayValues,arrayWeights);
1999 AliError("Cannot calculate mean - only one value collected during the run, but no value before with which to calculate the statistical quantities");
2000 return AliGRPObject::GetInvalidFloat();
2003 else { // iCountsRun == 0, using the point immediately before SOR and the one immediately after EOR
2004 if (timestampBeforeSOR == -1 || timestampAfterEOR == -1){
2005 if (timestampBeforeSOR == -1){
2006 AliError("Cannot calculate mean - no points during the run collected, and point before SOR missing");
2008 if (timestampAfterEOR == -1){
2009 AliError("Cannot calculate maen - no points during the run collected, and point after EOR missing");
2011 return AliGRPObject::GetInvalidFloat();
2014 AliWarning("Using last entry before SOR and first entry after EOR.");
2016 arrayValues = new Float_t[2];
2017 arrayWeights = new Double_t[2];
2018 arrayValues[0] = valueBeforeSOR;
2019 arrayWeights[0] = (Double_t)(timestampAfterEOR - timestampBeforeSOR);
2020 arrayValues[1] = valueAfterEOR;
2021 arrayWeights[1] = 1.;
2022 AliDebug(2,Form("value0 = %f, with weight = %f",arrayValues[0],arrayWeights[0]));
2023 AliDebug(2,Form("value1 = %f, with weight = %f",arrayValues[1],arrayWeights[1]));
2024 aDCSArrayMean = TMath::Mean(1,arrayValues,arrayWeights);
2028 AliInfo(Form("mean = %f ",aDCSArrayMean));
2029 return aDCSArrayMean;
2034 //_______________________________________________________________
2036 AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
2038 // extract DCS pressure maps. Perform fits to save space
2040 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
2042 AliDebug(2,Form("Map has %d entries",map->GetEntries()));
2043 fPressure->MakeSplineFit(map);
2044 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
2045 if (fitFraction > kFitFraction ) {
2046 AliInfo(Form("Pressure values extracted, %d fits performed for %d sensors.", fPressure->NumFits(),fPressure->NumSensors()));
2048 AliInfo("Too few pressure maps fitted!!!");
2051 AliInfo("no atmospheric pressure map extracted!!!");
2060 //_______________________________________________________________
2061 Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* dbHost, Int_t dbPort, const char* dbName, const char* user, const char* password, const char *cdbRoot, TString &gdc)
2064 // Retrieves logbook and trigger information from the online logbook
2065 // This information is needed for prompt reconstruction
2069 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
2073 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
2074 // 0 on success and no run was found
2075 // negative on error
2077 // This function is NOT called during the preprocessor run in the Shuttle!
2085 AliCDBManager* cdb = AliCDBManager::Instance();
2086 cdb->SetDefaultStorage(cdbRoot);
2089 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
2093 Printf("ERROR: Could not connect to DAQ LB");
2099 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
2100 TSQLResult* result = server->Query(sqlQuery);
2103 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2107 if (result->GetRowCount() == 0)
2109 Printf("ERROR: Run %d not found", run);
2114 TSQLRow* row = result->Next();
2117 Printf("ERROR: Could not receive data from run %d", run);
2122 TString timeStartString(row->GetField(0));
2123 TString runType(row->GetField(1));
2124 TString detectorMaskString(row->GetField(2));
2125 TString l3CurrentString(row->GetField(3));
2126 TString dipoleCurrentString(row->GetField(4));
2127 time_t timeStart = (time_t)(timeStartString.Atoi());
2128 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
2129 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
2130 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
2131 Char_t l3Polarity = (l3CurrentString.Atof() < 0) ? 1 : 0;
2132 Char_t dipolePolarity = (dipoleCurrentString.Atof() < 0) ? 1 : 0;
2134 AliGRPObject * grpObj = new AliGRPObject();
2135 grpObj->SetTimeStart(timeStart);
2136 grpObj->SetRunType((TString)(row->GetField(1)));
2137 grpObj->SetDetectorMask(detectorMask);
2138 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
2139 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
2140 grpObj->SetL3Polarity(l3Polarity);
2141 grpObj->SetDipolePolarity(dipolePolarity);
2142 grpObj->SetPolarityConventionLHC(); // after the dipole cables swap we comply with LHC convention
2150 Printf("Storing GRP/GRP/Data object with the following content");
2153 AliCDBMetaData metadata;
2154 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
2155 metadata.SetComment("GRP Output parameters received during online running");
2157 AliCDBId id("GRP/GRP/Data", run, run);
2158 Bool_t success = cdb->Put(grpObj, id, &metadata);
2164 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
2168 // Receive trigger information
2169 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
2170 result = server->Query(sqlQuery);
2173 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2177 if (result->GetRowCount() == 0)
2179 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
2184 row = result->Next();
2187 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
2192 TString triggerConfig(row->GetField(0));
2200 Printf("Found trigger configuration: %s", triggerConfig.Data());
2202 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
2205 Printf("ERROR: Could not create CTP configuration object");
2209 metadata.SetComment("CTP run configuration received during online running");
2211 AliCDBId id2("GRP/CTP/Config", run, run);
2212 success = cdb->Put(runcfg, id2, &metadata);
2219 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
2224 // Receive list of GDCs for this run
2225 sqlQuery.Form("SELECT GDC FROM logbook_stats_GDC WHERE run = %d", run);
2226 result = server->Query(sqlQuery);
2229 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2233 if (result->GetRowCount() == 0)
2235 Printf("ERROR: Run %d not found in logbook_stats_GDC", run);
2241 for (Int_t iGDC = 0; iGDC < result->GetRowCount(); iGDC++) {
2242 row = result->Next();
2245 Printf("ERROR: Could not receive logbook_stats_GDC data from run %d", run);
2249 gdc += row->GetField(0);
2259 Printf("Found GDC: %s", gdc.Data());
2261 // get last run with same run type that was already processed by the SHUTTLE
2263 sqlQuery.Form("SELECT max(logbook.run) FROM logbook LEFT JOIN logbook_shuttle ON logbook_shuttle.run = logbook.run WHERE run_type = '%s' AND shuttle_done = 1", runType.Data());
2264 result = server->Query(sqlQuery);
2267 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
2271 if (result->GetRowCount() == 0)
2273 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
2278 row = result->Next();
2281 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
2286 TString lastRunStr(row->GetField(0));
2287 Int_t lastRun = lastRunStr.Atoi();
2289 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);