Update
[u/mrichter/AliRoot.git] / FMD / FMDPedestalda.cxx
CommitLineData
4a243071 1/*
2
3 FMD DA for online calibration of conditions
4
5 Contact: canute@nbi.dk
6 Link: fmd.nbi.dk/fmd/offline
7 Run Type: PEDESTAL
8bd95799 8 DA Type: LDC
4a243071 9 Number of events needed: 1000
10 Input Files: raw data
11 Output Files: peds.csv
12 Trigger types used: PEDESTAL
13*/
24954a29 14#include <iostream>
4a243071 15#include <TSystem.h>
5dd86feb 16#include <TString.h>
4a243071 17#include <AliFMDParameters.h>
18#include <AliRawReader.h>
19#include <TStopwatch.h>
20#include <AliFMDPedestalDA.h>
21#include <AliRawReaderDate.h>
5dd86feb 22#include <AliRawReaderRoot.h>
23#include "daqDA.h"
4a243071 24#include "TROOT.h"
25#include "TPluginManager.h"
24954a29 26#include <AliLog.h>
2a082c96 27#ifdef ALI_AMORE
28# include <AmoreDA.h>
29# include <TH2.h>
30#endif
4a243071 31
32int main(int argc, char **argv)
33{
4a243071 34 /* magic line from Rene - for future reference! */
35 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
24954a29 36 "*",
4a243071 37 "TStreamerInfo",
38 "RIO",
39 "TStreamerInfo()");
276b1261 40 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit",
41 "TMinuitMinimizer",
42 "Minuit",
43 "TMinuitMinimizer(const char *)");
44 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
45 "GSLMultiMin",
46 "ROOT::Math::GSLMinimizer",
47 "MathMore",
48 "GSLMinimizer(const char *)");
49 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
50 "GSLMultiFit",
51 "ROOT::Math::GSLNLSMinimizer",
52 "MathMore", "GSLNLSMinimizer(int)");
53 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
54 "GSLSimAn",
55 "ROOT::Math::GSLSimAnMinimizer",
56 "MathMore",
57 "GSLSimAnMinimizer(int)");
58 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
59 "Linear",
60 "TLinearMinimizer",
61 "Minuit",
62 "TLinearMinimizer(const char *)");
63 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer",
64 "Fumili",
65 "TFumiliMinimizer",
66 "Fumili",
67 "TFumiliMinimizer(int)");
68
69
24954a29 70
4a243071 71
5dd86feb 72 Bool_t diagnostics = kFALSE;
276b1261 73 if (argc < 2) {
74 std::cerr << "No input file given" << std::endl;
75 return 1;
76 }
77 TString fileName(argv[1]);
78 if (fileName.Contains("--help")) {
79 std::cout << "Usage: " << argv[0] << " FILENAME [OPTIONS]\n\n"
80 << "Options:\n"
81 << " --diagnostics=BOOL Make diagnostics ROOT file\n"
82 << std::endl;
83 return 0;
84 }
85
408bf2b4 86 for (int i = 2; i < argc; i++) {
87 TString arg(argv[i]);
88 if (arg.Contains("--diagnostics=true")) diagnostics = kTRUE;
89 else if (arg.Contains("--help")) {
90 std::cout << "Usage: " << argv[0] << " FILENAME [OPTIONS]\n\n"
91 << "Options:\n"
92 << " --diagnostics=BOOL Make diagnostics ROOT file\n"
93 << std::endl;
94 return 0;
95 }
96 else {
97 std::cerr << "Unknown option: " << arg << "\n"
98 << "Try '" << argv[0] << " --help" << std::endl;
99 return 1;
100 }
5dd86feb 101 }
4a243071 102 Bool_t old = kTRUE;
103
1f12303f 104 AliLog::EnableDebug(kFALSE);
4a243071 105 AliFMDParameters::Instance()->Init(kFALSE,0);
4a243071 106 AliFMDParameters::Instance()->UseCompleteHeader(old);
107
5dd86feb 108 AliRawReader *reader = 0;
276b1261 109 if (fileName.EndsWith(".root"))
110 reader = new AliRawReaderRoot(fileName.Data());
111 else
112 reader = new AliRawReaderDate(fileName.Data());
5dd86feb 113 if (!reader) {
276b1261 114 std::cerr << "Don't know how to make reader for " << fileName
5dd86feb 115 << std::endl;
116 return -2;
117 }
4a243071 118 TStopwatch timer;
119 timer.Start();
120 AliFMDPedestalDA pedDA;
5dd86feb 121 pedDA.SetSaveDiagnostics(diagnostics);
2a082c96 122#ifdef ALI_AMORE
123 pedDA.SetMakeSummaries(kTRUE);
124#endif
4a243071 125 pedDA.Run(reader);
126
127 timer.Stop();
128 timer.Print();
5dd86feb 129
6cf6e7a0 130 Int_t retvalConditions =
131 daqDA_FES_storeFile("conditions.csv",
132 AliFMDParameters::Instance()->GetConditionsShuttleID());
133 Int_t retvalPeds =
134 daqDA_FES_storeFile("peds.csv",
135 AliFMDParameters::Instance()->GetPedestalShuttleID());
4a243071 136
5dd86feb 137 if(retvalConditions!=0 || retvalPeds!=0)
138 std::cerr << "Pedestal DA failed" << std::endl;
4a243071 139
2a082c96 140#ifdef ALI_AMORE
141 try {
142 amore::da::AmoreDA myAmore(amore::da::AmoreDA::kSender);
143
144 UShort_t det = 0;
145 for (det = 1; det <= 3; det++)
146 if (pedDA.HasSeenDetector(det)) break;
147 if (det >= 1 && det <= 3) {
148 TObject* runNo = new TObject;
149 runNo->SetUniqueID(reader->GetRunNumber());
150 myAmore.Send(Form("pedRunNoFMD%d", det), runNo);
151 }
152
153 TIter next(&pedDA.GetSummaries());
154 TObject* obj = 0;
155 while ((obj = next()))
156 myAmore.Send(obj->GetName(), obj);
157 }
158 catch (std::exception& e) {
159 std::cerr << "Failed to make AMORE instance: " << e.what() << std::endl;
160 }
161
162#endif
5dd86feb 163 if(retvalPeds != 0) return retvalPeds;
2a082c96 164 return retvalConditions;
165
4a243071 166}