Line data Source code
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 : // //
20 : // This class is a first implementation for the TRD. //
21 : // It takes data from HLT and computes the parameters //
22 : // and stores both reference data and online calibration //
23 : // parameters in the CDB //
24 : // It alsotakes DCS data, does spline fits //
25 : // and stores both reference data and spline fits results //
26 : // in the CDB //
27 : // //
28 : // Authors: //
29 : // R. Bailhache (R.Bailhache@gsi.de) //
30 : // J. Book (jbook@ikf.uni-frankfurt.de) //
31 : // W. Monange (w.monange@gsi.de) //
32 : // F. Kramer (kramer@ikf.uni-frankfurt.de) //
33 : // Maintainers: //
34 : // Hans.Beck@cern.ch //
35 : // R. Bailhache (R.Bailhache@gsi.de) //
36 : // //
37 : // //
38 : ////////////////////////////////////////////////////////////////////////////
39 :
40 : #include <fstream>
41 :
42 : #include <TFile.h>
43 : #include <TProfile2D.h>
44 : #include <TObjString.h>
45 : #include <TString.h>
46 : #include <TList.h>
47 : #include <TSAXParser.h>
48 :
49 : #include "AliCDBMetaData.h"
50 : #include "AliLog.h"
51 :
52 : #include "AliTRDPreprocessor.h"
53 : #include "AliTRDSensorArray.h"
54 : #include "AliTRDCalibraFit.h"
55 : #include "AliTRDCalibraMode.h"
56 : #include "AliTRDCalibPadStatus.h"
57 : #include "AliTRDSaxHandler.h"
58 : #include "AliTRDgeometry.h"
59 : #include "AliTRDCalibChamberStatus.h"
60 : #include "AliTRDCalPad.h"
61 : #include "AliTRDCalPadStatus.h"
62 : #include "AliTRDCalDCSv2.h"
63 : #include "AliTRDCalSingleChamberStatus.h"
64 : #include "AliTRDCalChamberStatus.h"
65 : #include "AliTRDCalROC.h"
66 :
67 48 : ClassImp(AliTRDPreprocessor)
68 :
69 : //______________________________________________________________________________________________
70 : AliTRDPreprocessor::AliTRDPreprocessor(AliShuttleInterface *shuttle)
71 0 : :AliPreprocessor("TRD", shuttle)
72 0 : ,fCalDCSObjSOR(0)
73 0 : ,fCalDCSObjEOR(0)
74 0 : ,fVdriftHLT(0)
75 0 : {
76 : //
77 : // Constructor
78 : //
79 :
80 :
81 0 : AddRunType("PHYSICS");
82 0 : AddRunType("STANDALONE");
83 0 : AddRunType("PEDESTAL");
84 0 : AddRunType("DAQ");
85 :
86 :
87 0 : }
88 : //______________________________________________________________________________________________
89 : AliTRDPreprocessor::AliTRDPreprocessor(const AliTRDPreprocessor& ) :
90 0 : AliPreprocessor("TRD",0),
91 0 : fCalDCSObjSOR(0),
92 0 : fCalDCSObjEOR(0),
93 0 : fVdriftHLT(0)
94 0 : {
95 :
96 0 : Fatal("AliTRDPreprocessor", "copy constructor not implemented");
97 :
98 0 : }
99 : //______________________________________________________________________________________________
100 : AliTRDPreprocessor::~AliTRDPreprocessor()
101 0 : {
102 : //
103 : // Destructor
104 : //
105 :
106 0 : if (fCalDCSObjSOR ) delete fCalDCSObjSOR;
107 0 : if (fCalDCSObjEOR ) delete fCalDCSObjEOR;
108 :
109 0 : }
110 : //______________________________________________________________________________________________
111 : AliTRDPreprocessor& AliTRDPreprocessor::operator = (const AliTRDPreprocessor& )
112 : {
113 0 : Fatal("operator =", "assignment operator not implemented");
114 0 : return *this;
115 : }
116 : //______________________________________________________________________________________________
117 : void AliTRDPreprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
118 : {
119 : //
120 : // Initialization routine for the TRD preprocessor
121 : //
122 :
123 0 : AliPreprocessor::Initialize(run,startTime,endTime);
124 :
125 0 : }
126 :
127 : //______________________________________________________________________________________________
128 : UInt_t AliTRDPreprocessor::Process(TMap* dcsAliasMap)
129 : {
130 : //
131 : // Process DCS and calibration part for HLT
132 : //
133 :
134 0 : const TString runType = GetRunType();
135 0 : Log(Form("runtype %s\n",runType.Data()));
136 :
137 : // We initialize the return values of all
138 : // subfunctions to zero, ie 'good'
139 : Int_t DCSConfigReturn = 0;
140 : Int_t pedastalReturn = 0;
141 : Int_t DCSReturn = 0;
142 : Int_t HLTReturn = 0;
143 : Int_t DAQReturn = 0;
144 :
145 : // Always process the configuration data
146 0 : DCSConfigReturn = ProcessDCSConfigData();
147 :
148 : // Extract pedastals in pedastal runs
149 0 : if (runType=="PEDESTAL"){
150 0 : pedastalReturn = ExtractPedestals();
151 0 : }
152 :
153 : // Process the DCS sensors
154 0 : if ((runType=="PHYSICS") || (runType=="STANDALONE") || (runType=="DAQ")){
155 : // DCS
156 0 : DCSReturn = ProcessDCS(dcsAliasMap);
157 :
158 : /*
159 : if(runType=="PHYSICS"){
160 : // HLT if On
161 : //TString runPar = GetRunParameter("HLTStatus");
162 : //if(runPar=="1") {
163 : if(GetHLTStatus()) {
164 : HLTReturn = ExtractHLT();
165 : }
166 : // DAQ if HLT failed
167 : if(!fVdriftHLT) {
168 : DAQReturn = ExtractDriftVelocityDAQ();
169 : }
170 : }
171 : */
172 :
173 0 : }
174 :
175 : // Check for any errors
176 0 : if(DCSConfigReturn || pedastalReturn || DCSReturn
177 : || HLTReturn || DAQReturn){
178 : // Error
179 0 : Log(Form("ERROR - Listing return values for subfunctions (0=good)"));
180 0 : Log(Form("DCSConfig %d, pedastal %d, DCS %d, HLT %d, DAQ %d"
181 : ,DCSConfigReturn,pedastalReturn,DCSReturn
182 : ,HLTReturn,DAQReturn));
183 0 : return 1;
184 : }
185 : else{
186 : // Good
187 0 : Log(Form("SUCCESS All subfuntions returned without error"));
188 0 : return 0;
189 : }
190 0 : }
191 : //______________________________________________________________________________
192 : Bool_t AliTRDPreprocessor::ProcessDCS()
193 : {
194 : //
195 : // Default process DCS method
196 : //
197 :
198 0 : TString runType = GetRunType();
199 0 : if ((runType == "PHYSICS") || (runType == "STANDALONE")) {
200 0 : return kTRUE;
201 : }
202 0 : return kFALSE;
203 :
204 0 : }
205 :
206 : //______________________________________________________________________________
207 : Bool_t AliTRDPreprocessor::ProcessDCS(TMap *dcsAliasMap)
208 : {
209 : //
210 : // Process DCS method
211 : //
212 :
213 : Bool_t error = kFALSE;
214 :
215 0 : AliCDBMetaData metaData;
216 0 : metaData.SetBeamPeriod(0);
217 0 : metaData.SetResponsible("Wilfried Monange/Raphaelle Bailhache");
218 0 : metaData.SetComment("TRD calib test");
219 :
220 0 : Log("****** DCS ******\n");
221 :
222 0 : TObjArray * list=AliTRDSensorArray::GetList();
223 :
224 0 : if (list == 0x0) {
225 0 : Log ("Error during AliTRDSensorArray::GetList");
226 0 : Log ("DCS will not be processing");
227 0 : return kTRUE;
228 : }
229 :
230 0 : const Int_t nEntries = list->GetEntries ();
231 0 : Log (Form ("%d alias loaded", nEntries));
232 :
233 0 : Bool_t results[nEntries];
234 0 : Int_t nGraph[nEntries];
235 :
236 0 : for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
237 :
238 0 : AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
239 :
240 0 : oneTRDDCS->SetStartTime (TTimeStamp (fStartTime));
241 0 : oneTRDDCS->SetEndTime (TTimeStamp (fEndTime));
242 :
243 0 : Log(Form("Processing DCS : \"%s\"", oneTRDDCS->GetStoreName ().Data ()));
244 :
245 0 : TMap *map=oneTRDDCS->ExtractDCS (dcsAliasMap);
246 :
247 0 : nGraph [iAlias] = map->GetEntries ();
248 :
249 0 : if (nGraph [iAlias] == 0) {
250 0 : Log("No TGraph for this dcsDatapointAlias : not stored");
251 0 : results [iAlias] = kFALSE;
252 : //error = kTRUE;
253 0 : delete map;
254 : map=0;
255 0 : continue;
256 : }
257 :
258 0 : oneTRDDCS->SetGraph(map);
259 :
260 : // Remove duplicate entries where the value did not change
261 : // more than a relative precision. We take a std precision
262 : // of 1e-4 and apply a higher precision for special cases
263 : Double_t precision=1e-4;
264 : // precision 1e-5 for HV
265 0 : if( oneTRDDCS->GetStoreName().Contains("trd_hvAnodeUmon") ||
266 0 : oneTRDDCS->GetStoreName().Contains("trd_hvDriftUmon") ){
267 : precision=1e-5;
268 0 : }
269 0 : oneTRDDCS->RemoveGraphDuplicates(precision);
270 : // Remove HV anode current points below a threshold (in uA)
271 : // when both neighbors are also below threshold
272 0 : if(oneTRDDCS->GetStoreName().Contains("trd_hvAnodeImon")){
273 0 : oneTRDDCS->RemoveAbsBelowThreshold(0.010);
274 : }
275 0 : if(oneTRDDCS->GetStoreName().Contains("trd_hvDriftImon")){
276 0 : oneTRDDCS->RemoveAbsBelowThreshold(0.10);
277 : }
278 :
279 : // Store the data point
280 0 : results[iAlias]=Store("Calib", oneTRDDCS->GetStoreName().Data(), oneTRDDCS, &metaData, 0, kFALSE);
281 0 : delete map;
282 : map=0;
283 0 : oneTRDDCS->ClearGraph();
284 : //results [iAlias] = StoreReferenceData("Calib", oneTRDDCS->GetStoreName ().Data (), oneTRDDCS, &metaData);
285 :
286 0 : if (!results[iAlias]) {
287 0 : AliError("Problem during StoreRef DCS");
288 : //error=kTRUE;
289 : }
290 :
291 : //BEGIN TEST (should not be removed ...)
292 : /*
293 : oneTRDDCS->ClearGraph();
294 : oneTRDDCS->ClearFit();
295 : oneTRDDCS->SetDiffCut2 (0.1);
296 : map=oneTRDDCS->ExtractDCS (dcsAliasMap);
297 : oneTRDDCS->SetGraph (map);
298 : Store("Calib", ("cut_"+oneTRDDCS->GetStoreName()).Data(), oneTRDDCS, &metaData, 0, kTRUE);
299 : delete map;
300 :
301 :
302 : if(iAlias==1 || iAlias==19) continue;
303 :
304 : oneTRDDCS->ClearGraph();
305 : oneTRDDCS->ClearFit();
306 : oneTRDDCS->SetDiffCut2(0);
307 : map=oneTRDDCS->ExtractDCS(dcsAliasMap);
308 : oneTRDDCS->MakeSplineFit(map);
309 : Store("Calib", ("fit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
310 : delete map;
311 :
312 :
313 : oneTRDDCS->ClearGraph();
314 : oneTRDDCS->ClearFit();
315 : oneTRDDCS->SetDiffCut2 (0.1);
316 : map=oneTRDDCS->ExtractDCS (dcsAliasMap);
317 : oneTRDDCS->MakeSplineFit(map);
318 : Store("Calib", ("cutfit_"+oneTRDDCS->GetStoreName()).Data() , oneTRDDCS, &metaData, 0, kTRUE);
319 : delete map;
320 : */
321 : //END TEST
322 :
323 0 : }
324 :
325 : // Check errors
326 : Int_t nbCount = 0;
327 0 : for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
328 0 : if (results[iAlias]) {
329 0 : nbCount++;
330 0 : }
331 : }
332 0 : if(nbCount == 0) error = kTRUE;
333 :
334 :
335 0 : Log (" Summury of DCS :\n");
336 0 : Log (Form("%30s %10s %10s", "dcsDatapointAlias", "Stored ?", "# graph"));
337 0 : for (Int_t iAlias = 0; iAlias < nEntries; iAlias++) {
338 0 : AliTRDSensorArray * oneTRDDCS = (AliTRDSensorArray *)list->At (iAlias);
339 0 : Log (Form ("%30s %10s %4d",
340 0 : oneTRDDCS->GetStoreName ().Data (),
341 0 : results[iAlias] ? "ok" : "X",
342 0 : nGraph [iAlias]));
343 : }
344 0 : Log ("*********** End of DCS **********");
345 :
346 : // Clean up
347 0 : delete list;
348 : list=0;
349 :
350 0 : return error;
351 :
352 0 : }
353 : //______________________________________________________________________________________________
354 : Bool_t AliTRDPreprocessor::ExtractHalfChamberStatusDAQ()
355 : {
356 : //
357 : // Half chamber status algorithm running on DAQ
358 : //
359 :
360 : Bool_t error = kFALSE;
361 :
362 0 : AliCDBMetaData metaData;
363 0 : metaData.SetBeamPeriod(0);
364 0 : metaData.SetResponsible("Raphaelle Bailhache");
365 0 : metaData.SetComment("TRD calib test");
366 :
367 : // Take the output of the DA on DAQ
368 0 : TList * listpad = GetFileSources(kDAQ,"HALFCHAMBERSTATUS");
369 0 : if (!listpad) {
370 0 : Log("No list found for the HalfChamberStatus");
371 0 : return kTRUE;
372 : }
373 :
374 0 : AliTRDCalibChamberStatus *calPed = 0x0;
375 :
376 : // loop through all files (only one normally)
377 : UInt_t index = 0;
378 0 : while (listpad->At(index)!=NULL) {
379 0 : TObjString* fileNameEntry = (TObjString*) listpad->At(index);
380 0 : if (fileNameEntry != NULL)
381 : {
382 0 : TString fileName = GetFile(kDAQ, "HALFCHAMBERSTATUS",
383 0 : fileNameEntry->GetString().Data());
384 0 : if(fileName.Length() ==0){
385 0 : Log(Form("Error by retrieving the file %d for the halfchamberstatus",(Int_t)index));
386 0 : delete listpad;
387 0 : return kTRUE;
388 : }
389 :
390 0 : TFile *f = TFile::Open(fileName);
391 0 : f->GetObject("calibchamberstatus",calPed);
392 :
393 0 : if(calPed) {
394 :
395 : // store as reference data
396 0 : TString name("HalfChamberStatus");
397 0 : if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
398 0 : Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
399 : error = kTRUE;
400 0 : }
401 0 : } // calPed
402 0 : else Log(Form("Error getting AliTRDCalibChamberStatus onject from file"));
403 :
404 0 : } // fileNameEntry
405 0 : ++index;
406 0 : }// while (list)
407 :
408 0 : Log(Form("%d elements found in the list for the halfchamberstatus",(Int_t)index));
409 0 : if(index!=1){
410 0 : delete listpad;
411 0 : return kTRUE;
412 : }
413 :
414 : //
415 : // Produce the AliTRDCalChamberStatus name calHalfChamberStatus
416 : //
417 : AliTRDCalChamberStatus *calHalfChamberStatus = 0x0;
418 0 : if(calPed) {
419 : //calPed->AnalyseHisto(); // check number of events, create calHalfChamberStatus (done on DAQ)
420 0 : if(fCalDCSObjEOR) {
421 0 : calPed->CheckEORStatus((AliTRDCalDCSv2 *)fCalDCSObjEOR);
422 : }
423 0 : calHalfChamberStatus=(AliTRDCalChamberStatus *)calPed->GetCalChamberStatus();
424 0 : }
425 :
426 : //
427 : // Store
428 : //
429 :
430 0 : AliCDBMetaData md3;
431 0 : md3.SetObjectClassName("AliTRDCalChamberStatus");
432 0 : md3.SetResponsible("Raphaelle Bailhache");
433 0 : md3.SetBeamPeriod(1);
434 0 : md3.SetComment("TRD calib test");
435 0 : if(!Store("Calib","ChamberStatus" ,(TObject *)calHalfChamberStatus, &md3, 0, kTRUE)){
436 0 : Log("Error storing the pedestal");
437 0 : delete listpad;
438 0 : return kTRUE;
439 : }
440 :
441 0 : delete listpad;
442 0 : return error;
443 :
444 0 : }
445 : //______________________________________________________________________________________________
446 : Bool_t AliTRDPreprocessor::ExtractPedestals()
447 : {
448 : //
449 : // Pedestal running on LDCs at the DAQ
450 : //
451 :
452 : //
453 : // The reference data are stored in:
454 : // PadStatus1 for sm-00-01-02-09-10-11
455 : // PadStatus2 for sm-03-04-05-12-13-14
456 : // PadStatus3 for sm-06-07-08-15-16-17
457 : // PadStatus0 if nothing found..means problems
458 : //
459 :
460 : Bool_t error = kFALSE;
461 :
462 : // Init a AliTRDCalibPadStatus
463 0 : AliTRDCalibPadStatus calPedSum = AliTRDCalibPadStatus();
464 :
465 0 : AliCDBMetaData metaData;
466 0 : metaData.SetBeamPeriod(0);
467 0 : metaData.SetResponsible("Raphaelle Bailhache");
468 0 : metaData.SetComment("TRD calib test");
469 :
470 : // Sum the contributions of the LDCs
471 0 : TList * listpad = GetFileSources(kDAQ,"PADSTATUS");
472 0 : if (!listpad) {
473 0 : Log("No list found for the PEDESTRAL Run");
474 0 : return kTRUE;
475 : }
476 :
477 : // loop through all files from LDCs
478 : UInt_t index = 0;
479 0 : while (listpad->At(index)!=NULL) {
480 0 : TObjString* fileNameEntry = (TObjString*) listpad->At(index);
481 0 : if (fileNameEntry != NULL)
482 : {
483 0 : TString fileName = GetFile(kDAQ, "PADSTATUS",
484 0 : fileNameEntry->GetString().Data());
485 0 : if(fileName.Length() ==0){
486 0 : Log(Form("Error by retrieving the file %d for the pedestal",(Int_t)index));
487 0 : delete listpad;
488 0 : return kTRUE;
489 : }
490 :
491 0 : TFile *f = TFile::Open(fileName);
492 0 : AliTRDCalibPadStatus *calPed;
493 0 : f->GetObject("calibpadstatus",calPed);
494 :
495 0 : if(calPed){
496 :
497 : // analyse
498 : //calPed->AnalyseHisto();
499 :
500 : // Add to the calPedSum
501 0 : for (Int_t idet=0; idet<540; idet++) {
502 0 : AliTRDCalROC *rocMean = calPed->GetCalRocMean(idet, kFALSE);
503 0 : if ( rocMean ) {
504 0 : calPedSum.SetCalRocMean(rocMean,idet);
505 : }
506 0 : AliTRDCalROC *rocRMS = calPed->GetCalRocRMS(idet, kFALSE);
507 0 : if ( rocRMS ) {
508 0 : calPedSum.SetCalRocRMS(rocRMS,idet);
509 : }
510 0 : AliTRDCalROC *rocMeand = calPed->GetCalRocMeand(idet, kFALSE);
511 0 : if ( rocMeand ) {
512 0 : calPedSum.SetCalRocMeand(rocMeand,idet);
513 : }
514 0 : AliTRDCalROC *rocRMSd = calPed->GetCalRocRMSd(idet, kFALSE);
515 0 : if ( rocRMSd ) {
516 0 : calPedSum.SetCalRocRMSd(rocRMSd,idet);
517 : }
518 : }// det loop
519 :
520 : // store as reference data
521 0 : TString name("PadStatus");
522 0 : name += index;
523 0 : if(!StoreReferenceData("DAQData",(const char *)name,(TObject *) calPed,&metaData)){
524 0 : Log(Form("Error storing AliTRDCalibPadStatus object %d as reference data",(Int_t)index));
525 : error = kTRUE;
526 0 : }
527 :
528 0 : } // calPed
529 0 : } // fileNameEntry
530 0 : ++index;
531 0 : }// while (list)
532 :
533 0 : Log(Form("%d elements found in the list for the pedestal",(Int_t)index));
534 0 : if(index==0){
535 0 : delete listpad;
536 0 : return kTRUE;
537 : }
538 :
539 : //
540 : // Create pedestal
541 : //
542 :
543 : // Create Pad Status
544 0 : AliTRDCalPadStatus *calPadStatus = calPedSum.CreateCalPadStatus();
545 : // Create Noise
546 : //Make the AliTRDCalPad
547 0 : AliTRDCalPad *calPad2 = calPedSum.CreateCalPad();
548 : //Make the AliTRDCalDet correspondant
549 0 : AliTRDCalDet *calDet = calPedSum.CreateCalDet();
550 :
551 : //
552 : // Take the noise and Pad status from the previous OCDB
553 : //
554 :
555 : AliTRDCalPad *calPadPrevious=0;
556 0 : AliCDBEntry* entry = GetFromOCDB("Calib", "PadNoise");
557 0 : if (entry) calPadPrevious = (AliTRDCalPad*)entry->GetObject();
558 0 : if ( calPadPrevious==NULL ) {
559 0 : Log("AliTRDPreprocsessor: No previous TRD pad noise entry available.\n");
560 0 : calPadPrevious = new AliTRDCalPad("PadNoise", "PadNoise");
561 0 : }
562 :
563 : AliTRDCalPadStatus *calPadStatusPrevious=0;
564 0 : entry = GetFromOCDB("Calib", "PadStatus");
565 0 : if (entry) calPadStatusPrevious = (AliTRDCalPadStatus*)entry->GetObject();
566 0 : if ( calPadStatusPrevious==NULL ) {
567 0 : Log("AliTRDPreprocsessor: No previous TRD pad status entry available.\n");
568 0 : calPadStatusPrevious = new AliTRDCalPadStatus("padstatus", "padstatus");
569 0 : for (Int_t idet=0; idet<540; ++idet)
570 : {
571 0 : AliTRDCalSingleChamberStatus *calROC = calPadStatusPrevious->GetCalROC(idet);
572 0 : for(Int_t k = 0; k < calROC->GetNchannels(); k++){
573 0 : calROC->SetStatus(k,AliTRDCalPadStatus::kMasked);
574 : }
575 : }
576 0 : }
577 :
578 :
579 : // Loop over detectors for check
580 0 : for (Int_t det=0; det<AliTRDgeometry::kNdet; ++det) {
581 :
582 : // noise
583 0 : AliTRDCalROC *calROCPreviousNoise = calPadPrevious->GetCalROC(det);
584 0 : AliTRDCalROC *calROCNoise = calPad2->GetCalROC(det);
585 :
586 : // padstatus
587 0 : AliTRDCalSingleChamberStatus *calROCPreviousStatus = calPadStatusPrevious->GetCalROC(det);
588 0 : AliTRDCalSingleChamberStatus *calROCStatus = calPadStatus->GetCalROC(det);
589 :
590 :
591 : // loop over first half and second half chamber
592 0 : for(Int_t half = 0; half < 2; half++){
593 :
594 0 : Bool_t data = AreThereDataPedestal(calROCStatus,(Bool_t)half);
595 : //printf("There are data for the detector %d the half %d: %d\n",det,half,data);
596 0 : if(!data){
597 : // look if data in the OCDB
598 0 : Bool_t dataPrevious = AreThereDataPedestal(calROCPreviousStatus,(Bool_t)half);
599 : // if no data at all, set to default value
600 0 : if(!dataPrevious){
601 0 : SetDefaultStatus(*calROCStatus,(Bool_t)half);
602 0 : SetDefaultNoise(*calROCNoise,(Bool_t)half);
603 : }
604 : else{
605 : // if data, set to previous value
606 0 : SetStatus(*calROCStatus,calROCPreviousStatus,(Bool_t)half);
607 0 : SetNoise(*calROCNoise,calROCPreviousNoise,(Bool_t)half);
608 : }
609 0 : }
610 : }
611 : }
612 :
613 : //
614 : // Store
615 : //
616 :
617 0 : AliCDBMetaData md3;
618 0 : md3.SetObjectClassName("AliTRDCalPadStatus");
619 0 : md3.SetResponsible("Raphaelle Bailhache");
620 0 : md3.SetBeamPeriod(1);
621 0 : md3.SetComment("TRD calib test");
622 0 : if(!Store("Calib","PadStatus" ,(TObject *)calPadStatus, &md3, 0, kTRUE)){
623 0 : Log("Error storing the pedestal");
624 0 : delete listpad;
625 0 : return kTRUE;
626 : }
627 :
628 0 : AliCDBMetaData md4;
629 0 : md4.SetObjectClassName("AliTRDCalPad");
630 0 : md4.SetResponsible("Raphaelle Bailhache");
631 0 : md4.SetBeamPeriod(1);
632 0 : md4.SetComment("TRD calib test");
633 0 : if(!Store("Calib","PadNoise" ,(TObject *)calPad2, &md4, 0, kTRUE)){
634 0 : Log("Error storing the pedestal");
635 0 : delete listpad;
636 0 : return kTRUE;
637 : }
638 :
639 0 : AliCDBMetaData md5;
640 0 : md5.SetObjectClassName("AliTRDCalDet");
641 0 : md5.SetResponsible("Raphaelle Bailhache");
642 0 : md5.SetBeamPeriod(1);
643 0 : md5.SetComment("TRD calib test");
644 0 : if(!Store("Calib","DetNoise" ,(TObject *)calDet, &md5, 0, kTRUE)){
645 0 : Log("Error storing the pedestal");
646 0 : delete listpad;
647 0 : return kTRUE;
648 : }
649 :
650 0 : delete listpad;
651 0 : return error;
652 :
653 0 : }
654 :
655 : //__________________________________________________________________
656 : Bool_t AliTRDPreprocessor::AreThereDataPedestal(const AliTRDCalSingleChamberStatus * const calROCStatus
657 : , Bool_t second)
658 : {
659 :
660 : //
661 : // Data for this half chamber
662 : //
663 :
664 : Bool_t data = kFALSE;
665 0 : Int_t nCols = calROCStatus->GetNcols();
666 : Int_t nCol0 = 0;
667 0 : Int_t nColE = (Int_t) nCols/2 - 2;
668 0 : if(second) {
669 0 : nCol0 = nColE + 4;
670 : nColE = nCols;
671 0 : }
672 :
673 : Int_t totalnumberofpads = 0;
674 : Int_t totalnumberofdata = 0;
675 :
676 0 : for(Int_t col = nCol0; col < nColE; col++){
677 0 : for(Int_t row = 0; row < calROCStatus->GetNrows(); row++){
678 0 : totalnumberofpads++;
679 : //printf("ismasked %d\n",(Int_t)calROCStatus->IsMasked(col,row));
680 0 : if(!calROCStatus->GetStatus(col,row)) {
681 : data = kTRUE;
682 0 : totalnumberofdata++;
683 0 : }
684 : }
685 : }
686 0 : if(totalnumberofdata < (Int_t)(totalnumberofpads/2)) data = kFALSE;
687 :
688 0 : return data;
689 :
690 : }
691 : //__________________________________________________________________
692 : void AliTRDPreprocessor::SetDefaultStatus(AliTRDCalSingleChamberStatus &calROCStatus, Bool_t second){
693 :
694 : //
695 : // default status for this half chamber
696 : //
697 :
698 0 : Int_t nCols = calROCStatus.GetNcols();
699 : Int_t nCol0 = 0;
700 0 : Int_t nColE = (Int_t) nCols/2;
701 0 : if(second) {
702 : nCol0 = nColE;
703 : nColE = nCols;
704 0 : }
705 0 : for(Int_t col = nCol0; col < nColE; col++){
706 0 : for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
707 0 : calROCStatus.SetStatus(col,row,0);
708 : }
709 : }
710 0 : }
711 : //__________________________________________________________________
712 : void AliTRDPreprocessor::SetStatus(AliTRDCalSingleChamberStatus &calROCStatus, AliTRDCalSingleChamberStatus *calROCStatusPrevious,Bool_t second){
713 :
714 : //
715 : // previous status for this half chamber
716 : //
717 :
718 0 : Int_t nCols = calROCStatus.GetNcols();
719 : Int_t nCol0 = 0;
720 0 : Int_t nColE = (Int_t) nCols/2;
721 0 : if(second) {
722 : nCol0 = nColE;
723 : nColE = nCols;
724 0 : }
725 0 : for(Int_t col = nCol0; col < nColE; col++){
726 0 : for(Int_t row = 0; row < calROCStatus.GetNrows(); row++){
727 0 : calROCStatus.SetStatus(col,row,calROCStatusPrevious->GetStatus(col,row));
728 : }
729 : }
730 0 : }
731 : //__________________________________________________________________
732 : void AliTRDPreprocessor::SetDefaultNoise(AliTRDCalROC &calROCNoise, Bool_t second){
733 :
734 : //
735 : // default noise for this half chamber
736 : //
737 :
738 0 : Int_t nCols = calROCNoise.GetNcols();
739 : Int_t nCol0 = 0;
740 0 : Int_t nColE = (Int_t) nCols/2;
741 0 : if(second) {
742 : nCol0 = nColE;
743 : nColE = nCols;
744 0 : }
745 0 : for(Int_t col = nCol0; col < nColE; col++){
746 0 : for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
747 0 : calROCNoise.SetValue(col,row,0.12);
748 : }
749 : }
750 0 : }
751 : //__________________________________________________________________
752 : void AliTRDPreprocessor::SetNoise(AliTRDCalROC &calROCNoise, AliTRDCalROC *calROCNoisePrevious, Bool_t second){
753 :
754 : //
755 : // previous noise for this half chamber
756 : //
757 :
758 0 : Int_t nCols = calROCNoise.GetNcols();
759 : Int_t nCol0 = 0;
760 0 : Int_t nColE = (Int_t) nCols/2;
761 0 : if(second) {
762 : nCol0 = nColE;
763 : nColE = nCols;
764 0 : }
765 0 : for(Int_t col = nCol0; col < nColE; col++){
766 0 : for(Int_t row = 0; row < calROCNoise.GetNrows(); row++){
767 0 : calROCNoise.SetValue(col,row,calROCNoisePrevious->GetValue(col,row));
768 : }
769 : }
770 0 : }
771 : //______________________________________________________________________________________________
772 : Bool_t AliTRDPreprocessor::ExtractDriftVelocityDAQ()
773 : {
774 : //
775 : // Drift velocity DA running on monitoring servers at the DAQ
776 : //
777 :
778 : Bool_t error = kFALSE;
779 :
780 : // Objects for HLT and DAQ zusammen
781 0 : AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
782 0 : AliCDBMetaData metaData;
783 0 : metaData.SetBeamPeriod(0);
784 0 : metaData.SetResponsible("Raphaelle Bailhache");
785 0 : metaData.SetComment("TRD calib test");
786 : // Store the infos for the detector
787 0 : AliCDBMetaData md1;
788 0 : md1.SetObjectClassName("AliTRDCalDet");
789 0 : md1.SetResponsible("Raphaelle Bailhache");
790 0 : md1.SetBeamPeriod(0);
791 0 : md1.SetComment("TRD calib test");
792 : // Store the infos for the pads
793 0 : AliCDBMetaData md2;
794 0 : md2.SetObjectClassName("AliTRDCalPad");
795 0 : md2.SetResponsible("Raphaelle Bailhache");
796 0 : md2.SetBeamPeriod(0);
797 0 : md2.SetComment("TRD calib test");
798 :
799 : // Take the file from the DAQ file exchange server
800 0 : TList *listdaq = GetFileSources(kDAQ,"VDRIFT");
801 0 : if (!listdaq) {
802 0 : Log("No list found for vdrift (DAQ)");
803 0 : return kTRUE;
804 : }
805 :
806 0 : if(listdaq->GetSize() !=1){
807 0 : Log(Form("Problem on the size of the list: %d (DAQ)",listdaq->GetSize()));
808 0 : delete listdaq;
809 0 : return kTRUE;
810 : }
811 :
812 0 : TObjString* fileNameEntry = (TObjString*) listdaq->At(0);
813 0 : if(fileNameEntry != NULL){
814 0 : TString fileName = GetFile(kDAQ, "VDRIFT",
815 0 : fileNameEntry->GetString().Data());
816 0 : if(fileName.Length() ==0){
817 0 : Log("Error retrieving the file vdrift (DAQ)");
818 0 : delete listdaq;
819 0 : return kTRUE;
820 : }
821 0 : TFile *filedaq = TFile::Open(fileName);
822 0 : TProfile2D *histodriftvelocity = (TProfile2D *) filedaq->Get("PH2d");
823 0 : if (histodriftvelocity) {
824 :
825 : // store as reference data
826 0 : if(!StoreReferenceData("DAQData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
827 0 : Log("Error storing 2D Profile for vdrift from the DAQ");
828 : error = kTRUE;
829 0 : }
830 :
831 : // analyse
832 :
833 0 : Log("Take the PH reference data. Now we will try to fit\n");
834 0 : calibra->SetMinEntries(2000); // If there is less than 2000
835 0 : calibra->AnalysePH(histodriftvelocity);
836 :
837 0 : Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
838 0 : + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
839 0 : Int_t nbfit = calibra->GetNumberFit();
840 0 : Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
841 0 : Int_t nbE = calibra->GetNumberEnt();
842 :
843 : // if enough statistics store the results
844 0 : if ((nbtg > 0) &&
845 0 : (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
846 : // create the cal objects
847 0 : calibra->RemoveOutliers(1,kTRUE);
848 0 : calibra->PutMeanValueOtherVectorFit(1,kTRUE);
849 0 : calibra->RemoveOutliers2(kTRUE);
850 0 : calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
851 0 : TObjArray object = calibra->GetVectorFit();
852 0 : AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
853 : // TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
854 0 : object = calibra->GetVectorFit2();
855 0 : AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
856 : // TObject *objtime0pad = calibra->CreatePadObjectT0();
857 0 : calibra->ResetVectorFit();
858 : // store
859 0 : if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
860 0 : Log("Error storing the calibration object for the chamber vdrift (DAQ)");
861 : error = kTRUE;
862 0 : }
863 0 : if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
864 0 : Log("Error storing the calibration object for the chamber t0 (DAQ)");
865 : error = kTRUE;
866 0 : }
867 : // if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
868 : // Log("Error storing the calibration object for the local drift velocity (DAQ)");
869 : // error = kTRUE;
870 : // }
871 : // if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
872 : // Log("Error storing the calibration object for the local time0 (DAQ)");
873 : // error = kTRUE;
874 : // }
875 0 : }
876 : else{
877 0 : Log("Not enough statistics for the average pulse height (DAQ)");
878 : }
879 0 : } // histo here
880 0 : }// if fileNameEntry
881 :
882 0 : delete listdaq;
883 0 : return error;
884 :
885 0 : }
886 :
887 : //______________________________________________________________________________________________
888 : Bool_t AliTRDPreprocessor::ExtractHLT()
889 : {
890 : //
891 : // Gain, vdrift and PRF calibration running on HLT
892 : // return kTRUE if NULL pointer to the list
893 : //
894 :
895 : Bool_t error = kFALSE;
896 :
897 : // Objects for HLT and DAQ zusammen
898 0 : AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
899 0 : AliCDBMetaData metaData;
900 0 : metaData.SetBeamPeriod(0);
901 0 : metaData.SetResponsible("Raphaelle Bailhache");
902 0 : metaData.SetComment("TRD calib test");
903 : // Store the infos for the detector
904 0 : AliCDBMetaData md1;
905 0 : md1.SetObjectClassName("AliTRDCalDet");
906 0 : md1.SetResponsible("Raphaelle Bailhache");
907 0 : md1.SetBeamPeriod(0);
908 0 : md1.SetComment("TRD calib test");
909 : // Store the infos for the pads
910 0 : AliCDBMetaData md2;
911 0 : md2.SetObjectClassName("AliTRDCalPad");
912 0 : md2.SetResponsible("Raphaelle Bailhache");
913 0 : md2.SetBeamPeriod(0);
914 0 : md2.SetComment("TRD calib test");
915 :
916 : // Take the file from the HLT file exchange server
917 0 : TList *listhlt = GetFileSources(kHLT,"GAINDRIFTPRF");
918 0 : if (!listhlt) {
919 0 : Log("No list found for the HLT");
920 0 : return kTRUE;
921 : }
922 :
923 0 : if(listhlt->GetSize() != 1) {
924 0 : Log(Form("Problem on the size of the list: %d (HLT)",listhlt->GetSize()));
925 0 : delete listhlt;
926 0 : return kTRUE;
927 : }
928 :
929 0 : TObjString* fileNameEntry = (TObjString*) listhlt->At(0);
930 0 : if(fileNameEntry != NULL){
931 0 : TString fileName = GetFile(kHLT, "GAINDRIFTPRF",
932 0 : fileNameEntry->GetString().Data());
933 0 : if(fileName.Length() ==0){
934 0 : Log("Error retrieving the file (HLT)");
935 0 : delete listhlt;
936 0 : return kTRUE;
937 : }
938 : // Take the file
939 0 : TFile *filehlt = TFile::Open(fileName);
940 :
941 : // gain
942 0 : TH2I *histogain = (TH2I *) filehlt->Get("CH2d");
943 0 : if (histogain) {
944 0 : histogain->SetDirectory(0);
945 : // store the reference data
946 0 : if(!StoreReferenceData("HLTData","Gain",(TObject *) histogain,&metaData)){
947 0 : Log("Error storing 2D histos for gain");
948 : error = kTRUE;
949 0 : }
950 : // analyse
951 0 : Log("Take the CH reference data. Now we will try to fit\n");
952 0 : calibra->SetMinEntries(800); // If there is less than 1000 entries in the histo: no fit
953 0 : calibra->AnalyseCH(histogain);
954 0 : Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
955 0 : + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
956 0 : Int_t nbfit = calibra->GetNumberFit();
957 0 : Int_t nbE = calibra->GetNumberEnt();
958 : // enough statistics
959 0 : if ((nbtg > 0) &&
960 0 : (nbfit >= 0.5*nbE) && (nbE > 30)) {
961 : // create the cal objects
962 0 : calibra->PutMeanValueOtherVectorFit(1,kTRUE);
963 0 : TObjArray object = calibra->GetVectorFit();
964 0 : AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object);
965 : // TObject *objgainpad = calibra->CreatePadObjectGain();
966 : // store them
967 0 : if(!Store("Calib","ChamberGainFactor",(TObject *) objgaindet ,&md1,0,kTRUE)){
968 0 : Log("Error storing the calibration object for the chamber gain");
969 : error = kTRUE;
970 0 : }
971 : // if(!Store("Calib","LocalGainFactor" ,(TObject *) objgainpad ,&md2,0,kTRUE)){
972 : // Log("Error storing the calibration object for the local gain factor");
973 : // error = kTRUE;
974 : // }
975 0 : }
976 0 : calibra->ResetVectorFit();
977 0 : }// if histogain
978 :
979 : // vdrift
980 0 : fVdriftHLT = kFALSE;
981 0 : TProfile2D *histodriftvelocity = (TProfile2D *) filehlt->Get("PH2d");
982 0 : if (histodriftvelocity) {
983 0 : histodriftvelocity->SetDirectory(0);
984 : // store the reference data
985 0 : if(!StoreReferenceData("HLTData","VdriftT0",(TObject *) histodriftvelocity,&metaData)){
986 0 : Log("Error storing 2D Profile for average pulse height (HLT)");
987 : error = kTRUE;
988 0 : }
989 : // analyse
990 0 : Log("Take the PH reference data. Now we will try to fit\n");
991 0 : calibra->SetMinEntries(800*20); // If there is less than 20000
992 0 : calibra->AnalysePH(histodriftvelocity);
993 0 : Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
994 0 : + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
995 0 : Int_t nbfit = calibra->GetNumberFit();
996 0 : Int_t nbfitSuccess = calibra->GetNumberFitSuccess();
997 0 : Int_t nbE = calibra->GetNumberEnt();
998 : // enough statistics
999 0 : if ((nbtg > 0) &&
1000 0 : (nbfit >= 0.5*nbE) && (nbE > 30) && (nbfitSuccess > 30)) {
1001 : // create the cal objects
1002 0 : calibra->RemoveOutliers(1,kTRUE);
1003 0 : calibra->PutMeanValueOtherVectorFit(1,kTRUE);
1004 0 : calibra->RemoveOutliers2(kTRUE);
1005 0 : calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
1006 0 : TObjArray object = calibra->GetVectorFit();
1007 0 : AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
1008 : // TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
1009 0 : object = calibra->GetVectorFit2();
1010 0 : AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
1011 : //TObject *objtime0pad = calibra->CreatePadObjectT0();
1012 : // store them
1013 0 : if(!Store("Calib","ChamberVdrift" ,(TObject *) objdriftvelocitydet,&md1,0,kTRUE)){
1014 0 : Log("Error storing the calibration object for the chamber vdrift (HLT)");
1015 : error = kTRUE;
1016 0 : }
1017 0 : if(!Store("Calib","ChamberT0" ,(TObject *) objtime0det ,&md1,0,kTRUE)){
1018 0 : Log("Error storing the calibration object for the chamber t0 (HLT)");
1019 : error = kTRUE;
1020 0 : }
1021 : // if(!Store("Calib","LocalVdrift" ,(TObject *) objdriftvelocitypad,&md2,0,kTRUE)){
1022 : // Log("Error storing the calibration object for the local drift velocity (HLT)");
1023 : // error = kTRUE;
1024 : // }
1025 : // if(!Store("Calib","LocalT0" ,(TObject *) objtime0pad ,&md2,0,kTRUE)){
1026 : // Log("Error storing the calibration object for the local time0 (HLT)");
1027 : // error = kTRUE;
1028 : // }
1029 0 : fVdriftHLT = kTRUE;
1030 0 : }
1031 0 : calibra->ResetVectorFit();
1032 0 : }// if TProfile2D
1033 :
1034 : // prf
1035 : /*
1036 : TProfile2D *histoprf = (TProfile2D *) filehlt->Get("PRF2d");
1037 : if (histoprf) {
1038 : histoprf->SetDirectory(0);
1039 : // store reference data
1040 : if(!StoreReferenceData("HLTData","PRF",(TObject *) histoprf,&metaData)){
1041 : Log("Error storing the 2D Profile for Pad Response Function");
1042 : error = kTRUE;
1043 : }
1044 : // analyse
1045 : Log("Take the PRF reference data. Now we will try to fit\n");
1046 : calibra->SetMinEntries(600); // If there is less than 20000
1047 : calibra->AnalysePRFMarianFit(histoprf);
1048 : Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
1049 : + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
1050 : Int_t nbfit = calibra->GetNumberFit();
1051 : Int_t nbE = calibra->GetNumberEnt();
1052 : // enough statistics
1053 : if ((nbtg > 0) &&
1054 : (nbfit >= 0.95*nbE) && (nbE > 30)) {
1055 : // create cal pad objects
1056 : TObjArray object = calibra->GetVectorFit();
1057 : TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
1058 : // store them
1059 : if(!Store("Calib","PRFWidth" ,(TObject *) objPRFpad ,&md2,0,kTRUE)){
1060 : Log("Error storing the calibration object for the Pad Response Function");
1061 : error = kTRUE;
1062 : }
1063 : }
1064 : calibra->ResetVectorFit();
1065 : }// if PRF
1066 : */
1067 0 : }// if fileNameEntry
1068 :
1069 0 : delete listhlt;
1070 0 : return error;
1071 :
1072 0 : }
1073 :
1074 : //_____________________________________________________________________________
1075 : UInt_t AliTRDPreprocessor::ProcessDCSConfigData()
1076 : {
1077 : // process the configuration of FEE, PTR and GTU
1078 : // reteive XML filei(s) from the DCS FXS
1079 : // parse it/them and store TObjArrays in the CDB
1080 :
1081 0 : Log("Processing the DCS config summary files.");
1082 :
1083 0 : if(fCalDCSObjSOR) delete fCalDCSObjSOR; fCalDCSObjSOR=0;
1084 0 : if(fCalDCSObjEOR) delete fCalDCSObjEOR; fCalDCSObjEOR=0;
1085 :
1086 0 : TString xmlFile[2];
1087 0 : TString esor[2] = {"SOR", "EOR"};
1088 : // get the XML files
1089 0 : xmlFile[0] = GetFile(kDCS,"CONFIGSUMMARYSOR","");
1090 0 : xmlFile[1] = GetFile(kDCS,"CONFIGSUMMARYEOR","");
1091 :
1092 : // check both files
1093 0 : for (Int_t iFile=0; iFile<2; iFile++) {
1094 :
1095 : // check if the file are there
1096 0 : if (xmlFile[iFile].IsNull()) {
1097 0 : Log(Form("Warning: %s file not found!", esor[iFile].Data()));
1098 : continue;
1099 : }
1100 0 : Log(Form("%s file found: %s", esor[iFile].Data(), xmlFile[iFile].Data()));
1101 :
1102 : // test the file
1103 0 : std::ifstream fileTest;
1104 0 : fileTest.open(xmlFile[iFile].Data(), std::ios_base::binary | std::ios_base::in);
1105 0 : if (!fileTest.good() || fileTest.eof() || !fileTest.is_open()) {
1106 0 : Log(Form("Warning: %s file not valid!", esor[iFile].Data()));
1107 0 : continue;
1108 : }
1109 : // check if the file is empty
1110 0 : fileTest.seekg(0, std::ios_base::end);
1111 0 : if (static_cast<int>(fileTest.tellg()) < 2) {
1112 0 : Log(Form("Warning: %s file empty!", esor[iFile].Data()));
1113 0 : continue;
1114 : }
1115 0 : Log(Form("%s file is valid.", esor[iFile].Data()));
1116 : // Close the file descriptor
1117 0 : fileTest.close();
1118 :
1119 : // make a robust XML validation
1120 0 : TSAXParser testParser;
1121 0 : if (testParser.ParseFile(xmlFile[iFile].Data()) < 0 ) {
1122 0 : Log(Form("Warning: %s XML content is not well-formed!", esor[iFile].Data()));
1123 0 : continue;
1124 : }
1125 0 : Log(Form("%s XML content is well-formed.", esor[iFile].Data()));
1126 :
1127 : // create parser and parse
1128 0 : TSAXParser saxParser;
1129 0 : AliTRDSaxHandler saxHandler;
1130 0 : saxParser.ConnectToHandler("AliTRDSaxHandler", &saxHandler);
1131 0 : saxParser.ParseFile(xmlFile[iFile].Data());
1132 :
1133 : // report errors of the parser if present
1134 0 : if (saxParser.GetParseCode() != 0) {
1135 0 : Log(Form("Warning: %s XML file validation failed! Parse code: %d", esor[iFile].Data(), saxParser.GetParseCode()));
1136 0 : continue;
1137 : }
1138 0 : Log(Form("%s XML validation OK.", esor[iFile].Data()));
1139 :
1140 : // report errors of the handler if present
1141 0 : if (saxHandler.GetHandlerStatus() != 0) {
1142 0 : Log(Form("Warning: Creating %s calibration object failed! Error code: %d", esor[iFile].Data(), saxHandler.GetHandlerStatus()));
1143 0 : continue;
1144 : }
1145 0 : Log(Form("%s SAX handler reports no errors.", esor[iFile].Data()));
1146 :
1147 : // get the calibration object storing the data from the handler
1148 0 : AliTRDCalDCSv2 *calDCSObj = (AliTRDCalDCSv2*)saxHandler.GetCalDCSObj()->Clone();
1149 0 : calDCSObj->EvaluateGlobalParameters();
1150 0 : calDCSObj->SetRunType(GetRunType());
1151 0 : calDCSObj->SetStartTime(GetStartTimeDCSQuery());
1152 0 : calDCSObj->SetEndTime(GetEndTimeDCSQuery());
1153 0 : if (iFile == 0) fCalDCSObjSOR = calDCSObj;
1154 0 : if (iFile == 1) fCalDCSObjEOR = calDCSObj;
1155 0 : }
1156 :
1157 : // If none of the two objects exists we don't even store a CDB entry
1158 0 : if (!fCalDCSObjSOR && !fCalDCSObjEOR) {
1159 0 : Log("ERROR: Failed reading both files!");
1160 0 : return 1;
1161 : }
1162 :
1163 : // put both objects in one TObjArray to store them
1164 0 : TObjArray calObjArray(2);
1165 0 : calObjArray.SetOwner();
1166 :
1167 0 : if (fCalDCSObjSOR) {
1168 0 : calObjArray.AddAt(fCalDCSObjSOR,0);
1169 0 : Log("TRDCalDCS object for SOR created.");
1170 : }
1171 0 : if (fCalDCSObjEOR) {
1172 0 : calObjArray.AddAt(fCalDCSObjEOR,1);
1173 0 : Log("TRDCalDCS object for EOR created.");
1174 : }
1175 :
1176 : // store the DCS calib data in the CDB
1177 0 : AliCDBMetaData metaData1;
1178 0 : metaData1.SetBeamPeriod(0);
1179 0 : metaData1.SetResponsible("Frederick Kramer");
1180 0 : metaData1.SetComment("DCS configuration data in two AliTRDCalDCSv2 objects in one TObjArray (0:SOR, 1:EOR).");
1181 0 : if (!Store("Calib", "DCS", &calObjArray, &metaData1, 0, kTRUE)) { Log("ERROR: Storing DCS config data object failed!"); return 1; }
1182 :
1183 : // ALICE policy is to always have an SOR object
1184 0 : if(!fCalDCSObjSOR){
1185 0 : Log("ERROR: Could not build an SOR object.");
1186 0 : return 1;
1187 : }
1188 :
1189 0 : Log("SUCCESS: Processing of the DCS config summary file DONE.");
1190 0 : return 0;
1191 0 : }
1192 :
|