Changes to make DAs publish information to AMORE.
[u/mrichter/AliRoot.git] / FMD / FMDPedestalda.cxx
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
8   DA Type:                 LDC
9   Number of events needed: 1000
10   Input Files:             raw data 
11   Output Files:            peds.csv
12   Trigger types used:      PEDESTAL
13 */
14 #include <iostream>
15 #include <TSystem.h>
16 #include <TString.h>
17 #include <AliFMDParameters.h>
18 #include <AliRawReader.h>
19 #include <TStopwatch.h>
20 #include <AliFMDPedestalDA.h>
21 #include <AliRawReaderDate.h>
22 #include <AliRawReaderRoot.h>
23 #include "daqDA.h"
24 #include "TROOT.h"
25 #include "TPluginManager.h"
26 #include <AliLog.h>
27 #ifdef ALI_AMORE
28 # include <AmoreDA.h>
29 # include <TH2.h>
30 #endif
31
32 int main(int argc, char **argv) 
33 {
34   /* magic line from Rene - for future reference! */
35   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
36                                         "*",
37                                         "TStreamerInfo",
38                                         "RIO",
39                                         "TStreamerInfo()");
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
70   
71   
72   Bool_t diagnostics = kFALSE;
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       
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     }
101   }
102   Bool_t old = kTRUE;
103
104   AliLog::EnableDebug(kFALSE);
105   AliFMDParameters::Instance()->Init(kFALSE,0);
106   AliFMDParameters::Instance()->UseCompleteHeader(old);
107
108   AliRawReader *reader = 0;
109   if (fileName.EndsWith(".root")) 
110     reader = new AliRawReaderRoot(fileName.Data());
111   else 
112     reader = new AliRawReaderDate(fileName.Data());
113   if (!reader) { 
114     std::cerr << "Don't know how to make reader for " << fileName
115               << std::endl;
116     return -2;
117   }
118   TStopwatch timer;
119   timer.Start();
120   AliFMDPedestalDA pedDA;
121   pedDA.SetSaveDiagnostics(diagnostics);
122 #ifdef ALI_AMORE
123   pedDA.SetMakeSummaries(kTRUE);
124 #endif
125   pedDA.Run(reader);
126   
127   timer.Stop();
128   timer.Print();
129  
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());
136
137   if(retvalConditions!=0 || retvalPeds!=0)
138     std::cerr << "Pedestal DA failed" << std::endl;
139   
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
163   if(retvalPeds != 0) return retvalPeds;
164   return retvalConditions;
165
166 }