]>
Commit | Line | Data |
---|---|---|
c4d90345 | 1 | /************************************************************************** |
a69c8ba0 | 2 | - Contact: Oleksandr_Borysov aborysov@ts.infnf.it |
3 | - Link: /afs/infn.it/ts/user/efragiac/public/testCosm3125.001 | |
4 | - Run Type: | |
5 | - DA Type: LDC | |
be4f467e | 6 | - Number of events needed: ~500 |
7 | - Input Files: raw_data_file_on_LDC, ssddaconfig txt, ssdddlmap.txt, badchannels.root | |
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 | ||
13 | ||
14 | #include <iostream> | |
be4f467e | 15 | #include <fstream> |
16 | #include <sstream> | |
17 | #include <string> | |
c4d90345 | 18 | #include "TString.h" |
f67db810 | 19 | #include "TFile.h" |
20 | #include "daqDA.h" | |
f67db810 | 21 | #include "AliITSHandleDaSSD.h" |
7bad8b65 | 22 | #include "TROOT.h" |
23 | #include "TPluginManager.h" | |
f67db810 | 24 | |
25 | using namespace std; | |
26 | ||
f67db810 | 27 | |
be4f467e | 28 | struct ConfigStruct { |
29 | Int_t fNModuleProcess; | |
30 | string fSsdDdlMap; | |
31 | string fBadChannels; | |
32 | ConfigStruct() : fNModuleProcess(108), fSsdDdlMap(""), fBadChannels("") {} | |
33 | }; | |
34 | ||
35 | ||
36 | Int_t SaveEquipmentCalibrationData(const AliITSHandleDaSSD *ssddaldc, const Char_t *fprefix = NULL); | |
37 | Bool_t ReadDAConfigurationFile(const Char_t *configfname, AliITSHandleDaSSD *const ssddaldc, ConfigStruct& cfg); | |
38 | ||
39 | ||
f67db810 | 40 | int main( int argc, char** argv ) |
41 | { | |
be4f467e | 42 | const Char_t *configfname = "ssddaconfig.txt"; |
43 | const Char_t *bcfname = "badchannels.root"; | |
44 | const Char_t *ddlmfname = "ssdddlmap.txt"; | |
f67db810 | 45 | AliITSHandleDaSSD *ssddaldc; |
6e7691a5 | 46 | TString feefname, fcdbsave, lfname; |
f67db810 | 47 | Int_t status; |
fc566f79 | 48 | Char_t *dafname = NULL; |
be4f467e | 49 | ConfigStruct cfg; |
7bad8b65 | 50 | |
be4f467e | 51 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", |
7bad8b65 | 52 | "*", |
53 | "TStreamerInfo", | |
54 | "RIO", | |
55 | "TStreamerInfo()"); | |
56 | ||
57 | ||
f67db810 | 58 | /* check that we got some arguments = list of files */ |
59 | if (argc<2) { | |
a69c8ba0 | 60 | fprintf(stderr, "Wrong number of arguments\n"); |
f67db810 | 61 | return -1; |
62 | } | |
63 | ||
64 | char *datafilename = argv[1]; | |
c4d90345 | 65 | ssddaldc = new AliITSHandleDaSSD(datafilename); |
be4f467e | 66 | if (ssddaldc->IsZombie()) { |
67 | cerr << "Failed to process raw data file " << datafilename << "! Exit DA!\n"; | |
68 | return -1; | |
69 | } | |
6e7691a5 | 70 | |
be4f467e | 71 | lfname.Form("./%s", configfname); |
72 | if (!(status = daqDA_DB_getFile(configfname, lfname.Data()))) { | |
73 | if (!ReadDAConfigurationFile(lfname.Data(), ssddaldc, cfg)) cerr << "Error reading configuration file " << lfname.Data() << " !\n"; | |
74 | } else fprintf(stderr, "Failed to import DA configuration file %s from the detector db: %d, %s \n", configfname, status, lfname.Data()); | |
75 | ||
76 | if (cfg.fBadChannels.size() > 0) bcfname = cfg.fBadChannels.c_str(); | |
6e7691a5 | 77 | lfname.Form("./%s", bcfname); |
be4f467e | 78 | if (status = daqDA_DB_getFile(bcfname, lfname.Data())) { |
79 | fprintf(stderr, "Failed to import the file %s from the detector db: %d, %s! Exit DA!\n", bcfname, status, lfname.Data()); | |
80 | delete ssddaldc; | |
81 | return -3; | |
82 | } | |
83 | if (!ssddaldc->ReadStaticBadChannelsMap(lfname.Data())) { | |
84 | cerr << "Error reading static bad channels map " << lfname.Data() << "! Exit DA!\n"; | |
85 | delete ssddaldc; | |
86 | return -4; | |
87 | } | |
88 | ||
89 | if (cfg.fSsdDdlMap.size() > 0) ddlmfname = cfg.fSsdDdlMap.c_str(); | |
6e7691a5 | 90 | lfname.Form("./%s", ddlmfname); |
be4f467e | 91 | if (!(status = daqDA_DB_getFile(ddlmfname, lfname.Data()))) { |
6e7691a5 | 92 | if (!ssddaldc->ReadDDLModuleMap(lfname.Data())) cerr << "Error reading DDL map from file " << lfname.Data() << " !\n"; |
93 | } else { | |
be4f467e | 94 | fprintf(stderr, "Failed to import file %s from the detector db: %d, %s \n", ddlmfname, status, lfname.Data()); |
6e7691a5 | 95 | if (!ssddaldc->ReadDDLModuleMap()) cerr << "Failed to load the DDL map from AliITSRawStreamSSD!\n"; |
96 | } | |
be4f467e | 97 | |
98 | if (!ssddaldc->ProcessRawData(cfg.fNModuleProcess)) { | |
a69c8ba0 | 99 | cerr << "Error !ssddaldc->ProcessRawData()" << endl; |
f67db810 | 100 | delete ssddaldc; |
101 | return -1; | |
371588bb | 102 | } |
f67db810 | 103 | daqDA_progressReport(90); |
c4d90345 | 104 | |
fc566f79 | 105 | dafname = "."; |
a69c8ba0 | 106 | if (ssddaldc->SaveCalibrationSSDLDC(dafname)) { |
107 | cout << "SSDDA data are saved in " << dafname << endl; | |
3af1c47d | 108 | status = daqDA_FES_storeFile(dafname, "CALIBRATION"); |
a69c8ba0 | 109 | if (status) fprintf(stderr, "Failed to export file : %d\n", status); |
be4f467e | 110 | } else cerr << "Error saving DA data to the file!\n"; |
fac3826c | 111 | |
371588bb | 112 | feefname.Form("%s/ssddaldc_%i.root", ".", ssddaldc->GetLdcId()); |
a69c8ba0 | 113 | cout << "Saving feessdda data in " << feefname << endl; |
114 | TFile *fileRun = new TFile (feefname.Data(),"RECREATE"); | |
115 | if (fileRun->IsZombie()) { | |
116 | cerr << "Error open file " << feefname << endl; | |
117 | delete ssddaldc; | |
118 | delete fileRun; | |
be4f467e | 119 | return -2; |
a69c8ba0 | 120 | } |
121 | ssddaldc->Write(); | |
122 | fileRun->Close(); | |
123 | delete fileRun; | |
124 | ||
fac3826c | 125 | fcdbsave.Form("ssddaldc_%i.root", ssddaldc->GetLdcId()); |
126 | status = daqDA_DB_storeFile(feefname.Data(), fcdbsave.Data()); | |
127 | if (status) fprintf(stderr, "Failed to export file %s to the detector db: %d, %s \n", feefname.Data(), status, fcdbsave.Data()); | |
be4f467e | 128 | cout << SaveEquipmentCalibrationData(ssddaldc) << " files were uploaded to DetDB!\n"; |
f67db810 | 129 | delete ssddaldc; |
130 | daqDA_progressReport(100); | |
131 | return 0; | |
a69c8ba0 | 132 | } |
be4f467e | 133 | |
134 | ||
135 | ||
136 | //__________________________________________________________________________________________ | |
137 | Int_t SaveEquipmentCalibrationData(const AliITSHandleDaSSD *ssddaldc, const Char_t *fprefix) | |
138 | { | |
139 | TString feefilename; | |
140 | Int_t count = 0, status; | |
141 | for (Int_t ddli = 0; ddli < 16; ddli++) { | |
142 | for(Int_t adi = 1; adi <= 9; adi++) { | |
143 | if (!ssddaldc->AdDataPresent(ddli, adi)) continue; | |
144 | if (fprefix) feefilename.Form("%s%i_%i", fprefix, ssddaldc->DdlToEquipmentId(ddli), adi); | |
145 | else feefilename.Form("%i_%i", ssddaldc->DdlToEquipmentId(ddli), adi); | |
146 | if (ssddaldc->SaveEqSlotCalibrationData(ddli, adi, feefilename)) { | |
147 | status = daqDA_DB_storeFile(feefilename, feefilename); | |
148 | if (status) fprintf(stderr, "Error %i, failed to export file %s\n", status, feefilename.Data()); | |
149 | else count++; | |
150 | } | |
151 | } | |
152 | } | |
153 | return count; | |
154 | } | |
155 | ||
156 | ||
157 | //__________________________________________________________________________________________ | |
158 | Bool_t ReadDAConfigurationFile(const Char_t *configfname, AliITSHandleDaSSD *const ssddaldc, ConfigStruct& cfg) | |
159 | { | |
160 | // Dowload configuration parameters from configuration file or database | |
161 | const int nkwords = 8; | |
162 | char *keywords[nkwords] = {"ZsDefault", "OffsetDefault", "ZsFactor", "PedestalThresholdFactor", "CmThresholdFactor", | |
163 | "NModulesToProcess", "DDLMapFile", "BadChannelsFile"}; | |
164 | Int_t tmpint; | |
165 | Float_t tmpflt; | |
166 | fstream dfile; | |
167 | if (!configfname) { | |
168 | cerr << "No DA configuration file name is specified, defaul value are used!\n"; | |
169 | return kFALSE; | |
170 | } | |
171 | dfile.open(configfname, ios::in); | |
172 | if (!dfile.is_open()) { | |
173 | cerr << "Error open DA configuration file " << configfname << " defaul value are used!\n"; | |
174 | return kFALSE; | |
175 | } | |
176 | while (!dfile.eof()) { | |
177 | string str, keystr, tmpstr; | |
178 | getline(dfile, str); | |
179 | stringstream strline(str); | |
180 | strline >> keystr; | |
181 | if (keystr.size() == 0) continue; | |
182 | if ((keystr.at(0) == '#') ) continue; | |
183 | int ind = 0; | |
184 | while (keystr.compare(keywords[ind])) if (++ind == nkwords) break; | |
185 | switch (ind) { | |
186 | case 0: | |
187 | strline >> tmpint; | |
188 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
189 | else { | |
190 | ssddaldc->SetZsDefaul(tmpint); | |
191 | cout << "Default value for ZS thereshold " << keystr << ": " << ssddaldc->GetZsDefault() << endl; | |
192 | } break; | |
193 | case 1: | |
194 | strline >> tmpint; | |
195 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
196 | else { | |
197 | ssddaldc->SetOffsetDefault(tmpint); | |
198 | cout << "Default value for offset correction " << keystr << ": " << ssddaldc->GetOffsetDefault() << endl; | |
199 | } break; | |
200 | case 2: | |
201 | strline >> tmpflt; | |
202 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
203 | else { | |
204 | ssddaldc->SetZsFactor(tmpflt); | |
205 | cout << keystr << ": " << ssddaldc->GetZsFactor() << endl; | |
206 | } break; | |
207 | case 3: | |
208 | strline >> tmpflt; | |
209 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
210 | else { | |
211 | ssddaldc->SetPedestalThresholdFactor(tmpflt); | |
212 | cout << keystr << ": " << ssddaldc->GetPedestalThresholdFactor() << endl; | |
213 | } break; | |
214 | case 4: | |
215 | strline >> tmpflt; | |
216 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
217 | else { | |
218 | ssddaldc->SetCmThresholdFactor(tmpflt); | |
219 | cout << keystr << ": " << ssddaldc->GetCmThresholdFactor() << endl; | |
220 | } break; | |
221 | case 5: | |
222 | strline >> tmpint; | |
223 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
224 | else { | |
225 | cfg.fNModuleProcess = tmpint; | |
226 | cout << keystr << ": " << cfg.fNModuleProcess << endl; | |
227 | } break; | |
228 | case 6: | |
229 | strline >> tmpstr; | |
230 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
231 | else { | |
232 | if (tmpstr.size() == 0) continue; | |
233 | if (tmpstr.at(0) == '#') continue; | |
234 | cfg.fSsdDdlMap = tmpstr; | |
235 | cout << keystr << ": " << cfg.fSsdDdlMap.c_str() << endl; | |
236 | } break; | |
237 | case 7: | |
238 | strline >> tmpstr; | |
239 | if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n"; | |
240 | else { | |
241 | if (tmpstr.size() == 0) continue; | |
242 | if (tmpstr.at(0) == '#') continue; | |
243 | cfg.fBadChannels = tmpstr; | |
244 | cout << keystr << ": " << cfg.fBadChannels.c_str() << endl; | |
245 | } break; | |
246 | default: | |
247 | cerr << keystr << " is not a key word, no assignment were made!\n"; | |
248 | } | |
249 | } | |
250 | return kTRUE; | |
251 | } |