]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/ITSSSDPEDda.cxx
Fix for the problem during PbPb run of Nov 2010 (Indra)
[u/mrichter/AliRoot.git] / ITS / ITSSSDPEDda.cxx
CommitLineData
c4d90345 1/**************************************************************************
61a57d07 2- Contact: Oleksandr_Borysov oborysov@cern.ch
d86972f6 3- Link: /afs/cern.ch/user/o/oborysov/public/ssdda/run75491.raw, ssddaconfig.txt, ssdddlmap_v09.txt, ssdbcmap_1258498704.root
61a57d07 4- Run Type: PEDESTAL
a69c8ba0 5- DA Type: LDC
61a57d07 6- Number of events needed: ~200
d86972f6 7- Input Files: raw_data_file_on_LDC, in the daqDetDB: ssddaconfig.txt, ssdddlmap_v09.txt, ssdbcmap_1258498704.root
be4f467e 8- Output Files: ./<EqId_Slot> ./ssddaldc_<LDCID>.root, FXS_name=ITSSSDda_<LDCID>.root
a69c8ba0 9 local files are persistent over runs: data source
10- Trigger types used:
c4d90345 11 **************************************************************************/
12
61a57d07 13
c4d90345 14#include <iostream>
be4f467e 15#include <fstream>
16#include <sstream>
17#include <string>
61a57d07 18#include <vector>
19#include <ctype.h>
c4d90345 20#include "TString.h"
f67db810 21#include "TFile.h"
22#include "daqDA.h"
f67db810 23#include "AliITSHandleDaSSD.h"
61a57d07 24
7bad8b65 25#include "TROOT.h"
26#include "TPluginManager.h"
f67db810 27
28using namespace std;
29
f67db810 30
292c304e 31class ConfigStruct {
32public:
be4f467e 33 Int_t fNModuleProcess;
34 string fSsdDdlMap;
35 string fBadChannels;
d86972f6 36 Bool_t fCheckChipsOff, fUseWelford;
37 ConfigStruct() : fNModuleProcess(108), fSsdDdlMap(""), fBadChannels(""), fCheckChipsOff(kFALSE), fUseWelford(kTRUE) {}
be4f467e 38};
39
40
41Int_t SaveEquipmentCalibrationData(const AliITSHandleDaSSD *ssddaldc, const Char_t *fprefix = NULL);
42Bool_t ReadDAConfigurationFile(const Char_t *configfname, AliITSHandleDaSSD *const ssddaldc, ConfigStruct& cfg);
43
44
f67db810 45int main( int argc, char** argv )
46{
292c304e 47// Implements SSD DA executable.
be4f467e 48 const Char_t *configfname = "ssddaconfig.txt";
49 const Char_t *bcfname = "badchannels.root";
50 const Char_t *ddlmfname = "ssdddlmap.txt";
f67db810 51 AliITSHandleDaSSD *ssddaldc;
6e7691a5 52 TString feefname, fcdbsave, lfname;
f67db810 53 Int_t status;
fc566f79 54 Char_t *dafname = NULL;
be4f467e 55 ConfigStruct cfg;
7bad8b65 56
be4f467e 57 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
7bad8b65 58 "*",
59 "TStreamerInfo",
60 "RIO",
61 "TStreamerInfo()");
62
63
f67db810 64 /* check that we got some arguments = list of files */
65 if (argc<2) {
a69c8ba0 66 fprintf(stderr, "Wrong number of arguments\n");
f67db810 67 return -1;
68 }
69
70 char *datafilename = argv[1];
c4d90345 71 ssddaldc = new AliITSHandleDaSSD(datafilename);
be4f467e 72 if (ssddaldc->IsZombie()) {
73 cerr << "Failed to process raw data file " << datafilename << "! Exit DA!\n";
74 return -1;
75 }
6e7691a5 76
be4f467e 77 lfname.Form("./%s", configfname);
78 if (!(status = daqDA_DB_getFile(configfname, lfname.Data()))) {
79 if (!ReadDAConfigurationFile(lfname.Data(), ssddaldc, cfg)) cerr << "Error reading configuration file " << lfname.Data() << " !\n";
80 } else fprintf(stderr, "Failed to import DA configuration file %s from the detector db: %d, %s \n", configfname, status, lfname.Data());
81
82 if (cfg.fBadChannels.size() > 0) bcfname = cfg.fBadChannels.c_str();
6e7691a5 83 lfname.Form("./%s", bcfname);
d86972f6 84 if ((status = daqDA_DB_getFile(bcfname, lfname.Data()))) {
be4f467e 85 fprintf(stderr, "Failed to import the file %s from the detector db: %d, %s! Exit DA!\n", bcfname, status, lfname.Data());
86 delete ssddaldc;
87 return -3;
88 }
89 if (!ssddaldc->ReadStaticBadChannelsMap(lfname.Data())) {
90 cerr << "Error reading static bad channels map " << lfname.Data() << "! Exit DA!\n";
91 delete ssddaldc;
92 return -4;
93 }
94
95 if (cfg.fSsdDdlMap.size() > 0) ddlmfname = cfg.fSsdDdlMap.c_str();
6e7691a5 96 lfname.Form("./%s", ddlmfname);
be4f467e 97 if (!(status = daqDA_DB_getFile(ddlmfname, lfname.Data()))) {
6e7691a5 98 if (!ssddaldc->ReadDDLModuleMap(lfname.Data())) cerr << "Error reading DDL map from file " << lfname.Data() << " !\n";
99 } else {
be4f467e 100 fprintf(stderr, "Failed to import file %s from the detector db: %d, %s \n", ddlmfname, status, lfname.Data());
6e7691a5 101 if (!ssddaldc->ReadDDLModuleMap()) cerr << "Failed to load the DDL map from AliITSRawStreamSSD!\n";
102 }
be4f467e 103
d86972f6 104 if (!ssddaldc->ProcessRawData(cfg.fNModuleProcess, cfg.fUseWelford)) {
a69c8ba0 105 cerr << "Error !ssddaldc->ProcessRawData()" << endl;
f67db810 106 delete ssddaldc;
107 return -1;
371588bb 108 }
f67db810 109 daqDA_progressReport(90);
c4d90345 110
fc566f79 111 dafname = ".";
a69c8ba0 112 if (ssddaldc->SaveCalibrationSSDLDC(dafname)) {
113 cout << "SSDDA data are saved in " << dafname << endl;
3af1c47d 114 status = daqDA_FES_storeFile(dafname, "CALIBRATION");
a69c8ba0 115 if (status) fprintf(stderr, "Failed to export file : %d\n", status);
be4f467e 116 } else cerr << "Error saving DA data to the file!\n";
fac3826c 117
371588bb 118 feefname.Form("%s/ssddaldc_%i.root", ".", ssddaldc->GetLdcId());
a69c8ba0 119 cout << "Saving feessdda data in " << feefname << endl;
120 TFile *fileRun = new TFile (feefname.Data(),"RECREATE");
121 if (fileRun->IsZombie()) {
122 cerr << "Error open file " << feefname << endl;
123 delete ssddaldc;
124 delete fileRun;
be4f467e 125 return -2;
a69c8ba0 126 }
127 ssddaldc->Write();
128 fileRun->Close();
129 delete fileRun;
130
fac3826c 131 fcdbsave.Form("ssddaldc_%i.root", ssddaldc->GetLdcId());
132 status = daqDA_DB_storeFile(feefname.Data(), fcdbsave.Data());
133 if (status) fprintf(stderr, "Failed to export file %s to the detector db: %d, %s \n", feefname.Data(), status, fcdbsave.Data());
be4f467e 134 cout << SaveEquipmentCalibrationData(ssddaldc) << " files were uploaded to DetDB!\n";
61a57d07 135 if(cfg.fCheckChipsOff) ssddaldc->CheckOffChips();
f67db810 136 delete ssddaldc;
137 daqDA_progressReport(100);
138 return 0;
a69c8ba0 139}
be4f467e 140
141
142
143//__________________________________________________________________________________________
144Int_t SaveEquipmentCalibrationData(const AliITSHandleDaSSD *ssddaldc, const Char_t *fprefix)
145{
292c304e 146// Saves the files with Offset correction and ZS threshold.
be4f467e 147 TString feefilename;
148 Int_t count = 0, status;
149 for (Int_t ddli = 0; ddli < 16; ddli++) {
150 for(Int_t adi = 1; adi <= 9; adi++) {
151 if (!ssddaldc->AdDataPresent(ddli, adi)) continue;
152 if (fprefix) feefilename.Form("%s%i_%i", fprefix, ssddaldc->DdlToEquipmentId(ddli), adi);
153 else feefilename.Form("%i_%i", ssddaldc->DdlToEquipmentId(ddli), adi);
154 if (ssddaldc->SaveEqSlotCalibrationData(ddli, adi, feefilename)) {
155 status = daqDA_DB_storeFile(feefilename, feefilename);
156 if (status) fprintf(stderr, "Error %i, failed to export file %s\n", status, feefilename.Data());
157 else count++;
158 }
159 }
160 }
161 return count;
162}
163
164
165//__________________________________________________________________________________________
166Bool_t ReadDAConfigurationFile(const Char_t *configfname, AliITSHandleDaSSD *const ssddaldc, ConfigStruct& cfg)
167{
168// Dowload configuration parameters from configuration file or database
d86972f6 169 const int nkwords = 13;
59087bde 170 char const *keywords[nkwords] = {"ZsDefault", "OffsetDefault", "ZsFactor", "PedestalThresholdFactor", "CmThresholdFactor",
61a57d07 171 "NModulesToProcess", "DDLMapFile", "BadChannelsFile", "ZSMinValue", "MergeBCFlag",
d86972f6 172 "CheckChipsOff", "UseWelford", "OffLadder"};
61a57d07 173 Int_t tmpint, laddern;
be4f467e 174 Float_t tmpflt;
175 fstream dfile;
61a57d07 176 vector<short> allist(0), cllist(0);
be4f467e 177 if (!configfname) {
61a57d07 178 cerr << "No DA configuration file name is specified, Return!\n";
179 return kFALSE;
180 }
181 if (!ssddaldc) {
182 cerr << "ssddaldc == 0, DA configuration file will not be read! Return!\n";
be4f467e 183 return kFALSE;
184 }
185 dfile.open(configfname, ios::in);
186 if (!dfile.is_open()) {
187 cerr << "Error open DA configuration file " << configfname << " defaul value are used!\n";
188 return kFALSE;
189 }
190 while (!dfile.eof()) {
191 string str, keystr, tmpstr;
192 getline(dfile, str);
193 stringstream strline(str);
194 strline >> keystr;
195 if (keystr.size() == 0) continue;
196 if ((keystr.at(0) == '#') ) continue;
197 int ind = 0;
198 while (keystr.compare(keywords[ind])) if (++ind == nkwords) break;
199 switch (ind) {
200 case 0:
201 strline >> tmpint;
202 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
203 else {
204 ssddaldc->SetZsDefaul(tmpint);
205 cout << "Default value for ZS thereshold " << keystr << ": " << ssddaldc->GetZsDefault() << endl;
206 } break;
207 case 1:
208 strline >> tmpint;
209 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
210 else {
211 ssddaldc->SetOffsetDefault(tmpint);
212 cout << "Default value for offset correction " << keystr << ": " << ssddaldc->GetOffsetDefault() << endl;
213 } break;
214 case 2:
215 strline >> tmpflt;
216 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
217 else {
218 ssddaldc->SetZsFactor(tmpflt);
219 cout << keystr << ": " << ssddaldc->GetZsFactor() << endl;
220 } break;
221 case 3:
222 strline >> tmpflt;
223 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
224 else {
225 ssddaldc->SetPedestalThresholdFactor(tmpflt);
226 cout << keystr << ": " << ssddaldc->GetPedestalThresholdFactor() << endl;
227 } break;
228 case 4:
229 strline >> tmpflt;
230 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
231 else {
232 ssddaldc->SetCmThresholdFactor(tmpflt);
233 cout << keystr << ": " << ssddaldc->GetCmThresholdFactor() << endl;
234 } break;
235 case 5:
236 strline >> tmpint;
237 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
238 else {
239 cfg.fNModuleProcess = tmpint;
240 cout << keystr << ": " << cfg.fNModuleProcess << endl;
241 } break;
242 case 6:
243 strline >> tmpstr;
244 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
245 else {
246 if (tmpstr.size() == 0) continue;
247 if (tmpstr.at(0) == '#') continue;
248 cfg.fSsdDdlMap = tmpstr;
249 cout << keystr << ": " << cfg.fSsdDdlMap.c_str() << endl;
250 } break;
251 case 7:
252 strline >> tmpstr;
253 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
254 else {
255 if (tmpstr.size() == 0) continue;
256 if (tmpstr.at(0) == '#') continue;
257 cfg.fBadChannels = tmpstr;
258 cout << keystr << ": " << cfg.fBadChannels.c_str() << endl;
259 } break;
61a57d07 260 case 8:
261 strline >> tmpint;
262 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
263 else {
264 ssddaldc->SetZsMinimum(tmpint);
265 cout << keystr << ": " << ssddaldc->GetZsMinimum() << endl;
266 } break;
267 case 9:
268 strline >> tmpint;
269 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
270 else {
271 ssddaldc->SetMergeBCFlag(static_cast<Byte_t>(tmpint));
272 cout << keystr << ": " << ssddaldc->GetMergeBCFlag() << endl;
273 } break;
274 case 10:
275 strline >> tmpint;
276 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
277 else {
278 cfg.fCheckChipsOff = static_cast<Bool_t>(tmpint);
279 cout << keystr << ": " << cfg.fCheckChipsOff << endl;
280 } break;
281 case 11:
d86972f6 282 strline >> tmpint;
283 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
284 else {
285 cfg.fUseWelford = static_cast<Bool_t>(tmpint);
286 cout << keystr << ": " << cfg.fUseWelford << endl;
287 } break;
288 case 12:
61a57d07 289 char dside;
290 while (!strline.eof()) {
291 strline >> tmpstr;
292 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
293 if (tmpstr.size() == 0) break;
294 if ((tmpstr.at(0) == '#') ) break;
295 if ( sscanf(tmpstr.c_str(), "%c%u", &dside, &laddern) < 2 ) {
296 cerr << "Error reading side and ladder number form the config file: " << tmpstr << "! Continue!\n";
297 continue;
298 }
299 if ( toupper(dside) == 'A') allist.push_back(laddern);
300 else if ( toupper(dside) == 'C') cllist.push_back(laddern);
301 else cerr << "Error! " << dside << " SSD ladder side can be either A or C! Continue!\n";
302 }
303 break;
be4f467e 304 default:
305 cerr << keystr << " is not a key word, no assignment were made!\n";
306 }
61a57d07 307 }
308 if (allist.size() == 0 && cllist.size() == 0) return kTRUE;
309 short *tmparr = 0, si;
310 vector<short>::iterator it;
311 if (allist.size() > 0) {
312 tmparr = new short [allist.size()];
313 cout << "Following A side " << (allist.size()>1?"ladders are":"ladder is") << " supposed to be off and will be suppressed :";
314 for ( it = allist.begin(), si = 0; it < allist.end(); it++, si++ ) {
315 tmparr[si] = *it;
316 cout << " " << tmparr[si];
317 }
318 cout << ";" << endl;
319 ssddaldc->SetALaddersOff(allist.size(), tmparr);
320 }
321 if (tmparr) delete [] tmparr;
322 if (cllist.size() > 0) {
323 tmparr = new short [cllist.size()];
324 cout << "Following C side " << (cllist.size() > 1 ? "ladders are" : "ladder is") << " supposed to be off and will be suppressed :";
325 for ( it = cllist.begin(), si = 0; it < cllist.end(); it++, si++ ) {
326 tmparr[si] = *it;
327 cout << " " << tmparr[si];
328 }
329 cout << ";" << endl;
330 ssddaldc->SetCLaddersOff(cllist.size(), tmparr);
331 }
332 if (tmparr) delete [] tmparr;
be4f467e 333 return kTRUE;
334}