]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliGRPPreprocessor.cxx
Changing number of missing DCS DPs (now, only LHCState, LHCIntensity, BeamIntensity...
[u/mrichter/AliRoot.git] / STEER / AliGRPPreprocessor.cxx
CommitLineData
33c82fbf 1/**************************************************************************
3dedb44a 2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
7ca4655f 16/* $Id$ */
17
3dedb44a 18//-------------------------------------------------------------------------
19// Class AliGRPPreprocessor
20// Global Run Parameters (GRP) preprocessor
21// Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
e7a6790f 22// Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN
3dedb44a 23//-------------------------------------------------------------------------
24
836d8b4f 25#include <TChain.h>
7ca4655f 26#include <TList.h>
27#include <TMap.h>
28#include <TObjString.h>
44e45fac 29#include <TGraph.h>
7ca4655f 30
3dedb44a 31#include "AliGRPPreprocessor.h"
44e45fac 32#include "AliGRPObject.h"
33#include "AliDCSSensor.h"
34#include "AliSplineFit.h"
17984b61 35#include "AliDCSSensorArray.h"
3dedb44a 36
48b1b444 37#include "AliTriggerConfiguration.h"
38#include "AliTriggerRunScalers.h"
39
3dedb44a 40#include "AliCDBMetaData.h"
41#include "AliLog.h"
42
3dedb44a 43class AliDCSValue;
44class AliShuttleInterface;
45
1e27bb6b 46// needed for ReceivePromptRecoParameters
39e3007b 47
1e27bb6b 48#include <TSQLServer.h>
49#include <TSQLResult.h>
50#include <TSQLRow.h>
51#include <AliCDBManager.h>
52#include <AliCDBMetaData.h>
53#include <AliCDBId.h>
54#include <AliTriggerConfiguration.h>
55
17984b61 56const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
57
3dedb44a 58ClassImp(AliGRPPreprocessor)
59
17984b61 60//_______________________________________________________________
44e45fac 61
e7a6790f 62 const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook
44e45fac 63 const Int_t AliGRPPreprocessor::fgknDCSDP = 50; // number of dcs dps
39e3007b 64 const Int_t AliGRPPreprocessor::fgknDCSDPHallProbes = 40; // number of dcs dps
e7a6790f 65 const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
1676baf1 66 "LHCState", // missing in DCS
e7a6790f 67 "L3Polarity",
68 "DipolePolarity",
1676baf1 69 "LHCLuminosity", // missing in DCS
70 "BeamIntensity", // missing in DCS
e7a6790f 71 "L3Current",
72 "DipoleCurrent",
44e45fac 73 "L3_BSF17_H1",
74 "L3_BSF17_H2",
75 "L3_BSF17_H3",
76 "L3_BSF17_Temperature",
77 "L3_BSF4_H1",
78 "L3_BSF4_H2",
79 "L3_BSF4_H3",
80 "L3_BSF4_Temperature",
81 "L3_BKF17_H1",
82 "L3_BKF17_H2",
83 "L3_BKF17_H3",
84 "L3_BKF17_Temperature",
85 "L3_BKF4_H1",
86 "L3_BKF4_H2",
87 "L3_BKF4_H3",
88 "L3_BKF4_Temperature",
89 "L3_BSF13_H1",
90 "L3_BSF13_H2",
91 "L3_BSF13_H3",
92 "L3_BSF13_Temperature",
93 "L3_BSF8_H1",
94 "L3_BSF8_H2",
95 "L3_BSF8_H3",
96 "L3_BSF8_Temperature",
97 "L3_BKF13_H1",
98 "L3_BKF13_H2",
99 "L3_BKF13_H3",
100 "L3_BKF13_Temperature",
101 "L3_BKF8_H1",
102 "L3_BKF8_H2",
103 "L3_BKF8_H3",
104 "L3_BKF8_Temperature",
105 "Dipole_Inside_H1",
106 "Dipole_Inside_H2",
107 "Dipole_Inside_H3",
108 "Dipole_Inside_Temperature",
109 "Dipole_Outside_H1",
110 "Dipole_Outside_H2",
111 "Dipole_Outside_H3",
112 "Dipole_Outside_Temperature",
e7a6790f 113 "CavernTemperature",
114 "CavernAtmosPressure",
6240e6a4 115 "SurfaceAtmosPressure"
e7a6790f 116 };
44e45fac 117
39e3007b 118 const char* AliGRPPreprocessor::fgkDCSDataPointsHallProbes[AliGRPPreprocessor::fgknDCSDPHallProbes] = {
44e45fac 119 "L3_BSF17_H1",
120 "L3_BSF17_H2",
121 "L3_BSF17_H3",
122 "L3_BSF17_Temperature",
123 "L3_BSF4_H1",
124 "L3_BSF4_H2",
125 "L3_BSF4_H3",
126 "L3_BSF4_Temperature",
127 "L3_BKF17_H1",
128 "L3_BKF17_H2",
129 "L3_BKF17_H3",
130 "L3_BKF17_Temperature",
131 "L3_BKF4_H1",
132 "L3_BKF4_H2",
133 "L3_BKF4_H3",
134 "L3_BKF4_Temperature",
135 "L3_BSF13_H1",
136 "L3_BSF13_H2",
137 "L3_BSF13_H3",
138 "L3_BSF13_Temperature",
139 "L3_BSF8_H1",
140 "L3_BSF8_H2",
141 "L3_BSF8_H3",
142 "L3_BSF8_Temperature",
143 "L3_BKF13_H1",
144 "L3_BKF13_H2",
145 "L3_BKF13_H3",
146 "L3_BKF13_Temperature",
147 "L3_BKF8_H1",
148 "L3_BKF8_H2",
149 "L3_BKF8_H3",
150 "L3_BKF8_Temperature",
151 "Dipole_Inside_H1",
152 "Dipole_Inside_H2",
153 "Dipole_Inside_H3",
154 "Dipole_Inside_Temperature",
155 "Dipole_Outside_H1",
156 "Dipole_Outside_H2",
157 "Dipole_Outside_H3",
158 "Dipole_Outside_Temperature",
159 };
e7a6790f 160
44e45fac 161 const Short_t kSensors = 48; // start index position of sensor in DCS DPs
162 const Short_t kNumSensors = 2; // Number of sensors in DCS DPs
e7a6790f 163
164 const char* AliGRPPreprocessor::fgkLHCState[20] = {
165 "P", "PREPARE",
166 "J", "PREINJECTION",
167 "I", "INJECTION",
168 "F", "FILLING",
169 "A", "ADJUST",
170 "U", "UNSTABLE BEAMS",
171 "S", "STABLE BEAMS",
172 "D", "BEAM DUMP",
173 "R", "RECOVER",
174 "C", "PRECYCLE"
175 };
176
177 const char* kppError[] = {
178 "",
179 "(DAQ logbook ERROR)",
180 "(DAQ FXS ERROR)",
181 "(DCS FXS ERROR)",
7e1a6c0b 182 "(DCS data points ERROR)",
183 "(Trigger Configuration ERROR)"
e7a6790f 184 };
17984b61 185
3dedb44a 186//_______________________________________________________________
44e45fac 187
3dedb44a 188AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle):
08a446c2 189 AliPreprocessor("GRP",shuttle), fPressure(0)
e7a6790f 190{
44e45fac 191 // constructor - shuttle must be instantiated!
ad103e84 192
7eaa854b 193 AddRunType("COSMIC");
194 AddRunType("LASER");
44e45fac 195 AddRunType("PHYSICS");
c2ad5069 196 AddRunType("CALIBRATION_BC");
197 AddRunType("CALIBRATION_CENTRAL");
198 AddRunType("CALIBRATION_EMD");
199 AddRunType("CALIBRATION_MB");
200 AddRunType("CALIBRATION_SEMICENTRAL");
69bf9b19 201 AddRunType("CALIBRATION");
202 AddRunType("PEDESTAL");
7be24dea 203 AddRunType("STANDALONE");
204 AddRunType("GAIN");
3dedb44a 205}
206
207//_______________________________________________________________
44e45fac 208
e7a6790f 209AliGRPPreprocessor::~AliGRPPreprocessor()
210{
44e45fac 211 //destructor
212
213 delete fPressure;
3dedb44a 214}
215
216//_______________________________________________________________
44e45fac 217
e7a6790f 218void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
219{
3dedb44a 220 // Initialize preprocessor
5a5052e5 221
222 AliPreprocessor::Initialize(run, startTime, endTime);
e7a6790f 223
17984b61 224 AliInfo("Initialization of the GRP preprocessor.");
6240e6a4 225 TClonesArray * array = new TClonesArray("AliDCSSensor",kNumSensors);
226 for(Int_t j = 0; j < kNumSensors; j++) {
17984b61 227 AliDCSSensor * sens = new ((*array)[j])AliDCSSensor;
e7a6790f 228 sens->SetStringID(fgkDCSDataPoints[j+kSensors]);
17984b61 229 }
230 AliInfo(Form("Pressure Entries: %d",array->GetEntries()));
231
563f2a84 232 // fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array);
233 fPressure = new AliDCSSensorArray(GetStartTimeDCSQuery(), GetEndTimeDCSQuery(), array);
3dedb44a 234}
235
236//_______________________________________________________________
44e45fac 237
e7a6790f 238UInt_t AliGRPPreprocessor::Process(TMap* valueMap)
239{
44e45fac 240 // process data retrieved by the Shuttle
241
242 AliGRPObject *grpobj = new AliGRPObject(); // object to store data
243
244 //=================//
245 // DAQ logbook //
246 //=================//
247 UInt_t error = 0;
248
249 grpobj = ProcessDaqLB();
250
251 //=================//
252 // DAQ FXS //
253 //=================//
254 UInt_t iDaqFxs = ProcessDaqFxs();
255 if( iDaqFxs == 0 ) {
256 Log(Form("DAQ FXS, successful!"));
257 } else {
258 Log(Form("DAQ FXS, could not store run raw tag file!!!"));
259 error |= 2;
260 }
261
262 //=================//
263 // DCS FXS //
264 //=================//
265 UInt_t iDcsFxs = ProcessDcsFxs();
266 if( iDcsFxs == 0 ) {
267 Log(Form("DCS FXS, successful!"));
268 } else {
269 Log(Form("DCS FXS, Could not store CTP run configuration and scalers!!!"));
270 error |= 4;
271 }
272
273 //=================//
274 // DCS data points //
275 //=================//
7e6f5523 276 Log(Form("Starting DCS Query at %d and finishing at %d",GetStartTimeDCSQuery(),GetEndTimeDCSQuery()));
44e45fac 277 Int_t entries = ProcessDcsDPs( valueMap, grpobj );
7e6f5523 278 Log(Form("entries found = %d",entries));
24c16c5d 279 if( entries < fgknDCSDP-4 ) { // FIXME (!= ) LHState, LHCLuminosity, BeamIntensity, LH3_BSF4_H3 are not working yet...
44e45fac 280 Log(Form("Problem with the DCS data points!!!"));
281 error |= 8;
282 } else Log(Form("DCS data points, successful!"));
283
284 //=======================//
285 // Trigger Configuration //
286 //=======================//
287 // either from DAQ logbook.....
288 const char * triggerConf = GetTriggerConfiguration();
289 if (triggerConf!= NULL) {
290 Log("Found trigger configuration in DAQ logbook");
291 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf);
292 if (!runcfg) {
293 Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!");
294 error |= 16;
295 }
296 else {
297 TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun);
298 runcfg->SetTitle(titleCTPcfg);
299 AliCDBMetaData metaData;
300 metaData.SetBeamPeriod(0);
301 metaData.SetResponsible("Roman Lietava");
302 metaData.SetComment("CTP run configuration from DAQ logbook");
303 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
304 Log("Unable to store the CTP run configuration object to OCDB!");
305 error |= 16;
306 }
307 }
308 }
309 /* the DCS should not been used any more to access this stuff!!!
310 // ...or from DCS FXS
311 else{
312 Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS...");
313 TString runcfgfile = GetFile(kDCS, "CTP_runconfig", "");
314 if (runcfgfile.IsNull()) {
315 Log("No CTP runconfig files has been found in DCS FXS!");
316 error |= 16;
317 }
318 else {
319 Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data()));
320 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile);
321 if (!runcfg) {
322 Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!");
323 error |= 16;;
324 }
325 else {
326 TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun);
327 runcfg->SetTitle(titleCTPcfg);
328 AliCDBMetaData metaData;
329 metaData.SetBeamPeriod(0);
330 metaData.SetResponsible("Roman Lietava");
331 metaData.SetComment("CTP run configuration from DCS FXS");
332 if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) {
333 Log("Unable to store the CTP run configuration object to OCDB!");
334 error |= 16;
335 }
336 }
337 }
338 }
339 */
340 AliCDBMetaData md;
341 md.SetResponsible("Ernesto Lopez Torres");
342 md.SetComment("Output parameters from the GRP preprocessor.");
343
344 Bool_t result = kTRUE;
345 Log("Before storing");
346 result = Store("GRP", "Data", grpobj, &md);
347 delete grpobj;
348
349 if (result && !error ) {
350 Log("GRP Preprocessor Success");
351 return 0;
352 } else {
353 Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s",
354 kppError[(error&1)?1:0],
355 kppError[(error&2)?2:0],
356 kppError[(error&4)?3:0],
357 kppError[(error&8)?4:0],
358 kppError[(error&16)?5:0]
359 ));
360 return error;
361 }
17984b61 362}
363
17984b61 364//_______________________________________________________________
17984b61 365
44e45fac 366AliGRPObject* AliGRPPreprocessor::ProcessDaqLB()
367{
368 //Getting the DAQ lb information
369
370 time_t timeStart = (time_t)(((TString)GetRunParameter("DAQ_time_start")).Atoi());
371 time_t timeEnd = (time_t)(((TString)GetRunParameter("DAQ_time_end")).Atoi());
372 Float_t beamEnergy = (Float_t)(((TString)GetRunParameter("beamEnergy")).Atof());
373 TString beamType = (TString)GetRunParameter("beamType");
374 Char_t numberOfDetectors = (Char_t)(((TString)GetRunParameter("numberOfDetectors")).Atoi());
375 UInt_t detectorMask= (UInt_t)(((TString)GetRunParameter("detectorMask")).Atoi());
376 TString lhcPeriod = (TString)GetRunParameter("LHCperiod");
377 TString runType = (TString)GetRunType();
378
379 AliGRPObject* grpObj = new AliGRPObject();
380
381 if (timeStart != 0){
382 grpObj->SetTimeStart(timeStart);
383 Log(Form("Start time for run %d: %d",fRun, (Int_t)timeStart));
384 }
385 else {
386 Log(Form("Start time not put in logbook, setting to invalid in GRP entry!"));
387 }
388
389 if (timeEnd != 0){
390 grpObj->SetTimeEnd(timeEnd);
391 Log(Form("End time for run %d: %i",fRun, (Int_t)timeEnd));
392 }
393 else {
394 Log(Form("End time not put in logbook, setting to invalid in GRP entry!"));
395 }
396
397 if (beamEnergy != 0){
398 grpObj->SetBeamEnergy(beamEnergy);
399 Log(Form("Beam Energy for run %d: %f",fRun, beamEnergy));
400 }
401 else {
402 Log(Form("Beam Energy not put in logbook, setting to invalid in GRP entry!"));
403 }
404
405 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
406
407 if (beamType.Length() != 0){
408 grpObj->SetBeamType(beamType);
409 Log(Form("Beam Type for run %d: %s",fRun, beamType.Data()));
410 }
411 else {
412 Log(Form("Beam Type not put in logbook, setting to invalid in GRP entry!"));
413 }
414
415 if (numberOfDetectors != 0){
416 grpObj->SetNumberOfDetectors(numberOfDetectors);
417 Log(Form("Number Of Detectors for run %d: %d",fRun, (Int_t)numberOfDetectors));
418 }
419 else {
420 Log(Form("Number Of Detectors not put in logbook, setting to invalid in GRP entry!"));
421 }
422
423 if (detectorMask != 0){
424 grpObj->SetDetectorMask(detectorMask);
425 Log(Form("Detector Mask for run %d: %d",fRun, detectorMask));
426 }
427 else {
428 Log(Form("Detector Mask not put in logbook, setting to invalid in GRP entry!"));
429 }
430
431 if (lhcPeriod.Length() != 0) {
432 grpObj->SetLHCPeriod(lhcPeriod);
433 Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod.Data()));
434 } else {
435 Log(Form("LHCperiod not put in logbook, setting to invalid in GRP entry!"));
436 }
437 if (runType.Length() != 0) {
438 grpObj->SetRunType(runType);
439 Log(Form("Run Type (DAQ) for run %d: %s",fRun, runType.Data()));
440 } else {
441 Log(Form("Run Type not put in logbook, setting to invalid in GRP entry!"));
442 }
443
444 return grpObj;
445}
17984b61 446
44e45fac 447//_______________________________________________________________
17984b61 448
44e45fac 449UInt_t AliGRPPreprocessor::ProcessDaqFxs()
450{
451 //======DAQ FXS======//
452
453 TList* list = GetFileSources(kDAQ);
454 if (!list) {
455 Log("No raw data tag list: connection problems with DAQ FXS logbook!");
456 return 1;
457 }
458
459 if (list->GetEntries() == 0) {
460 Log("no raw data tags in this run: nothing to merge!");
461 delete list; list=0;
462 return 0;
463 }
464
465 TChain *fRawTagChain = new TChain("T");
466 Int_t nFiles=0;
467 TIterator* iter = list->MakeIterator();
468 TObject* obj = 0;
469 while ((obj = iter->Next())) {
470 TObjString* objStr = dynamic_cast<TObjString*> (obj);
471 if (objStr) {
472 Log(Form("Found source %s", objStr->String().Data()));
473 TList* list2 = GetFileIDs(kDAQ, objStr->String());
474 if (!list2) {
475 Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!");
476 delete fRawTagChain; fRawTagChain=0;
477 return 1;
478 }
479 Log(Form("Number of ids: %d",list2->GetEntries()));
480 for(Int_t i = 0; i < list2->GetEntries(); i++) {
481 TObjString *idStr = (TObjString *)list2->At(i);
482 TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data());
483 if (fileName.Length() > 0) {
484 Log(Form("Adding file in the chain: %s",fileName.Data()));
485 fRawTagChain->Add(fileName.Data());
486 nFiles++;
487 } else {
488 Log(Form("Could not retrieve file with id %s from source %s: "
489 "connection problems with DAQ FXS!",
490 idStr->String().Data(), objStr->String().Data()));
491 delete list; list=0;
492 delete list2; list2=0;
493 delete fRawTagChain; fRawTagChain=0;
494 return 2;
495 }
496 }
497 delete list2;
498 }
499 }
500
501 TString fRawDataFileName = "GRP_Merged.tag.root";
502 Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data()));
7e6f5523 503
44e45fac 504 if( fRawTagChain->Merge(fRawDataFileName) < 1 ) {
505 Log("Error merging raw data files!!!");
506 return 3;
507 }
7e6f5523 508
44e45fac 509 TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun);
510 Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data());
511
512 if (!result) {
513 Log("Problem storing raw data tags in local file!!!");
514 } else {
515 Log("Raw data tags merged successfully!!");
516 }
517
518 delete iter;
519 delete list;
520 delete fRawTagChain; fRawTagChain=0;
521
522 if (result == kFALSE) {
523 return 4;
524 }
525
526 return 0;
527
528}
17984b61 529
44e45fac 530//_______________________________________________________________
531UInt_t AliGRPPreprocessor::ProcessDcsFxs()
532{
39e3007b 533
534 // processing the info
535 // stored in the DCS FXS
536 // coming from the trigger
537
44e45fac 538 {
539 // Get the CTP counters information
540 TList* list = GetFileSources(kDCS,"CTP_xcounters");
541 if (!list) {
542 Log("No CTP counters file: connection problems with DAQ FXS logbook!");
543 return 1;
544 }
545
546 if (list->GetEntries() == 0) {
547 Log("No CTP counters file to be processed!");
548 return 1;
549 }
550 else {
551 TIter iter(list);
552 TObjString *source;
553 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
554 TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName());
555 if (countersfile.IsNull()) {
556 Log("No CTP counters files has been found: empty source!");
557 }
558 else {
559 Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data()));
560 AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile);
561 if (!scalers) {
562 Log("Bad CTP counters file! The corresponding CDB entry will not be filled!");
563 return 1;
564 }
565 else {
566 AliCDBMetaData metaData;
567 metaData.SetBeamPeriod(0);
568 metaData.SetResponsible("Roman Lietava");
569 metaData.SetComment("CTP scalers");
570 if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) {
571 Log("Unable to store the CTP scalers object to OCDB!");
572 }
573 }
574 }
575 }
576 }
577 delete list;
578 }
579
580 return 0;
581}
582//_______________________________________________________________
17984b61 583
44e45fac 584Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, AliGRPObject* grpObj)
585{
17984b61 586
44e45fac 587 //
588 // processing DCS DPs
589 //
590
26c1dff2 591 Int_t entries = 0; // counting the entries that are in the DCS DB, not taking care whether they have values or not
44e45fac 592 Int_t nLHCEntries = 0;
593 Int_t nL3Entries = 0;
594 Int_t nDipoleEntries = 0;
595 Int_t nEnvEntries = 0;
596 Int_t nHallProbesEntries = 0;
597 nLHCEntries = ProcessLHCDPs(valueMap, grpObj);
598 nL3Entries = ProcessL3DPs(valueMap, grpObj);
599 nDipoleEntries = ProcessDipoleDPs(valueMap, grpObj);
600 nEnvEntries = ProcessEnvDPs(valueMap, grpObj);
601 nHallProbesEntries = ProcessHPDPs(valueMap, grpObj);
602
603 entries = nLHCEntries + nL3Entries + nDipoleEntries + nEnvEntries + nHallProbesEntries;
604 return entries;
17984b61 605
17984b61 606}
607
608//_______________________________________________________________
29cc8704 609
39e3007b 610Int_t AliGRPPreprocessor::ProcessL3DPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 611{
39e3007b 612
613 // processing DPs
614 // related to
615 // L3 info
616
44e45fac 617 Int_t nL3Entries = 0;
618 TObjArray *array = 0x0;
619 Int_t indexDP = -1;
620
621 AliInfo(Form("==========L3Polarity==========="));
622 indexDP = kL3Polarity;
623 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
624 if(!array) {
625 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
626 }
627 else {
26c1dff2 628 if (array->GetEntries() == 0){
629 AliError(Form("No entries found in array! setting %s Polarity to invalid...",fgkDCSDataPoints[indexDP]));
630 }
631 else {
632 Char_t charDCS = ProcessBool(array);
633 grpObj->SetL3Polarity(charDCS);
634 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetL3Polarity())));
635 }
44e45fac 636 nL3Entries++;
637 }
638
639 if (array) array = 0x0;
640
641 AliInfo(Form("==========L3Current==========="));
642 indexDP = kL3Current;
643 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
644 if(!array) {
645 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
646 }
647 else {
26c1dff2 648 if (array->GetEntries() == 0){
649 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
650 }
651 else {
652 Float_t *floatDCS = ProcessFloatAll(array);
653 grpObj->SetL3Current(floatDCS);
654 delete floatDCS;
655 }
44e45fac 656 nL3Entries++;
657 }
658
659 return nL3Entries;
e7a6790f 660
44e45fac 661}
662//_______________________________________________________________
ff97356e 663
39e3007b 664Int_t AliGRPPreprocessor::ProcessDipoleDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 665{
39e3007b 666 // processing DPs
667 // related to
668 // the Dipole info
669
44e45fac 670 Int_t nDipoleEntries = 0;
671 TObjArray *array = 0x0;
672 Int_t indexDP = -1;
673
674 AliInfo(Form("==========DipolePolarity==========="));
675 indexDP = kDipolePolarity;
44e45fac 676 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
44e45fac 677 if(!array) {
678 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
679 }
680 else {
26c1dff2 681 if (array->GetEntries() == 0){
682 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
683 }
684 else {
685 Char_t charDCS = ProcessBool(array);
686 grpObj->SetDipolePolarity(charDCS);
687 AliInfo(Form("%s set to %d",fgkDCSDataPoints[indexDP],(Int_t)(grpObj->GetDipolePolarity())));
688 }
44e45fac 689 nDipoleEntries++;
690 }
691
692 if (array) array = 0x0;
693
694 AliInfo(Form("==========DipoleCurrent==========="));
695 indexDP = kDipoleCurrent;
696 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
697 if(!array) {
698 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
699 }
700 else {
26c1dff2 701 if (array->GetEntries() == 0){
702 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
703 }
704 else {
705 Float_t *floatDCS = ProcessFloatAll(array);
706 grpObj->SetDipoleCurrent(floatDCS);
707 delete floatDCS;
708 }
44e45fac 709 nDipoleEntries++;
710 }
711
712 return nDipoleEntries;
e7a6790f 713
44e45fac 714}
715//_______________________________________________________________
e7a6790f 716
44e45fac 717Int_t AliGRPPreprocessor::ProcessEnvDPs(TMap* valueMap, AliGRPObject* grpObj)
718{
39e3007b 719 // processing DPs
720 // related to
721 // evironment conditions (temperature, pressure) info
722
44e45fac 723 Int_t nEnvEntries = 0;
724 TObjArray *array = 0x0;
725 Int_t indexDP = -1;
726
727 AliInfo(Form("==========CavernTemperature==========="));
728 indexDP = kCavernTemperature;
729 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
730 if(!array) {
731 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
732 }
733 else {
26c1dff2 734 if (array->GetEntries() == 0){
735 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
736 }
737 else {
738 Float_t *floatDCS = ProcessFloatAll(array);
739 grpObj->SetCavernTemperature(floatDCS);
740 delete floatDCS;
741 }
44e45fac 742 nEnvEntries++;
743 }
744
745 if (array) array = 0x0;
746
747 AliInfo(Form("==========AtmosPressures (Cavern + Surface)==========="));
748 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
749 dcsSensorArray->Print();
44e45fac 750 if( fPressure->NumFits()==0 ) {
751 Log("Problem with the pressure sensor values!!!");
752 }
753 else {
754 AliInfo(Form("==========CavernAtmosPressure==========="));
755 indexDP = kCavernAtmosPressure;
756 AliDCSSensor* sensorCavernP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
757 AliDebug(2,Form("sensorCavernP2 = %p", sensorCavernP2));
758 if( sensorCavernP2->GetFit() ) {
759 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
760 grpObj->SetCavernAtmosPressure(sensorCavernP2);
761 nEnvEntries++;
762 }
763 //if (sensorP2) delete sensorP2;
764 else {
765 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
766 }
767 AliInfo(Form("==========SurfaceAtmosPressure==========="));
768 indexDP = kSurfaceAtmosPressure;
769 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
770 AliDebug(2,Form("sensorP2 = %p", sensorP2));
771 if( sensorP2->GetFit() ) {
772 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
773 grpObj->SetSurfaceAtmosPressure(sensorP2);
774 nEnvEntries++;
775 }
776 //if (sensorP2) delete sensorP2;
777 else {
778 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
779 }
780
781 }
782
783 /* indexDP = kCavernAtmosPressure;
784 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
785 if(!array) {
786 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
787 }
788 else {
789 Float_t *floatDCS = ProcessFloatAll(array);
790 grpObj->SetCavernAtmosPressure(floatDCS);
791 delete floatDCS;
792 nEnvEntries++;
793 }
794
795
796 if (array) array = 0x0;
797
798 AliInfo(Form("==========SurfaceAtmosPressure==========="));
799 indexDP = kSurfaceAtmosPressure;
800 AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap);
801 dcsSensorArray->Print();
802 AliInfo(Form("fPressure = %p",fPressure));
803 AliInfo(Form("dcsSensorArray = %p",dcsSensorArray));
804 if( fPressure->NumFits()==0 ) {
805 Log("Problem with the pressure sensor values!!!");
806 }
807 else {
808 AliDCSSensor* sensorP2 = dcsSensorArray->GetSensor(fgkDCSDataPoints[indexDP]);
809 AliDebug(2,Form("sensorP2 = %p", sensorP2));
810 if( sensorP2->GetFit() ) {
811 Log(Form("<%s> for run %d: Sensor Fit found",fgkDCSDataPoints[indexDP], fRun));
812 grpObj->SetSurfaceAtmosPressure(sensorP2);
813 nEnvEntries++;
814 }
815 //if (sensorP2) delete sensorP2;
816 else {
817 Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[indexDP] ));
818 }
819
820 }
821 */
822
823 return nEnvEntries;
824}
825//_______________________________________________________________
e7a6790f 826
39e3007b 827Int_t AliGRPPreprocessor::ProcessHPDPs(const TMap* valueMap, AliGRPObject* grpObj)
44e45fac 828{
39e3007b 829 // processing DPs
830 // related to
831 // Hall Probes info
832
44e45fac 833 Int_t nHPEntries = 0;
834 TObjArray *array = 0x0;
835 Int_t indexDP = -1;
836
39e3007b 837 if (fgknDCSDPHallProbes != AliGRPObject::GetNumberOfHP()){
838 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()));
44e45fac 839 }
840 for (indexDP = 0; indexDP < AliGRPObject::GetNumberOfHP(); indexDP++){
841 AliInfo(Form("==========%s===========",AliGRPObject::GetHPDP(indexDP)));
842 array = (TObjArray *)valueMap->GetValue(AliGRPObject::GetHPDP(indexDP));
843 if(!array) {
844 Log(Form("%s not found in the map!!!",AliGRPObject::GetHPDP(indexDP)));
845 }
846 else {
26c1dff2 847 if (array->GetEntries() == 0){
848 AliError(Form("No entries found in array! setting %s to invalid...",AliGRPObject::GetHPDP(indexDP)));
849 }
850 else {
851 Float_t *floatDCS = ProcessFloatAll(array);
852 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]));
853 grpObj->SetHallProbes((AliGRPObject::DP_HallProbes)indexDP,floatDCS);
854 for (Int_t kk = 0 ; kk< 5; kk++){
855 AliDebug(2,Form("HallProbe[%d][%d]=%f",indexDP,kk,grpObj->GetHallProbes((AliGRPObject::DP_HallProbes)indexDP,(AliGRPObject::Stats)kk)));
856 }
857 delete floatDCS;
44e45fac 858 }
44e45fac 859 nHPEntries++;
860 }
861 }
862
7e6f5523 863 Log(Form("Hall Probes = %d ", nHPEntries));
864 return nHPEntries;
17984b61 865}
866
48b1b444 867//_______________________________________________________________
44e45fac 868
39e3007b 869Int_t AliGRPPreprocessor::ProcessLHCDPs(const TMap* valueMap, AliGRPObject* grpObj)
e7a6790f 870{
48b1b444 871
44e45fac 872 //
873 // processing of LHC related DCS DPs, i.e.:
874 // LHCState
875 // LHCLuminosity
876 // BeamIntensity
877 //
878
879 Int_t nLHCEntries = 0;
880 TObjArray *array = 0x0;
881 Int_t indexDP = -1;
882
883 AliInfo(Form("==========LHCState==========="));
884 indexDP = kLHCState;
885 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
886 if(!array) {
887 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
888 }
889 else {
26c1dff2 890 if (array->GetEntries() == 0){
891 AliError(Form("No entries found in array! setting %s to invalid...",fgkDCSDataPoints[indexDP]));
892 }
893 else {
894 TString stringDCS = ProcessChar(array);
895 if (stringDCS.Length()!=0) {
896 Bool_t found = kFALSE;
897 for( Int_t i=0; i<20; i+=2 ) {
898 if( stringDCS.CompareTo(fgkLHCState[i]) == 0 ) {
899 stringDCS = fgkLHCState[i+1];
900 found = kTRUE;
901 break;
902 }
44e45fac 903 }
26c1dff2 904 if (found){
905 Log(Form("<%s> for run %d: %s",fgkDCSDataPoints[indexDP],fRun, stringDCS.Data()));
906 grpObj->SetLHCState(stringDCS);
907 }
908 else{
909 Log(Form("%s values found not valid!",fgkDCSDataPoints[indexDP]));
910 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
911 }
44e45fac 912 }
26c1dff2 913 else {
914 Log(Form("%s not valid (null length), string set as invalid!",fgkDCSDataPoints[indexDP]));
44e45fac 915 grpObj->SetLHCState(AliGRPObject::GetInvalidString());
26c1dff2 916 }
44e45fac 917 }
44e45fac 918 nLHCEntries++;
919 }
920
921 if (array) array = 0x0;
922
923 AliInfo(Form("==========LHCLuminosity==========="));
924 indexDP = kLHCLuminosity;
925 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
926 if(!array) {
927 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
928 }
929 else {
26c1dff2 930 if (array->GetEntries() == 0){
931 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
932 }
933 else {
934 Float_t *floatDCS = ProcessFloatAll(array);
935 grpObj->SetLHCLuminosity(floatDCS);
936 delete floatDCS;
937 AliSplineFit* splfit = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
938 grpObj->SetLHCLuminositySplineFit(splfit);
939 // delete splfit;
940 }
44e45fac 941 nLHCEntries++;
942 }
943
944 if (array) array = 0x0;
945
946 AliInfo(Form("==========BeamIntensity==========="));
947 indexDP = kBeamIntensity;
948 array = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[indexDP]);
949 if(!array) {
950 Log(Form("%s not found in the map!!!",fgkDCSDataPoints[indexDP]));
951 }
952 else {
26c1dff2 953 if (array->GetEntries() == 0){
954 AliError(Form("No entries found in array! setting %s and its Spline Fit to invalid...",fgkDCSDataPoints[indexDP]));
955 }
956 else {
957 Float_t *floatDCS = ProcessFloatAll(array);
958 grpObj->SetBeamIntensity(floatDCS);
959 delete floatDCS;
960 AliSplineFit* splfit1 = GetSplineFit(array,fgkDCSDataPoints[indexDP]);
961 grpObj->SetBeamIntensitySplineFit(splfit1);
962 //delete splfit;
963 }
44e45fac 964 nLHCEntries++;
965 }
966
967 return nLHCEntries;
968}
969//_________________________________________________________________________
970
39e3007b 971AliSplineFit* AliGRPPreprocessor::GetSplineFit(const TObjArray *array, const TString& stringID){
972
973
974 //
975 // returning Spline Fit
976 //
44e45fac 977
978 Int_t entriesarray = array->GetEntries();
979 Float_t* value = new Float_t[entriesarray];
980 Float_t* time = new Float_t[entriesarray];
981 AliDCSValue* v = 0x0;
982 for (Int_t iarray = 0; iarray < entriesarray; iarray++){
983 v = (AliDCSValue*)array->At(iarray);
984 value[iarray] = v->GetFloat();
985 time[iarray] = v->GetTimeStamp();
986 AliInfo(Form("iarray = %d, value = %f, time = %f",iarray,value[iarray],time[iarray]));
987 }
988 TGraph* gr = new TGraph(entriesarray,value,time);
989 if (!gr ) {
990 AliWarning(Form("%s: no input graph to compute SplineFit",stringID.Data()));
991 return NULL;
992 }
993 AliSplineFit *fit = new AliSplineFit();
994 fit->SetMinPoints(10);
995 fit->InitKnots(gr,10,10,0.0);
996 fit->SplineFit(2);
997 fit->Cleanup();
998 if (!fit) {
999 AliWarning(Form("%s: no fit performed",stringID.Data()));
1000 return NULL;
1001 }
1002 return fit;
48b1b444 1003}
1004
44e45fac 1005//_________________________________________________________________________
1006
39e3007b 1007TString AliGRPPreprocessor::ProcessChar(const TObjArray *array)
e7a6790f 1008{
17984b61 1009
44e45fac 1010 //
1011 // processing char
1012 //
1013
1014 TString aDCSString="";
1015
1016 AliDCSValue *v = 0x0;
1017 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1018 v = (AliDCSValue *)array->At(iCount);
26c1dff2 1019 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 1020 AliError(Form("DCS values for the parameter outside the queried interval"));
1021 continue;
1022 }
1023 if (iCount > 0) {
7e6f5523 1024 if (aDCSString != v->GetChar())
44e45fac 1025 AliError(Form("DCS values for the parameter changed from %s to %c within the queried interval", aDCSString.Data(), (Char_t)v->GetChar()));
1026 }
1027 aDCSString = (TString)v->GetChar(); // keeping always last value in the array
1028 }
1029 return aDCSString;
1030}
e7a6790f 1031
44e45fac 1032//__________________________________________________________________________________________________________________
e7a6790f 1033
39e3007b 1034Float_t* AliGRPPreprocessor::ProcessFloatAll(const TObjArray* array)
44e45fac 1035{
1036 //
1037 // processing Float values using Mean, Median, Standard Deviation wrt Mean, Standar Deviation wrt Median
1038 //
1039 // parameters[0] = mean
1040 // parameters[1] = truncated mean (calculated excluding points outside +/- 3RMS from mean
1041 // parameters[2] = median
1042 // parameters[3] = standard deviation wrt mean
1043 // parameters[4] = standard deviation wrt median
1044 //
1045
5138cd05 1046 Float_t* parameters = new Float_t[5];
44e45fac 1047 Double_t aDCSArrayMean = 0; // Mean
1048 Double_t aDCSArrayTruncMean = 0;// Truncated Mean
1049 Double_t aDCSArrayMedian = 0; // Median
1050 Double_t aDCSArraySDMean = 0; // Standard Deviation wrt Mean
1051 Double_t aDCSArraySDMedian = 0; // Standard Deviation wrt Median
1052 Float_t aDCSArraySum = 0.0;
1053 Int_t iCounts = 0;
1054 Int_t iCounts1 = 0;
1055 Float_t temp = 0;
1056 Float_t temp1 = 0;
1057 Int_t nCounts = array->GetEntries();
1058 Float_t *tempArray = new Float_t[nCounts];
1059 for(Int_t i = 0; i < nCounts; i++) {
1060 AliDCSValue *v = (AliDCSValue *)array->At(i);
26c1dff2 1061 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
44e45fac 1062 aDCSArraySum += v->GetFloat();
1063 tempArray[i] = v->GetFloat();
1064 AliDebug(2,Form("%d-th entry = %f",i,tempArray[i]));
1065 iCounts += 1;
1066 }
1067 }
1068
26c1dff2 1069 AliDebug(2,Form("Using %i entries, starting from %i entries",iCounts,nCounts));
44e45fac 1070 if(iCounts != 0) {
26c1dff2 1071 aDCSArrayMean = TMath::Mean(iCounts,tempArray);
1072 aDCSArrayMedian = TMath::Median(iCounts,tempArray);
1073 aDCSArraySDMean = TMath::RMS(iCounts,tempArray);
1074 AliDebug(2,Form("SD = %f",aDCSArraySDMean));
44e45fac 1075 // computing standard deviation wrt median
1076 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1077 for (Int_t i = 0; i < iCounts; i++){
1078 AliDCSValue *v = (AliDCSValue *)array->At(i);
1079 AliDebug(2,Form("maximum = %f, minimum = %f", aDCSArrayMean+3*aDCSArraySDMean, aDCSArrayMean-3*aDCSArraySDMean));
1080 AliDebug(2,Form("%i-th entry = %f",i, v->GetFloat()));
c135d475 1081 if ((v->GetFloat()<=aDCSArrayMean+3*aDCSArraySDMean) && (v->GetFloat()>=aDCSArrayMean-3*aDCSArraySDMean)){
44e45fac 1082 temp1+=v->GetFloat();
1083 iCounts1++;
c135d475 1084 AliDebug(2,Form("temp1 = %f, iCounts1 = %i",temp1,iCounts1));
44e45fac 1085 }
1086 temp += (v->GetFloat()-aDCSArrayMedian)*(v->GetFloat()-aDCSArrayMedian);
1087 }
c135d475 1088 AliDebug(3,Form("temp before the ratio = %f, with %d counts", temp, iCounts));
44e45fac 1089 temp/=iCounts;
c135d475 1090 AliDebug(3,Form("temp after the ratio = %f", temp));
44e45fac 1091 if (temp>0) {
1092 aDCSArraySDMedian = TMath::Sqrt(temp);
1093 }
c135d475 1094 else if (temp==0) {
1095 AliInfo(Form("Radical = 0 in computing standard deviation wrt median! Setting it to zero...."));
1096 aDCSArraySDMedian = 0;
1097 }
44e45fac 1098 else{
c135d475 1099 AliError(Form("Radical < 0 in computing standard deviation! Setting it to invalid...."));
44e45fac 1100 aDCSArraySDMedian = AliGRPObject::GetInvalidFloat();
1101 }
1102 }
1103 else {
1104 aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1105 aDCSArrayMedian = AliGRPObject::GetInvalidFloat();
1106 aDCSArraySDMean = AliGRPObject::GetInvalidFloat();
1107 }
c135d475 1108 AliDebug(2,Form("iCounts1 = %d and temp1 = %f",iCounts1, temp1));
44e45fac 1109 if (iCounts1 > 0) {
1110 aDCSArrayTruncMean = temp1/iCounts1;
1111 }
1112 else{
1113 aDCSArrayTruncMean = AliGRPObject::GetInvalidFloat();
1114 }
1115
1116
1117
26c1dff2 1118 AliDebug(2,Form("mean within %d counts = %f ",iCounts,aDCSArrayMean));
1119 AliDebug(2,Form("truncated mean within %d counts = %f (%i values used)",iCounts,aDCSArrayTruncMean,iCounts1));
1120 AliDebug(2,Form("median within %d counts = %f ",iCounts,aDCSArrayMedian));
1121 AliDebug(2,Form("standard deviation with mean within %d counts = %f ",iCounts,aDCSArraySDMean));
1122 AliDebug(2,Form("standard deviation with median within %d counts = %f ",iCounts,aDCSArraySDMedian));
44e45fac 1123
1124 parameters[0] = aDCSArrayMean;
1125 parameters[1] = aDCSArrayTruncMean;
1126 parameters[2] = aDCSArrayMedian;
1127 parameters[3] = aDCSArraySDMean;
1128 parameters[4] = aDCSArraySDMedian;
1129
c135d475 1130 // 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]));
1131 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]));
44e45fac 1132
1133 return parameters;
1134}
125567f8 1135
e97cc90e 1136
44e45fac 1137//_______________________________________________________________
e97cc90e 1138
39e3007b 1139Char_t AliGRPPreprocessor::ProcessBool(const TObjArray* array)
44e45fac 1140{
1141 //
1142 // processing Boolean values
1143 //
1144
1145 Bool_t aDCSBool = kTRUE;
1146
1147 AliDCSValue *v = 0x0;
26c1dff2 1148
44e45fac 1149 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1150 v = (AliDCSValue *)array->At(iCount);
26c1dff2 1151 if (((Int_t)(v->GetTimeStamp()) < (Int_t)GetStartTimeDCSQuery()) || ((Int_t)(v->GetTimeStamp()) > (Int_t)GetEndTimeDCSQuery())) {
44e45fac 1152 AliError(Form("DCS values for the parameter outside the queried interval"));
1153 continue;
1154 }
1155 if (iCount > 0) {
7e6f5523 1156 if (aDCSBool != v->GetBool())
44e45fac 1157 AliError(Form("DCS values for the parameter changed from %d to %d within the queried interval", (UInt_t)aDCSBool, (UInt_t)v->GetBool()));
1158 }
1159 aDCSBool = v->GetBool(); // always keeping last value
26c1dff2 1160 AliDebug(2,Form("Bool = %d",(Int_t)aDCSBool));
44e45fac 1161 }
1162
26c1dff2 1163 Char_t caDCSBool = (Char_t) aDCSBool;
44e45fac 1164 return caDCSBool;
1165
1166}
e97cc90e 1167
44e45fac 1168//_______________________________________________________________
e97cc90e 1169
39e3007b 1170Float_t AliGRPPreprocessor::ProcessInt(const TObjArray* array)
44e45fac 1171{
1172 //
1173 // processing Int values, returning mean
1174 //
1175
1176 Float_t aDCSArraySum = 0.0;
1177 Float_t aDCSArrayMean = 0.0;
1178 Int_t iCounts = 0;
1179 AliDCSValue* v = 0x0;
1180
1181 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1182 v = (AliDCSValue *)array->At(iCount);
26c1dff2 1183 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
44e45fac 1184 aDCSArraySum += v->GetInt();
1185 iCounts += 1;
1186 }
1187 }
1188
1189 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1190 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1191
1192 return aDCSArrayMean;
e97cc90e 1193
44e45fac 1194}
1195//_______________________________________________________________
e7a6790f 1196
39e3007b 1197Float_t AliGRPPreprocessor::ProcessUInt(const TObjArray* array)
44e45fac 1198{
1199 //
1200 // processing Int values, returning mean
1201 //
1202
1203 Float_t aDCSArraySum = 0.0;
1204 Float_t aDCSArrayMean = 0.0;
1205 Int_t iCounts = 0;
1206 AliDCSValue* v = 0x0;
1207
1208 for(Int_t iCount = 0; iCount < array->GetEntries(); iCount++) {
1209 v = (AliDCSValue *)array->At(iCount);
26c1dff2 1210 if(((Int_t)(v->GetTimeStamp()) >= (Int_t)GetStartTimeDCSQuery()) &&((Int_t)(v->GetTimeStamp()) <= (Int_t)GetEndTimeDCSQuery())) {
44e45fac 1211 aDCSArraySum += v->GetUInt();
1212 iCounts += 1;
1213 }
1214 }
1215
1216 if(iCounts != 0) aDCSArrayMean = aDCSArraySum/iCounts;
1217 else aDCSArrayMean = AliGRPObject::GetInvalidFloat();
1218
1219 return aDCSArrayMean;
e7a6790f 1220
17984b61 1221}
125567f8 1222
44e45fac 1223
17984b61 1224//_______________________________________________________________
44e45fac 1225
3ba92a38 1226AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap)
e7a6790f 1227{
44e45fac 1228 // extract DCS pressure maps. Perform fits to save space
1229
44e45fac 1230 TMap *map = fPressure->ExtractDCS(dcsAliasMap);
1231 if (map) {
1232 fPressure->MakeSplineFit(map);
1233 Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors();
1234 if (fitFraction > kFitFraction ) {
1235 AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits()));
1236 } else {
1237 AliInfo("Too few pressure maps fitted!!!");
1238 }
1239 } else {
1240 AliInfo("no atmospheric pressure map extracted!!!");
1241 }
1242 delete map;
1243
1244 return fPressure;
17984b61 1245}
e97cc90e 1246
1e27bb6b 1247
1248
1249//_______________________________________________________________
3dfcd47d 1250Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* dbHost, Int_t dbPort, const char* dbName, const char* user, const char* password, const char *cdbRoot)
1e27bb6b 1251{
44e45fac 1252 //
1253 // Retrieves logbook and trigger information from the online logbook
1254 // This information is needed for prompt reconstruction
1255 //
1256 // Parameters are:
1257 // Run number
1258 // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable
1259 // cdbRoot
1260 //
1261 // returns:
1262 // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE
1263 // 0 on success and no run was found
1264 // negative on error
1265 //
1266 // This function is NOT called during the preprocessor run in the Shuttle!
1267 //
1268
1269 // defaults
1270 if (dbPort == 0)
1271 dbPort = 3306;
1272
1273 // CDB connection
1274 AliCDBManager* cdb = AliCDBManager::Instance();
1275 cdb->SetDefaultStorage(cdbRoot);
1276
1277 // SQL connection
1278 TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password);
1279
1280 if (!server)
1281 {
1282 Printf("ERROR: Could not connect to DAQ LB");
1283 return -1;
1284 }
1285
1286 // main logbook
1287 TString sqlQuery;
26c1dff2 1288 sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask, L3_magnetCurrent, Dipole_magnetCurrent FROM logbook WHERE run = %d", run);
44e45fac 1289 TSQLResult* result = server->Query(sqlQuery);
1290 if (!result)
1291 {
1292 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1293 return -2;
1294 }
1295
1296 if (result->GetRowCount() == 0)
1297 {
1298 Printf("ERROR: Run %d not found", run);
1299 delete result;
1300 return -3;
1301 }
1302
1303 TSQLRow* row = result->Next();
1304 if (!row)
1305 {
1306 Printf("ERROR: Could not receive data from run %d", run);
1307 delete result;
1308 return -4;
1309 }
1310
26c1dff2 1311 TString timeStartString(row->GetField(0));
44e45fac 1312 TString runType(row->GetField(1));
26c1dff2 1313 TString detectorMaskString(row->GetField(2));
1314 TString l3CurrentString(row->GetField(3));
1315 TString dipoleCurrentString(row->GetField(4));
1316 time_t timeStart = (time_t)(timeStartString.Atoi());
1317 UInt_t detectorMask = (UInt_t)(detectorMaskString.Atoi());
1318 Float_t l3Current = (Float_t)(TMath::Abs(l3CurrentString.Atof()));
1319 Float_t dipoleCurrent = (Float_t)(TMath::Abs(dipoleCurrentString.Atof()));
44e45fac 1320
26c1dff2 1321 AliGRPObject * grpObj = new AliGRPObject();
1322 grpObj->SetTimeStart(timeStart);
1323 grpObj->SetRunType((TString)(row->GetField(1)));
1324 grpObj->SetDetectorMask(detectorMask);
1325 grpObj->SetL3Current(l3Current,(AliGRPObject::Stats)0);
1326 grpObj->SetDipoleCurrent(dipoleCurrent,(AliGRPObject::Stats)0);
1327
44e45fac 1328 delete row;
1329 row = 0;
1330
1331 delete result;
1332 result = 0;
1333
1334 Printf("Storing GRP/GRP/Data object with the following content");
26c1dff2 1335 grpObj->Dump();
44e45fac 1336
1337 AliCDBMetaData metadata;
26c1dff2 1338 metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus & Chiara Zampolli");
44e45fac 1339 metadata.SetComment("GRP Output parameters received during online running");
1340
1341 AliCDBId id("GRP/GRP/Data", run, run);
26c1dff2 1342 Bool_t success = cdb->Put(grpObj, id, &metadata);
44e45fac 1343
26c1dff2 1344 delete grpObj;
44e45fac 1345
1346 if (!success)
1347 {
1348 Printf("ERROR: Could not store GRP/GRP/Data into OCDB");
1349 return -5;
1350 }
1351
1352 // Receive trigger information
1353 sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run);
1354 result = server->Query(sqlQuery);
1355 if (!result)
1356 {
1357 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1358 return -11;
1359 }
1360
1361 if (result->GetRowCount() == 0)
1362 {
1363 Printf("ERROR: Run %d not found in logbook_trigger_config", run);
1364 delete result;
1365 return -12;
1366 }
1367
1368 row = result->Next();
1369 if (!row)
1370 {
1371 Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run);
1372 delete result;
1373 return -13;
1374 }
1375
1376 TString triggerConfig(row->GetField(0));
1377
1378 delete row;
1379 row = 0;
1380
1381 delete result;
1382 result = 0;
1383
1384 Printf("Found trigger configuration: %s", triggerConfig.Data());
1385
1386 AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig);
1387 if (!runcfg)
1388 {
1389 Printf("ERROR: Could not create CTP configuration object");
1390 return -14;
1391 }
1392
1393 metadata.SetComment("CTP run configuration received during online running");
1394
1395 AliCDBId id2("GRP/CTP/Config", run, run);
1396 success = cdb->Put(runcfg, id2, &metadata);
1397
1398 delete runcfg;
1399 runcfg = 0;
1400
1401 if (!success)
1402 {
1403 Printf("ERROR: Could not store GRP/CTP/Config into OCDB");
1404 return -15;
1405 }
1406
1407 // get last run with same run type that was already processed by the SHUTTLE
1408
1409 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());
1410 result = server->Query(sqlQuery);
1411 if (!result)
1412 {
1413 Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data());
1414 return -21;
1415 }
1416
1417 if (result->GetRowCount() == 0)
1418 {
1419 Printf("ERROR: No result with query <%s>", sqlQuery.Data());
1420 delete result;
1421 return -22;
1422 }
1423
1424 row = result->Next();
1425 if (!row)
1426 {
1427 Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data());
1428 delete result;
1429 return -23;
1430 }
1431
1432 TString lastRunStr(row->GetField(0));
1433 Int_t lastRun = lastRunStr.Atoi();
1434
1435 Printf("Last run with same run type %s is %d", runType.Data(), lastRun);
1436
1437 delete row;
1438 row = 0;
1439
1440 delete result;
1441 result = 0;
1442
1443 server->Close();
1444 delete server;
1445 server = 0;
1446
1447 return lastRun;
1e27bb6b 1448}