AliRoot Core  edcc906 (edcc906)
AliFMDBaseDA.cxx
Go to the documentation of this file.
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 
21 //
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.
27 //
28 
29 #include "AliFMDBaseDA.h"
30 #include "AliRawReader.h"
31 #include "AliFMDDigit.h"
32 #include "AliFMDParameters.h"
33 #include "AliFMDRawReader.h"
34 #include "AliFMDCalibSampleRate.h"
35 #include "AliFMDCalibStripRange.h"
36 #include "AliLog.h"
37 #include "AliRawEventHeaderBase.h"
38 #include "AliFMDDigit.h"
39 #include <TClonesArray.h>
40 #include <TFile.h>
41 #include <TDatime.h>
42 #include <TSystem.h>
43 #include <TH2F.h>
44 #include <TStopwatch.h>
45 #include <TROOT.h>
46 #include <TPluginManager.h>
47 #include <iostream>
48 #include <fstream>
49 
50 //_____________________________________________________________________
51 ClassImp(AliFMDBaseDA)
52 #if 0
53 ; // Do not delete - to let Emacs for mat the code
54 #endif
55 
56 //_____________________________________________________________________
57 TString
59  Char_t ring,
60  UShort_t sec,
61  UShort_t str,
62  Bool_t full) const
63 {
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
75  return TString::Format("%s%sFMD%d%c[%02d,%03d]",
76  (full ? GetSectorPath(det, ring, sec, full).Data() : ""),
77  (full ? "/" : ""), det, ring, sec, str);
78 }
79 //_____________________________________________________________________
80 TString
82  Char_t ring,
83  UShort_t sec,
84  Bool_t full) const
85 {
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
97  return TString::Format("%s%sFMD%d%c[%02d]",
98  (full ? GetRingPath(det, ring, full).Data() : ""),
99  (full ? "/" : ""), det, ring, sec);
100 }
101 //_____________________________________________________________________
102 TString
104  Char_t ring,
105  Bool_t full) const
106 {
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
118  return TString::Format("%s%sFMD%d%c",
119  (full ? GetDetectorPath(det, full).Data() : ""),
120  (full ? "/" : ""), det, ring);
121 }
122 //_____________________________________________________________________
123 TString
125  Bool_t full) const
126 {
127  // Get the strip path
128  //
129  // Parameters
130  // det Detector number
131  // ring Rg identifier
132  // sec Sector number
133  // str Strip number
134  // full If true, return full path
135  //
136  // Return
137  // The path
138  return TString::Format("%s%sFMD%d",
139  (full ? fDiagnosticsFilename.Data() : ""),
140  (full ? ":/" : ""), det);
141 }
142 
143 //_____________________________________________________________________
145  TNamed(),
146  fDiagnosticsFilename("diagnosticsHistograms.root"),
147  fOutputFile(),
148  fConditionsFile(),
149  fSaveHistograms(kFALSE),
150  fMakeSummaries(kFALSE),
151  fDetectorArray(),
152  fPulseSize(10),
153  fPulseLength(10),
154  fRequiredEvents(0),
155  fCurrentEvent(0),
156  fRunno(0),
157  fSummaries(0),
158  fAll(false)
159 {
160  //Constructor
161  for(Int_t i = 0; i< 3;i++) {
162  fSeenDetectors[i] = false;
163  fNEventsPerDetector[i] = 0;
164  }
165 }
166 
167 
168 //_____________________________________________________________________
170  TNamed(baseDA),
172  fOutputFile(),
173  fConditionsFile(),
177  fPulseSize(baseDA.fPulseSize),
178  fPulseLength(baseDA.fPulseLength),
181  fRunno(baseDA.fRunno),
182  fSummaries(0),
183  fAll(baseDA.fAll)
184 {
185  //Copy constructor
186  for(Int_t i = 0; i< 3;i++) {
187  fSeenDetectors[i] = baseDA.fSeenDetectors[0];
189  }
190 
191  fDetectorArray.SetOwner();
192  fDetectorArray.ResetBit(TObject::kMustCleanup);
193  fSummaries.ResetBit(TObject::kMustCleanup);
194  fDetectorArray.ResetBit(TObject::kIsOnHeap);
195  fSummaries.ResetBit(TObject::kIsOnHeap);
196 }
197 
198 
199 //_____________________________________________________________________
201 {
202  //destructor
203  // fDetectorArray.ls();
204  // fSummaries.ls();
205  // fDetectorArray.SetOwner(false);
206  // fSummaries.SetOwner(false);
207 
208 }
209 
210 //_____________________________________________________________________
211 Bool_t
212 AliFMDBaseDA::OpenFiles(Bool_t appendRun)
213 {
214  fDetectorArray.SetOwner();
215  if (!appendRun || fRunno == 0) {
216  Rotate("conditions.csv", 3);
217  fConditionsFile.open("conditions.csv");
218  }
219  else {
220  fConditionsFile.open(Form("conditions_%09d.csv",
221  fRunno));
222  }
223  if (!fConditionsFile) {
224  Error("OpenFiles", "Failed to open conditions file");
225  return false;
226  }
227  return true;
228 }
229 
230 //_____________________________________________________________________
231 void
233 {
234  // If we have an output file, close it
235  if(!fOutputFile.is_open()) return;
236 
237  fOutputFile.write("# EOF\n",6);
238  fOutputFile.close();
239 }
240 
241 //_____________________________________________________________________
242 Bool_t AliFMDBaseDA::HaveEnough(Int_t nEvents) const
243 {
244  // if (!fAll) return nEvents > GetRequiredEvents();
245  if (nEvents <= 1) return false;
246 
247  Bool_t ret = true; // Assume we have it
248  for (Int_t i = 0; i < 3; i++) {
249  if (!fSeenDetectors[i]) continue;
250  if (Int_t(fNEventsPerDetector[i]) <= GetRequiredEvents()) ret = false;
251  }
252  return ret;
253 }
254 //_____________________________________________________________________
255 UShort_t AliFMDBaseDA::GetProgress(Int_t nEvents) const
256 {
257  // if (!fAll)
258  // return UShort_t((nEvents *100)/ GetRequiredEvents());
259 
260  if (nEvents <= 1) return 0;
261 
262  Int_t got = 0;
263  Int_t total = 0;
264  for (Int_t i = 0; i < 3; i++) {
265  if (!fSeenDetectors[i]) continue;
266  got += fNEventsPerDetector[i];
267  total += GetRequiredEvents();
268  }
269  return UShort_t(total > 0 ? (got * 100.) / total : 0);
270 }
271 
272 //_____________________________________________________________________
273 Bool_t
274 AliFMDBaseDA::Run(AliRawReader* reader, Bool_t appendRun, Bool_t isBase)
275 {
276  //Run the FMD DA
277  TFile* diagFile = 0;
278  // if (fSaveHistograms)
279  // diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
280 
281  reader->Reset();
282  fRunno = reader->GetRunNumber();
283  if (fRunno <= 0) {
284  TString dateRunNumber(gSystem->Getenv("DATE_RUN_NUMBER"));
285  if (!dateRunNumber.IsNull()) fRunno = dateRunNumber.Atoll();
286  }
287 
288  // Open our output files
289  if (!OpenFiles(appendRun)) return false;
290 
291  // Create our reader
292  AliFMDRawReader* fmdReader = new AliFMDRawReader(reader,0);
293  TClonesArray* digitArray = new TClonesArray("AliFMDDigit",0);
294 
295  // Look for SOD
296  Bool_t sodread = kFALSE;
297  for(Int_t i=0;i<3;i++) {
298  if (!reader->NextEvent()) {
299  // Read Start-of-Run / Start-of-Files event
300  AliWarning(Form("Failed to read the %d%s event",
301  i+1, (i == 0 ? "st" : (i == 1 ? "nd" : "rd"))));
302  break;
303  }
304 
305  UInt_t eventType = reader->GetType();
306  if(eventType == AliRawEventHeaderBase::kStartOfData ||
307  eventType == AliRawEventHeaderBase::kFormatError) {
308 
309  WriteConditionsData(fmdReader);
310  sodread = kTRUE;
311  break;
312  }
313  }
314  if (isBase)
315  // IF this is the base DA, do thing more
316  return true;
317 
318  // Initialize everything
319  Init();
320  // Initialize our containers
321  InitContainer(diagFile);
322  if (AliLog::GetDebugLevel("FMD","") >= 3) {
323  fDetectorArray.ls();
324  }
325 
326  if(!sodread)
327  AliWarning("No SOD event detected!");
328 
329  int lastProgress = 0;
330 
331  // Reset event counters
332  for(Int_t i = 0; i< 3;i++) fNEventsPerDetector[i] = 0;
333 
334  // Loop until we have enough
335  for(Int_t n = 1; !HaveEnough(n); n++) {
336  AliDebugF(1,"Get the next event %d", n);
337  if(!reader->NextEvent()) { n--; continue; }
338  UInt_t eventType = reader->GetType();
339  AliDebugF(3, "Event type is %d", eventType);
340  if(eventType != AliRawEventHeaderBase::kPhysicsEvent) { n--; continue; }
341 
342  Bool_t seen[] = { false, false, false };
343  SetCurrentEvent(n);
344  digitArray->Clear();
345  fmdReader->ReadAdcs(digitArray);
346 
347  for(Int_t i = 0; i<digitArray->GetEntriesFast();i++) {
348  AliFMDDigit* digit = static_cast<AliFMDDigit*>(digitArray->At(i));
349  UShort_t det = digit->Detector();
350  fSeenDetectors[det-1] = true;
351  seen[det-1] = true;
352 
353  // Only fill if we do not have enough for this detector
354  if (Int_t(fNEventsPerDetector[det-1]) < GetRequiredEvents())
355  FillChannels(digit);
356  }
357  for(Int_t i = 0; i< 3;i++)
358  if (seen[i]) (fNEventsPerDetector[i])++;
359 
360  FinishEvent();
361 
362  Int_t nReq = GetRequiredEvents();
363  AliDebugF(5, "%9d: %6d/%6d %6d/%6d %6d/%6d", n,
364  fNEventsPerDetector[0], nReq,
365  fNEventsPerDetector[1], nReq,
366  fNEventsPerDetector[2], nReq);
367 
368  int progress = GetProgress(n);
369  if (progress <= lastProgress) continue;
370  lastProgress = progress;
371  std::cout << "Progress: " << lastProgress << " / 100 " << std::endl;
372  }
373 
374  // Now at end of processing
375  AliInfoF("Looped over %d events (%d,%d,%d)",GetCurrentEvent(),
380 
381  // Analyse the data and make summaries
382  for(UShort_t det=1;det<=3;det++) {
383  if (!fSeenDetectors[det-1]) continue;
384  std::cout << "FMD" << det << std::endl;
385  UShort_t firstRing = (det == 1 ? 1 : 0);
386  for (UShort_t ir = firstRing; ir < 2; ir++) {
387  Char_t ring = (ir == 0 ? 'O' : 'I');
388  UShort_t nsec = (ir == 0 ? 40 : 20);
389  UShort_t nstr = (ir == 0 ? 256 : 512);
390 
391  if (fMakeSummaries) MakeSummary(det, ring);
392 
393  std::cout << " Ring " << ring << ": " << std::flush;
394  for(UShort_t sec =0; sec < nsec; sec++) {
395  for(UShort_t strip = 0; strip < nstr; strip++) {
396  Analyse(det,ring,sec,strip);
397  }
398  std::cout << '.' << std::flush;
399  }
400  // if(fSaveHistograms)
401  // diagFile->Flush();
402  std::cout << "done" << std::endl;
403  }
404  }
405  // Close output files
406  CloseFiles();
407 
408  // Do final stuff on the diagnostics file
409  Terminate(diagFile);
410 
411  // Possibly write histograms to diagnostics file
412  if(fSaveHistograms ) {
413  diagFile = TFile::Open(fDiagnosticsFilename.Data(),"RECREATE");
414  fDetectorArray.Write("FMD", TObject::kSingleKey);
415  fSummaries.Write();
416  AliInfo("Closing diagnostics file - please wait ...");
417  // diagFile->Write();
418  diagFile->Close();
419  AliInfo("done");
420  }
421 
422  // All is good
423  return true;
424 }
425 //_____________________________________________________________________
426 
427 void AliFMDBaseDA::InitContainer(TDirectory* diagFile)
428 {
429  //Prepare container for diagnostics
430  TDirectory* savDir = gDirectory;
431  Bool_t owners = true;
432 
433  for(UShort_t det=1;det<=3;det++) {
434  Array* detArray = new Array(det == 1 ? 1 : 2);
435  detArray->SetOwner(owners);
436  detArray->SetName(GetDetectorPath(det, false));
437  fDetectorArray.AddAtAndExpand(detArray,det);
438 
439  TDirectory* detDir = 0;
440  if (diagFile) {
441  diagFile->cd();
442  detDir = diagFile->mkdir(GetDetectorPath(det, kFALSE));
443  }
444 
445  UShort_t FirstRing = (det == 1 ? 1 : 0);
446  for (UShort_t ir = FirstRing; ir < 2; ir++) {
447  Char_t ring = (ir == 0 ? 'O' : 'I');
448  UShort_t nsec = (ir == 0 ? 40 : 20);
449  UShort_t nstr = (ir == 0 ? 256 : 512);
450  Array* ringArray = new Array(nsec);
451  ringArray->SetOwner(owners);
452  ringArray->SetName(GetRingPath(det, ring, false));
453  ringArray->ResetBit(TObject::kMustCleanup);
454  detArray->AddAtAndExpand(ringArray,ir);
455 
456 
457  TDirectory* ringDir = 0;
458  if (detDir) {
459  detDir->cd();
460  ringDir = detDir->mkdir(GetRingPath(det,ring, kFALSE));
461  }
462 
463 
464  for(UShort_t sec =0; sec < nsec; sec++) {
465  Array* sectorArray = new Array(nstr);
466  sectorArray->SetOwner(owners);
467  sectorArray->SetName(GetSectorPath(det, ring, sec, false));
468  sectorArray->ResetBit(TObject::kMustCleanup);
469  ringArray->AddAtAndExpand(sectorArray,sec);
470 
471 
472  TDirectory* secDir = 0;
473  if (ringDir) {
474  ringDir->cd();
475  secDir = ringDir->mkdir(GetSectorPath(det, ring, sec, kFALSE));
476  }
477 
478  for(UShort_t strip = 0; strip < nstr; strip++) {
479  if (secDir) {
480  secDir->cd();
481  secDir->mkdir(GetStripPath(det, ring, sec, strip, kFALSE));
482  }
483  Array* stripArray = new Array(0);
484  stripArray->SetOwner(owners);
485  stripArray->SetName(GetStripPath(det, ring, sec, strip, false));
486  stripArray->ResetBit(TObject::kMustCleanup);
487  sectorArray->AddAtAndExpand(stripArray, strip);
488  AddChannelContainer(stripArray, det, ring, sec, strip);
489  }
490  AddSectorSummary(sectorArray, det, ring, sec, nstr);
491  }
492  }
493  }
494  savDir->cd();
495 }
496 
497 //_____________________________________________________________________
499 {
500  //Write the conditions data to file
502  fConditionsFile.write(Form("# %s \n",pars->GetConditionsShuttleID()),14);
503  TDatime now;
504  fConditionsFile << "# This file created from run number " << fRunno
505  << " at " << now.AsString() << std::endl;
506 
507  AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
508  AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
509 
510  fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
512 
515 
516 
517  // Zero Suppresion
518 
519  // Strip Range
520 
521  fConditionsFile.write("# Gain Events \n",15);
522 
523  for(UShort_t det=1; det<=3;det++) {
524  if (!fSeenDetectors[det-1]) {
525  continue;
526  }
527  UShort_t firstring = (det == 1 ? 1 : 0);
528  for(UShort_t iring = firstring; iring <=1;iring++) {
529  Char_t ring = (iring == 1 ? 'I' : 'O');
530  for(UShort_t board =0 ; board <=1; board++) {
531 
532  Int_t idx = GetHalfringIndex(det,ring,board);
533 
534  fConditionsFile << det << ','
535  << ring << ','
536  << board << ','
537  << fPulseLength.At(idx) << "\n";
538 
539  }
540  }
541  }
542 
543  fConditionsFile.write("# Gain Pulse \n",14);
544 
545  for(UShort_t det=1; det<=3;det++) {
546  if (!fSeenDetectors[det-1]) {
547  continue;
548  }
549  UShort_t firstring = (det == 1 ? 1 : 0);
550  for(UShort_t iring = firstring; iring <=1;iring++) {
551  Char_t ring = (iring == 1 ? 'I' : 'O');
552  for(UShort_t board =0 ; board <=1; board++) {
553 
554  Int_t idx = GetHalfringIndex(det,ring,board);
555 
556  fConditionsFile << det << ','
557  << ring << ','
558  << board << ','
559  << fPulseSize.At(idx) << "\n";
560 
561  }
562  }
563  }
564  // sampleRate->WriteToFile(std::cout, fSeenDetectors);
565  // stripRange->WriteToFile(std::cout, fSeenDetectors);
566 
567  if(fConditionsFile.is_open()) {
568 
569  fConditionsFile.write("# EOF\n",6);
570  fConditionsFile.close();
571 
572  }
573 
574 }
575 //_____________________________________________________________________
576 Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring,
577  UShort_t board) const
578 {
579  // Get the index corresponding to a half-ring
580  //
581  // Parameters:
582  // det Detector number
583  // ring Ring identifier
584  // board Board number
585  //
586  // Return
587  // Internal index of the board
588  UShort_t iring = (ring == 'I' ? 1 : 0);
589 
590  Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
591 
592  return index-2;
593 
594 }
595 //_____________________________________________________________________
596 void AliFMDBaseDA::Rotate(const char* base, int max) const
597 {
598  //
599  // Rotate a set of files. base is the basic name of the files.
600  // If the file base.max exists it is removed.
601  // If the file base.n exists (where n < max) it is renamed to
602  // base.(n-1).
603  // If the file base exists, it is renamed to base.1
604  //
605  // Parameters:
606  // base Base name of the files
607  // max Maximum number to keep (minus one for the current).
608 
609  // Note: TSystem::AccessPathName returns false if the condition is
610  // fulfilled!
611 
612  // Check if we have base.max, and if so, remove it.
613  TString testName(Form("%s.%d", base, max));
614  if (!gSystem->AccessPathName(testName.Data()))
615  gSystem->Unlink(testName.Data());
616 
617  // Loop down from max-1 to 1 and move files
618  for (int i = max-1; i >= 1; i--) {
619  testName = Form("%s.%d", base, i);
620  if (!gSystem->AccessPathName(testName.Data())) {
621  TString newName(Form("%s.%d", base, i+1));
622  gSystem->Rename(testName.Data(), newName.Data());
623  }
624  }
625 
626  // If we have the file base, rename it to base.1
627  testName = Form("%s", base);
628  if (!gSystem->AccessPathName(testName.Data())){
629  TString newName(Form("%s.%d", base, 1));
630  gSystem->Rename(testName.Data(), newName.Data());
631  }
632 }
633 
634 //_____________________________________________________________________
635 TH2*
636 AliFMDBaseDA::MakeSummaryHistogram(const char* prefix, const char* title,
637  UShort_t d, Char_t r)
638 {
639  //
640  // Utility function for defining summary histograms
641  //
642  // Parameters:
643  // det Detector
644  // ring Ring identifier
645  // prefix Histogram prefix
646  // title Histogram title
647  //
648  Int_t nX = ((d == 1 || r == 'I' || r == 'i') ? 20 : 40);
649  Int_t nY = ((d == 1 || r == 'I' || r == 'i') ? 512 : 256);
650 
651  TString n = TString::Format("%sFMD%d%c", prefix, d, r);
652  TString t = TString::Format("%s for FMD%d%c", title, d, r);
653  TH2* ret = new TH2F(n, t, nX, -0.5, nX-0.5, nY, -0.5, nY-0.5);
654  ret->SetXTitle("Sector #");
655  ret->SetYTitle("Strip #");
656  ret->SetDirectory(0);
657  // if (!fSummaries) fSummaries = new Array;
658  fSummaries.Add(ret);
659  return ret;
660 }
661 
662 //_____________________________________________________________________
665 {
666  if (det < 1 || det > 3) {
667  AliErrorF("Detector index %d out of bounds", det);
668  return 0;
669  }
670  return static_cast<Array*>(fDetectorArray.At(det));
671 }
672 //_____________________________________________________________________
674 AliFMDBaseDA::GetRingArray(UShort_t det, Char_t ring)
675 {
676  Int_t idx = (ring == 'O' || ring == 'o' ? 0 : 1);
677  Array* array = GetDetectorArray(det);
678  if (!array) return 0;
679  array = static_cast<Array*>(array->At(idx));
680  if (!array) AliErrorF("No ring array for FMD%d%c (%d)", det, ring, idx);
681  return array;
682 }
683 //_____________________________________________________________________
685 AliFMDBaseDA::GetSectorArray(UShort_t det, Char_t ring, UShort_t sector)
686 {
687  Array* array = GetRingArray(det,ring);
688  if (!array) return 0;
689  array = static_cast<Array*>(array->At(sector));
690  if (!array) AliErrorF("No sector array for FMD%d%c[%02d]", det, ring, sector);
691  return array;
692 }
693 //_____________________________________________________________________
695 AliFMDBaseDA::GetStripArray(UShort_t det, Char_t ring,
696  UShort_t sector, UShort_t strip)
697 {
698  Array* array = GetSectorArray(det,ring,sector);
699  if (!array) return 0;
700  array = static_cast<Array*>(array->At(strip));
701  if (!array) AliErrorF("No strip array for FMD%d%c[%02d,%03d]",
702  det, ring, sector, strip);
703  return array;
704 }
705 
706 //=====================================================================
708  : fReader(0),
709  fSource(""),
710  fDiagFile(""),
711  fDiag(false),
712  fAll(false),
713  fFast(true),
714  fUpload(true),
715  fAppendRun(false),
716  fOwnUpload(false)
717 {}
718 
719 //_____________________________________________________________________
720 void
722 {
723  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
724  "*",
725  "TStreamerInfo",
726  "RIO",
727  "TStreamerInfo()");
728  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit",
729  "TMinuitMinimizer",
730  "Minuit",
731  "TMinuitMinimizer(const char *)");
732  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
733  "GSLMultiMin",
734  "ROOT::Math::GSLMinimizer",
735  "MathMore",
736  "GSLMinimizer(const char *)");
737  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
738  "GSLMultiFit",
739  "ROOT::Math::GSLNLSMinimizer",
740  "MathMore", "GSLNLSMinimizer(int)");
741  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
742  "GSLSimAn",
743  "ROOT::Math::GSLSimAnMinimizer",
744  "MathMore",
745  "GSLSimAnMinimizer(int)");
746  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
747  "Linear",
748  "TLinearMinimizer",
749  "Minuit",
750  "TLinearMinimizer(const char *)");
751  gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
752  "Fumili",
753  "TFumiliMinimizer",
754  "Fumili",
755  "TFumiliMinimizer(int)");
756 }
757 //_____________________________________________________________________
758 void
759 AliFMDBaseDA::Runner::ShowUsage(std::ostream& o, const char* progname)
760 {
761  o << "Usage: " << progname << " SOURCE [OPTIONS]\n\n"
762  << "Options:\n"
763  << " -h,--help Show this help\n"
764  << " -d,--diagnostics[=FILE] Write diagnostics to file\n"
765  << " -D,--debug=LEVEL Set the debug level\n"
766  << " -A,--all Try to get data from all detectors (" << fAll << ")\n"
767  << " -F,--fast Fast exit (" <<fFast <<")\n"
768  << " -U,--upload Upload to FXS (" <<fUpload <<")\n"
769  << " -R,--append Append run # to filename (" <<fAppendRun <<")\n"
770  << " -Z,--own Use custom upload (" << fOwnUpload << ")\n"
771  << "\n"
772  << "SOURCE is one of\n"
773  << " * FILE.raw Raw data file\n"
774  << " * FILE.root ROOT'ified raw data file\n"
775  << " * collection://FILE.root Event list in a ROOT file\n"
776  << " * collection://FILE File containing list of ROOT files\n"
777  << " * ^FMD Monitor source\n"
778  << "There are other options too. Check the AliRawReader docs\n"
779  << std::endl;
780 }
781 
782 //_____________________________________________________________________
783 namespace {
784  Bool_t ExtractValue(const TString& arg, TString& val)
785  {
786  val = "";
787  Int_t eq = arg.Index("=");
788  if (eq == kNPOS) return false;
789 
790  val = arg(eq+1, arg.Length()-eq-1);
791  return true;
792  }
793 }
794 
795 //_____________________________________________________________________
796 Int_t
797 AliFMDBaseDA::Runner::Init(int argc, char** argv, Bool_t reader)
798 {
799  AddHandlers();
800 
801  // --- Process the command line ------------------------------------
802  TString source;
803  Int_t debugLevel = 0;
804  Bool_t help = false;
805 
806  for (int i = 1; i < argc; i++) {
807  TString arg(argv[i]);
808  Bool_t badOption = false;
809 
810  if (arg[0] == '-') { // It's an option
811  if (arg[1] == '-') { // It's a long option
812  TString val;
813  if (arg.EqualTo("--help")) help = true;
814  else if (arg.BeginsWith("--debug")) {
815  if (ExtractValue(arg, val))
816  debugLevel = val.Atoi();
817  }
818  else if (arg.BeginsWith("--diagnostics")) {
819  fDiag = !fDiag;
820  if (ExtractValue(arg, val))
821  fDiagFile = val;
822  }
823  else if (arg.EqualTo("--all")) fAll = !fAll;
824  else if (arg.EqualTo("--fast")) fFast = !fFast;
825  else if (arg.EqualTo("--upload")) fUpload = !fUpload;
826  else if (arg.EqualTo("--append")) fAppendRun = !fAppendRun;
827  else if (arg.EqualTo("--own")) fOwnUpload = !fOwnUpload;
828  else badOption = true;
829  }
830  else { // Short option
831  TString next(i < argc-1 ? argv[i+1] : "");
832  switch (arg[1]) {
833  case 'h': help = true; break;
834  case 'd': fDiag = !fDiag;
835  if (!next.IsNull() && next[0] != '-') {
836  fDiagFile = next;
837  i++;
838  }
839  break;
840  case 'D':
841  if (!next.IsNull() && next[0] != '-') {
842  debugLevel = next.Atoi();
843  i++;
844  }
845  break;
846  case 'A': fAll = !fAll ; break ;
847  case 'F': fFast = !fFast ; break ;
848  case 'U': fUpload = !fUpload ; break ;
849  case 'R': fAppendRun = !fAppendRun ; break ;
850  case 'Z': fOwnUpload = !fOwnUpload ; break ;
851  default: badOption = true;
852  }
853  } // End of options
854  if (badOption) {
855  std::cerr << argv[0] << ": Unknown option " << argv[i]
856  << std::endl;
857  return -1;
858  }
859  }
860  else { // source or compatibility debug level
861  source = arg;
862  }
863  }
864 
865  // --- Check if help was requested ---------------------------------
866  if (help) {
867  ShowUsage(std::cout, argv[0]);
868  return 1;
869  }
870 
871  // --- Check if we have a source -----------------------------------
872  if (source.IsNull()) {
873  std::cerr << "No source given" << std::endl;
874  return -2;
875  }
876  fSource = source;
877 
878  // --- Initialize various things -----------------------------------
879  AliFMDParameters::Instance()->Init(kFALSE,0);
880 
881  //This will only work for FDR 1 data. When newer data becomes
882  //available the ! must be removed!
883  Bool_t old = kTRUE;
885 
886  AliLog::EnableDebug(debugLevel > 0);
887  AliLog::SetModuleDebugLevel("FMD", debugLevel);
888 
889  // --- Make our reader ---------------------------------------------
890  if (!reader) return 0;
891  fReader = AliRawReader::Create(source);
892  if (!fReader) {
893  std::cerr << "Failed to make raw reader for source \"" << source
894  << "\"" << std::endl;
895  return -3;
896  }
897  return 0;
898 }
899 
900 //_____________________________________________________________________
901 Int_t
903 {
904  Int_t run = -1;
905  if (fReader)
906  run = fReader->GetRunNumber();
907  if (run <= 0) {
908  TString dateRunNumber(gSystem->Getenv("DATE_RUN_NUMBER"));
909  if (!dateRunNumber.IsNull())
910  run = dateRunNumber.Atoll();
911  else
912  run = -1;
913  }
914  return run;
915 }
916 
917 //_____________________________________________________________________
918 Bool_t
920 {
921  TStopwatch timer;
922  timer.Start();
923 
924  da.SetSaveDiagnostics(fDiag || !fDiagFile.IsNull());
925  da.SetTryAll(fAll);
926  if (!fDiagFile.IsNull()) da.SetDiagnosticsFilename(fDiagFile);
927 
928  Bool_t ret = da.Run(fReader, fAppendRun);
929 
930  timer.Stop();
931  timer.Print();
932 
933  return ret;
934 }
935 
936 #if 0
937 AliFMDBaseDA::_Array::~_Array()
938 {
939  // Printf("Deleting %s (%p)", this->GetName(), this);
940  // SetOwner(false);
941  // Clear();
942 }
943 #endif
944 
945 
946 //_____________________________________________________________________
947 
948 //_____________________________________________________________________
949 //
950 // EOF
951 //
952 
class for digits
Definition: AliFMDDigit.h:28
virtual void AddSectorSummary(Array *, UShort_t, Char_t, UShort_t, UShort_t)
Definition: AliFMDBaseDA.h:225
void WriteToFile(std::ostream &outFile, Bool_t *detectors=0)
AliRawReader * fReader
Definition: AliFMDBaseDA.h:165
self initialized array, used for adding constraints
virtual void InitContainer(TDirectory *dir)
TFile * Open(const char *filename, Long64_t &nevents)
Bool_t Exec(AliFMDBaseDA &da)
virtual void FillChannels(AliFMDDigit *)
Definition: AliFMDBaseDA.h:207
Int_t GetHalfringIndex(UShort_t, Char_t, UShort_t) const
virtual void Terminate(TFile *)
Definition: AliFMDBaseDA.h:234
std::ofstream fConditionsFile
Definition: AliFMDBaseDA.h:384
Int_t GetCurrentEvent() const
Definition: AliFMDBaseDA.h:241
Array * GetDetectorArray(UShort_t det)
Digits for the FMD.
void Rotate(const char *base, int max) const
virtual void FinishEvent()
Definition: AliFMDBaseDA.h:230
std::ofstream fOutputFile
Definition: AliFMDBaseDA.h:383
TStopwatch timer
Definition: kNNSpeed.C:15
This class is a singleton that handles various parameters of the FMD detectors. This class reads from...
Manager of FMD parameters.
Class to read ALTRO formated raw data from an AliRawReader object.
Per digitizer card pulser calibration.
Array * GetRingArray(UShort_t det, Char_t ring)
TROOT * gROOT
TString GetRingPath(UShort_t det, Char_t ring, Bool_t full=kTRUE) const
Array fSummaries
Definition: AliFMDBaseDA.h:395
virtual void AddChannelContainer(Array *, UShort_t, Char_t, UShort_t, UShort_t)
Definition: AliFMDBaseDA.h:219
Int_t fCurrentEvent
Definition: AliFMDBaseDA.h:393
TObjArray Array
Definition: AliFMDBaseDA.h:62
Int_t Init(int argc, char **argv, Bool_t reader=true)
#define AliInfoF(message,...)
Definition: AliLog.h:499
Array fDetectorArray
Definition: AliFMDBaseDA.h:387
virtual UShort_t GetProgress(Int_t nEvent) const
Bool_t Run(AliRawReader *fmdReader, Bool_t appendRun, Bool_t isBase=false)
void SetDiagnosticsFilename(const TString &f)
Definition: AliFMDBaseDA.h:102
Per digitizer card pulser calibration.
TString GetSectorPath(UShort_t det, Char_t ring, UShort_t sec, Bool_t full=kTRUE) const
TString GetDetectorPath(UShort_t det, Bool_t full=kTRUE) const
#define AliWarning(message)
Definition: AliLog.h:541
Per digitizer card pulser calibration.
Int_t RunNumber() const
TObjArray * array
Definition: AnalyzeLaser.C:12
void UseCompleteHeader(Bool_t yes=kTRUE)
void WriteConditionsData(AliFMDRawReader *fmdReader)
TString GetStripPath(UShort_t det, Char_t ring, UShort_t sec, UShort_t str, Bool_t full=kTRUE) const
Bool_t fMakeSummaries
Definition: AliFMDBaseDA.h:386
TH2 * MakeSummaryHistogram(const char *prefix, const char *title, UShort_t det, Char_t ring)
char * prefix
#define AliInfo(message)
Definition: AliLog.h:484
void SetSaveDiagnostics(Bool_t save)
Definition: AliFMDBaseDA.h:96
static const char * GetConditionsShuttleID()
TArrayS fPulseLength
Definition: AliFMDBaseDA.h:389
virtual Bool_t ReadAdcs(TClonesArray *array)
UInt_t fNEventsPerDetector[3]
Definition: AliFMDBaseDA.h:391
virtual Bool_t ReadSODevent(AliFMDCalibSampleRate *samplerate, AliFMDCalibStripRange *striprange, TArrayS &pulseSize, TArrayS &pulseLength, Bool_t *detectors=0)
static AliFMDParameters * Instance()
static void SetModuleDebugLevel(const char *module, Int_t level)
Definition: AliLog.cxx:485
Class to read raw data.
Bool_t fSaveHistograms
Definition: AliFMDBaseDA.h:385
static void EnableDebug(Bool_t enabled)
Definition: AliLog.cxx:422
TString fDiagnosticsFilename
Definition: AliFMDBaseDA.h:382
void SetTryAll(Bool_t all=true)
Definition: AliFMDBaseDA.h:120
Per digitizer card pulser calibration.
void WriteToFile(std::ostream &, Bool_t *detectors=0)
virtual void CloseFiles()
Int_t GetRequiredEvents() const
Definition: AliFMDBaseDA.h:127
UShort_t Detector() const
virtual Bool_t OpenFiles(Bool_t appendRun=false)
virtual void WriteHeaderToFile()
Definition: AliFMDBaseDA.h:215
static Int_t GetDebugLevel(const char *module, const char *className)
Definition: AliLog.cxx:843
virtual void Init()
Definition: AliFMDBaseDA.h:203
Int_t debugLevel
virtual void MakeSummary(UShort_t, Char_t)
Definition: AliFMDBaseDA.h:375
Array * GetSectorArray(UShort_t det, Char_t ring, UShort_t sector)
#define AliErrorF(message,...)
Definition: AliLog.h:606
#define AliDebugF(logLevel, format,...)
Definition: AliLog.h:338
TArrayS fPulseSize
Definition: AliFMDBaseDA.h:388
Array * GetStripArray(UShort_t det, Char_t ring, UShort_t sector, UShort_t strip)
Bool_t fSeenDetectors[3]
Definition: AliFMDBaseDA.h:390
UShort_t Init(Bool_t forceReInit=kFALSE, UInt_t what=kAll)
Int_t fRequiredEvents
Definition: AliFMDBaseDA.h:392
void ShowUsage(std::ostream &o, const char *progname)
void SetCurrentEvent(Int_t currentEvent)
Definition: AliFMDBaseDA.h:354
virtual Bool_t HaveEnough(Int_t nEvent) const
virtual void Analyse(UShort_t, Char_t, UShort_t, UShort_t)
Definition: AliFMDBaseDA.h:211