Minor Bugfix
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDA.cxx
CommitLineData
a0180e76 1/**************************************************************************
2 * Copyright(c) 2004, 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/** @file AliFMDBaseDA.cxx
17 @author Hans Hjersing Dalsgaard <canute@nbi.dk>
18 @date Wed Mar 26 11:30:45 2008
19 @brief Base class for detector algorithms.
20*/
21//
e9c06036 22// This is the implementation of the (virtual) base class for the FMD
23// detector algorithms(DA). It implements the creation of the relevant
24// containers and handles the loop over the raw data. The derived
25// classes can control the parameters and action to be taken making
26// this the base class for the Pedestal, Gain and Physics DA.
a0180e76 27//
28
29#include "AliFMDBaseDA.h"
09b6c804 30#include "AliRawReader.h"
31#include "AliFMDDigit.h"
32#include "AliFMDParameters.h"
a0180e76 33#include "AliFMDRawReader.h"
1656783c 34#include "AliFMDCalibSampleRate.h"
bd727bee 35#include "AliFMDCalibStripRange.h"
a0180e76 36#include "AliLog.h"
3effc6e7 37#include "AliRawEventHeaderBase.h"
09b6c804 38#include "AliFMDDigit.h"
39#include <TClonesArray.h>
40#include <TFile.h>
6cf6e7a0 41#include <TDatime.h>
42#include <TSystem.h>
2a082c96 43#include <TH2F.h>
a31ea3ce 44#include <TStopwatch.h>
45#include <TROOT.h>
46#include <TPluginManager.h>
09b6c804 47#include <iostream>
48#include <fstream>
a31ea3ce 49
a0180e76 50//_____________________________________________________________________
51ClassImp(AliFMDBaseDA)
e9c06036 52#if 0
53; // Do not delete - to let Emacs for mat the code
54#endif
55
56//_____________________________________________________________________
57const char*
58AliFMDBaseDA::GetStripPath(UShort_t det,
59 Char_t ring,
60 UShort_t sec,
61 UShort_t str,
62 Bool_t full) const
63{
6cf6e7a0 64 // Get the strip path
65 //
66 // Parameters
67 // det Detector number
68 // ring Ring identifier
69 // sec Sector number
70 // str Strip number
71 // full If true, return full path
72 //
73 // Return
74 // The path
e9c06036 75 return Form("%s%sFMD%d%c[%02d,%03d]",
76 (full ? GetSectorPath(det, ring, sec, full) : ""),
77 (full ? "/" : ""), det, ring, sec, str);
78}
79//_____________________________________________________________________
80const char*
81AliFMDBaseDA::GetSectorPath(UShort_t det,
82 Char_t ring,
83 UShort_t sec,
84 Bool_t full) const
85{
6cf6e7a0 86 // Get the strip path
87 //
88 // Parameters
89 // det Detector number
90 // ring Ring identifier
91 // sec Sector number
92 // str Strip number
93 // full If true, return full path
94 //
95 // Return
96 // The path
e9c06036 97 return Form("%s%sFMD%d%c[%02d]",
98 (full ? GetRingPath(det, ring, full) : ""),
99 (full ? "/" : ""), det, ring, sec);
100}
101//_____________________________________________________________________
102const char*
103AliFMDBaseDA::GetRingPath(UShort_t det,
104 Char_t ring,
105 Bool_t full) const
106{
6cf6e7a0 107 // Get the strip path
108 //
109 // Parameters
110 // det Detector number
111 // ring Ring identifier
112 // sec Sector number
113 // str Strip number
114 // full If true, return full path
115 //
116 // Return
117 // The path
e9c06036 118 return Form("%s%sFMD%d%c",
119 (full ? GetDetectorPath(det, full) : ""),
120 (full ? "/" : ""), det, ring);
121}
122//_____________________________________________________________________
123const char*
124AliFMDBaseDA::GetDetectorPath(UShort_t det,
125 Bool_t full) const
126{
6cf6e7a0 127 // Get the strip path
128 //
129 // Parameters
130 // det Detector number
131 // ring Ring identifier
132 // sec Sector number
133 // str Strip number
134 // full If true, return full path
135 //
136 // Return
137 // The path
e9c06036 138 return Form("%s%sFMD%d",
139 (full ? fDiagnosticsFilename.Data() : ""),
140 (full ? ":/" : ""), det);
141}
a0180e76 142
143//_____________________________________________________________________
427e8f99 144AliFMDBaseDA::AliFMDBaseDA() :
145 TNamed(),
a0180e76 146 fDiagnosticsFilename("diagnosticsHistograms.root"),
147 fOutputFile(),
ce5a8b1a 148 fConditionsFile(),
a0180e76 149 fSaveHistograms(kFALSE),
2a082c96 150 fMakeSummaries(kFALSE),
a0180e76 151 fDetectorArray(),
29b7c86f 152 fPulseSize(10),
153 fPulseLength(10),
154 fRequiredEvents(0),
6cf6e7a0 155 fCurrentEvent(0),
2a082c96 156 fRunno(0),
157 fSummaries(0)
c5569fbc 158{
159 //Constructor
268ff6b8 160 for(Int_t i = 0; i< 3;i++) {
161 fSeenDetectors[i] = false;
162 fNEventsPerDetector[i] = 0;
163 }
a0180e76 164 fDetectorArray.SetOwner();
6cf6e7a0 165 Rotate("conditions.csv", 3);
ce5a8b1a 166 fConditionsFile.open("conditions.csv");
a0180e76 167}
168//_____________________________________________________________________
169AliFMDBaseDA::AliFMDBaseDA(const AliFMDBaseDA & baseDA) :
170 TNamed(baseDA),
a7e41e8d 171 fDiagnosticsFilename(baseDA.fDiagnosticsFilename.Data()),
a0180e76 172 fOutputFile(),
ce5a8b1a 173 fConditionsFile(),
a0180e76 174 fSaveHistograms(baseDA.fSaveHistograms),
2a082c96 175 fMakeSummaries(baseDA.fMakeSummaries),
a0180e76 176 fDetectorArray(baseDA.fDetectorArray),
427e8f99 177 fPulseSize(baseDA.fPulseSize),
178 fPulseLength(baseDA.fPulseLength),
a0180e76 179 fRequiredEvents(baseDA.fRequiredEvents),
6cf6e7a0 180 fCurrentEvent(baseDA.fCurrentEvent),
2a082c96 181 fRunno(baseDA.fRunno),
182 fSummaries(0)
a0180e76 183{
c5569fbc 184 //Copy constructor
268ff6b8 185 for(Int_t i = 0; i< 3;i++) {
186 fSeenDetectors[i] = baseDA.fSeenDetectors[0];
187 fNEventsPerDetector[i] = baseDA.fNEventsPerDetector[i];
188 }
408bf2b4 189
268ff6b8 190 fDetectorArray.SetOwner();
a0180e76 191}
192
82d71828 193
a0180e76 194//_____________________________________________________________________
e9c06036 195AliFMDBaseDA::~AliFMDBaseDA()
196{
a0180e76 197 //destructor
a0180e76 198}
199
200//_____________________________________________________________________
a31ea3ce 201Bool_t AliFMDBaseDA::HaveEnough(Int_t nEvents) const
202{
203 return nEvents > GetRequiredEvents();
204}
205//_____________________________________________________________________
206UShort_t AliFMDBaseDA::GetProgress(Int_t nEvents) const
207{
208 return UShort_t((nEvents *100)/ GetRequiredEvents());
209}
210
211//_____________________________________________________________________
e9c06036 212void AliFMDBaseDA::Run(AliRawReader* reader)
213{
c5569fbc 214 //Run the FMD DA
e9c06036 215 TFile* diagFile = 0;
a31ea3ce 216 // if (fSaveHistograms)
217 // diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
7bce699b 218
a0180e76 219 reader->Reset();
6cf6e7a0 220 fRunno = reader->GetRunNumber();
221
e9c06036 222 AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
223 TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
3effc6e7 224
c5569fbc 225 Bool_t sodread = kFALSE;
200d06f9 226
227 for(Int_t i=0;i<3;i++) {
56940d2b 228 if (!reader->NextEvent()) {
133f1578 229 // Read Start-of-Run / Start-of-Files event
230 AliWarning(Form("Failed to read the %d%s event",
231 i+1, (i == 0 ? "st" : (i == 1 ? "nd" : "rd"))));
232 break;
233 }
29b7c86f 234
200d06f9 235 UInt_t eventType = reader->GetType();
236 if(eventType == AliRawEventHeaderBase::kStartOfData ||
237 eventType == AliRawEventHeaderBase::kFormatError) {
238
239 WriteConditionsData(fmdReader);
240 Init();
c5569fbc 241 sodread = kTRUE;
200d06f9 242 break;
243 }
29b7c86f 244 }
200d06f9 245
7bce699b 246 InitContainer(diagFile);
a31ea3ce 247 if (AliLog::GetDebugLevel("FMD","") >= 3) {
248 fDetectorArray.ls();
249 }
7bce699b 250
c5569fbc 251 if(!sodread)
29b7c86f 252 AliWarning("No SOD event detected!");
3effc6e7 253
1656783c 254 int lastProgress = 0;
a0180e76 255
a31ea3ce 256 for(Int_t i = 0; i< 3;i++) fNEventsPerDetector[i] = 0;
257
258 for(Int_t n = 1; !HaveEnough(n); n++) {
259 if(!reader->NextEvent()) { n--; continue; }
3effc6e7 260 SetCurrentEvent(n);
e9c06036 261 digitArray->Clear();
262 fmdReader->ReadAdcs(digitArray);
7bce699b 263
a31ea3ce 264 Bool_t seen[] = { false, false, false };
e9c06036 265 for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
266 AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
a31ea3ce 267 UShort_t det = digit->Detector();
268 fSeenDetectors[det-1] = true;
269 seen[det-1] = true;
e9c06036 270 FillChannels(digit);
a0180e76 271 }
e9c06036 272
a31ea3ce 273 for(Int_t i = 0; i< 3;i++)
274 if (seen[i]) (fNEventsPerDetector[i])++;
275
e9c06036 276 FinishEvent();
7bce699b 277
a31ea3ce 278 int progress = GetProgress(n);
e9c06036 279 if (progress <= lastProgress) continue;
280 lastProgress = progress;
281 std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
7bce699b 282
e9c06036 283 }
7bce699b 284
a31ea3ce 285 AliInfoF("Looped over %d events (%d,%d,%d)",GetCurrentEvent(),
286 fNEventsPerDetector[0],
287 fNEventsPerDetector[1],
288 fNEventsPerDetector[2]);
a0180e76 289 WriteHeaderToFile();
290
291 for(UShort_t det=1;det<=3;det++) {
408bf2b4 292 if (!fSeenDetectors[det-1]) continue;
e9c06036 293 std::cout << "FMD" << det << std::endl;
c5569fbc 294 UShort_t firstRing = (det == 1 ? 1 : 0);
295 for (UShort_t ir = firstRing; ir < 2; ir++) {
a0180e76 296 Char_t ring = (ir == 0 ? 'O' : 'I');
297 UShort_t nsec = (ir == 0 ? 40 : 20);
298 UShort_t nstr = (ir == 0 ? 256 : 512);
2a082c96 299
300 if (fMakeSummaries) MakeSummary(det, ring);
301
e9c06036 302 std::cout << " Ring " << ring << ": " << std::flush;
a0180e76 303 for(UShort_t sec =0; sec < nsec; sec++) {
304 for(UShort_t strip = 0; strip < nstr; strip++) {
305 Analyse(det,ring,sec,strip);
a0180e76 306 }
e9c06036 307 std::cout << '.' << std::flush;
a0180e76 308 }
a31ea3ce 309 // if(fSaveHistograms)
310 // diagFile->Flush();
e9c06036 311 std::cout << "done" << std::endl;
a0180e76 312 }
313 }
7bce699b 314
a0180e76 315 if(fOutputFile.is_open()) {
a0180e76 316 fOutputFile.write("# EOF\n",6);
317 fOutputFile.close();
a0180e76 318 }
319
7bce699b 320 Terminate(diagFile);
321
a0180e76 322 if(fSaveHistograms ) {
a31ea3ce 323 diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
324 fDetectorArray.Write("FMD", TObject::kSingleKey);
325 fSummaries.Write();
e9c06036 326 AliInfo("Closing diagnostics file - please wait ...");
327 // diagFile->Write();
ce5a8b1a 328 diagFile->Close();
e9c06036 329 AliInfo("done");
7bce699b 330
a0180e76 331 }
332}
333//_____________________________________________________________________
334
e9c06036 335void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
336{
a31ea3ce 337 //Prepare container for diagnostics
e9c06036 338 TDirectory* savDir = gDirectory;
339
a0180e76 340 for(UShort_t det=1;det<=3;det++) {
a31ea3ce 341 TObjArray* detArray = new TObjArray(det == 1 ? 1 : 2);
a0180e76 342 detArray->SetOwner();
a31ea3ce 343 detArray->SetName(GetDetectorPath(det, false));
a0180e76 344 fDetectorArray.AddAtAndExpand(detArray,det);
e9c06036 345
346 TDirectory* detDir = 0;
347 if (diagFile) {
348 diagFile->cd();
349 detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
350 }
351
a0180e76 352 UShort_t FirstRing = (det == 1 ? 1 : 0);
353 for (UShort_t ir = FirstRing; ir < 2; ir++) {
354 Char_t ring = (ir == 0 ? 'O' : 'I');
355 UShort_t nsec = (ir == 0 ? 40 : 20);
356 UShort_t nstr = (ir == 0 ? 256 : 512);
a31ea3ce 357 TObjArray* ringArray = new TObjArray(nsec);
a0180e76 358 ringArray->SetOwner();
a31ea3ce 359 ringArray->SetName(GetRingPath(det, ring, false));
a0180e76 360 detArray->AddAtAndExpand(ringArray,ir);
e9c06036 361
362
363 TDirectory* ringDir = 0;
364 if (detDir) {
365 detDir->cd();
366 ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
367 }
368
369
a0180e76 370 for(UShort_t sec =0; sec < nsec; sec++) {
a31ea3ce 371 TObjArray* sectorArray = new TObjArray(nstr);
a0180e76 372 sectorArray->SetOwner();
a31ea3ce 373 sectorArray->SetName(GetSectorPath(det, ring, sec, false));
a0180e76 374 ringArray->AddAtAndExpand(sectorArray,sec);
e9c06036 375
376
377 TDirectory* secDir = 0;
378 if (ringDir) {
379 ringDir->cd();
380 secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
381 }
382
a0180e76 383 for(UShort_t strip = 0; strip < nstr; strip++) {
e9c06036 384 if (secDir) {
385 secDir->cd();
386 secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
387 }
a31ea3ce 388 TObjArray* stripArray = new TObjArray(0);
389 stripArray->SetOwner(true);
390 stripArray->SetName(GetStripPath(det, ring, sec, strip, false));
391 sectorArray->AddAtAndExpand(stripArray, strip);
392 AddChannelContainer(stripArray, det, ring, sec, strip);
a0180e76 393 }
a31ea3ce 394 AddSectorSummary(sectorArray, det, ring, sec, nstr);
a0180e76 395 }
396 }
397 }
e9c06036 398 savDir->cd();
a0180e76 399}
ce5a8b1a 400
401//_____________________________________________________________________
3effc6e7 402void AliFMDBaseDA::WriteConditionsData(AliFMDRawReader* fmdReader)
e9c06036 403{
c5569fbc 404 //Write the conditions data to file
ce5a8b1a 405 AliFMDParameters* pars = AliFMDParameters::Instance();
406 fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
6cf6e7a0 407 TDatime now;
408 fConditionsFile << "# This file created from run number " << fRunno
409 << " at " << now.AsString() << std::endl;
427e8f99 410
3effc6e7 411 AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
412 AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
427e8f99 413
408bf2b4 414 fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
415 fSeenDetectors);
bd727bee 416
408bf2b4 417 sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
418 stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
bd727bee 419
420
427e8f99 421 // Zero Suppresion
422
423 // Strip Range
424
29b7c86f 425 fConditionsFile.write("# Gain Events \n",15);
bd727bee 426
29b7c86f 427 for(UShort_t det=1; det<=3;det++) {
408bf2b4 428 if (!fSeenDetectors[det-1]) {
429 continue;
430 }
29b7c86f 431 UShort_t firstring = (det == 1 ? 1 : 0);
432 for(UShort_t iring = firstring; iring <=1;iring++) {
433 Char_t ring = (iring == 1 ? 'I' : 'O');
434 for(UShort_t board =0 ; board <=1; board++) {
435
436 Int_t idx = GetHalfringIndex(det,ring,board);
437
438 fConditionsFile << det << ','
439 << ring << ','
440 << board << ','
441 << fPulseLength.At(idx) << "\n";
442
443 }
444 }
445 }
bd727bee 446
29b7c86f 447 fConditionsFile.write("# Gain Pulse \n",14);
bd727bee 448
29b7c86f 449 for(UShort_t det=1; det<=3;det++) {
408bf2b4 450 if (!fSeenDetectors[det-1]) {
451 continue;
452 }
29b7c86f 453 UShort_t firstring = (det == 1 ? 1 : 0);
454 for(UShort_t iring = firstring; iring <=1;iring++) {
455 Char_t ring = (iring == 1 ? 'I' : 'O');
456 for(UShort_t board =0 ; board <=1; board++) {
457
458 Int_t idx = GetHalfringIndex(det,ring,board);
459
460 fConditionsFile << det << ','
461 << ring << ','
462 << board << ','
463 << fPulseSize.At(idx) << "\n";
464
465 }
466 }
467 }
2d6778fb 468 // sampleRate->WriteToFile(std::cout, fSeenDetectors);
469 // stripRange->WriteToFile(std::cout, fSeenDetectors);
470
1656783c 471 if(fConditionsFile.is_open()) {
ce5a8b1a 472
427e8f99 473 fConditionsFile.write("# EOF\n",6);
1656783c 474 fConditionsFile.close();
475
476 }
ce5a8b1a 477
478}
427e8f99 479//_____________________________________________________________________
6cf6e7a0 480Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring,
481 UShort_t board) const
482{
483 // Get the index corresponding to a half-ring
484 //
485 // Parameters:
486 // det Detector number
487 // ring Ring identifier
488 // board Board number
489 //
490 // Return
491 // Internal index of the board
427e8f99 492 UShort_t iring = (ring == 'I' ? 1 : 0);
493
494 Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
495
29b7c86f 496 return index-2;
427e8f99 497
498}
6cf6e7a0 499//_____________________________________________________________________
500void AliFMDBaseDA::Rotate(const char* base, int max) const
501{
502 //
503 // Rotate a set of files. base is the basic name of the files.
504 // If the file base.max exists it is removed.
505 // If the file base.n exists (where n < max) it is renamed to
506 // base.(n-1).
507 // If the file base exists, it is renamed to base.1
508 //
509 // Parameters:
510 // base Base name of the files
511 // max Maximum number to keep (minus one for the current).
512
513 // Note: TSystem::AccessPathName returns false if the condition is
514 // fulfilled!
515
516 // Check if we have base.max, and if so, remove it.
517 TString testName(Form("%s.%d", base, max));
518 if (!gSystem->AccessPathName(testName.Data()))
519 gSystem->Unlink(testName.Data());
520
521 // Loop down from max-1 to 1 and move files
522 for (int i = max-1; i >= 1; i--) {
523 testName = Form("%s.%d", base, i);
524 if (!gSystem->AccessPathName(testName.Data())) {
525 TString newName(Form("%s.%d", base, i+1));
526 gSystem->Rename(testName.Data(), newName.Data());
527 }
528 }
529
530 // If we have the file base, rename it to base.1
531 testName = Form("%s", base);
532 if (!gSystem->AccessPathName(testName.Data())){
533 TString newName(Form("%s.%d", base, 1));
534 gSystem->Rename(testName.Data(), newName.Data());
535 }
536}
427e8f99 537
2a082c96 538//_____________________________________________________________________
539TH2*
540AliFMDBaseDA::MakeSummaryHistogram(const char* prefix, const char* title,
541 UShort_t d, Char_t r)
542{
09b6c804 543 //
544 // Utility function for defining summary histograms
545 //
546 // Parameters:
547 // det Detector
548 // ring Ring identifier
549 // prefix Histogram prefix
550 // title Histogram title
551 //
2a082c96 552 Int_t nX = ((d == 1 || r == 'I' || r == 'i') ? 20 : 40);
553 Int_t nY = ((d == 1 || r == 'I' || r == 'i') ? 512 : 256);
554
555 TH2* ret = new TH2F(Form("%sFMD%d%c", prefix, d, r),
556 Form("%s for FMD%d%c", title, d, r),
557 nX, -0.5, nX-0.5, nY, -0.5, nY-0.5);
558 ret->SetXTitle("Sector #");
559 ret->SetYTitle("Strip #");
a31ea3ce 560 ret->SetDirectory(0);
2a082c96 561 // if (!fSummaries) fSummaries = new TObjArray;
562 fSummaries.Add(ret);
563 return ret;
564}
ce5a8b1a 565
a0180e76 566//_____________________________________________________________________
a31ea3ce 567TObjArray*
568AliFMDBaseDA::GetDetectorArray(UShort_t det)
569{
570 if (det < 1 || det > 3) {
571 AliErrorF("Detector index %d out of bounds", det);
572 return 0;
573 }
574 return static_cast<TObjArray*>(fDetectorArray.At(det));
575}
576//_____________________________________________________________________
577TObjArray*
578AliFMDBaseDA::GetRingArray(UShort_t det, Char_t ring)
579{
580 Int_t idx = (ring == 'O' || ring == 'o' ? 0 : 1);
581 TObjArray* array = GetDetectorArray(det);
582 if (!array) return 0;
583 array = static_cast<TObjArray*>(array->At(idx));
584 if (!array) AliErrorF("No ring array for FMD%d%c (%d)", det, ring, idx);
585 return array;
586}
587//_____________________________________________________________________
588TObjArray*
589AliFMDBaseDA::GetSectorArray(UShort_t det, Char_t ring, UShort_t sector)
590{
591 TObjArray* array = GetRingArray(det,ring);
592 if (!array) return 0;
593 array = static_cast<TObjArray*>(array->At(sector));
594 if (!array) AliErrorF("No sector array for FMD%d%c[%02d]", det, ring, sector);
595 return array;
596}
597//_____________________________________________________________________
598TObjArray*
599AliFMDBaseDA::GetStripArray(UShort_t det, Char_t ring,
600 UShort_t sector, UShort_t strip)
601{
602 TObjArray* array = GetSectorArray(det,ring,sector);
603 if (!array) return 0;
604 array = static_cast<TObjArray*>(array->At(strip));
605 if (!array) AliErrorF("No strip array for FMD%d%c[%02d,%03d]",
606 det, ring, sector, strip);
607 return array;
608}
609
610//=====================================================================
611AliFMDBaseDA::Runner::Runner()
612 : fReader(0),
613 fDiagFile(""),
614 fDiag(false)
615{}
616
617//_____________________________________________________________________
618void
619AliFMDBaseDA::Runner::AddHandlers()
620{
621 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
622 "*",
623 "TStreamerInfo",
624 "RIO",
625 "TStreamerInfo()");
626 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit",
627 "TMinuitMinimizer",
628 "Minuit",
629 "TMinuitMinimizer(const char *)");
630 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
631 "GSLMultiMin",
632 "ROOT::Math::GSLMinimizer",
633 "MathMore",
634 "GSLMinimizer(const char *)");
635 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
636 "GSLMultiFit",
637 "ROOT::Math::GSLNLSMinimizer",
638 "MathMore", "GSLNLSMinimizer(int)");
639 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
640 "GSLSimAn",
641 "ROOT::Math::GSLSimAnMinimizer",
642 "MathMore",
643 "GSLSimAnMinimizer(int)");
644 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
645 "Linear",
646 "TLinearMinimizer",
647 "Minuit",
648 "TLinearMinimizer(const char *)");
649 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
650 "Fumili",
651 "TFumiliMinimizer",
652 "Fumili",
653 "TFumiliMinimizer(int)");
654}
655//_____________________________________________________________________
656void
657AliFMDBaseDA::Runner::ShowUsage(std::ostream& o, const char* progname)
658{
659 o << "Usage: " << progname << " SOURCE [OPTIONS]\n\n"
660 << "Options:\n"
661 << " -h,--help Show this help\n"
662 << " -d,--diagnostics[=FILE] Write diagnostics to file\n"
663 << " -D,--debug=LEVEL Set the debug level\n\n"
664 << "SOURCE is one of\n"
665 << " * FILE.raw Raw data file\n"
666 << " * FILE.root ROOT'ified raw data file\n"
667 << " * collection://FILE.root Event list in a ROOT file\n"
668 << " * collection://FILE File containing list of ROOT files\n"
669 << " * ^FMD Monitor source\n"
670 << "There are other options too. Check the AliRawReader docs\n"
671 << std::endl;
672}
673
674//_____________________________________________________________________
675namespace {
676 Bool_t ExtractValue(const TString& arg, TString& val)
677 {
678 val = "";
679 Int_t eq = arg.Index("=");
680 if (eq == kNPOS) return false;
681
682 val = arg(eq+1, arg.Length()-eq-1);
683 return true;
684 }
685}
686
687//_____________________________________________________________________
688Int_t
689AliFMDBaseDA::Runner::Init(int argc, char** argv)
690{
691 AddHandlers();
692
693 // --- Process the command line ------------------------------------
694 TString source;
695 Int_t debugLevel = 0;
696 Bool_t help = false;
697
698 for (int i = 1; i < argc; i++) {
699 TString arg(argv[i]);
700 Bool_t badOption = false;
701
702 if (arg[0] == '-') { // It's an option
703 if (arg[1] == '-') { // It's a long option
704 TString val;
705 if (arg.EqualTo("--help")) help = true;
706 else if (arg.BeginsWith("--debug")) {
707 if (ExtractValue(arg, val))
708 debugLevel = val.Atoi();
709 }
710 else if (arg.BeginsWith("--diagnostics")) {
711 fDiag = true;
712 if (ExtractValue(arg, val))
713 fDiagFile = val;
714 }
715 else badOption = true;
716 }
717 else { // Short option
718 TString next(i < argc-1 ? argv[i+1] : "");
719 switch (arg[1]) {
720 case 'h': help = true; break;
721 case 'd': fDiag = true;
722 if (!next.IsNull() && next[0] != '-') {
723 fDiagFile = next;
724 i++;
725 }
726 break;
727 case 'D':
728 if (!next.IsNull() && next[0] != '-') {
729 debugLevel = next.Atoi();
730 i++;
731 }
732 break;
733 default: badOption = true;
734 }
735 } // End of options
736 if (badOption) {
737 std::cerr << argv[0] << ": Unknown option " << argv[i]
738 << std::endl;
739 return -1;
740 }
741 }
742 else { // source or compatibility debug level
743 if (source.IsNull()) source = arg;
744 else debugLevel = arg.Atoi();
745 }
746 }
747
748 // --- Check if help was requested ---------------------------------
749 if (help) {
750 ShowUsage(std::cout, argv[0]);
751 return 1;
752 }
753
754 // --- Check if we have a source -----------------------------------
755 if (source.IsNull()) {
756 std::cerr << "No source given" << std::endl;
757 return -2;
758 }
759
760 // --- Initialize various things -----------------------------------
761 AliFMDParameters::Instance()->Init(kFALSE,0);
762
763 //This will only work for FDR 1 data. When newer data becomes
764 //available the ! must be removed!
765 Bool_t old = kTRUE;
766 AliFMDParameters::Instance()->UseCompleteHeader(old);
767
768 AliLog::EnableDebug(debugLevel > 0);
769 AliLog::SetModuleDebugLevel("FMD", debugLevel);
770
771 // --- Make our reader ---------------------------------------------
772 fReader = AliRawReader::Create(source);
773 if (!fReader) {
774 std::cerr << "Failed to make raw reader for source \"" << source
775 << "\"" << std::endl;
776 return -3;
777 }
778 return 0;
779}
780
781//_____________________________________________________________________
782Int_t
783AliFMDBaseDA::Runner::RunNumber() const
784{
785 if (!fReader) return -1;
786 return fReader->GetRunNumber();
787}
788
789//_____________________________________________________________________
790void
791AliFMDBaseDA::Runner::Exec(AliFMDBaseDA& da)
792{
793 TStopwatch timer;
794 timer.Start();
795
796 da.SetSaveDiagnostics(fDiag || !fDiagFile.IsNull());
797 if (!fDiagFile.IsNull()) da.SetDiagnosticsFilename(fDiagFile);
798
799 da.Run(fReader);
800
801 timer.Stop();
802 timer.Print();
803
804#ifdef ALI_AMORE
805 try {
806 amore::da::AmoreDA myAmore(amore::da::AmoreDA::kSender);
807
808 for (UShort_t det = 1; det <= 3; det++) {
809 if (!da.HasSeenDetector(det)) continue;
810 TObject* runNo = new TObject;
811 runNo->SetUniqueID(fReader->GetRunNumber());
812 myAmore.Send(Form("gainRunNoFMD%d", det), runNo);
813 }
814
815 TIter next(&da.GetSummaries());
816 TObject* obj = 0;
817 while ((obj = next()))
818 myAmore.Send(obj->GetName(), obj);
819
820 }
821 catch (exception& e) {
822 cerr << "Failed to make AMORE instance: " << e.what() << endl;
823 }
824
825#endif
826}
827
828
829
830
831
832//_____________________________________________________________________
833
834//_____________________________________________________________________
a0180e76 835//
836// EOF
837//