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