]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
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 | ||
16 | /* $Id$ */ | |
17 | ||
18 | //------------------------------------------------------------------------- | |
19 | // Class AliGRPPreprocessor | |
20 | // Global Run Parameters (GRP) preprocessor | |
21 | // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch | |
22 | // Modified: Ernesto.Lopez.Torres@cern.ch CEADEN-CERN | |
23 | //------------------------------------------------------------------------- | |
24 | ||
25 | #include <TChain.h> | |
26 | #include <TList.h> | |
27 | #include <TMap.h> | |
28 | #include <TObjString.h> | |
29 | #include <TTimeStamp.h> | |
30 | #include <TSystem.h> | |
31 | #include <TFile.h> | |
32 | ||
33 | #include "AliGRPPreprocessor.h" | |
34 | #include "AliGRPDCS.h" | |
35 | #include "AliDCSSensorArray.h" | |
36 | ||
37 | #include "AliTriggerConfiguration.h" | |
38 | #include "AliTriggerRunScalers.h" | |
39 | ||
40 | #include "AliCDBMetaData.h" | |
41 | #include "AliLog.h" | |
42 | ||
43 | class AliDCSValue; | |
44 | class AliShuttleInterface; | |
45 | ||
46 | #include <TH1.h> | |
47 | ||
48 | // needed for ReceivePromptRecoParameters | |
49 | #include <TSQLServer.h> | |
50 | #include <TSQLResult.h> | |
51 | #include <TSQLRow.h> | |
52 | #include <AliCDBManager.h> | |
53 | #include <AliCDBMetaData.h> | |
54 | #include <AliCDBId.h> | |
55 | #include <AliTriggerConfiguration.h> | |
56 | ||
57 | const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required | |
58 | ||
59 | ClassImp(AliGRPPreprocessor) | |
60 | ||
61 | //_______________________________________________________________ | |
62 | const Int_t AliGRPPreprocessor::fgknDAQLbPar = 8; // num parameters in the logbook | |
63 | const Int_t AliGRPPreprocessor::fgknDCSDP = 11; // number of dcs dps | |
64 | const char* AliGRPPreprocessor::fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = { | |
65 | "LHCState", // missing in DCS | |
66 | "L3Polarity", | |
67 | "DipolePolarity", | |
68 | "LHCLuminosity", // missing in DCS | |
69 | "BeamIntensity", // missing in DCS | |
70 | "L3Current", | |
71 | "DipoleCurrent", | |
72 | "CavernTemperature", | |
73 | "CavernAtmosPressure", | |
74 | "gva_cr5AtmosphericPressure", // missing in DCS | |
75 | "gva_meyrinAtmosphericPressure" // missing in DCS | |
76 | }; | |
77 | ||
78 | const Short_t kSensors = 9; // start index position of sensor in DCS DPs | |
79 | ||
80 | const char* AliGRPPreprocessor::fgkLHCState[20] = { | |
81 | "P", "PREPARE", | |
82 | "J", "PREINJECTION", | |
83 | "I", "INJECTION", | |
84 | "F", "FILLING", | |
85 | "A", "ADJUST", | |
86 | "U", "UNSTABLE BEAMS", | |
87 | "S", "STABLE BEAMS", | |
88 | "D", "BEAM DUMP", | |
89 | "R", "RECOVER", | |
90 | "C", "PRECYCLE" | |
91 | }; | |
92 | ||
93 | const char* kppError[] = { | |
94 | "", | |
95 | "(DAQ logbook ERROR)", | |
96 | "(DAQ FXS ERROR)", | |
97 | "(DCS FXS ERROR)", | |
98 | "(DCS data points ERROR)", | |
99 | "(Trigger Configuration ERROR)" | |
100 | }; | |
101 | ||
102 | //_______________________________________________________________ | |
103 | AliGRPPreprocessor::AliGRPPreprocessor(AliShuttleInterface* shuttle): | |
104 | AliPreprocessor("GRP",shuttle), fPressure(0) | |
105 | { | |
106 | // constructor - shuttle must be instantiated! | |
107 | ||
108 | AddRunType("PHYSICS"); | |
109 | } | |
110 | ||
111 | //_______________________________________________________________ | |
112 | AliGRPPreprocessor::~AliGRPPreprocessor() | |
113 | { | |
114 | //destructor | |
115 | ||
116 | delete fPressure; | |
117 | } | |
118 | ||
119 | //_______________________________________________________________ | |
120 | void AliGRPPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) | |
121 | { | |
122 | // Initialize preprocessor | |
123 | ||
124 | AliPreprocessor::Initialize(run, startTime, endTime); | |
125 | ||
126 | AliInfo("Initialization of the GRP preprocessor."); | |
127 | ||
128 | TClonesArray * array = new TClonesArray("AliDCSSensor",2); | |
129 | for(Int_t j = 0; j < 2; j++) { | |
130 | AliDCSSensor * sens = new ((*array)[j])AliDCSSensor; | |
131 | sens->SetStringID(fgkDCSDataPoints[j+kSensors]); | |
132 | } | |
133 | AliInfo(Form("Pressure Entries: %d",array->GetEntries())); | |
134 | ||
135 | fPressure = new AliDCSSensorArray(fStartTime, fEndTime, array); | |
136 | } | |
137 | ||
138 | //_______________________________________________________________ | |
139 | UInt_t AliGRPPreprocessor::Process(TMap* valueMap) | |
140 | { | |
141 | // process data retrieved by the Shuttle | |
142 | ||
143 | //=================// | |
144 | // DAQ logbook // | |
145 | //=================// | |
146 | UInt_t error = 0; | |
147 | ||
148 | TMap *grpmap = ProcessDaqLB(); | |
149 | if( grpmap->GetEntries() == fgknDAQLbPar ) { | |
150 | Log(Form("DAQ logbook, successful!")); | |
151 | } else { | |
152 | Log(Form("DAQ logbook, missing parameters!!!")); | |
153 | error |= 1; | |
154 | } | |
155 | //=================// | |
156 | // DAQ FXS // | |
157 | //=================// | |
158 | UInt_t iDaqFxs = ProcessDaqFxs(); | |
159 | if( iDaqFxs == 0 ) { | |
160 | Log(Form("DAQ FXS, successful!")); | |
161 | } else { | |
162 | Log(Form("DAQ FXS, could not store run raw tag file!!!")); | |
163 | error |= 2; | |
164 | } | |
165 | ||
166 | //=================// | |
167 | // DCS FXS // | |
168 | //=================// | |
169 | UInt_t iDcsFxs = ProcessDcsFxs(); | |
170 | if( iDcsFxs == 0 ) { | |
171 | Log(Form("DCS FXS, successful!")); | |
172 | } else { | |
173 | Log(Form("DCS FXS, Could not store CTP run configuration and scalers!!!")); | |
174 | error |= 4; | |
175 | } | |
176 | ||
177 | //=================// | |
178 | // DCS data points // | |
179 | //=================// | |
180 | Int_t entries = ProcessDcsDPs( valueMap, grpmap ); | |
181 | if( entries < fgknDCSDP-5 ) { // FIXME (!= ) LHState and pressure map are not working yet... | |
182 | Log(Form("Problem with the DCS data points!!!")); | |
183 | error |= 8; | |
184 | } else Log(Form("DCS data points, successful!")); | |
185 | ||
186 | //=======================// | |
187 | // Trigger Configuration // | |
188 | //=======================// | |
189 | // either from DAQ logbook..... | |
190 | const char * triggerConf = GetTriggerConfiguration(); | |
191 | if (triggerConf!= NULL) { | |
192 | Log("Found trigger configuration in DAQ logbook"); | |
193 | AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConf); | |
194 | if (!runcfg) { | |
195 | Log("Bad CTP run configuration file from DAQ logbook! The corresponding CDB entry will not be filled!"); | |
196 | error |= 16; | |
197 | } | |
198 | else { | |
199 | TString titleCTPcfg = Form("CTP cfg for run %i from DAQ",fRun); | |
200 | runcfg->SetTitle(titleCTPcfg); | |
201 | AliCDBMetaData metaData; | |
202 | metaData.SetBeamPeriod(0); | |
203 | metaData.SetResponsible("Roman Lietava"); | |
204 | metaData.SetComment("CTP run configuration from DAQ logbook"); | |
205 | if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) { | |
206 | Log("Unable to store the CTP run configuration object to OCDB!"); | |
207 | error |= 16; | |
208 | } | |
209 | } | |
210 | } | |
211 | // ...or from DCS FXS | |
212 | else{ | |
213 | Log("No trigger configuration found in the DAQ logbook!! Trying reading from DCS FXS..."); | |
214 | TString runcfgfile = GetFile(kDCS, "CTP_runconfig", ""); | |
215 | if (runcfgfile.IsNull()) { | |
216 | Log("No CTP runconfig files has been found in DCS FXS!"); | |
217 | error |= 16; | |
218 | } | |
219 | else { | |
220 | Log(Form("File with Id CTP_runconfig found! Copied to %s",runcfgfile.Data())); | |
221 | AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile); | |
222 | if (!runcfg) { | |
223 | Log("Bad CTP run configuration file from DCS FXS! The corresponding CDB entry will not be filled!"); | |
224 | error |= 16;; | |
225 | } | |
226 | else { | |
227 | TString titleCTPcfg = Form("CTP cfg for run %i from DCS",fRun); | |
228 | runcfg->SetTitle(titleCTPcfg); | |
229 | AliCDBMetaData metaData; | |
230 | metaData.SetBeamPeriod(0); | |
231 | metaData.SetResponsible("Roman Lietava"); | |
232 | metaData.SetComment("CTP run configuration from DCS FXS"); | |
233 | if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) { | |
234 | Log("Unable to store the CTP run configuration object to OCDB!"); | |
235 | error |= 16; | |
236 | } | |
237 | } | |
238 | } | |
239 | } | |
240 | ||
241 | grpmap->SetOwner(1); | |
242 | AliInfo(Form("Final list entries: %d",grpmap->GetEntries())); | |
243 | ||
244 | AliCDBMetaData md; | |
245 | md.SetResponsible("Ernesto Lopez Torres"); | |
246 | md.SetComment("Output parameters from the GRP preprocessor."); | |
247 | ||
248 | Bool_t result = Store("GRP", "Data", grpmap, &md); | |
249 | ||
250 | delete grpmap; | |
251 | ||
252 | if (result && !error ) { | |
253 | Log("GRP Preprocessor Success"); | |
254 | return 0; | |
255 | } else { | |
256 | Log( Form("GRP Preprocessor FAILS!!! %s%s%s%s%s", | |
257 | kppError[(error&1)?1:0], | |
258 | kppError[(error&2)?2:0], | |
259 | kppError[(error&4)?3:0], | |
260 | kppError[(error&8)?4:0], | |
261 | kppError[(error&16)?5:0] | |
262 | )); | |
263 | return error; | |
264 | } | |
265 | } | |
266 | ||
267 | //_______________________________________________________________ | |
268 | TMap *AliGRPPreprocessor::ProcessDaqLB() | |
269 | { | |
270 | //Getting the DAQ lb information | |
271 | ||
272 | const char* timeStart = GetRunParameter("DAQ_time_start"); | |
273 | const char* timeEnd = GetRunParameter("DAQ_time_end"); | |
274 | const char* beamEnergy = GetRunParameter("beamEnergy"); | |
275 | const char* beamType = GetRunParameter("beamType"); | |
276 | const char* numberOfDetectors = GetRunParameter("numberOfDetectors"); | |
277 | const char* detectorMask = GetRunParameter("detectorMask"); | |
278 | const char* lhcPeriod = GetRunParameter("LHCperiod"); | |
279 | ||
280 | TMap *mapDAQ = new TMap(); | |
281 | ||
282 | if (timeStart) { | |
283 | Log(Form("Start time for run %d: %s",fRun, timeStart)); | |
284 | } else { | |
285 | Log(Form("Start time not put in logbook!")); | |
286 | } | |
287 | mapDAQ->Add(new TObjString("fAliceStartTime"), new TObjString(timeStart)); | |
288 | ||
289 | if (timeEnd) { | |
290 | Log(Form("End time for run %d: %s",fRun, timeEnd)); | |
291 | } else { | |
292 | Log(Form("End time not put in logbook!")); | |
293 | } | |
294 | mapDAQ->Add(new TObjString("fAliceStopTime"), new TObjString(timeEnd)); | |
295 | ||
296 | if (beamEnergy) { | |
297 | Log(Form("Beam energy for run %d: %s",fRun, beamEnergy)); | |
298 | } else { | |
299 | Log(Form("Beam energy not put in logbook!")); | |
300 | } | |
301 | mapDAQ->Add(new TObjString("fAliceBeamEnergy"), new TObjString(beamEnergy)); | |
302 | ||
303 | if (beamType) { | |
304 | Log(Form("Beam type for run %d: %s",fRun, beamType)); | |
305 | } else { | |
306 | Log(Form("Beam type not put in logbook!")); | |
307 | } | |
308 | mapDAQ->Add(new TObjString("fAliceBeamType"), new TObjString(beamType)); | |
309 | ||
310 | if (numberOfDetectors) { | |
311 | Log(Form("Number of active detectors for run %d: %s",fRun, numberOfDetectors)); | |
312 | } else { | |
313 | Log(Form("Number of active detectors not put in logbook!")); | |
314 | } | |
315 | mapDAQ->Add(new TObjString("fNumberOfDetectors"), new TObjString(numberOfDetectors)); | |
316 | ||
317 | if (detectorMask) { | |
318 | Log(Form("Detector mask for run %d: %s",fRun, detectorMask)); | |
319 | } else { | |
320 | Log(Form("Detector mask not put in logbook!")); | |
321 | } | |
322 | mapDAQ->Add(new TObjString("fDetectorMask"), new TObjString(detectorMask)); | |
323 | ||
324 | if (lhcPeriod) { | |
325 | Log(Form("LHC period (DAQ) for run %d: %s",fRun, lhcPeriod)); | |
326 | } else { | |
327 | Log(Form("LHCperiod not put in logbook!")); | |
328 | } | |
329 | mapDAQ->Add(new TObjString("fLHCPeriod"), new TObjString(lhcPeriod)); | |
330 | ||
331 | mapDAQ->Add(new TObjString("fRunType"), new TObjString(GetRunType())); | |
332 | Log( Form("Retrived %d parameters from logbook", mapDAQ->GetEntries() ) ); | |
333 | ||
334 | return mapDAQ; | |
335 | } | |
336 | ||
337 | //_______________________________________________________________ | |
338 | UInt_t AliGRPPreprocessor::ProcessDaqFxs() | |
339 | { | |
340 | //======DAQ FXS======// | |
341 | ||
342 | TList* list = GetFileSources(kDAQ); | |
343 | if (!list) { | |
344 | Log("No raw data tag list: connection problems with DAQ FXS logbook!"); | |
345 | return 1; | |
346 | } | |
347 | ||
348 | if (list->GetEntries() == 0) { | |
349 | Log("no raw data tags in this run: nothing to merge!"); | |
350 | delete list; list=0; | |
351 | return 0; | |
352 | } | |
353 | ||
354 | TChain *fRawTagChain = new TChain("T"); | |
355 | Int_t nFiles=0; | |
356 | TIterator* iter = list->MakeIterator(); | |
357 | TObject* obj = 0; | |
358 | while ((obj = iter->Next())) { | |
359 | TObjString* objStr = dynamic_cast<TObjString*> (obj); | |
360 | if (objStr) { | |
361 | Log(Form("Found source %s", objStr->String().Data())); | |
362 | TList* list2 = GetFileIDs(kDAQ, objStr->String()); | |
363 | if (!list2) { | |
364 | Log("No list with ids from DAQ was found: connection problems with DAQ FXS logbook!"); | |
365 | delete fRawTagChain; fRawTagChain=0; | |
366 | return 1; | |
367 | } | |
368 | Log(Form("Number of ids: %d",list2->GetEntries())); | |
369 | for(Int_t i = 0; i < list2->GetEntries(); i++) { | |
370 | TObjString *idStr = (TObjString *)list2->At(i); | |
371 | TString fileName = GetFile(kDAQ,idStr->String().Data(),objStr->String().Data()); | |
372 | if (fileName.Length() > 0) { | |
373 | Log(Form("Adding file in the chain: %s",fileName.Data())); | |
374 | fRawTagChain->Add(fileName.Data()); | |
375 | nFiles++; | |
376 | } else { | |
377 | Log(Form("Could not retrieve file with id %s from source %s: " | |
378 | "connection problems with DAQ FXS!", | |
379 | idStr->String().Data(), objStr->String().Data())); | |
380 | delete list; list=0; | |
381 | delete list2; list2=0; | |
382 | delete fRawTagChain; fRawTagChain=0; | |
383 | return 2; | |
384 | } | |
385 | } | |
386 | delete list2; | |
387 | } | |
388 | } | |
389 | ||
390 | TString fRawDataFileName = "GRP_Merged.tag.root"; | |
391 | Log(Form("Merging %d raw data tags into file: %s", nFiles, fRawDataFileName.Data())); | |
392 | if( fRawTagChain->Merge(fRawDataFileName) < 1 ) { | |
393 | Log("Error merging raw data files!!!"); | |
394 | return 3; | |
395 | } | |
396 | ||
397 | TString outputfile = Form("Run%d.Merged.RAW.tag.root", fRun); | |
398 | Bool_t result = StoreRunMetadataFile(fRawDataFileName.Data(),outputfile.Data()); | |
399 | ||
400 | if (!result) { | |
401 | Log("Problem storing raw data tags in local file!!!"); | |
402 | } else { | |
403 | Log("Raw data tags merged successfully!!"); | |
404 | } | |
405 | ||
406 | delete iter; | |
407 | delete list; | |
408 | delete fRawTagChain; fRawTagChain=0; | |
409 | ||
410 | if (result == kFALSE) { | |
411 | return 4; | |
412 | } | |
413 | ||
414 | return 0; | |
415 | ||
416 | } | |
417 | ||
418 | //_______________________________________________________________ | |
419 | UInt_t AliGRPPreprocessor::ProcessDcsFxs() | |
420 | { | |
421 | //======DCS FXS======// | |
422 | // Get the CTP run configuration | |
423 | // and scalers from DCS FXS | |
424 | ||
425 | /* | |
426 | { | |
427 | ||
428 | // Get the CTP run configuration | |
429 | TList* list = GetFileSources(kDCS,"CTP_runconfig"); | |
430 | if (!list) { | |
431 | Log("No CTP runconfig file: connection problems with DCS FXS logbook!"); | |
432 | return 1; | |
433 | } | |
434 | ||
435 | if (list->GetEntries() == 0) { | |
436 | Log("No CTP runconfig file to be processed!"); | |
437 | return 1; | |
438 | } | |
439 | else { | |
440 | TIter iter(list); | |
441 | TObjString *source; | |
442 | while ((source = dynamic_cast<TObjString *> (iter.Next()))) { | |
443 | TString runcfgfile = GetFile(kDCS, "CTP_runconfig", source->GetName()); | |
444 | if (runcfgfile.IsNull()) { | |
445 | Log("No CTP runconfig files has been found: empty source!"); | |
446 | } | |
447 | else { | |
448 | Log(Form("File with Id CTP_runconfig found in source %s! Copied to %s",source->GetName(),runcfgfile.Data())); | |
449 | AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfiguration(runcfgfile); | |
450 | if (!runcfg) { | |
451 | Log("Bad CTP run configuration file! The corresponding CDB entry will not be filled!"); | |
452 | return 1; | |
453 | } | |
454 | else { | |
455 | AliCDBMetaData metaData; | |
456 | metaData.SetBeamPeriod(0); | |
457 | metaData.SetResponsible("Roman Lietava"); | |
458 | metaData.SetComment("CTP run configuration"); | |
459 | if (!Store("CTP","Config", runcfg, &metaData, 0, 0)) { | |
460 | Log("Unable to store the CTP run configuration object to OCDB!"); | |
461 | } | |
462 | } | |
463 | } | |
464 | } | |
465 | } | |
466 | delete list; | |
467 | } | |
468 | */ | |
469 | { | |
470 | // Get the CTP counters information | |
471 | TList* list = GetFileSources(kDCS,"CTP_xcounters"); | |
472 | if (!list) { | |
473 | Log("No CTP counters file: connection problems with DAQ FXS logbook!"); | |
474 | return 1; | |
475 | } | |
476 | ||
477 | if (list->GetEntries() == 0) { | |
478 | Log("No CTP counters file to be processed!"); | |
479 | return 1; | |
480 | } | |
481 | else { | |
482 | TIter iter(list); | |
483 | TObjString *source; | |
484 | while ((source = dynamic_cast<TObjString *> (iter.Next()))) { | |
485 | TString countersfile = GetFile(kDCS, "CTP_xcounters", source->GetName()); | |
486 | if (countersfile.IsNull()) { | |
487 | Log("No CTP counters files has been found: empty source!"); | |
488 | } | |
489 | else { | |
490 | Log(Form("File with Id CTP_xcounters found in source %s! Copied to %s",source->GetName(),countersfile.Data())); | |
491 | AliTriggerRunScalers *scalers = AliTriggerRunScalers::ReadScalers(countersfile); | |
492 | if (!scalers) { | |
493 | Log("Bad CTP counters file! The corresponding CDB entry will not be filled!"); | |
494 | return 1; | |
495 | } | |
496 | else { | |
497 | AliCDBMetaData metaData; | |
498 | metaData.SetBeamPeriod(0); | |
499 | metaData.SetResponsible("Roman Lietava"); | |
500 | metaData.SetComment("CTP scalers"); | |
501 | if (!Store("CTP","Scalers", scalers, &metaData, 0, 0)) { | |
502 | Log("Unable to store the CTP scalers object to OCDB!"); | |
503 | } | |
504 | } | |
505 | } | |
506 | } | |
507 | } | |
508 | delete list; | |
509 | } | |
510 | ||
511 | return 0; | |
512 | } | |
513 | ||
514 | //_______________________________________________________________ | |
515 | Int_t AliGRPPreprocessor::ProcessDcsDPs(TMap* valueMap, TMap* mapDCS) | |
516 | { | |
517 | //Getting the DCS dps | |
518 | //===========// | |
519 | ||
520 | //DCS data points | |
521 | //===========// | |
522 | ||
523 | Int_t entries = 0; | |
524 | ||
525 | AliInfo(Form("==========LHCState===========")); | |
526 | TObjArray *aliasLHCState = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[0]); | |
527 | if(!aliasLHCState) { | |
528 | Log(Form("LHCState not found!!!")); | |
529 | } else { | |
530 | AliGRPDCS *dcs1 = new AliGRPDCS(aliasLHCState,fStartTime,fEndTime); | |
531 | TString sLHCState = dcs1->ProcessDCS(2); | |
532 | if (sLHCState) { | |
533 | for( Int_t i=0; i<20; i+=2 ) { | |
534 | if( sLHCState.CompareTo(fgkLHCState[i]) == 0 ) { | |
535 | sLHCState = fgkLHCState[i+1]; | |
536 | break; | |
537 | } | |
538 | } | |
539 | Log(Form("<LHCState> for run %d: %s",fRun, sLHCState.Data())); | |
540 | } else { | |
541 | Log("LHCState not put in TMap!"); | |
542 | } | |
543 | mapDCS->Add(new TObjString("fLHCState"),new TObjString(sLHCState)); | |
544 | ++entries; | |
545 | } | |
546 | ||
547 | AliInfo(Form("==========L3Polarity===========")); | |
548 | TObjArray *aliasL3Polarity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[1]); | |
549 | if(!aliasL3Polarity) { | |
550 | Log(Form("L3Polarity not found!!!")); | |
551 | } else { | |
552 | AliGRPDCS *dcs6 = new AliGRPDCS(aliasL3Polarity,fStartTime,fEndTime); | |
553 | TString sL3Polarity = dcs6->ProcessDCS(1); | |
554 | if (sL3Polarity) { | |
555 | Log(Form("<L3Polarity> for run %d: %s",fRun, sL3Polarity.Data())); | |
556 | } else { | |
557 | Log("L3Polarity not put in TMap!"); | |
558 | } | |
559 | mapDCS->Add(new TObjString("fL3Polarity"),new TObjString(sL3Polarity)); | |
560 | ++entries; | |
561 | } | |
562 | ||
563 | AliInfo(Form("==========DipolePolarity===========")); | |
564 | TObjArray *aliasDipolePolarity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[2]); | |
565 | if(!aliasDipolePolarity) { | |
566 | Log(Form("DipolePolarity not found!!!")); | |
567 | } else { | |
568 | AliGRPDCS *dcs8 = new AliGRPDCS(aliasDipolePolarity,fStartTime,fEndTime); | |
569 | TString sDipolePolarity = dcs8->ProcessDCS(1); | |
570 | if (sDipolePolarity) { | |
571 | Log(Form("<DipolePolarity> for run %d: %s",fRun, sDipolePolarity.Data())); | |
572 | } else { | |
573 | Log("DipolePolarity not put in TMap!"); | |
574 | } | |
575 | mapDCS->Add(new TObjString("fDipolePolarity"),new TObjString(sDipolePolarity)); | |
576 | ++entries; | |
577 | } | |
578 | ||
579 | AliInfo(Form("==========LHCLuminosity===========")); | |
580 | TObjArray *aliasLHCLuminosity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[3]); | |
581 | if(!aliasLHCLuminosity) { | |
582 | Log(Form("LHCLuminosity not found!!!")); | |
583 | } else { | |
584 | AliGRPDCS *dcs3 = new AliGRPDCS(aliasLHCLuminosity,fStartTime,fEndTime); | |
585 | TString sMeanLHCLuminosity = dcs3->ProcessDCS(5); | |
586 | if (sMeanLHCLuminosity) { | |
587 | Log(Form("<LHCLuminosity> for run %d: %s",fRun, sMeanLHCLuminosity.Data())); | |
588 | } else { | |
589 | Log("LHCLuminosity not put in TMap!"); | |
590 | } | |
591 | mapDCS->Add(new TObjString("fLHCLuminosity"), new TObjString(sMeanLHCLuminosity)); | |
592 | ++entries; | |
593 | } | |
594 | ||
595 | AliInfo(Form("==========BeamIntensity===========")); | |
596 | TObjArray *aliasBeamIntensity = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[4]); | |
597 | if(!aliasBeamIntensity) { | |
598 | Log(Form("BeamIntensity not found!!!")); | |
599 | } else { | |
600 | AliGRPDCS *dcs4 = new AliGRPDCS(aliasBeamIntensity,fStartTime,fEndTime); | |
601 | TString sMeanBeamIntensity = dcs4->ProcessDCS(5); | |
602 | if (sMeanBeamIntensity) { | |
603 | Log(Form("<BeamIntensity> for run %d: %s",fRun, sMeanBeamIntensity.Data())); | |
604 | } else { | |
605 | Log("BeamIntensity not put in TMap!"); | |
606 | } | |
607 | mapDCS->Add(new TObjString("fBeamIntensity"),new TObjString(sMeanBeamIntensity)); | |
608 | ++entries; | |
609 | } | |
610 | ||
611 | AliInfo(Form("==========L3Current===========")); | |
612 | TObjArray *aliasL3Current = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[5]); | |
613 | if(!aliasL3Current) { | |
614 | Log(Form("L3Current not found!!!")); | |
615 | } else { | |
616 | AliGRPDCS *dcs5 = new AliGRPDCS(aliasL3Current,fStartTime,fEndTime); | |
617 | TString sMeanL3Current = dcs5->ProcessDCS(5); | |
618 | if (sMeanL3Current) { | |
619 | Log(Form("<L3Current> for run %d: %s",fRun, sMeanL3Current.Data())); | |
620 | } else { | |
621 | Log("L3Current not put in TMap!"); | |
622 | } | |
623 | mapDCS->Add(new TObjString("fL3Current"),new TObjString(sMeanL3Current)); | |
624 | ++entries; | |
625 | } | |
626 | ||
627 | ||
628 | AliInfo(Form("==========DipoleCurrent===========")); | |
629 | TObjArray *aliasDipoleCurrent = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[6]); | |
630 | if(!aliasDipoleCurrent) { | |
631 | Log(Form("DipoleCurrent not found!!!")); | |
632 | } else { | |
633 | AliGRPDCS *dcs7 = new AliGRPDCS(aliasDipoleCurrent,fStartTime,fEndTime); | |
634 | TString sMeanDipoleCurrent = dcs7->ProcessDCS(5); | |
635 | if (sMeanDipoleCurrent) { | |
636 | Log(Form("<DipoleCurrent> for run %d: %s",fRun, sMeanDipoleCurrent.Data())); | |
637 | } else { | |
638 | Log("DipoleCurrent not put in TMap!"); | |
639 | } | |
640 | mapDCS->Add(new TObjString("fDipoleCurrent"),new TObjString(sMeanDipoleCurrent)); | |
641 | ++entries; | |
642 | } | |
643 | ||
644 | AliInfo(Form("==========CavernTemperature===========")); | |
645 | TObjArray *aliasCavernTemperature = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[7]); | |
646 | if(!aliasCavernTemperature) { | |
647 | Log(Form("CavernTemperature not found!!!")); | |
648 | } else { | |
649 | AliGRPDCS *dcs9 = new AliGRPDCS(aliasCavernTemperature,fStartTime,fEndTime); | |
650 | TString sMeanCavernTemperature = dcs9->ProcessDCS(5); | |
651 | if (sMeanCavernTemperature) { | |
652 | Log(Form("<CavernTemperature> for run %d: %s",fRun, sMeanCavernTemperature.Data())); | |
653 | } else { | |
654 | Log("CavernTemperature not put in TMap!"); | |
655 | } | |
656 | mapDCS->Add(new TObjString("fCavernTemperature"),new TObjString(sMeanCavernTemperature)); | |
657 | ++entries; | |
658 | } | |
659 | ||
660 | AliInfo(Form("==========CavernPressure===========")); | |
661 | TObjArray *aliasCavernPressure = (TObjArray *)valueMap->GetValue(fgkDCSDataPoints[8]); | |
662 | if(!aliasCavernPressure) { | |
663 | Log("CavernPressure not found!!!"); | |
664 | } else { | |
665 | AliGRPDCS *dcs10 = new AliGRPDCS(aliasCavernPressure,fStartTime,fEndTime); | |
666 | TString sMeanCavernPressure = dcs10->ProcessDCS(5); | |
667 | if (sMeanCavernPressure) { | |
668 | Log(Form("<CavernPressure> for run %d: %s",fRun, sMeanCavernPressure.Data())); | |
669 | } else { | |
670 | Log("CavernPressure not put in TMap!"); | |
671 | } | |
672 | mapDCS->Add(new TObjString("fCavernPressure"),new TObjString(sMeanCavernPressure)); | |
673 | ++entries; | |
674 | } | |
675 | ||
676 | ||
677 | // NEEDS TO BE REVISED, CONFIRMED | |
678 | AliInfo(Form("==========GenevaPressureMaps===========")); | |
679 | AliDCSSensorArray *dcsSensorArray = GetPressureMap(valueMap); | |
680 | if( fPressure->NumFits()==0 ) { | |
681 | Log("Problem with the pressure sensor values!!!"); | |
682 | } else { | |
683 | AliDCSSensor* sensorCr5 = dcsSensorArray->GetSensor(fgkDCSDataPoints[9]); | |
684 | if( sensorCr5->GetFit() ) { | |
685 | Log(Form("<GvaCr5Pressure> for run %d: Sensor Fit found",fRun)); | |
686 | mapDCS->Add( new TObjString("fCr5Pressure"), sensorCr5 ); | |
687 | ++entries; | |
688 | } else { | |
689 | Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[9] )); | |
690 | } | |
691 | ||
692 | AliDCSSensor* sensorMeyrin = dcsSensorArray->GetSensor(fgkDCSDataPoints[10]); | |
693 | if( sensorMeyrin->GetFit() ) { | |
694 | Log(Form("<MeyrinPressure> for run %d: Sensor Fit found",fRun)); | |
695 | mapDCS->Add( new TObjString("fMeyrinPressure"), sensorMeyrin ); | |
696 | ++entries; | |
697 | } else { | |
698 | Log(Form("ERROR Sensor Fit for %s not found: ", fgkDCSDataPoints[10] )); | |
699 | } | |
700 | ||
701 | } | |
702 | ||
703 | return entries; | |
704 | } | |
705 | ||
706 | //_______________________________________________________________ | |
707 | AliDCSSensorArray *AliGRPPreprocessor::GetPressureMap(TMap* dcsAliasMap) | |
708 | { | |
709 | // extract DCS pressure maps. Perform fits to save space | |
710 | ||
711 | TMap *map = fPressure->ExtractDCS(dcsAliasMap); | |
712 | if (map) { | |
713 | fPressure->MakeSplineFit(map); | |
714 | Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors(); | |
715 | if (fitFraction > kFitFraction ) { | |
716 | AliInfo(Form("Pressure values extracted, %d fits performed.", fPressure->NumFits())); | |
717 | } else { | |
718 | AliInfo("Too few pressure maps fitted!!!"); | |
719 | } | |
720 | } else { | |
721 | AliInfo("no atmospheric pressure map extracted!!!"); | |
722 | } | |
723 | delete map; | |
724 | ||
725 | return fPressure; | |
726 | } | |
727 | ||
728 | //_______________________________________________________________ | |
729 | /*UInt_t AliGRPPreprocessor::MapPressure(TMap* dcsAliasMap) { | |
730 | // extract DCS pressure maps. Perform fits to save space | |
731 | ||
732 | UInt_t result=0; | |
733 | TMap *map = fPressure->ExtractDCS(dcsAliasMap); | |
734 | if (map) { | |
735 | fPressure->MakeSplineFit(map); | |
736 | Double_t fitFraction = fPressure->NumFits()/fPressure->NumSensors(); | |
737 | if (fitFraction > kFitFraction ) { | |
738 | AliInfo(Form("Pressure values extracted, fits performed.\n")); | |
739 | } else { | |
740 | Log ("Too few pressure maps fitted. \n"); | |
741 | result = 9; | |
742 | } | |
743 | } else { | |
744 | Log("AliTPCPreprocsessor: no atmospheric pressure map extracted. \n"); | |
745 | result=9; | |
746 | } | |
747 | delete map; | |
748 | // Now store the final CDB file | |
749 | ||
750 | if ( result == 0 ) { | |
751 | AliCDBMetaData metaData; | |
752 | metaData.SetBeamPeriod(0); | |
753 | metaData.SetResponsible("Panos Christakoglou"); | |
754 | metaData.SetComment("Preprocessor AliGRP data base pressure entries."); | |
755 | ||
756 | Bool_t storeOK = Store("Calib", "Pressure", fPressure, &metaData, 0, 0); | |
757 | if ( !storeOK ) result=1; | |
758 | } | |
759 | ||
760 | return result; | |
761 | }*/ | |
762 | ||
763 | ||
764 | //_______________________________________________________________ | |
765 | Int_t AliGRPPreprocessor::ReceivePromptRecoParameters(UInt_t run, const char* dbHost, Int_t dbPort, const char* dbName, const char* user, const char* password, const char *cdbRoot) | |
766 | { | |
767 | // | |
768 | // Retrieves logbook and trigger information from the online logbook | |
769 | // This information is needed for prompt reconstruction | |
770 | // | |
771 | // Parameters are: | |
772 | // Run number | |
773 | // DAQ params: dbHost, dbPort, dbName, user, password, logbookTable, triggerTable | |
774 | // cdbRoot | |
775 | // | |
776 | // returns: | |
777 | // positive on success: the return code is the run number of last run processed of the same run type already processed by the SHUTTLE | |
778 | // 0 on success and no run was found | |
779 | // negative on error | |
780 | // | |
781 | // This function is NOT called during the preprocessor run in the Shuttle! | |
782 | // | |
783 | ||
784 | // defaults | |
785 | if (dbPort == 0) | |
786 | dbPort = 3306; | |
787 | ||
788 | // CDB connection | |
789 | AliCDBManager* cdb = AliCDBManager::Instance(); | |
790 | cdb->SetDefaultStorage(cdbRoot); | |
791 | ||
792 | // SQL connection | |
793 | TSQLServer* server = TSQLServer::Connect(Form("mysql://%s:%d/%s", dbHost, dbPort, dbName), user, password); | |
794 | ||
795 | if (!server) | |
796 | { | |
797 | Printf("ERROR: Could not connect to DAQ LB"); | |
798 | return -1; | |
799 | } | |
800 | ||
801 | // main logbook | |
802 | TString sqlQuery; | |
803 | sqlQuery.Form("SELECT DAQ_time_start, run_type, detectorMask FROM logbook WHERE run = %d", run); | |
804 | TSQLResult* result = server->Query(sqlQuery); | |
805 | if (!result) | |
806 | { | |
807 | Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data()); | |
808 | return -2; | |
809 | } | |
810 | ||
811 | if (result->GetRowCount() == 0) | |
812 | { | |
813 | Printf("ERROR: Run %d not found", run); | |
814 | delete result; | |
815 | return -3; | |
816 | } | |
817 | ||
818 | TSQLRow* row = result->Next(); | |
819 | if (!row) | |
820 | { | |
821 | Printf("ERROR: Could not receive data from run %d", run); | |
822 | delete result; | |
823 | return -4; | |
824 | } | |
825 | ||
826 | TString runType(row->GetField(1)); | |
827 | ||
828 | TMap grpData; | |
829 | grpData.Add(new TObjString("DAQ_time_start"), new TObjString(row->GetField(0))); | |
830 | grpData.Add(new TObjString("run_type"), new TObjString(runType)); | |
831 | grpData.Add(new TObjString("detectorMask"), new TObjString(row->GetField(2))); | |
832 | ||
833 | delete row; | |
834 | row = 0; | |
835 | ||
836 | delete result; | |
837 | result = 0; | |
838 | ||
839 | Printf("Storing GRP/GRP/Data object with the following content"); | |
840 | grpData.Print(); | |
841 | ||
842 | AliCDBMetaData metadata; | |
843 | metadata.SetResponsible("Jan Fiete Grosse-Oetringhaus"); | |
844 | metadata.SetComment("GRP Output parameters received during online running"); | |
845 | ||
846 | AliCDBId id("GRP/GRP/Data", run, run); | |
847 | Bool_t success = cdb->Put(&grpData, id, &metadata); | |
848 | ||
849 | grpData.DeleteAll(); | |
850 | ||
851 | if (!success) | |
852 | { | |
853 | Printf("ERROR: Could not store GRP/GRP/Data into OCDB"); | |
854 | return -5; | |
855 | } | |
856 | ||
857 | // Receive trigger information | |
858 | sqlQuery.Form("SELECT configFile FROM logbook_trigger_config WHERE run = %d", run); | |
859 | result = server->Query(sqlQuery); | |
860 | if (!result) | |
861 | { | |
862 | Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data()); | |
863 | return -11; | |
864 | } | |
865 | ||
866 | if (result->GetRowCount() == 0) | |
867 | { | |
868 | Printf("ERROR: Run %d not found in logbook_trigger_config", run); | |
869 | delete result; | |
870 | return -12; | |
871 | } | |
872 | ||
873 | row = result->Next(); | |
874 | if (!row) | |
875 | { | |
876 | Printf("ERROR: Could not receive logbook_trigger_config data from run %d", run); | |
877 | delete result; | |
878 | return -13; | |
879 | } | |
880 | ||
881 | TString triggerConfig(row->GetField(0)); | |
882 | ||
883 | delete row; | |
884 | row = 0; | |
885 | ||
886 | delete result; | |
887 | result = 0; | |
888 | ||
889 | Printf("Found trigger configuration: %s", triggerConfig.Data()); | |
890 | ||
891 | AliTriggerConfiguration *runcfg = AliTriggerConfiguration::LoadConfigurationFromString(triggerConfig); | |
892 | if (!runcfg) | |
893 | { | |
894 | Printf("ERROR: Could not create CTP configuration object"); | |
895 | return -14; | |
896 | } | |
897 | ||
898 | metadata.SetComment("CTP run configuration received during online running"); | |
899 | ||
900 | AliCDBId id2("GRP/CTP/Config", run, run); | |
901 | success = cdb->Put(runcfg, id2, &metadata); | |
902 | ||
903 | delete runcfg; | |
904 | runcfg = 0; | |
905 | ||
906 | if (!success) | |
907 | { | |
908 | Printf("ERROR: Could not store GRP/CTP/Config into OCDB"); | |
909 | return -15; | |
910 | } | |
911 | ||
912 | // get last run with same run type that was already processed by the SHUTTLE | |
913 | ||
914 | 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()); | |
915 | result = server->Query(sqlQuery); | |
916 | if (!result) | |
917 | { | |
918 | Printf("ERROR: Can't execute query <%s>!", sqlQuery.Data()); | |
919 | return -21; | |
920 | } | |
921 | ||
922 | if (result->GetRowCount() == 0) | |
923 | { | |
924 | Printf("ERROR: No result with query <%s>", sqlQuery.Data()); | |
925 | delete result; | |
926 | return -22; | |
927 | } | |
928 | ||
929 | row = result->Next(); | |
930 | if (!row) | |
931 | { | |
932 | Printf("ERROR: Could not receive data for query <%s>", sqlQuery.Data()); | |
933 | delete result; | |
934 | return -23; | |
935 | } | |
936 | ||
937 | TString lastRunStr(row->GetField(0)); | |
938 | Int_t lastRun = lastRunStr.Atoi(); | |
939 | ||
940 | Printf("Last run with same run type %s is %d", runType.Data(), lastRun); | |
941 | ||
942 | delete row; | |
943 | row = 0; | |
944 | ||
945 | delete result; | |
946 | result = 0; | |
947 | ||
948 | server->Close(); | |
949 | delete server; | |
950 | server = 0; | |
951 | ||
952 | return lastRun; | |
953 | } |