1 /**************************************************************************
2 - Contact: Oleksandr_Borysov aborysov@ts.infnf.it
3 - Link: /afs/infn.it/ts/user/efragiac/public/testCosm3125.001
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
9 local files are persistent over runs: data source
11 **************************************************************************/
21 #include "AliITSHandleDaSSD.h"
23 #include "TPluginManager.h"
29 Int_t fNModuleProcess;
32 ConfigStruct() : fNModuleProcess(108), fSsdDdlMap(""), fBadChannels("") {}
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);
40 int main( int argc, char** argv )
42 const Char_t *configfname = "ssddaconfig.txt";
43 const Char_t *bcfname = "badchannels.root";
44 const Char_t *ddlmfname = "ssdddlmap.txt";
45 AliITSHandleDaSSD *ssddaldc;
46 TString feefname, fcdbsave, lfname;
48 Char_t *dafname = NULL;
51 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
58 /* check that we got some arguments = list of files */
60 fprintf(stderr, "Wrong number of arguments\n");
64 char *datafilename = argv[1];
65 ssddaldc = new AliITSHandleDaSSD(datafilename);
66 if (ssddaldc->IsZombie()) {
67 cerr << "Failed to process raw data file " << datafilename << "! Exit DA!\n";
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());
76 if (cfg.fBadChannels.size() > 0) bcfname = cfg.fBadChannels.c_str();
77 lfname.Form("./%s", bcfname);
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());
83 if (!ssddaldc->ReadStaticBadChannelsMap(lfname.Data())) {
84 cerr << "Error reading static bad channels map " << lfname.Data() << "! Exit DA!\n";
89 if (cfg.fSsdDdlMap.size() > 0) ddlmfname = cfg.fSsdDdlMap.c_str();
90 lfname.Form("./%s", ddlmfname);
91 if (!(status = daqDA_DB_getFile(ddlmfname, lfname.Data()))) {
92 if (!ssddaldc->ReadDDLModuleMap(lfname.Data())) cerr << "Error reading DDL map from file " << lfname.Data() << " !\n";
94 fprintf(stderr, "Failed to import file %s from the detector db: %d, %s \n", ddlmfname, status, lfname.Data());
95 if (!ssddaldc->ReadDDLModuleMap()) cerr << "Failed to load the DDL map from AliITSRawStreamSSD!\n";
98 if (!ssddaldc->ProcessRawData(cfg.fNModuleProcess)) {
99 cerr << "Error !ssddaldc->ProcessRawData()" << endl;
103 daqDA_progressReport(90);
106 if (ssddaldc->SaveCalibrationSSDLDC(dafname)) {
107 cout << "SSDDA data are saved in " << dafname << endl;
108 status = daqDA_FES_storeFile(dafname, "CALIBRATION");
109 if (status) fprintf(stderr, "Failed to export file : %d\n", status);
110 } else cerr << "Error saving DA data to the file!\n";
112 feefname.Form("%s/ssddaldc_%i.root", ".", ssddaldc->GetLdcId());
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;
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());
128 cout << SaveEquipmentCalibrationData(ssddaldc) << " files were uploaded to DetDB!\n";
130 daqDA_progressReport(100);
136 //__________________________________________________________________________________________
137 Int_t SaveEquipmentCalibrationData(const AliITSHandleDaSSD *ssddaldc, const Char_t *fprefix)
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());
157 //__________________________________________________________________________________________
158 Bool_t ReadDAConfigurationFile(const Char_t *configfname, AliITSHandleDaSSD *const ssddaldc, ConfigStruct& cfg)
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"};
168 cerr << "No DA configuration file name is specified, defaul value are used!\n";
171 dfile.open(configfname, ios::in);
172 if (!dfile.is_open()) {
173 cerr << "Error open DA configuration file " << configfname << " defaul value are used!\n";
176 while (!dfile.eof()) {
177 string str, keystr, tmpstr;
179 stringstream strline(str);
181 if (keystr.size() == 0) continue;
182 if ((keystr.at(0) == '#') ) continue;
184 while (keystr.compare(keywords[ind])) if (++ind == nkwords) break;
188 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
190 ssddaldc->SetZsDefaul(tmpint);
191 cout << "Default value for ZS thereshold " << keystr << ": " << ssddaldc->GetZsDefault() << endl;
195 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
197 ssddaldc->SetOffsetDefault(tmpint);
198 cout << "Default value for offset correction " << keystr << ": " << ssddaldc->GetOffsetDefault() << endl;
202 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
204 ssddaldc->SetZsFactor(tmpflt);
205 cout << keystr << ": " << ssddaldc->GetZsFactor() << endl;
209 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
211 ssddaldc->SetPedestalThresholdFactor(tmpflt);
212 cout << keystr << ": " << ssddaldc->GetPedestalThresholdFactor() << endl;
216 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
218 ssddaldc->SetCmThresholdFactor(tmpflt);
219 cout << keystr << ": " << ssddaldc->GetCmThresholdFactor() << endl;
223 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
225 cfg.fNModuleProcess = tmpint;
226 cout << keystr << ": " << cfg.fNModuleProcess << endl;
230 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
232 if (tmpstr.size() == 0) continue;
233 if (tmpstr.at(0) == '#') continue;
234 cfg.fSsdDdlMap = tmpstr;
235 cout << keystr << ": " << cfg.fSsdDdlMap.c_str() << endl;
239 if (strline.fail()) cerr << "Failed to read " << keystr << " value from DA configuration file!\n";
241 if (tmpstr.size() == 0) continue;
242 if (tmpstr.at(0) == '#') continue;
243 cfg.fBadChannels = tmpstr;
244 cout << keystr << ": " << cfg.fBadChannels.c_str() << endl;
247 cerr << keystr << " is not a key word, no assignment were made!\n";