1 /**************************************************************************
2 - Contact: Oleksandr_Borysov oborysov@cern.ch
3 - Link: /afs/cern.ch/user/o/oborysov/public/da/pedestal36186.000.raw, ssddaconfig.txt, ssdddlmap.txt, badchannels.root
6 - Number of events needed: ~200
7 - Input Files: raw_data_file_on_LDC, in the daqDetDB: ssddaconfig.txt, ssdddlmap.txt, badchannels.root
8 - Output Files: ./<EqId_Slot> ./ssddaldc_<LDCID>.root, FXS_name=ITSSSDda_<LDCID>.root
9 local files are persistent over runs: data source
11 **************************************************************************/
23 #include "AliITSHandleDaSSD.h"
26 #include "TPluginManager.h"
32 Int_t fNModuleProcess;
35 Bool_t fCheckChipsOff;
36 ConfigStruct() : fNModuleProcess(108), fSsdDdlMap(""), fBadChannels(""), fCheckChipsOff(kFALSE) {}
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);
44 int main( int argc, char** argv )
46 const Char_t *configfname = "ssddaconfig.txt";
47 const Char_t *bcfname = "badchannels.root";
48 const Char_t *ddlmfname = "ssdddlmap.txt";
49 AliITSHandleDaSSD *ssddaldc;
50 TString feefname, fcdbsave, lfname;
52 Char_t *dafname = NULL;
55 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
62 /* check that we got some arguments = list of files */
64 fprintf(stderr, "Wrong number of arguments\n");
68 char *datafilename = argv[1];
69 ssddaldc = new AliITSHandleDaSSD(datafilename);
70 if (ssddaldc->IsZombie()) {
71 cerr << "Failed to process raw data file " << datafilename << "! Exit DA!\n";
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());
80 if (cfg.fBadChannels.size() > 0) bcfname = cfg.fBadChannels.c_str();
81 lfname.Form("./%s", bcfname);
82 if (status = daqDA_DB_getFile(bcfname, lfname.Data())) {
83 fprintf(stderr, "Failed to import the file %s from the detector db: %d, %s! Exit DA!\n", bcfname, status, lfname.Data());
87 if (!ssddaldc->ReadStaticBadChannelsMap(lfname.Data())) {
88 cerr << "Error reading static bad channels map " << lfname.Data() << "! Exit DA!\n";
93 if (cfg.fSsdDdlMap.size() > 0) ddlmfname = cfg.fSsdDdlMap.c_str();
94 lfname.Form("./%s", ddlmfname);
95 if (!(status = daqDA_DB_getFile(ddlmfname, lfname.Data()))) {
96 if (!ssddaldc->ReadDDLModuleMap(lfname.Data())) cerr << "Error reading DDL map from file " << lfname.Data() << " !\n";
98 fprintf(stderr, "Failed to import file %s from the detector db: %d, %s \n", ddlmfname, status, lfname.Data());
99 if (!ssddaldc->ReadDDLModuleMap()) cerr << "Failed to load the DDL map from AliITSRawStreamSSD!\n";
102 if (!ssddaldc->ProcessRawData(cfg.fNModuleProcess)) {
103 cerr << "Error !ssddaldc->ProcessRawData()" << endl;
107 daqDA_progressReport(90);
110 if (ssddaldc->SaveCalibrationSSDLDC(dafname)) {
111 cout << "SSDDA data are saved in " << dafname << endl;
112 status = daqDA_FES_storeFile(dafname, "CALIBRATION");
113 if (status) fprintf(stderr, "Failed to export file : %d\n", status);
114 } else cerr << "Error saving DA data to the file!\n";
116 feefname.Form("%s/ssddaldc_%i.root", ".", ssddaldc->GetLdcId());
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;
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());
132 cout << SaveEquipmentCalibrationData(ssddaldc) << " files were uploaded to DetDB!\n";
133 if(cfg.fCheckChipsOff) ssddaldc->CheckOffChips();
135 daqDA_progressReport(100);
141 //__________________________________________________________________________________________
142 Int_t SaveEquipmentCalibrationData(const AliITSHandleDaSSD *ssddaldc, const Char_t *fprefix)
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());
162 //__________________________________________________________________________________________
163 Bool_t ReadDAConfigurationFile(const Char_t *configfname, AliITSHandleDaSSD *const ssddaldc, ConfigStruct& cfg)
165 // Dowload configuration parameters from configuration file or database
166 const int nkwords = 12;
167 char const *keywords[nkwords] = {"ZsDefault", "OffsetDefault", "ZsFactor", "PedestalThresholdFactor", "CmThresholdFactor",
168 "NModulesToProcess", "DDLMapFile", "BadChannelsFile", "ZSMinValue", "MergeBCFlag",
169 "CheckChipsOff", "OffLadder"};
170 Int_t tmpint, laddern;
173 vector<short> allist(0), cllist(0);
175 cerr << "No DA configuration file name is specified, Return!\n";
179 cerr << "ssddaldc == 0, DA configuration file will not be read! Return!\n";
182 dfile.open(configfname, ios::in);
183 if (!dfile.is_open()) {
184 cerr << "Error open DA configuration file " << configfname << " defaul value are used!\n";
187 while (!dfile.eof()) {
188 string str, keystr, tmpstr;
190 stringstream strline(str);
192 if (keystr.size() == 0) continue;
193 if ((keystr.at(0) == '#') ) continue;
195 while (keystr.compare(keywords[ind])) if (++ind == nkwords) break;
199 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
201 ssddaldc->SetZsDefaul(tmpint);
202 cout << "Default value for ZS thereshold " << keystr << ": " << ssddaldc->GetZsDefault() << endl;
206 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
208 ssddaldc->SetOffsetDefault(tmpint);
209 cout << "Default value for offset correction " << keystr << ": " << ssddaldc->GetOffsetDefault() << endl;
213 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
215 ssddaldc->SetZsFactor(tmpflt);
216 cout << keystr << ": " << ssddaldc->GetZsFactor() << endl;
220 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
222 ssddaldc->SetPedestalThresholdFactor(tmpflt);
223 cout << keystr << ": " << ssddaldc->GetPedestalThresholdFactor() << endl;
227 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
229 ssddaldc->SetCmThresholdFactor(tmpflt);
230 cout << keystr << ": " << ssddaldc->GetCmThresholdFactor() << endl;
234 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
236 cfg.fNModuleProcess = tmpint;
237 cout << keystr << ": " << cfg.fNModuleProcess << endl;
241 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
243 if (tmpstr.size() == 0) continue;
244 if (tmpstr.at(0) == '#') continue;
245 cfg.fSsdDdlMap = tmpstr;
246 cout << keystr << ": " << cfg.fSsdDdlMap.c_str() << endl;
250 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
252 if (tmpstr.size() == 0) continue;
253 if (tmpstr.at(0) == '#') continue;
254 cfg.fBadChannels = tmpstr;
255 cout << keystr << ": " << cfg.fBadChannels.c_str() << endl;
259 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
261 ssddaldc->SetZsMinimum(tmpint);
262 cout << keystr << ": " << ssddaldc->GetZsMinimum() << endl;
266 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
268 ssddaldc->SetMergeBCFlag(static_cast<Byte_t>(tmpint));
269 cout << keystr << ": " << ssddaldc->GetMergeBCFlag() << endl;
273 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
275 cfg.fCheckChipsOff = static_cast<Bool_t>(tmpint);
276 cout << keystr << ": " << cfg.fCheckChipsOff << endl;
280 while (!strline.eof()) {
282 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
283 if (tmpstr.size() == 0) break;
284 if ((tmpstr.at(0) == '#') ) break;
285 if ( sscanf(tmpstr.c_str(), "%c%u", &dside, &laddern) < 2 ) {
286 cerr << "Error reading side and ladder number form the config file: " << tmpstr << "! Continue!\n";
289 if ( toupper(dside) == 'A') allist.push_back(laddern);
290 else if ( toupper(dside) == 'C') cllist.push_back(laddern);
291 else cerr << "Error! " << dside << " SSD ladder side can be either A or C! Continue!\n";
295 cerr << keystr << " is not a key word, no assignment were made!\n";
298 if (allist.size() == 0 && cllist.size() == 0) return kTRUE;
299 short *tmparr = 0, si;
300 vector<short>::iterator it;
301 if (allist.size() > 0) {
302 tmparr = new short [allist.size()];
303 cout << "Following A side " << (allist.size()>1?"ladders are":"ladder is") << " supposed to be off and will be suppressed :";
304 for ( it = allist.begin(), si = 0; it < allist.end(); it++, si++ ) {
306 cout << " " << tmparr[si];
309 ssddaldc->SetALaddersOff(allist.size(), tmparr);
311 if (tmparr) delete [] tmparr;
312 if (cllist.size() > 0) {
313 tmparr = new short [cllist.size()];
314 cout << "Following C side " << (cllist.size() > 1 ? "ladders are" : "ladder is") << " supposed to be off and will be suppressed :";
315 for ( it = cllist.begin(), si = 0; it < cllist.end(); it++, si++ ) {
317 cout << " " << tmparr[si];
320 ssddaldc->SetCLaddersOff(cllist.size(), tmparr);
322 if (tmparr) delete [] tmparr;