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