]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEERBase/AliDAQ.cxx
Update master to aliroot
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliDAQ.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //////////////////////////////////////////////////////////////////////////////
17 //                                                                          //
18 // The AliDAQ class is responsible for handling all the information about   //
19 // Data Acquisition configuration. It defines the detector indexing,        //
20 // the number of DDLs and LDCs per detector.                                //
21 // The number of LDCs per detector is used only in the simulation in order  //
22 // to define the configuration of the dateStream application. Therefore the //
23 // numbers in the corresponding array can be changed without affecting the  //
24 // rest of the aliroot code.                                                //
25 // The equipment ID (DDL ID) is an integer (32-bit) number defined as:      //
26 // Equipment ID = (detectorID << 8) + DDLIndex                              //
27 // where the detectorID is given by fgkDetectorName array and DDLIndex is   //
28 // the index of the corresponding DDL inside the detector partition.        //
29 // Due to DAQ/HLT limitations, the ddl indexes should be consequtive, or    //
30 // at least without big gaps in between.                                    //
31 // The sub-detector code use only this class in the simulation and reading  //
32 // of the raw data.                                                         //
33 //                                                                          //
34 // cvetan.cheshkov@cern.ch  2006/06/09                                      //
35 //                                                                          //
36 //////////////////////////////////////////////////////////////////////////////
37
38 #include <TClass.h>
39 #include <TString.h>
40
41 #include "AliDAQ.h"
42 #include "AliLog.h"
43
44 ClassImp(AliDAQ)
45
46 const char* AliDAQ::fgkDetectorName[AliDAQ::kNDetectors] = {
47   "ITSSPD",
48   "ITSSDD",
49   "ITSSSD",
50   "TPC",
51   "TRD",
52   "TOF",
53   "HMPID",
54   "PHOS",
55   "CPV",
56   "PMD",
57   "MUONTRK",
58   "MUONTRG",
59   "FMD",
60   "T0",
61   "VZERO",
62   "ZDC",
63   "ACORDE",
64   "TRG",
65   "EMCAL",
66   "DAQ_TEST",
67   "EMPTY",
68   "AD",
69   "MFT",
70   "FIT",
71   "HLT"
72 };
73
74 Int_t AliDAQ::fgkNumberOfDdls[AliDAQ::kNDetectors] = {
75   20,   // ITSSPD
76   24,   // ITSSDD
77   16,   // ITSSSD
78   216,  // TPC
79   18,   // TRD
80   72,   // TOF
81   20,   // HMPID
82   20,   // PHOS
83   10,   // CPV
84   6,    // PMD
85   20,   // MUONTRK
86   2,    // MUONTRG
87   3,    // FMD
88   1,    // T0
89   1,    // VZERO
90   1,    // ZDC
91   1,    // ACORDE
92   1,    // TRG
93   46,   // EMCAL
94   1,    // DAQ_TEST
95   0,    // EMPTY
96   1,    // AD
97   10,   // MFT
98   1,    // FIT
99   28    // HLT
100 };
101
102 Float_t AliDAQ::fgkNumberOfLdcs[AliDAQ::kNDetectors] = {
103   4,    // ITSSPD
104   4,    // ITSSDD
105   4,    // ITSSSD
106   36,   // TPC
107   3,    // TRD
108   12,   // TOF
109   4,    // HMPID
110   4,    // PHOS
111   2,    // CPV
112   1,    // PMD
113   5,    // MUONTRK
114   1,    // MUONTRG
115   1,    // FMD
116   0.5,  // T0
117   0.5,  // VZERO
118   1,    // ZDC
119   1,    // ACORDE
120   1,    // TRG
121   8,    // EMCAL
122   1,    // DAQ_TEST
123   0,    // EMPTY
124   1,    // AD
125   1,    // MFT
126   1,    // FIT
127   7     // HLT
128 };
129
130 const char* AliDAQ::fgkOfflineModuleName[AliDAQ::kNDetectors] = {
131   "ITS",
132   "ITS",
133   "ITS",
134   "TPC",
135   "TRD",
136   "TOF",
137   "HMPID",
138   "PHOS",
139   "CPV",
140   "PMD",
141   "MUON",
142   "MUON",
143   "FMD",
144   "T0",
145   "VZERO",
146   "ZDC",
147   "ACORDE",
148   "CTP",
149   "EMCAL",
150   "DAQ_TEST",
151   "EMPTY",
152   "AD",
153   "MFT",
154   "FIT",
155   "HLT"
156 };
157
158 const char* AliDAQ::fgkOnlineName[AliDAQ::kNDetectors] = {
159   "SPD",
160   "SDD",
161   "SSD",
162   "TPC",
163   "TRD",
164   "TOF",
165   "HMP",
166   "PHS",
167   "CPV",
168   "PMD",
169   "MCH",
170   "MTR",
171   "FMD",
172   "T00",
173   "V00",
174   "ZDC",
175   "ACO",
176   "TRI",
177   "EMC",
178   "TST",
179   "EMP",
180   "AD0",
181   "MFT",
182   "FIT",
183   "HLT"
184 };
185
186 AliDAQ::AliDAQ(const AliDAQ& source) :
187   TObject(source)
188 {
189   // Copy constructor
190   // Nothing to be done
191 }
192
193 AliDAQ& AliDAQ::operator = (const AliDAQ& /* source */)
194 {
195   // Assignment operator
196   // Nothing to be done
197   return *this;
198 }
199
200 Int_t AliDAQ::DetectorID(const char *detectorName)
201 {
202   // Return the detector index
203   // corresponding to a given
204   // detector name
205   TString detStr = detectorName;
206
207   Int_t iDet;
208   for(iDet = 0; iDet < kNDetectors; iDet++) {
209     if (detStr.CompareTo(fgkDetectorName[iDet],TString::kIgnoreCase) == 0)
210       break;
211   }
212   if (iDet == kNDetectors) {
213     AliErrorClass(Form("Invalid detector name: %s !",detectorName));
214     return -1;
215   }
216   return iDet;
217 }
218
219 const char *AliDAQ::DetectorName(Int_t detectorID)
220 {
221   // Returns the name of particular
222   // detector identified by its index
223   if (detectorID < 0 || detectorID >= kNDetectors) {
224     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
225     return "";
226   }
227   return fgkDetectorName[detectorID];
228 }
229
230 Int_t AliDAQ::DdlIDOffset(const char *detectorName)
231 {
232   // Returns the DDL ID offset
233   // for a given detector
234   Int_t detectorID = DetectorID(detectorName);
235   if (detectorID < 0)
236     return -1;
237   
238   return DdlIDOffset(detectorID);
239 }
240
241 Int_t AliDAQ::DdlIDOffset(Int_t detectorID)
242 {
243   // Returns the DDL ID offset
244   // for a given detector identified
245   // by its index
246   if (detectorID < 0 || detectorID >= kNDetectors) {
247     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
248     return -1;
249   }
250   // HLT has a DDL offset = 30
251   if (detectorID == (kNDetectors-1)) return (kHLTId << 8);
252
253   return (detectorID << 8);
254 }
255
256 const char *AliDAQ::DetectorNameFromDdlID(Int_t ddlID,Int_t &ddlIndex)
257 {
258   // Returns the detector name for
259   // a given DDL ID
260   ddlIndex = -1;
261   Int_t detectorID = DetectorIDFromDdlID(ddlID,ddlIndex);
262   if (detectorID < 0)
263     return "";
264
265   return DetectorName(detectorID);
266 }
267
268 Int_t AliDAQ::DetectorIDFromDdlID(Int_t ddlID,Int_t &ddlIndex)
269 {
270   // Returns the detector ID and
271   // the ddl index within the
272   // detector range for
273   // a given input DDL ID
274   Int_t detectorID = ddlID >> 8;
275
276   // HLT
277   if (detectorID == kHLTId) detectorID = kNDetectors-1;
278
279   if (detectorID < 0 || detectorID >= kNDetectors) {
280     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
281     return -1;
282   }
283   ddlIndex = ddlID & 0xFF;
284   if (ddlIndex >= fgkNumberOfDdls[detectorID]) {
285     AliErrorClass(Form("Invalid DDL index %d (%d -> %d) for detector %d",
286                        ddlIndex,0,fgkNumberOfDdls[detectorID],detectorID));
287     ddlIndex = -1;
288     return -1;
289   }
290   return detectorID;
291 }
292
293 Int_t AliDAQ::DdlID(const char *detectorName, Int_t ddlIndex)
294 {
295   // Returns the DDL ID starting from
296   // the detector name and the DDL
297   // index inside the detector
298   Int_t detectorID = DetectorID(detectorName);
299   if (detectorID < 0)
300     return -1;
301
302   return DdlID(detectorID,ddlIndex);
303 }
304
305 Int_t AliDAQ::DdlID(Int_t detectorID, Int_t ddlIndex)
306 {
307   // Returns the DDL ID starting from
308   // the detector ID and the DDL
309   // index inside the detector
310   Int_t ddlID = DdlIDOffset(detectorID);
311   if (ddlID < 0)
312     return -1;
313   
314   if (ddlIndex >= fgkNumberOfDdls[detectorID]) {
315     AliErrorClass(Form("Invalid DDL index %d (%d -> %d) for detector %d",
316                        ddlIndex,0,fgkNumberOfDdls[detectorID],detectorID));
317     return -1;
318   }
319
320   ddlID += ddlIndex;
321   return ddlID;
322 }
323
324 const char *AliDAQ::DdlFileName(const char *detectorName, Int_t ddlIndex)
325 {
326   // Returns the DDL file name
327   // (used in the simulation) starting from
328   // the detector name and the DDL
329   // index inside the detector
330   Int_t detectorID = DetectorID(detectorName);
331   if (detectorID < 0)
332     return "";
333
334   return DdlFileName(detectorID,ddlIndex);
335 }
336
337 const char *AliDAQ::DdlFileName(Int_t detectorID, Int_t ddlIndex)
338 {
339   // Returns the DDL file name
340   // (used in the simulation) starting from
341   // the detector ID and the DDL
342   // index inside the detector
343   Int_t ddlID = DdlIDOffset(detectorID);
344   if (ddlID < 0)
345     return "";
346   
347   if (ddlIndex >= fgkNumberOfDdls[detectorID]) {
348     AliErrorClass(Form("Invalid DDL index %d (%d -> %d) for detector %d",
349                        ddlIndex,0,fgkNumberOfDdls[detectorID],detectorID));
350     return "";
351   }
352
353   ddlID += ddlIndex;
354   static TString fileName;
355
356   fileName = DetectorName(detectorID);
357   fileName += "_";
358   fileName += ddlID;
359   fileName += ".ddl";
360   return fileName.Data();
361 }
362
363 Int_t AliDAQ::NumberOfDdls(const char *detectorName)
364 {
365   // Returns the number of DDLs for
366   // a given detector
367   Int_t detectorID = DetectorID(detectorName);
368   if (detectorID < 0)
369     return -1;
370
371   return NumberOfDdls(detectorID);
372 }
373
374 Int_t AliDAQ::NumberOfDdls(Int_t detectorID)
375 {
376   // Returns the number of DDLs for
377   // a given detector
378   if (detectorID < 0 || detectorID >= kNDetectors) {
379     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
380     return -1;
381   }
382
383   return fgkNumberOfDdls[detectorID];
384 }
385
386 Float_t AliDAQ::NumberOfLdcs(const char *detectorName)
387 {
388   // Returns the number of DDLs for
389   // a given detector
390   Int_t detectorID = DetectorID(detectorName);
391   if (detectorID < 0)
392     return -1;
393
394   return NumberOfLdcs(detectorID);
395 }
396
397 Float_t AliDAQ::NumberOfLdcs(Int_t detectorID)
398 {
399   // Returns the number of DDLs for
400   // a given detector
401   if (detectorID < 0 || detectorID >= kNDetectors) {
402     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
403     return -1;
404   }
405
406   return fgkNumberOfLdcs[detectorID];
407 }
408
409 void AliDAQ::PrintConfig()
410 {
411   // Print the DAQ configuration
412   // for all the detectors
413   printf("===================================================================================================\n"
414          "|                              ALICE Data Acquisition Configuration                               |\n"
415          "===================================================================================================\n"
416          "| Detector ID | Detector Name | DDL Offset | # of DDLs | # of LDCs | Online Name | AliRoot Module |\n"
417          "===================================================================================================\n");
418   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
419     printf("|%11d  |%13s  |%10d  |%9d  |%9.1f  |%11s  |%14s  |\n",
420            iDet,DetectorName(iDet),DdlIDOffset(iDet),NumberOfDdls(iDet),NumberOfLdcs(iDet),
421            OnlineName(iDet),OfflineModuleName(iDet));
422   }
423   printf("===================================================================================================\n");
424
425 }
426
427 const char *AliDAQ::ListOfTriggeredDetectors(UInt_t detectorPattern)
428 {
429   // Returns a string with the list of
430   // active detectors. The input is the
431   // trigger pattern word contained in
432   // the raw-data event header.
433
434   static TString detList;
435   detList = "";
436   for(Int_t iDet = 0; iDet < (kNDetectors-1); iDet++) {
437     if ((detectorPattern >> iDet) & 0x1) {
438       detList += fgkDetectorName[iDet];
439       detList += " ";
440     }
441   }
442
443   // Always remember HLT
444   if ((detectorPattern >> kHLTId) & 0x1) detList += fgkDetectorName[kNDetectors-1];
445
446   return detList.Data();
447 }
448
449 UInt_t  AliDAQ::DetectorPattern(const char *detectorList)
450 {
451   // Returns a 32-bit word containing the
452   // the detector pattern corresponding to a given
453   // list of detectors
454   UInt_t pattern = 0;
455   TString detList = detectorList;
456   for(Int_t iDet = 0; iDet < (kNDetectors-1); iDet++) {
457     TString det = fgkDetectorName[iDet];
458     if((detList.CompareTo(det) == 0) || 
459        detList.BeginsWith(det) ||
460        detList.EndsWith(det) ||
461        detList.Contains( " "+det+" " )) pattern |= (1 << iDet) ;
462   }
463
464   // HLT
465   TString hltDet = fgkDetectorName[kNDetectors-1];
466   if((detList.CompareTo(hltDet) == 0) || 
467        detList.BeginsWith(hltDet) ||
468        detList.EndsWith(hltDet) ||
469        detList.Contains( " "+hltDet+" " )) pattern |= (1 << kHLTId) ;
470   
471   return pattern;
472 }
473
474 UInt_t  AliDAQ::DetectorPatternOffline(const char *detectorList)
475 {
476   // Returns a 32-bit word containing the
477   // the detector pattern corresponding to a given
478   // list of detectors.
479   // The list of detectors must follow offline module
480   // name convention.
481   UInt_t pattern = 0;
482   TString detList = detectorList;
483   for(Int_t iDet = 0; iDet < (kNDetectors-1); iDet++) {
484     TString det = fgkOfflineModuleName[iDet];
485     if((detList.CompareTo(det) == 0) || 
486        detList.BeginsWith(det) ||
487        detList.EndsWith(det) ||
488        detList.Contains( " "+det+" " )) pattern |= (1 << iDet) ;
489   }
490
491   // HLT
492   TString hltDet = fgkOfflineModuleName[kNDetectors-1];
493   if((detList.CompareTo(hltDet) == 0) || 
494        detList.BeginsWith(hltDet) ||
495        detList.EndsWith(hltDet) ||
496        detList.Contains( " "+hltDet+" " )) pattern |= (1 << kHLTId) ;
497   
498   return pattern;
499 }
500
501 const char *AliDAQ::OfflineModuleName(const char *detectorName)
502 {
503   // Returns the name of the offline module
504   // for a given detector (online naming convention)
505   Int_t detectorID = DetectorID(detectorName);
506   if (detectorID < 0)
507     return "";
508
509   return OfflineModuleName(detectorID);
510 }
511
512 const char *AliDAQ::OfflineModuleName(Int_t detectorID)
513 {
514   // Returns the name of the offline module
515   // for a given detector (online naming convention)
516   if (detectorID < 0 || detectorID >= kNDetectors) {
517     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
518     return "";
519   }
520
521   return fgkOfflineModuleName[detectorID];
522 }
523
524 const char *AliDAQ::OnlineName(const char *detectorName)
525 {
526   // Returns the name of the online detector name (3 characters)
527   // for a given detector
528   Int_t detectorID = DetectorID(detectorName);
529   if (detectorID < 0)
530     return "";
531
532   return OnlineName(detectorID);
533 }
534
535 const char *AliDAQ::OnlineName(Int_t detectorID)
536 {
537   // Returns the name of the online detector name (3 characters)
538   // for a given detector
539   if (detectorID < 0 || detectorID >= kNDetectors) {
540     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
541     return "";
542   }
543
544   return fgkOnlineName[detectorID];
545 }
546