3 //====================================================================
11 # include <AliPreprocessor.h>
12 # include <../FMD/AliFMDPreprocessor.h>
13 # include <AliShuttleInterface.h>
14 # include <AliCDBStorage.h>
15 # include <AliCDBEntry.h>
16 # include <AliCDBManager.h>
17 # include <AliCDBId.h>
18 # include <AliCDBMetaData.h>
19 # include <AliDCSValue.h>
21 // # include <../FMD/AliFMDCalibZeroSuppression.h>
22 // # include <../FMD/AliFMDCalibDeadMap.h>
23 # include <../FMD/AliFMDParameters.h>
24 # include <../SHUTTLE/TestShuttle/AliTestShuttle.h>
27 # include <TObjString.h>
33 //====================================================================
37 Float_t Hardware2Ped(int ddl, int board, int chip, int, int)
39 return ((chip & 0xf) | ((board & 0x1F) << 4) | (ddl << 9) & 0x3);
41 Float_t Hardware2Noise(int ddl, int board, int chip, int channel, int strip)
43 return ((strip & 0x7f) | ((channel & 0xf) << 7));
45 Float_t Hardware2Gain(int ddl, int board, int chip, int channel, int strip)
47 return (((strip & 0x7f) << 0) |
48 ((channel & 0x0f) << 7) |
49 ((chip & 0x07) << 11) |
50 ((board & 0x1f) << 14) |
51 ((ddl & 0x03) << 19));
54 //====================================================================
58 //__________________________________________________________________
59 class CreateDummyDaData
62 CreateDummyDaData(const char* output,
63 int firstDDL, int lastDDL,
64 int firstStrip, int lastStrip)
66 fFirstDDL(firstDDL), fLastDDL(lastDDL),
67 fFirstStrip(firstStrip), fLastStrip(lastStrip)
71 std::cout << "Will write on " << fOutput << std::endl;
72 std::ofstream file(fOutput.Data());
74 std::cerr << "Failed to open output file " << fOutput << std::endl;
78 for (int ddl = fFirstDDL; ddl <= fLastDDL; ddl++) {
79 int boards[] = { 0, 16, (ddl==1 ? -1 : 1), (ddl==1 ? -1 : 17), -1};
82 while ((board = (*bptr++)) >= 0) {
83 for (int chip = 0; chip < 3; chip++) {
84 for (int channel = 0; channel < (chip == 1 ? 8 : 16); channel++) {
85 for (int strip = fFirstStrip; strip <= fLastStrip; strip++) {
86 Output(file, ddl, board, chip, channel, strip);
94 virtual void Header(std::ostream& file) = 0;
95 virtual void Output(std::ostream& file, int ddl, int board, int chip,
96 int channel, int strip) = 0;
105 //__________________________________________________________________
106 class CreateDummyPeds : public CreateDummyDaData
109 CreateDummyPeds(const char* out="peds.csv",
111 int firstDDL=0, int lastDDL=2,
112 int firstStrip=0, int lastStrip=127)
113 : CreateDummyDaData(out, firstDDL, lastDDL, firstStrip, lastStrip),
114 fOverSampling(overSampling)
116 void Output(std::ostream& file, int ddl, int board, int chip, int channel,
120 // ddl,board,chip,channel,strip,sample,ped,noise,mu,sigma,chi2
121 for (int sample = 0; sample < fOverSampling; sample++) {
122 Float_t ped = Hardware2Ped(ddl, board, chip, channel, strip);
123 Float_t noise = Hardware2Noise(ddl, board, chip, channel, strip);
124 file // << ddl << ","
132 << chip << "," // Predictable mu
133 << channel << "," // Predictable sigma
134 << strip // Predictable chi2/ndf
138 void Header(std::ostream& file)
140 file << "# Pedestals\n"
141 << "# ddl,board,chip,channel,strip,sample,mean,noise,mu,sigma,chi"
148 //__________________________________________________________________
149 class CreateDummyGains : public CreateDummyDaData
152 CreateDummyGains(const char* out="gains.csv",
153 int firstDDL=0, int lastDDL=2,
154 int firstStrip=0, int lastStrip=127)
155 : CreateDummyDaData(out, firstDDL, lastDDL, firstStrip, lastStrip)
157 void Output(std::ostream& file, int ddl, int board, int chip, int channel,
161 // ddl,board,chip,channel,strip,gain,error,chi2
162 Float_t gain = Hardware2Gain(ddl, board, chip, channel, strip);
163 file // << ddl << ","
168 << gain << "," // Predictable gain
169 << board << "," // Predictable error
170 << strip // Predictable chi2/ndf
173 void Header(std::ostream& file)
176 << "# ddl,board,chip,channel,strip,gain,errorchi"
182 //====================================================================
184 // Read back the calibrations written, and check the values
186 void ReadBack(const char* dbBase="local://$ALICE_ROOT/FMD/")
188 AliLog::SetModuleDebugLevel("FMD", 1);
189 // Set specific storage of FMD ALTRO map
190 AliCDBManager::Instance()->SetDefaultStorage(Form("%s/TestCDB", dbBase));
191 AliCDBManager::Instance()->SetSpecificStorage("FMD/Calib/AltroMap",
192 "local://$ALICE_ROOT");
193 AliCDBManager::Instance()->SetRun(0);
195 AliFMDParameters* param = AliFMDParameters::Instance();
196 std::cout << "Getting the stuff via AliFMDParameters ... " << std::flush;
197 param->Init(kTRUE,AliFMDParameters::kPulseGain|
198 AliFMDParameters::kPedestal|
199 AliFMDParameters::kAltroMap);
200 std::cout << "done" << std::endl;
201 // param->Print("FMD1I[*,*]");
203 for (UShort_t det = 3; det <= 3; det++) {
204 Char_t rs[] = { 'I', (det==1 ? '\0' : 'O'), '\0' };
207 while ((rng = *(pr++)) != '\0') {
208 UShort_t nsec = (rng == 'I' ? 20 : 40);
209 UShort_t nstr = (rng == 'I' ? 512 : 256);
210 for (UShort_t sec = 0; sec < nsec; sec++) {
211 for (UShort_t str = 0; str < nstr; str++) {
212 Float_t gain = param->GetPulseGain(det,rng,sec,str);
213 Float_t ped = param->GetPedestal(det,rng,sec,str);
214 Float_t noise = param->GetPedestalWidth(det,rng,sec,str);
215 UInt_t ddl, board, chip, channel;
216 param->Detector2Hardware(det,rng,sec,str,ddl,board,chip,channel);
217 UShort_t strip = str % 128;
218 Float_t eped = Hardware2Ped(ddl, board, chip, channel, strip);
219 Float_t enoise = Hardware2Noise(ddl, board, chip, channel, strip);
220 Float_t egain = Hardware2Gain(ddl, board, chip, channel, strip);
222 Error(Form("FMD%d%c[%2d,%3d] (%d,%2d,%1d,%2d)",
223 det,rng,sec,str,ddl,board,chip,channel),
224 "pedestal=%14.7f != %14.7f", ped, eped);
226 Error(Form("FMD%d%c[%2d,%3d] (%d,%2d,%1d,%2d)",
227 det,rng,sec,str,ddl,board,chip,channel),
228 "noise=%14.7f != %14.7f", noise, enoise);
230 // Will fail due to rounding errors.
232 Error(Form("FMD%d%c[%2d,%3d] (%d,%2d,%1d,%2d)",
233 det,rng,sec,str,ddl,board,chip,channel),
234 "gain=%14.7f != %14.7f", gain, egain);
243 //====================================================================
245 // This script runs the test preprocessor. It uses AliTestShuttle to
246 // simulate a full Shuttle process
248 // The input data is created in the functions
250 // CreateDCSAliasMap() creates input that would in the same way come
252 // ReadDCSAliasMap() reads from a file
253 // CreateInputFilesMap() creates a list of local files, that can be
254 // accessed by the shuttle
256 void TestPreprocessor(Bool_t createDummies=kTRUE,
257 const char* dbBase="local://$ALICE_ROOT/FMD/")
261 CreateDummyPeds pedMaker;
263 CreateDummyGains gainMaker;
267 // load library - needs to be built using make
268 gSystem->Load("libTestSHUTTLE.so");
270 // create AliTestShuttle instance
271 // The parameters are run, startTime, endTime
272 AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1);
274 // Set specific storage of FMD ALTRO map
275 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
276 AliCDBManager::Instance()->SetSpecificStorage("FMD/Calib/AltroMap",
277 "local://$ALICE_ROOT");
278 AliCDBManager::Instance()->SetRun(0);
279 // TODO if needed, change location of OCDB and Reference test
280 // folders by default they are set to
281 // $ALICE_ROOT/TestCDB and TestReference
282 AliTestShuttle::SetMainCDB(Form("%s/TestCDB", dbBase));
283 AliTestShuttle::SetMainRefStorage(Form("%s/TestReference", dbBase));
285 std::cout << "Test OCDB storage URI: " << AliShuttleInterface::GetMainCDB()
287 << "Test Reference storage Uri: "
288 << AliShuttleInterface::GetMainRefStorage().Data()
291 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "FMD", "pedestal",
292 "source1", "peds.csv");
293 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "FMD", "gain",
294 "source2", "gains.csv");
295 shuttle->SetInputRunType("PHYSICS");
297 new AliFMDPreprocessor(shuttle);
298 // Test the preprocessor
306 //____________________________________________________________________
307 // We do not use this functions .....yet
308 TMap* CreateDCSAliasMap()
310 // Creates a DCS structure
311 // The structure is the following:
313 // TMap (key --> value)
314 // <DCSAlias> --> <valueList>
315 // <DCSAlias> is a string
316 // <valueList> is a TObjArray of AliDCSValue
317 // An AliDCSValue consists of timestamp and a value in form of a
320 // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
321 // Each contains 1000 values randomly generated by TRandom::Gaus +
324 TMap* aliasMap = new TMap;
325 aliasMap->SetOwner(1);
327 for(int nAlias=0;nAlias<6;nAlias++) {
328 TObjArray* valueSet = new TObjArray;
329 valueSet->SetOwner(1);
331 TString aliasName="DCSAlias";
333 //printf("\n\n alias: %s\n\n",aliasName.Data());
334 for (int timeStamp = 0; timeStamp < 1000; timeStamp += 10) {
335 Float_t x = Float_t(random.Gaus()+5*nAlias);
336 AliDCSValue* dcsVal = new AliDCSValue(x, timeStamp);
337 valueSet->Add(dcsVal);
339 aliasMap->Add(new TObjString(aliasName), valueSet);
345 //____________________________________________________________________
346 TMap* ReadDCSAliasMap()
348 // Open a file that contains DCS input data
350 // The CDB framework is used to open the file, this means the file
353 // $ALICE_ROOT/FMD/TestCDB/<detector>/DCS/Data
355 // The file contains an AliCDBEntry that contains a TMap with the
356 // DCS structure. An explanation of the structure can be found in
357 // CreateDCSAliasMap()
359 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
360 ->Get("DET/DCS/Data", 0);
361 return dynamic_cast<TMap*> (entry->GetObject());
364 //____________________________________________________________________
365 void WriteDCSAliasMap()
367 // This writes the output from CreateDCSAliasMap to a CDB file
369 TMap* dcsAliasMap = CreateDCSAliasMap();
370 AliCDBMetaData metaData;
371 metaData.SetBeamPeriod(0);
372 metaData.SetResponsible("Responsible person");
373 metaData.SetComment("Test object for TestPreprocessor.C");
375 AliCDBId id("DET/DCS/Data", 0, 0);
377 // look into AliTestShuttle's CDB main folder
378 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
379 ->Put(dcsAliasMap, id, &metaData);
382 //____________________________________________________________________