]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliDAQ.cxx
Warnings removed (R.Shahoyan)
[u/mrichter/AliRoot.git] / STEER / 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", // Name to be changed to V0 ?
62   "ZDC",
63   "ACORDE",
64   "TRG",
65   "EMCAL",
66   "DAQ_TEST",
67   "HLT"
68 };
69
70 Int_t AliDAQ::fgkNumberOfDdls[AliDAQ::kNDetectors] = {
71   20,
72   24,
73   16,
74   216,
75   18,
76   72,
77   20,
78   20,
79   10,
80   6,
81   20,
82   2,
83   3,
84   1,
85   1,
86   1,
87   1,
88   1,
89   46,
90   1,
91   10
92 };
93
94 Float_t AliDAQ::fgkNumberOfLdcs[AliDAQ::kNDetectors] = {
95   4,
96   4,
97   4,
98   36,
99   3,
100   12,
101   4,
102   4,
103   2,
104   1,
105   5,
106   1,
107   1,
108   0.5,
109   0.5,
110   1,
111   1,
112   1,
113   8,
114   1,
115   5
116 };
117
118 const char* AliDAQ::fgkOfflineModuleName[AliDAQ::kNDetectors] = {
119   "ITS",
120   "ITS",
121   "ITS",
122   "TPC",
123   "TRD",
124   "TOF",
125   "HMPID",
126   "PHOS",
127   "CPV",
128   "PMD",
129   "MUON",
130   "MUON",
131   "FMD",
132   "T0",
133   "VZERO",
134   "ZDC",
135   "ACORDE",
136   "CTP",
137   "EMCAL",
138   "",
139   "HLT"
140 };
141
142 const char* AliDAQ::fgkOnlineName[AliDAQ::kNDetectors] = {
143   "SPD",
144   "SDD",
145   "SSD",
146   "TPC",
147   "TRD",
148   "TOF",
149   "HMP",
150   "PHS",
151   "CPV",
152   "PMD",
153   "MCH",
154   "MTR",
155   "FMD",
156   "T00",
157   "V00",
158   "ZDC",
159   "ACO",
160   "TRI",
161   "EMC",
162   "TST",
163   "HLT"
164 };
165
166 AliDAQ::AliDAQ(const AliDAQ& source) :
167   TObject(source)
168 {
169   // Copy constructor
170   // Nothing to be done
171 }
172
173 AliDAQ& AliDAQ::operator = (const AliDAQ& /* source */)
174 {
175   // Assignment operator
176   // Nothing to be done
177   return *this;
178 }
179
180 Int_t AliDAQ::DetectorID(const char *detectorName)
181 {
182   // Return the detector index
183   // corresponding to a given
184   // detector name
185   TString detStr = detectorName;
186
187   Int_t iDet;
188   for(iDet = 0; iDet < kNDetectors; iDet++) {
189     if (detStr.CompareTo(fgkDetectorName[iDet],TString::kIgnoreCase) == 0)
190       break;
191   }
192   if (iDet == kNDetectors) {
193     AliErrorClass(Form("Invalid detector name: %s !",detectorName));
194     return -1;
195   }
196   return iDet;
197 }
198
199 const char *AliDAQ::DetectorName(Int_t detectorID)
200 {
201   // Returns the name of particular
202   // detector identified by its index
203   if (detectorID < 0 || detectorID >= kNDetectors) {
204     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
205     return "";
206   }
207   return fgkDetectorName[detectorID];
208 }
209
210 Int_t AliDAQ::DdlIDOffset(const char *detectorName)
211 {
212   // Returns the DDL ID offset
213   // for a given detector
214   Int_t detectorID = DetectorID(detectorName);
215   if (detectorID < 0)
216     return -1;
217   
218   return DdlIDOffset(detectorID);
219 }
220
221 Int_t AliDAQ::DdlIDOffset(Int_t detectorID)
222 {
223   // Returns the DDL ID offset
224   // for a given detector identified
225   // by its index
226   if (detectorID < 0 || detectorID >= kNDetectors) {
227     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
228     return -1;
229   }
230   // HLT has a DDL offset = 30
231   if (detectorID == (kNDetectors-1)) return (kHLTId << 8);
232
233   return (detectorID << 8);
234 }
235
236 const char *AliDAQ::DetectorNameFromDdlID(Int_t ddlID,Int_t &ddlIndex)
237 {
238   // Returns the detector name for
239   // a given DDL ID
240   ddlIndex = -1;
241   Int_t detectorID = DetectorIDFromDdlID(ddlID,ddlIndex);
242   if (detectorID < 0)
243     return "";
244
245   return DetectorName(detectorID);
246 }
247
248 Int_t AliDAQ::DetectorIDFromDdlID(Int_t ddlID,Int_t &ddlIndex)
249 {
250   // Returns the detector ID and
251   // the ddl index within the
252   // detector range for
253   // a given input DDL ID
254   Int_t detectorID = ddlID >> 8;
255
256   // HLT
257   if (detectorID == kHLTId) detectorID = kNDetectors-1;
258
259   if (detectorID < 0 || detectorID >= kNDetectors) {
260     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
261     return -1;
262   }
263   ddlIndex = ddlID & 0xFF;
264   if (ddlIndex >= fgkNumberOfDdls[detectorID]) {
265     AliErrorClass(Form("Invalid DDL index %d (%d -> %d) for detector %d",
266                        ddlIndex,0,fgkNumberOfDdls[detectorID],detectorID));
267     ddlIndex = -1;
268     return -1;
269   }
270   return detectorID;
271 }
272
273 Int_t AliDAQ::DdlID(const char *detectorName, Int_t ddlIndex)
274 {
275   // Returns the DDL ID starting from
276   // the detector name and the DDL
277   // index inside the detector
278   Int_t detectorID = DetectorID(detectorName);
279   if (detectorID < 0)
280     return -1;
281
282   return DdlID(detectorID,ddlIndex);
283 }
284
285 Int_t AliDAQ::DdlID(Int_t detectorID, Int_t ddlIndex)
286 {
287   // Returns the DDL ID starting from
288   // the detector ID and the DDL
289   // index inside the detector
290   Int_t ddlID = DdlIDOffset(detectorID);
291   if (ddlID < 0)
292     return -1;
293   
294   if (ddlIndex >= fgkNumberOfDdls[detectorID]) {
295     AliErrorClass(Form("Invalid DDL index %d (%d -> %d) for detector %d",
296                        ddlIndex,0,fgkNumberOfDdls[detectorID],detectorID));
297     return -1;
298   }
299
300   ddlID += ddlIndex;
301   return ddlID;
302 }
303
304 const char *AliDAQ::DdlFileName(const char *detectorName, Int_t ddlIndex)
305 {
306   // Returns the DDL file name
307   // (used in the simulation) starting from
308   // the detector name and the DDL
309   // index inside the detector
310   Int_t detectorID = DetectorID(detectorName);
311   if (detectorID < 0)
312     return "";
313
314   return DdlFileName(detectorID,ddlIndex);
315 }
316
317 const char *AliDAQ::DdlFileName(Int_t detectorID, Int_t ddlIndex)
318 {
319   // Returns the DDL file name
320   // (used in the simulation) starting from
321   // the detector ID and the DDL
322   // index inside the detector
323   Int_t ddlID = DdlIDOffset(detectorID);
324   if (ddlID < 0)
325     return "";
326   
327   if (ddlIndex >= fgkNumberOfDdls[detectorID]) {
328     AliErrorClass(Form("Invalid DDL index %d (%d -> %d) for detector %d",
329                        ddlIndex,0,fgkNumberOfDdls[detectorID],detectorID));
330     return "";
331   }
332
333   ddlID += ddlIndex;
334   static TString fileName;
335
336   fileName = DetectorName(detectorID);
337   fileName += "_";
338   fileName += ddlID;
339   fileName += ".ddl";
340   return fileName.Data();
341 }
342
343 Int_t AliDAQ::NumberOfDdls(const char *detectorName)
344 {
345   // Returns the number of DDLs for
346   // a given detector
347   Int_t detectorID = DetectorID(detectorName);
348   if (detectorID < 0)
349     return -1;
350
351   return NumberOfDdls(detectorID);
352 }
353
354 Int_t AliDAQ::NumberOfDdls(Int_t detectorID)
355 {
356   // Returns the number of DDLs for
357   // a given detector
358   if (detectorID < 0 || detectorID >= kNDetectors) {
359     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
360     return -1;
361   }
362
363   return fgkNumberOfDdls[detectorID];
364 }
365
366 Float_t AliDAQ::NumberOfLdcs(const char *detectorName)
367 {
368   // Returns the number of DDLs for
369   // a given detector
370   Int_t detectorID = DetectorID(detectorName);
371   if (detectorID < 0)
372     return -1;
373
374   return NumberOfLdcs(detectorID);
375 }
376
377 Float_t AliDAQ::NumberOfLdcs(Int_t detectorID)
378 {
379   // Returns the number of DDLs for
380   // a given detector
381   if (detectorID < 0 || detectorID >= kNDetectors) {
382     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
383     return -1;
384   }
385
386   return fgkNumberOfLdcs[detectorID];
387 }
388
389 void AliDAQ::PrintConfig()
390 {
391   // Print the DAQ configuration
392   // for all the detectors
393   printf("===================================================================================================\n"
394          "|                              ALICE Data Acquisition Configuration                               |\n"
395          "===================================================================================================\n"
396          "| Detector ID | Detector Name | DDL Offset | # of DDLs | # of LDCs | Online Name | AliRoot Module |\n"
397          "===================================================================================================\n");
398   for(Int_t iDet = 0; iDet < kNDetectors; iDet++) {
399     printf("|%11d  |%13s  |%10d  |%9d  |%9.1f  |%11s  |%14s  |\n",
400            iDet,DetectorName(iDet),DdlIDOffset(iDet),NumberOfDdls(iDet),NumberOfLdcs(iDet),
401            OnlineName(iDet),OfflineModuleName(iDet));
402   }
403   printf("===================================================================================================\n");
404
405 }
406
407 const char *AliDAQ::ListOfTriggeredDetectors(UInt_t detectorPattern)
408 {
409   // Returns a string with the list of
410   // active detectors. The input is the
411   // trigger pattern word contained in
412   // the raw-data event header.
413
414   static TString detList;
415   detList = "";
416   for(Int_t iDet = 0; iDet < (kNDetectors-1); iDet++) {
417     if ((detectorPattern >> iDet) & 0x1) {
418       detList += fgkDetectorName[iDet];
419       detList += " ";
420     }
421   }
422
423   // Always remember HLT
424   if ((detectorPattern >> kHLTId) & 0x1) detList += fgkDetectorName[kNDetectors-1];
425
426   return detList.Data();
427 }
428
429 UInt_t  AliDAQ::DetectorPattern(const char *detectorList)
430 {
431   // Returns a 32-bit word containing the
432   // the detector pattern corresponding to a given
433   // list of detectors
434   UInt_t pattern = 0;
435   TString detList = detectorList;
436   for(Int_t iDet = 0; iDet < (kNDetectors-1); iDet++) {
437     TString det = fgkDetectorName[iDet];
438     if((detList.CompareTo(det) == 0) || 
439        detList.BeginsWith(det) ||
440        detList.EndsWith(det) ||
441        detList.Contains( " "+det+" " )) pattern |= (1 << iDet) ;
442   }
443
444   // HLT
445   TString hltDet = fgkDetectorName[kNDetectors-1];
446   if((detList.CompareTo(hltDet) == 0) || 
447        detList.BeginsWith(hltDet) ||
448        detList.EndsWith(hltDet) ||
449        detList.Contains( " "+hltDet+" " )) pattern |= (1 << kHLTId) ;
450   
451   return pattern;
452 }
453
454 UInt_t  AliDAQ::DetectorPatternOffline(const char *detectorList)
455 {
456   // Returns a 32-bit word containing the
457   // the detector pattern corresponding to a given
458   // list of detectors.
459   // The list of detectors must follow offline module
460   // name convention.
461   UInt_t pattern = 0;
462   TString detList = detectorList;
463   for(Int_t iDet = 0; iDet < (kNDetectors-1); iDet++) {
464     TString det = fgkOfflineModuleName[iDet];
465     if((detList.CompareTo(det) == 0) || 
466        detList.BeginsWith(det) ||
467        detList.EndsWith(det) ||
468        detList.Contains( " "+det+" " )) pattern |= (1 << iDet) ;
469   }
470
471   // HLT
472   TString hltDet = fgkOfflineModuleName[kNDetectors-1];
473   if((detList.CompareTo(hltDet) == 0) || 
474        detList.BeginsWith(hltDet) ||
475        detList.EndsWith(hltDet) ||
476        detList.Contains( " "+hltDet+" " )) pattern |= (1 << kHLTId) ;
477   
478   return pattern;
479 }
480
481 const char *AliDAQ::OfflineModuleName(const char *detectorName)
482 {
483   // Returns the name of the offline module
484   // for a given detector (online naming convention)
485   Int_t detectorID = DetectorID(detectorName);
486   if (detectorID < 0)
487     return "";
488
489   return OfflineModuleName(detectorID);
490 }
491
492 const char *AliDAQ::OfflineModuleName(Int_t detectorID)
493 {
494   // Returns the name of the offline module
495   // for a given detector (online naming convention)
496   if (detectorID < 0 || detectorID >= kNDetectors) {
497     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
498     return "";
499   }
500
501   return fgkOfflineModuleName[detectorID];
502 }
503
504 const char *AliDAQ::OnlineName(const char *detectorName)
505 {
506   // Returns the name of the online detector name (3 characters)
507   // for a given detector
508   Int_t detectorID = DetectorID(detectorName);
509   if (detectorID < 0)
510     return "";
511
512   return OnlineName(detectorID);
513 }
514
515 const char *AliDAQ::OnlineName(Int_t detectorID)
516 {
517   // Returns the name of the online detector name (3 characters)
518   // for a given detector
519   if (detectorID < 0 || detectorID >= kNDetectors) {
520     AliErrorClass(Form("Invalid detector index: %d (%d -> %d) !",detectorID,0,kNDetectors-1));
521     return "";
522   }
523
524   return fgkOnlineName[detectorID];
525 }
526