+ TDatime now;
+ fConditionsFile << "# This file created from run number " << fRunno
+ << " at " << now.AsString() << std::endl;
+
+ AliFMDCalibSampleRate* sampleRate = new AliFMDCalibSampleRate();
+ AliFMDCalibStripRange* stripRange = new AliFMDCalibStripRange();
+
+ fmdReader->ReadSODevent(sampleRate,stripRange,fPulseSize,fPulseLength,
+ fSeenDetectors);
+
+ sampleRate->WriteToFile(fConditionsFile, fSeenDetectors);
+ stripRange->WriteToFile(fConditionsFile, fSeenDetectors);
+
+
+ // Zero Suppresion
+
+ // Strip Range
+
+ fConditionsFile.write("# Gain Events \n",15);
+
+ for(UShort_t det=1; det<=3;det++) {
+ if (!fSeenDetectors[det-1]) {
+ continue;
+ }
+ UShort_t firstring = (det == 1 ? 1 : 0);
+ for(UShort_t iring = firstring; iring <=1;iring++) {
+ Char_t ring = (iring == 1 ? 'I' : 'O');
+ for(UShort_t board =0 ; board <=1; board++) {
+
+ Int_t idx = GetHalfringIndex(det,ring,board);
+
+ fConditionsFile << det << ','
+ << ring << ','
+ << board << ','
+ << fPulseLength.At(idx) << "\n";
+
+ }
+ }
+ }
+
+ fConditionsFile.write("# Gain Pulse \n",14);
+
+ for(UShort_t det=1; det<=3;det++) {
+ if (!fSeenDetectors[det-1]) {
+ continue;
+ }
+ UShort_t firstring = (det == 1 ? 1 : 0);
+ for(UShort_t iring = firstring; iring <=1;iring++) {
+ Char_t ring = (iring == 1 ? 'I' : 'O');
+ for(UShort_t board =0 ; board <=1; board++) {
+
+ Int_t idx = GetHalfringIndex(det,ring,board);
+
+ fConditionsFile << det << ','
+ << ring << ','
+ << board << ','
+ << fPulseSize.At(idx) << "\n";
+
+ }
+ }
+ }
+ // sampleRate->WriteToFile(std::cout, fSeenDetectors);
+ // stripRange->WriteToFile(std::cout, fSeenDetectors);
+
+ if(fConditionsFile.is_open()) {
+
+ fConditionsFile.write("# EOF\n",6);
+ fConditionsFile.close();
+
+ }
+
+}
+//_____________________________________________________________________
+Int_t AliFMDBaseDA::GetHalfringIndex(UShort_t det, Char_t ring,
+ UShort_t board) const
+{
+ // Get the index corresponding to a half-ring
+ //
+ // Parameters:
+ // det Detector number
+ // ring Ring identifier
+ // board Board number
+ //
+ // Return
+ // Internal index of the board
+ UShort_t iring = (ring == 'I' ? 1 : 0);
+
+ Int_t index = (((det-1) << 2) | (iring << 1) | (board << 0));
+
+ return index-2;
+
+}
+//_____________________________________________________________________
+void AliFMDBaseDA::Rotate(const char* base, int max) const
+{
+ //
+ // Rotate a set of files. base is the basic name of the files.
+ // If the file base.max exists it is removed.
+ // If the file base.n exists (where n < max) it is renamed to
+ // base.(n-1).
+ // If the file base exists, it is renamed to base.1
+ //
+ // Parameters:
+ // base Base name of the files
+ // max Maximum number to keep (minus one for the current).
+
+ // Note: TSystem::AccessPathName returns false if the condition is
+ // fulfilled!
+
+ // Check if we have base.max, and if so, remove it.
+ TString testName(Form("%s.%d", base, max));
+ if (!gSystem->AccessPathName(testName.Data()))
+ gSystem->Unlink(testName.Data());
+
+ // Loop down from max-1 to 1 and move files
+ for (int i = max-1; i >= 1; i--) {
+ testName = Form("%s.%d", base, i);
+ if (!gSystem->AccessPathName(testName.Data())) {
+ TString newName(Form("%s.%d", base, i+1));
+ gSystem->Rename(testName.Data(), newName.Data());
+ }
+ }
+
+ // If we have the file base, rename it to base.1
+ testName = Form("%s", base);
+ if (!gSystem->AccessPathName(testName.Data())){
+ TString newName(Form("%s.%d", base, 1));
+ gSystem->Rename(testName.Data(), newName.Data());
+ }
+}
+
+//_____________________________________________________________________
+TH2*
+AliFMDBaseDA::MakeSummaryHistogram(const char* prefix, const char* title,
+ UShort_t d, Char_t r)
+{
+ //
+ // Utility function for defining summary histograms
+ //
+ // Parameters:
+ // det Detector
+ // ring Ring identifier
+ // prefix Histogram prefix
+ // title Histogram title
+ //
+ Int_t nX = ((d == 1 || r == 'I' || r == 'i') ? 20 : 40);
+ Int_t nY = ((d == 1 || r == 'I' || r == 'i') ? 512 : 256);
+
+ TH2* ret = new TH2F(Form("%sFMD%d%c", prefix, d, r),
+ Form("%s for FMD%d%c", title, d, r),
+ nX, -0.5, nX-0.5, nY, -0.5, nY-0.5);
+ ret->SetXTitle("Sector #");
+ ret->SetYTitle("Strip #");
+ ret->SetDirectory(0);
+ // if (!fSummaries) fSummaries = new TObjArray;
+ fSummaries.Add(ret);
+ return ret;
+}
+
+//_____________________________________________________________________
+TObjArray*
+AliFMDBaseDA::GetDetectorArray(UShort_t det)
+{
+ if (det < 1 || det > 3) {
+ AliErrorF("Detector index %d out of bounds", det);
+ return 0;
+ }
+ return static_cast<TObjArray*>(fDetectorArray.At(det));
+}
+//_____________________________________________________________________
+TObjArray*
+AliFMDBaseDA::GetRingArray(UShort_t det, Char_t ring)
+{
+ Int_t idx = (ring == 'O' || ring == 'o' ? 0 : 1);
+ TObjArray* array = GetDetectorArray(det);
+ if (!array) return 0;
+ array = static_cast<TObjArray*>(array->At(idx));
+ if (!array) AliErrorF("No ring array for FMD%d%c (%d)", det, ring, idx);
+ return array;
+}
+//_____________________________________________________________________
+TObjArray*
+AliFMDBaseDA::GetSectorArray(UShort_t det, Char_t ring, UShort_t sector)
+{
+ TObjArray* array = GetRingArray(det,ring);
+ if (!array) return 0;
+ array = static_cast<TObjArray*>(array->At(sector));
+ if (!array) AliErrorF("No sector array for FMD%d%c[%02d]", det, ring, sector);
+ return array;
+}
+//_____________________________________________________________________
+TObjArray*
+AliFMDBaseDA::GetStripArray(UShort_t det, Char_t ring,
+ UShort_t sector, UShort_t strip)
+{
+ TObjArray* array = GetSectorArray(det,ring,sector);
+ if (!array) return 0;
+ array = static_cast<TObjArray*>(array->At(strip));
+ if (!array) AliErrorF("No strip array for FMD%d%c[%02d,%03d]",
+ det, ring, sector, strip);
+ return array;
+}
+
+//=====================================================================
+AliFMDBaseDA::Runner::Runner()
+ : fReader(0),
+ fDiagFile(""),
+ fDiag(false)
+{}
+
+//_____________________________________________________________________
+void
+AliFMDBaseDA::Runner::AddHandlers()
+{
+ gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
+ "*",
+ "TStreamerInfo",
+ "RIO",
+ "TStreamerInfo()");
+ gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit",
+ "TMinuitMinimizer",
+ "Minuit",
+ "TMinuitMinimizer(const char *)");
+ gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
+ "GSLMultiMin",
+ "ROOT::Math::GSLMinimizer",
+ "MathMore",
+ "GSLMinimizer(const char *)");
+ gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
+ "GSLMultiFit",
+ "ROOT::Math::GSLNLSMinimizer",
+ "MathMore", "GSLNLSMinimizer(int)");
+ gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
+ "GSLSimAn",
+ "ROOT::Math::GSLSimAnMinimizer",
+ "MathMore",
+ "GSLSimAnMinimizer(int)");
+ gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
+ "Linear",
+ "TLinearMinimizer",
+ "Minuit",
+ "TLinearMinimizer(const char *)");
+ gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
+ "Fumili",
+ "TFumiliMinimizer",
+ "Fumili",
+ "TFumiliMinimizer(int)");
+}
+//_____________________________________________________________________
+void
+AliFMDBaseDA::Runner::ShowUsage(std::ostream& o, const char* progname)
+{
+ o << "Usage: " << progname << " SOURCE [OPTIONS]\n\n"
+ << "Options:\n"
+ << " -h,--help Show this help\n"
+ << " -d,--diagnostics[=FILE] Write diagnostics to file\n"
+ << " -D,--debug=LEVEL Set the debug level\n\n"
+ << "SOURCE is one of\n"
+ << " * FILE.raw Raw data file\n"
+ << " * FILE.root ROOT'ified raw data file\n"
+ << " * collection://FILE.root Event list in a ROOT file\n"
+ << " * collection://FILE File containing list of ROOT files\n"
+ << " * ^FMD Monitor source\n"
+ << "There are other options too. Check the AliRawReader docs\n"
+ << std::endl;
+}
+
+//_____________________________________________________________________
+namespace {
+ Bool_t ExtractValue(const TString& arg, TString& val)
+ {
+ val = "";
+ Int_t eq = arg.Index("=");
+ if (eq == kNPOS) return false;
+
+ val = arg(eq+1, arg.Length()-eq-1);
+ return true;
+ }
+}
+
+//_____________________________________________________________________
+Int_t
+AliFMDBaseDA::Runner::Init(int argc, char** argv)
+{
+ AddHandlers();
+
+ // --- Process the command line ------------------------------------
+ TString source;
+ Int_t debugLevel = 0;
+ Bool_t help = false;
+
+ for (int i = 1; i < argc; i++) {
+ TString arg(argv[i]);
+ Bool_t badOption = false;