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>
34 //====================================================================
38 Float_t Hardware2Ped(int ddl, int board, int chip, int, int)
40 return ((chip & 0xf) | ((board & 0x1F) << 4) | (ddl << 9) & 0x3);
42 Float_t Hardware2Noise(int ddl, int board, int chip, int channel, int strip)
44 return ((strip & 0x7f) | ((channel & 0xf) << 7));
46 Float_t Hardware2Gain(int ddl, int board, int chip, int channel, int strip)
48 return (((strip & 0x7f) << 0) |
49 ((channel & 0x0f) << 7) |
50 ((chip & 0x07) << 11) |
51 ((board & 0x1f) << 14) |
52 ((ddl & 0x03) << 19));
55 //====================================================================
59 //__________________________________________________________________
60 class CreateDummyDaData
63 CreateDummyDaData(const char* output,
64 int firstDDL, int lastDDL,
65 int firstStrip, int lastStrip)
67 fFirstDDL(firstDDL), fLastDDL(lastDDL),
68 fFirstStrip(firstStrip), fLastStrip(lastStrip)
72 std::cout << "Will write on " << fOutput << std::endl;
73 std::ofstream file(fOutput.Data());
75 std::cerr << "Failed to open output file " << fOutput << std::endl;
79 for (int ddl = fFirstDDL; ddl <= fLastDDL; ddl++) {
80 int boards[] = { 0, 16, (ddl==1 ? -1 : 1), (ddl==1 ? -1 : 17), -1};
83 while ((board = (*bptr++)) >= 0) {
84 for (int chip = 0; chip < 3; chip++) {
85 for (int channel = 0; channel < (chip == 1 ? 8 : 16); channel++) {
86 for (int strip = fFirstStrip; strip <= fLastStrip; strip++) {
87 Output(file, ddl, board, chip, channel, strip);
95 virtual void Header(std::ostream& file) = 0;
96 virtual void Output(std::ostream& file, int ddl, int board, int chip,
97 int channel, int strip) = 0;
106 //__________________________________________________________________
107 class CreateDummyPeds : public CreateDummyDaData
110 CreateDummyPeds(const char* out="peds.csv",
112 int firstDDL=0, int lastDDL=2,
113 int firstStrip=0, int lastStrip=127)
114 : CreateDummyDaData(out, firstDDL, lastDDL, firstStrip, lastStrip),
115 fOverSampling(overSampling)
117 void Output(std::ostream& file, int ddl, int board, int chip, int channel,
121 // ddl,board,chip,channel,strip,sample,ped,noise,mu,sigma,chi2
122 for (int sample = 0; sample < fOverSampling; sample++) {
123 Float_t ped = Hardware2Ped(ddl, board, chip, channel, strip);
124 Float_t noise = Hardware2Noise(ddl, board, chip, channel, strip);
125 file // << ddl << ","
133 << chip << "," // Predictable mu
134 << channel << "," // Predictable sigma
135 << strip // Predictable chi2/ndf
139 void Header(std::ostream& file)
141 file << "# Pedestals\n"
142 << "# ddl,board,chip,channel,strip,sample,mean,noise,mu,sigma,chi"
149 //__________________________________________________________________
150 class CreateDummyGains : public CreateDummyDaData
153 CreateDummyGains(const char* out="gains.csv",
154 int firstDDL=0, int lastDDL=2,
155 int firstStrip=0, int lastStrip=127)
156 : CreateDummyDaData(out, firstDDL, lastDDL, firstStrip, lastStrip)
158 void Output(std::ostream& file, int ddl, int board, int chip, int channel,
162 // ddl,board,chip,channel,strip,gain,error,chi2
163 Float_t gain = Hardware2Gain(ddl, board, chip, channel, strip);
164 file // << ddl << ","
169 << gain << "," // Predictable gain
170 << board << "," // Predictable error
171 << strip // Predictable chi2/ndf
174 void Header(std::ostream& file)
177 << "# ddl,board,chip,channel,strip,gain,errorchi"
183 //====================================================================
185 // Read back the calibrations written, and check the values
187 void ReadBack(const char* dbBase="local://$ALICE_ROOT/OCDB/FMD/")
189 // AliLog::SetModuleDebugLevel("FMD", 1);
190 // Set specific storage of FMD ALTRO map
191 AliCDBManager::Instance()->SetDefaultStorage(Form("%s/TestCDB", dbBase));
192 AliCDBManager::Instance()->SetSpecificStorage("FMD/Calib/AltroMap",
193 "local://$ALICE_ROOT/OCDB");
194 AliCDBManager::Instance()->SetRun(0);
196 AliFMDParameters* param = AliFMDParameters::Instance();
197 std::cout << "Getting the stuff via AliFMDParameters ... " << std::flush;
198 param->Init(kTRUE,AliFMDParameters::kPulseGain|
199 AliFMDParameters::kPedestal|
200 AliFMDParameters::kAltroMap);
201 std::cout << "done" << std::endl;
202 // param->Print("FMD1I[*,*]");
204 for (UShort_t det = 3; det <= 3; det++) {
205 Char_t rs[] = { 'I', (det==1 ? '\0' : 'O'), '\0' };
208 while ((rng = *(pr++)) != '\0') {
209 UShort_t nsec = (rng == 'I' ? 20 : 40);
210 UShort_t nstr = (rng == 'I' ? 512 : 256);
211 for (UShort_t sec = 0; sec < nsec; sec++) {
212 for (UShort_t str = 0; str < nstr; str++) {
213 Float_t gain = param->GetPulseGain(det,rng,sec,str);
214 Float_t ped = param->GetPedestal(det,rng,sec,str);
215 Float_t noise = param->GetPedestalWidth(det,rng,sec,str);
216 UInt_t ddl, board, chip, channel;
217 param->Detector2Hardware(det,rng,sec,str,ddl,board,chip,channel);
218 UShort_t strip = str % 128;
219 Float_t eped = Hardware2Ped(ddl, board, chip, channel, strip);
220 Float_t enoise = Hardware2Noise(ddl, board, chip, channel, strip);
221 Float_t egain = Hardware2Gain(ddl, board, chip, channel, strip);
223 Error(Form("FMD%d%c[%2d,%3d] (%d,%2d,%1d,%2d)",
224 det,rng,sec,str,ddl,board,chip,channel),
225 "pedestal=%14.7f != %14.7f", ped, eped);
227 Error(Form("FMD%d%c[%2d,%3d] (%d,%2d,%1d,%2d)",
228 det,rng,sec,str,ddl,board,chip,channel),
229 "noise=%14.7f != %14.7f", noise, enoise);
231 // Will fail due to rounding errors.
233 Error(Form("FMD%d%c[%2d,%3d] (%d,%2d,%1d,%2d)",
234 det,rng,sec,str,ddl,board,chip,channel),
235 "gain=%14.7f != %14.7f", gain, egain);
244 //====================================================================
246 // This script runs the test preprocessor. It uses AliTestShuttle to
247 // simulate a full Shuttle process
249 // The input data is created in the functions
251 // CreateDCSAliasMap() creates input that would in the same way come
253 // ReadDCSAliasMap() reads from a file
254 // CreateInputFilesMap() creates a list of local files, that can be
255 // accessed by the shuttle
257 void TestPreprocessor(const char* runType="PEDESTAL",
258 Bool_t createDummies=kTRUE,
259 const char* dbBase="local://$ALICE_ROOT/OCDB/FMD/")
263 CreateDummyPeds pedMaker;
265 CreateDummyGains gainMaker;
269 // load library - needs to be built using make
270 gSystem->Load("libTestSHUTTLE");
272 // create AliTestShuttle instance
273 // The parameters are run, startTime, endTime
274 AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1);
275 AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/OCDB/FMD/TestCDB");
276 AliTestShuttle::SetLocalCDB(Form("%s/TestCDB", dbBase));
277 AliTestShuttle::SetMainRefStorage(Form("%s/TestReference", dbBase));
279 std::cout << "Test OCDB storage URI: " << AliShuttleInterface::GetMainCDB()
281 << "Test Reference storage Uri: "
282 << AliShuttleInterface::GetMainRefStorage().Data()
285 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "FMD", "pedestal",
286 "source1", "peds.csv");
287 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "FMD", "gain",
288 "source2", "gains.csv");
289 shuttle->SetInputRunType(runType);
290 // shuttle->SetInputRunType("PEDESTAL PULSER PHYSICS");
292 new AliFMDPreprocessor(shuttle);
293 // Test the preprocessor
301 //____________________________________________________________________
302 // We do not use this functions .....yet
303 TMap* CreateDCSAliasMap()
305 // Creates a DCS structure
306 // The structure is the following:
308 // TMap (key --> value)
309 // <DCSAlias> --> <valueList>
310 // <DCSAlias> is a string
311 // <valueList> is a TObjArray of AliDCSValue
312 // An AliDCSValue consists of timestamp and a value in form of a
315 // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
316 // Each contains 1000 values randomly generated by TRandom::Gaus +
319 TMap* aliasMap = new TMap;
320 aliasMap->SetOwner(1);
322 for(int nAlias=0;nAlias<6;nAlias++) {
323 TObjArray* valueSet = new TObjArray;
324 valueSet->SetOwner(1);
326 TString aliasName="DCSAlias";
328 //printf("\n\n alias: %s\n\n",aliasName.Data());
329 for (int timeStamp = 0; timeStamp < 1000; timeStamp += 10) {
330 Float_t x = Float_t(random.Gaus()+5*nAlias);
331 AliDCSValue* dcsVal = new AliDCSValue(x, timeStamp);
332 valueSet->Add(dcsVal);
334 aliasMap->Add(new TObjString(aliasName), valueSet);
340 //____________________________________________________________________
341 TMap* ReadDCSAliasMap()
343 // Open a file that contains DCS input data
345 // The CDB framework is used to open the file, this means the file
348 // $ALICE_ROOT/FMD/TestCDB/<detector>/DCS/Data
350 // The file contains an AliCDBEntry that contains a TMap with the
351 // DCS structure. An explanation of the structure can be found in
352 // CreateDCSAliasMap()
354 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
355 ->Get("DET/DCS/Data", 0);
356 return dynamic_cast<TMap*> (entry->GetObject());
359 //____________________________________________________________________
360 void WriteDCSAliasMap()
362 // This writes the output from CreateDCSAliasMap to a CDB file
364 TMap* dcsAliasMap = CreateDCSAliasMap();
365 AliCDBMetaData metaData;
366 metaData.SetBeamPeriod(0);
367 metaData.SetResponsible("Responsible person");
368 metaData.SetComment("Test object for TestPreprocessor.C");
370 AliCDBId id("DET/DCS/Data", 0, 0);
372 // look into AliTestShuttle's CDB main folder
373 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
374 ->Put(dcsAliasMap, id, &metaData);
379 main(int argc, char** argv)
381 Bool_t createDummies = kTRUE;
382 TString dbBase = "local://$ALICE_ROOT/OCDB/FMD/";
383 for (int i = 1; i < argc; i++) {
384 if (argv[i][0] == '-') {
385 switch (argv[i][1]) {
387 std::cout << "Usage: " << argv[0] << " [OPTIONS]\n\n"
389 << "\t-h\tThis help\n"
390 << "\t-d\tToggle dummies\n"
391 << "\t-b DIR\tSet database dir\n"
394 case 'd': createDummies = !createDummies; break;
395 case 'b': dbBase = argv[++i]; break;
400 TestPreprocessor(createDummies, dbBase);
406 //____________________________________________________________________