]>
Commit | Line | Data |
---|---|---|
a6e7b125 | 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 | ||
bea6b2a4 | 16 | /* $Id$ */ |
17 | ||
a6e7b125 | 18 | /////////////////////////////////////////////////////////////////////////////// |
bea6b2a4 | 19 | /// |
20 | /// This is the base class for reading raw data. | |
21 | /// | |
22 | /// The derived classes, which operate on concrete raw data formats, | |
23 | /// should implement | |
24 | /// - ReadHeader to read the next (data/equipment) header | |
25 | /// - ReadNextData to read the next raw data block (=1 DDL) | |
26 | /// - ReadNext to read a given number of bytes | |
27 | /// - several getters like GetType | |
28 | /// | |
29 | /// Sequential access to the raw data is provided by the methods | |
30 | /// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar | |
31 | /// | |
32 | /// If only data from a specific detector (and a given range of DDL numbers) | |
33 | /// should be read, this can be achieved by the Select method. | |
34 | /// Several getters provide information about the current event and the | |
35 | /// current type of raw data. | |
36 | /// | |
a6e7b125 | 37 | /////////////////////////////////////////////////////////////////////////////// |
38 | ||
43787b8e | 39 | #include <TClass.h> |
40 | #include <TPluginManager.h> | |
41 | #include <TROOT.h> | |
56918e2f | 42 | #include <TInterpreter.h> |
13b20641 | 43 | #include <TSystem.h> |
764daca3 | 44 | #include <TPRegexp.h> |
5dfb32c1 | 45 | #include <THashList.h> |
43787b8e | 46 | |
0cfe2438 | 47 | #include <Riostream.h> |
a6e7b125 | 48 | #include "AliRawReader.h" |
43787b8e | 49 | #include "AliRawReaderFile.h" |
50 | #include "AliRawReaderDate.h" | |
51 | #include "AliRawReaderRoot.h" | |
a6e0640d | 52 | #include "AliRawReaderChain.h" |
362c9d61 | 53 | #include "AliDAQ.h" |
38cf12f3 | 54 | #include "AliLog.h" |
8de97894 | 55 | |
714281ef | 56 | using std::ifstream; |
a6e7b125 | 57 | ClassImp(AliRawReader) |
58 | ||
59 | ||
c946ab02 | 60 | AliRawReader::AliRawReader() : |
0cfe2438 | 61 | fEquipmentIdsIn(NULL), |
62 | fEquipmentIdsOut(NULL), | |
18882b3b | 63 | fRequireHeader(kTRUE), |
39f9963f | 64 | fHeader(NULL), |
c946ab02 | 65 | fCount(0), |
f224de6c | 66 | fSelectEquipmentType(-1), |
67 | fSelectMinEquipmentId(-1), | |
68 | fSelectMaxEquipmentId(-1), | |
39f9963f | 69 | fSkipInvalid(kFALSE), |
dd9a70fe | 70 | fSelectEventType(-1), |
00665a00 | 71 | fSelectTriggerMask(0), |
56918e2f | 72 | fSelectTriggerExpr(), |
38cf12f3 | 73 | fErrorCode(0), |
74 | fEventNumber(-1), | |
edd06192 | 75 | fErrorLogs("AliRawDataErrorLog",100), |
a97af23d | 76 | fHeaderSwapped(NULL), |
b21d9ff2 | 77 | fIsValid(kTRUE), |
78 | fIsTriggerClassLoaded(kFALSE) | |
a6e7b125 | 79 | { |
42d20574 | 80 | // default constructor: initialize data members |
edd06192 | 81 | // Allocate the swapped header in case of Mac |
82 | #ifndef R__BYTESWAP | |
83 | fHeaderSwapped=new AliRawDataHeader(); | |
84 | #endif | |
0cfe2438 | 85 | } |
42d20574 | 86 | |
0cfe2438 | 87 | Bool_t AliRawReader::LoadEquipmentIdsMap(const char *fileName) |
88 | { | |
89 | // Open the mapping file | |
90 | // and load the mapping data | |
91 | ifstream input(fileName); | |
92 | if (input.is_open()) { | |
93 | Warning("AliRawReader","Equipment ID mapping file is found !"); | |
94 | const Int_t kMaxDDL = 256; | |
95 | fEquipmentIdsIn = new TArrayI(kMaxDDL); | |
96 | fEquipmentIdsOut = new TArrayI(kMaxDDL); | |
97 | Int_t equipIn, equipOut; | |
98 | Int_t nIds = 0; | |
99 | while (input >> equipIn >> equipOut) { | |
100 | if (nIds >= kMaxDDL) { | |
101 | Error("AliRawReader","Too many equipment Id mappings found ! Truncating the list !"); | |
102 | break; | |
103 | } | |
104 | fEquipmentIdsIn->AddAt(equipIn,nIds); | |
105 | fEquipmentIdsOut->AddAt(equipOut,nIds); | |
106 | nIds++; | |
107 | } | |
108 | fEquipmentIdsIn->Set(nIds); | |
109 | fEquipmentIdsOut->Set(nIds); | |
110 | input.close(); | |
111 | return kTRUE; | |
112 | } | |
113 | else { | |
114 | Error("AliRawReader","equipment id map file is not found ! Skipping the mapping !"); | |
115 | return kFALSE; | |
116 | } | |
a6e7b125 | 117 | } |
118 | ||
42d20574 | 119 | AliRawReader::AliRawReader(const AliRawReader& rawReader) : |
c946ab02 | 120 | TObject(rawReader), |
0cfe2438 | 121 | fEquipmentIdsIn(rawReader.fEquipmentIdsIn), |
122 | fEquipmentIdsOut(rawReader.fEquipmentIdsOut), | |
18882b3b | 123 | fRequireHeader(rawReader.fRequireHeader), |
39f9963f | 124 | fHeader(rawReader.fHeader), |
c946ab02 | 125 | fCount(rawReader.fCount), |
f224de6c | 126 | fSelectEquipmentType(rawReader.fSelectEquipmentType), |
127 | fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId), | |
128 | fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId), | |
39f9963f | 129 | fSkipInvalid(rawReader.fSkipInvalid), |
dd9a70fe | 130 | fSelectEventType(rawReader.fSelectEventType), |
00665a00 | 131 | fSelectTriggerMask(rawReader.fSelectTriggerMask), |
56918e2f | 132 | fSelectTriggerExpr(rawReader.fSelectTriggerExpr), |
38cf12f3 | 133 | fErrorCode(0), |
134 | fEventNumber(-1), | |
edd06192 | 135 | fErrorLogs("AliRawDataErrorLog",100), |
a97af23d | 136 | fHeaderSwapped(NULL), |
b21d9ff2 | 137 | fIsValid(rawReader.fIsValid), |
138 | fIsTriggerClassLoaded(rawReader.fIsTriggerClassLoaded) | |
42d20574 | 139 | { |
140 | // copy constructor | |
edd06192 | 141 | // Allocate the swapped header in case of Mac |
142 | #ifndef R__BYTESWAP | |
143 | fHeaderSwapped=new AliRawDataHeader(*rawReader.fHeaderSwapped); | |
144 | #endif | |
42d20574 | 145 | } |
146 | ||
147 | AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader) | |
148 | { | |
149 | // assignment operator | |
2a4ff083 | 150 | if(&rawReader == this) return *this; |
0cfe2438 | 151 | fEquipmentIdsIn = rawReader.fEquipmentIdsIn; |
152 | fEquipmentIdsOut = rawReader.fEquipmentIdsOut; | |
42d20574 | 153 | |
39f9963f | 154 | fHeader = rawReader.fHeader; |
42d20574 | 155 | fCount = rawReader.fCount; |
156 | ||
39f9963f | 157 | fSelectEquipmentType = rawReader.fSelectEquipmentType; |
158 | fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId; | |
159 | fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId; | |
160 | fSkipInvalid = rawReader.fSkipInvalid; | |
dd9a70fe | 161 | fSelectEventType = rawReader.fSelectEventType; |
00665a00 | 162 | fSelectTriggerMask = rawReader.fSelectTriggerMask; |
56918e2f | 163 | fSelectTriggerExpr = rawReader.fSelectTriggerExpr; |
42d20574 | 164 | |
b4857df7 | 165 | fErrorCode = rawReader.fErrorCode; |
166 | ||
38cf12f3 | 167 | fEventNumber = rawReader.fEventNumber; |
168 | fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone()); | |
169 | ||
a97af23d | 170 | fIsValid = rawReader.fIsValid; |
b21d9ff2 | 171 | fIsTriggerClassLoaded = rawReader.fIsTriggerClassLoaded; |
a97af23d | 172 | |
42d20574 | 173 | return *this; |
174 | } | |
175 | ||
0cfe2438 | 176 | AliRawReader::~AliRawReader() |
177 | { | |
178 | // destructor | |
179 | // delete the mapping arrays if | |
180 | // initialized | |
181 | if (fEquipmentIdsIn) delete fEquipmentIdsIn; | |
182 | if (fEquipmentIdsOut) delete fEquipmentIdsOut; | |
79dac785 | 183 | fErrorLogs.Delete(); |
edd06192 | 184 | if (fHeaderSwapped) delete fHeaderSwapped; |
0cfe2438 | 185 | } |
186 | ||
43787b8e | 187 | AliRawReader* AliRawReader::Create(const char *uri) |
188 | { | |
189 | // RawReader's factory | |
190 | // It instantiate corresponding raw-reader implementation class object | |
191 | // depending on the URI provided | |
192 | // Normal URIs point to files, while the URI starting with | |
193 | // 'mem://:' or 'mem://<filename>' will create | |
194 | // AliRawReaderDateOnline object which is supposed to be used | |
195 | // in the online reconstruction | |
196 | ||
197 | TString strURI = uri; | |
198 | ||
199 | if (strURI.IsNull()) { | |
200 | AliWarningClass("No raw-reader created"); | |
201 | return NULL; | |
202 | } | |
203 | ||
3f7450e0 | 204 | TObjArray *fields = strURI.Tokenize("?"); |
205 | TString &fileURI = ((TObjString*)fields->At(0))->String(); | |
206 | ||
43787b8e | 207 | AliRawReader *rawReader = NULL; |
3ae8c60d | 208 | if (fileURI.BeginsWith("mem://") || fileURI.BeginsWith("^")) { |
209 | if (fileURI.BeginsWith("mem://")) fileURI.ReplaceAll("mem://",""); | |
3f7450e0 | 210 | AliInfoClass(Form("Creating raw-reader in order to read events in shared memory (option=%s)",fileURI.Data())); |
43787b8e | 211 | |
212 | TPluginManager* pluginManager = gROOT->GetPluginManager(); | |
213 | TString rawReaderName = "AliRawReaderDateOnline"; | |
214 | TPluginHandler* pluginHandler = pluginManager->FindHandler("AliRawReader", "online"); | |
215 | // if not, add a plugin for it | |
216 | if (!pluginHandler) { | |
217 | pluginManager->AddHandler("AliRawReader", "online", | |
218 | "AliRawReaderDateOnline", "RAWDatarecOnline", "AliRawReaderDateOnline(const char*)"); | |
219 | pluginHandler = pluginManager->FindHandler("AliRawReader", "online"); | |
220 | } | |
221 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
3f7450e0 | 222 | rawReader = (AliRawReader*)pluginHandler->ExecPlugin(1,fileURI.Data()); |
43787b8e | 223 | } |
224 | else { | |
a6e0640d | 225 | delete fields; |
43787b8e | 226 | return NULL; |
227 | } | |
228 | } | |
2f954aba | 229 | else if (fileURI.BeginsWith("amore://")) { |
230 | // A special raw-data URL used in case | |
231 | // the raw-data reading is steered from | |
232 | // ouside, i.e. from AMORE | |
233 | fileURI.ReplaceAll("amore://",""); | |
234 | AliInfoClass("Creating raw-reader in order to read events sent by AMORE"); | |
235 | rawReader = new AliRawReaderDate((void *)NULL); | |
236 | } | |
a6e0640d | 237 | else if (fileURI.BeginsWith("collection://")) { |
238 | fileURI.ReplaceAll("collection://",""); | |
239 | AliInfoClass(Form("Creating raw-reader in order to read raw-data files collection defined in %s",fileURI.Data())); | |
240 | rawReader = new AliRawReaderChain(fileURI); | |
241 | } | |
bb0edcaf | 242 | else if (fileURI.BeginsWith("raw://run")) { |
243 | fileURI.ReplaceAll("raw://run",""); | |
244 | if (fileURI.IsDigit()) { | |
245 | rawReader = new AliRawReaderChain(fileURI.Atoi()); | |
246 | } | |
247 | else { | |
248 | AliErrorClass(Form("Invalid syntax: %s",fileURI.Data())); | |
249 | fields->Delete(); | |
250 | return NULL; | |
251 | } | |
252 | } | |
a6e0640d | 253 | else { |
254 | AliInfoClass(Form("Creating raw-reader in order to read raw-data file: %s",fileURI.Data())); | |
13b20641 | 255 | TString filename(gSystem->ExpandPathName(fileURI.Data())); |
256 | if (filename.EndsWith("/")) { | |
257 | rawReader = new AliRawReaderFile(filename); | |
258 | } else if (filename.EndsWith(".root")) { | |
259 | rawReader = new AliRawReaderRoot(filename); | |
a6e0640d | 260 | } else { |
13b20641 | 261 | rawReader = new AliRawReaderDate(filename); |
a6e0640d | 262 | } |
263 | } | |
43787b8e | 264 | |
a97af23d | 265 | if (!rawReader->IsRawReaderValid()) { |
266 | AliErrorClass(Form("Raw-reader is invalid - check the input URI (%s)",fileURI.Data())); | |
267 | delete rawReader; | |
268 | fields->Delete(); | |
269 | delete fields; | |
270 | return NULL; | |
271 | } | |
272 | ||
3f7450e0 | 273 | // Now apply event selection criteria (if specified) |
274 | if (fields->GetEntries() > 1) { | |
275 | Int_t eventType = -1; | |
276 | ULong64_t triggerMask = 0; | |
56918e2f | 277 | TString triggerExpr; |
3f7450e0 | 278 | for(Int_t i = 1; i < fields->GetEntries(); i++) { |
279 | if (!fields->At(i)) continue; | |
280 | TString &option = ((TObjString*)fields->At(i))->String(); | |
281 | if (option.BeginsWith("EventType=",TString::kIgnoreCase)) { | |
282 | option.ReplaceAll("EventType=",""); | |
283 | eventType = option.Atoi(); | |
284 | continue; | |
285 | } | |
286 | if (option.BeginsWith("Trigger=",TString::kIgnoreCase)) { | |
287 | option.ReplaceAll("Trigger=",""); | |
56918e2f | 288 | if (option.IsDigit()) { |
289 | triggerMask = option.Atoll(); | |
290 | } | |
291 | else { | |
292 | triggerExpr = option.Data(); | |
293 | } | |
3f7450e0 | 294 | continue; |
295 | } | |
296 | AliWarningClass(Form("Ignoring invalid event selection option: %s",option.Data())); | |
297 | } | |
56918e2f | 298 | AliInfoClass(Form("Event selection criteria specified: eventype=%d trigger mask=%llx trigger expression=%s", |
299 | eventType,triggerMask,triggerExpr.Data())); | |
300 | rawReader->SelectEvents(eventType,triggerMask,triggerExpr.Data()); | |
3f7450e0 | 301 | } |
302 | ||
303 | fields->Delete(); | |
304 | delete fields; | |
305 | ||
43787b8e | 306 | return rawReader; |
307 | } | |
308 | ||
0cfe2438 | 309 | Int_t AliRawReader::GetMappedEquipmentId() const |
310 | { | |
311 | if (!fEquipmentIdsIn || !fEquipmentIdsOut) { | |
312 | Error("AliRawReader","equipment Ids mapping is not initialized !"); | |
313 | return GetEquipmentId(); | |
314 | } | |
315 | Int_t equipmentId = GetEquipmentId(); | |
316 | for(Int_t iId = 0; iId < fEquipmentIdsIn->GetSize(); iId++) { | |
317 | if (equipmentId == fEquipmentIdsIn->At(iId)) { | |
318 | equipmentId = fEquipmentIdsOut->At(iId); | |
319 | break; | |
320 | } | |
321 | } | |
322 | return equipmentId; | |
323 | } | |
324 | ||
325 | Int_t AliRawReader::GetDetectorID() const | |
326 | { | |
327 | // Get the detector ID | |
328 | // The list of detector IDs | |
362c9d61 | 329 | // can be found in AliDAQ.h |
0cfe2438 | 330 | Int_t equipmentId; |
331 | if (fEquipmentIdsIn && fEquipmentIdsIn) | |
332 | equipmentId = GetMappedEquipmentId(); | |
333 | else | |
334 | equipmentId = GetEquipmentId(); | |
335 | ||
362c9d61 | 336 | if (equipmentId >= 0) { |
337 | Int_t ddlIndex; | |
338 | return AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex); | |
339 | } | |
0cfe2438 | 340 | else |
341 | return -1; | |
342 | } | |
343 | ||
344 | Int_t AliRawReader::GetDDLID() const | |
345 | { | |
346 | // Get the DDL ID (within one sub-detector) | |
347 | // The list of detector IDs | |
362c9d61 | 348 | // can be found in AliDAQ.h |
0cfe2438 | 349 | Int_t equipmentId; |
350 | if (fEquipmentIdsIn && fEquipmentIdsIn) | |
351 | equipmentId = GetMappedEquipmentId(); | |
352 | else | |
353 | equipmentId = GetEquipmentId(); | |
354 | ||
362c9d61 | 355 | if (equipmentId >= 0) { |
356 | Int_t ddlIndex; | |
357 | AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex); | |
358 | return ddlIndex; | |
359 | } | |
0cfe2438 | 360 | else |
361 | return -1; | |
362 | } | |
8de97894 | 363 | |
362c9d61 | 364 | void AliRawReader::Select(const char *detectorName, Int_t minDDLID, Int_t maxDDLID) |
365 | { | |
366 | // read only data of the detector with the given name and in the given | |
367 | // range of DDLs (minDDLID <= DDLID <= maxDDLID). | |
368 | // no selection is applied if a value < 0 is used. | |
369 | Int_t detectorID = AliDAQ::DetectorID(detectorName); | |
370 | if(detectorID >= 0) | |
371 | Select(detectorID,minDDLID,maxDDLID); | |
372 | } | |
373 | ||
8de97894 | 374 | void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID) |
a6e7b125 | 375 | { |
8de97894 | 376 | // read only data of the detector with the given ID and in the given |
f224de6c | 377 | // range of DDLs (minDDLID <= DDLID <= maxDDLID). |
8de97894 | 378 | // no selection is applied if a value < 0 is used. |
a6e7b125 | 379 | |
0cfe2438 | 380 | fSelectEquipmentType = -1; |
362c9d61 | 381 | |
382 | if (minDDLID < 0) | |
383 | fSelectMinEquipmentId = AliDAQ::DdlIDOffset(detectorID); | |
384 | else | |
385 | fSelectMinEquipmentId = AliDAQ::DdlID(detectorID,minDDLID); | |
386 | ||
387 | if (maxDDLID < 0) | |
388 | fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,AliDAQ::NumberOfDdls(detectorID)-1); | |
389 | else | |
390 | fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,maxDDLID); | |
8de97894 | 391 | } |
a6e7b125 | 392 | |
f224de6c | 393 | void AliRawReader::SelectEquipment(Int_t equipmentType, |
394 | Int_t minEquipmentId, Int_t maxEquipmentId) | |
395 | { | |
396 | // read only data of the equipment with the given type and in the given | |
397 | // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId). | |
398 | // no selection is applied if a value < 0 is used. | |
399 | ||
400 | fSelectEquipmentType = equipmentType; | |
401 | fSelectMinEquipmentId = minEquipmentId; | |
402 | fSelectMaxEquipmentId = maxEquipmentId; | |
403 | } | |
404 | ||
56918e2f | 405 | void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask, |
406 | const char *triggerExpr) | |
dd9a70fe | 407 | { |
00665a00 | 408 | // read only events with the given type and optionally |
409 | // trigger mask. | |
56918e2f | 410 | // no selection is applied if value = 0 is used. |
411 | // Trigger selection can be done via string (triggerExpr) | |
412 | // which defines the trigger logic to be used. It works only | |
413 | // after LoadTriggerClass() method is called for all involved | |
414 | // trigger classes. | |
dd9a70fe | 415 | |
416 | fSelectEventType = type; | |
00665a00 | 417 | fSelectTriggerMask = triggerMask; |
56918e2f | 418 | if (triggerExpr) fSelectTriggerExpr = triggerExpr; |
419 | } | |
420 | ||
421 | void AliRawReader::LoadTriggerClass(const char* name, Int_t index) | |
422 | { | |
423 | // Loads the list of trigger classes defined. | |
424 | // Used in conjunction with IsEventSelected in the | |
425 | // case when the trigger selection is given by | |
426 | // fSelectedTriggerExpr | |
427 | ||
428 | if (fSelectTriggerExpr.IsNull()) return; | |
429 | ||
b21d9ff2 | 430 | fIsTriggerClassLoaded = kTRUE; |
431 | ||
764daca3 | 432 | if (index >= 0) |
433 | fSelectTriggerExpr.ReplaceAll(name,Form("[%d]",index)); | |
434 | else | |
435 | fSelectTriggerExpr.ReplaceAll(name,"0"); | |
dd9a70fe | 436 | } |
437 | ||
5dfb32c1 | 438 | void AliRawReader::LoadTriggerAlias(const THashList *lst) |
439 | { | |
440 | // Loads the list of trigger aliases defined. | |
441 | // Replaces the alias by the OR of the triggers included in it. | |
442 | // The subsiquent call to LoadTriggerClass is needed | |
443 | // to obtain the final expression in | |
444 | // fSelectedTriggerExpr | |
445 | ||
446 | if (fSelectTriggerExpr.IsNull()) return; | |
447 | ||
448 | // Make a THashList alias -> trigger classes | |
449 | ||
450 | THashList alias2trig; | |
451 | TIter iter(lst); | |
452 | TNamed *nmd = 0; | |
453 | ||
454 | // Loop on triggers | |
455 | ||
456 | while((nmd = dynamic_cast<TNamed*>(iter.Next()))){ | |
457 | ||
458 | TString aliasList(nmd->GetTitle()); | |
459 | TObjArray* arrAliases = aliasList.Tokenize(','); | |
460 | Int_t nAliases = arrAliases->GetEntries(); | |
461 | ||
462 | // Loop on aliases for the current trigger | |
463 | for(Int_t i=0; i<nAliases; i++){ | |
464 | ||
465 | TObjString *alias = (TObjString*) arrAliases->At(i); | |
466 | ||
467 | // Find the current alias in the hash list. If it is not there, add TNamed entry | |
468 | TNamed * inlist = (TNamed*)alias2trig.FindObject((alias->GetString()).Data()); | |
469 | if (!inlist) { | |
470 | inlist = new TNamed((alias->GetString()).Data(),nmd->GetName()); | |
471 | alias2trig.Add(inlist); | |
472 | } | |
473 | else { | |
474 | TString tt(inlist->GetTitle()); | |
475 | tt += " || "; | |
476 | tt += nmd->GetName(); | |
477 | inlist->SetTitle(tt.Data()); | |
478 | } | |
479 | } | |
480 | ||
481 | delete arrAliases; | |
482 | } | |
483 | alias2trig.Sort(kSortDescending); | |
484 | ||
485 | // Replace all the aliases by the OR of triggers | |
486 | TIter iter1(&alias2trig); | |
487 | while((nmd = dynamic_cast<TNamed*>(iter1.Next()))){ | |
488 | fSelectTriggerExpr.ReplaceAll(nmd->GetName(),nmd->GetTitle()); | |
489 | } | |
490 | } | |
491 | ||
42d20574 | 492 | Bool_t AliRawReader::IsSelected() const |
a6e7b125 | 493 | { |
8de97894 | 494 | // apply the selection (if any) |
495 | ||
39f9963f | 496 | if (fSkipInvalid && !IsValid()) return kFALSE; |
f224de6c | 497 | |
0cfe2438 | 498 | if (fSelectEquipmentType >= 0) |
f224de6c | 499 | if (GetEquipmentType() != fSelectEquipmentType) return kFALSE; |
0cfe2438 | 500 | |
501 | Int_t equipmentId; | |
502 | if (fEquipmentIdsIn && fEquipmentIdsIn) | |
503 | equipmentId = GetMappedEquipmentId(); | |
504 | else | |
505 | equipmentId = GetEquipmentId(); | |
506 | ||
507 | if ((fSelectMinEquipmentId >= 0) && | |
508 | (equipmentId < fSelectMinEquipmentId)) | |
509 | return kFALSE; | |
510 | if ((fSelectMaxEquipmentId >= 0) && | |
511 | (equipmentId > fSelectMaxEquipmentId)) | |
512 | return kFALSE; | |
f224de6c | 513 | |
8de97894 | 514 | return kTRUE; |
a6e7b125 | 515 | } |
516 | ||
dd9a70fe | 517 | Bool_t AliRawReader::IsEventSelected() const |
518 | { | |
00665a00 | 519 | // apply the event selection (if any) |
dd9a70fe | 520 | |
00665a00 | 521 | // First check the event type |
dd9a70fe | 522 | if (fSelectEventType >= 0) { |
523 | if (GetType() != (UInt_t) fSelectEventType) return kFALSE; | |
524 | } | |
525 | ||
00665a00 | 526 | // Then check the trigger pattern and compared it |
527 | // to the required trigger mask | |
528 | if (fSelectTriggerMask != 0) { | |
529 | if ((GetClassMask() & fSelectTriggerMask) != fSelectTriggerMask) return kFALSE; | |
530 | } | |
531 | ||
b21d9ff2 | 532 | if ( fIsTriggerClassLoaded && !fSelectTriggerExpr.IsNull()) { |
56918e2f | 533 | TString expr(fSelectTriggerExpr); |
534 | ULong64_t mask = GetClassMask(); | |
535 | for(Int_t itrigger = 0; itrigger < 50; itrigger++) { | |
536 | if (mask & (1 << itrigger)) { | |
537 | expr.ReplaceAll(Form("[%d]",itrigger),"1"); | |
538 | } | |
539 | else { | |
540 | expr.ReplaceAll(Form("[%d]",itrigger),"0"); | |
541 | } | |
542 | } | |
31572b9e | 543 | // Possibility to introduce downscaling |
764daca3 | 544 | TPRegexp("(%\\s*\\d+)").Substitute(expr,Form("&& !(%d$1)",GetEventIndex()),"g"); |
56918e2f | 545 | Int_t error; |
546 | if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) && | |
547 | (error == TInterpreter::kNoError)) { | |
548 | return kFALSE; | |
549 | } | |
550 | } | |
551 | ||
dd9a70fe | 552 | return kTRUE; |
553 | } | |
554 | ||
91f76e9b | 555 | UInt_t AliRawReader::SwapWord(UInt_t x) const |
556 | { | |
557 | // Swap the endianess of the integer value 'x' | |
558 | ||
559 | return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) | | |
560 | ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24)); | |
561 | } | |
562 | ||
563 | UShort_t AliRawReader::SwapShort(UShort_t x) const | |
564 | { | |
565 | // Swap the endianess of the short value 'x' | |
566 | ||
567 | return (((x & 0x00ffU) << 8) | ((x & 0xff00U) >> 8)) ; | |
568 | } | |
a6e7b125 | 569 | |
a6e7b125 | 570 | Bool_t AliRawReader::ReadNextInt(UInt_t& data) |
571 | { | |
8de97894 | 572 | // reads the next 4 bytes at the current position |
573 | // returns kFALSE if the data could not be read | |
a6e7b125 | 574 | |
575 | while (fCount == 0) { | |
c946ab02 | 576 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 577 | } |
8de97894 | 578 | if (fCount < (Int_t) sizeof(data)) { |
579 | Error("ReadNextInt", | |
580 | "too few data left (%d bytes) to read an UInt_t!", fCount); | |
581 | return kFALSE; | |
582 | } | |
583 | if (!ReadNext((UChar_t*) &data, sizeof(data))) { | |
a6e7b125 | 584 | Error("ReadNextInt", "could not read data!"); |
585 | return kFALSE; | |
586 | } | |
91f76e9b | 587 | #ifndef R__BYTESWAP |
588 | data=SwapWord(data); | |
589 | #endif | |
a6e7b125 | 590 | return kTRUE; |
591 | } | |
592 | ||
593 | Bool_t AliRawReader::ReadNextShort(UShort_t& data) | |
594 | { | |
8de97894 | 595 | // reads the next 2 bytes at the current position |
596 | // returns kFALSE if the data could not be read | |
a6e7b125 | 597 | |
598 | while (fCount == 0) { | |
c946ab02 | 599 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 600 | } |
8de97894 | 601 | if (fCount < (Int_t) sizeof(data)) { |
602 | Error("ReadNextShort", | |
603 | "too few data left (%d bytes) to read an UShort_t!", fCount); | |
604 | return kFALSE; | |
605 | } | |
606 | if (!ReadNext((UChar_t*) &data, sizeof(data))) { | |
a6e7b125 | 607 | Error("ReadNextShort", "could not read data!"); |
608 | return kFALSE; | |
609 | } | |
91f76e9b | 610 | #ifndef R__BYTESWAP |
611 | data=SwapShort(data); | |
612 | #endif | |
a6e7b125 | 613 | return kTRUE; |
614 | } | |
615 | ||
616 | Bool_t AliRawReader::ReadNextChar(UChar_t& data) | |
617 | { | |
618 | // reads the next 1 byte at the current stream position | |
8de97894 | 619 | // returns kFALSE if the data could not be read |
a6e7b125 | 620 | |
621 | while (fCount == 0) { | |
c946ab02 | 622 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 623 | } |
8de97894 | 624 | if (!ReadNext((UChar_t*) &data, sizeof(data))) { |
a6e7b125 | 625 | Error("ReadNextChar", "could not read data!"); |
626 | return kFALSE; | |
627 | } | |
a6e7b125 | 628 | return kTRUE; |
629 | } | |
630 | ||
66964465 | 631 | Bool_t AliRawReader::GotoEvent(Int_t event) |
636c1780 | 632 | { |
66964465 | 633 | // Random access to certain |
634 | // event index. Could be very slow | |
635 | // for some non-root raw-readers. | |
636 | // So it should be reimplemented there. | |
637 | if (event < fEventNumber) RewindEvents(); | |
638 | ||
639 | while (fEventNumber < event) { | |
640 | if (!NextEvent()) return kFALSE; | |
641 | } | |
642 | ||
643 | return kTRUE; | |
636c1780 | 644 | } |
b4857df7 | 645 | |
646 | Int_t AliRawReader::CheckData() const | |
647 | { | |
648 | // check the consistency of the data | |
649 | // derived classes should overwrite the default method which returns 0 (no err) | |
650 | ||
651 | return 0; | |
652 | } | |
653 | ||
509a7696 | 654 | |
655 | void AliRawReader::DumpData(Int_t limit) | |
656 | { | |
657 | // print the raw data | |
658 | // if limit is not negative, only the first and last "limit" lines of raw data | |
659 | // are printed | |
660 | ||
661 | Reset(); | |
662 | if (!ReadHeader()) { | |
663 | Error("DumpData", "no header"); | |
664 | return; | |
665 | } | |
666 | printf("header:\n" | |
667 | " type = %d run = %d ", GetType(), GetRunNumber()); | |
668 | if (GetEventId()) { | |
669 | printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]); | |
670 | } else { | |
671 | printf("event = -------- --------\n"); | |
672 | } | |
673 | if (GetTriggerPattern()) { | |
674 | printf(" trigger = %8.8x %8.8x ", | |
675 | GetTriggerPattern()[1], GetTriggerPattern()[0]); | |
676 | } else { | |
677 | printf(" trigger = -------- -------- "); | |
678 | } | |
679 | if (GetDetectorPattern()) { | |
680 | printf("detector = %8.8x\n", GetDetectorPattern()[0]); | |
681 | } else { | |
682 | printf("detector = --------\n"); | |
683 | } | |
684 | if (GetAttributes()) { | |
685 | printf(" attributes = %8.8x %8.8x %8.8x ", | |
686 | GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]); | |
687 | } else { | |
688 | printf(" attributes = -------- -------- -------- "); | |
689 | } | |
690 | printf("GDC = %d\n", GetGDCId()); | |
691 | printf("\n"); | |
692 | ||
693 | do { | |
694 | printf("-------------------------------------------------------------------------------\n"); | |
695 | printf("LDC = %d\n", GetLDCId()); | |
696 | ||
697 | printf("equipment:\n" | |
698 | " size = %d type = %d id = %d\n", | |
699 | GetEquipmentSize(), GetEquipmentType(), GetEquipmentId()); | |
700 | if (GetEquipmentAttributes()) { | |
701 | printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2], | |
702 | GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]); | |
703 | } else { | |
704 | printf(" attributes = -------- -------- -------- "); | |
705 | } | |
706 | printf("element size = %d\n", GetEquipmentElementSize()); | |
707 | ||
39f9963f | 708 | printf("data header:\n" |
709 | " size = %d version = %d valid = %d compression = %d\n", | |
710 | GetDataSize(), GetVersion(), IsValid(), IsCompressed()); | |
509a7696 | 711 | |
712 | printf("\n"); | |
713 | if (limit == 0) continue; | |
714 | ||
715 | Int_t size = GetDataSize(); | |
716 | char line[70]; | |
717 | for (Int_t i = 0; i < 70; i++) line[i] = ' '; | |
718 | line[69] = '\0'; | |
719 | Int_t pos = 0; | |
720 | Int_t max = 16; | |
721 | UChar_t byte; | |
722 | ||
723 | for (Int_t n = 0; n < size; n++) { | |
724 | if (!ReadNextChar(byte)) { | |
725 | Error("DumpData", "couldn't read byte number %d\n", n); | |
726 | break; | |
727 | } | |
728 | if (pos >= max) { | |
729 | printf("%8.8x %s\n", n-pos, line); | |
730 | for (Int_t i = 0; i < 70; i++) line[i] = ' '; | |
731 | line[69] = '\0'; | |
732 | pos = 0; | |
733 | if ((limit > 0) && (n/max == limit)) { | |
734 | Int_t nContinue = ((size-1)/max+1-limit) * max; | |
735 | if (nContinue > n) { | |
736 | printf(" [skipping %d bytes]\n", nContinue-n); | |
737 | n = nContinue-1; | |
738 | continue; | |
739 | } | |
740 | } | |
741 | } | |
742 | Int_t offset = pos/4; | |
743 | if ((byte > 0x20) && (byte < 0x7f)) { | |
744 | line[pos+offset] = byte; | |
745 | } else { | |
746 | line[pos+offset] = '.'; | |
747 | } | |
748 | char hex[3]; | |
669f9a12 | 749 | snprintf(hex, 3, "%2.2x", byte); |
509a7696 | 750 | line[max+max/4+3+2*pos+offset] = hex[0]; |
751 | line[max+max/4+4+2*pos+offset] = hex[1]; | |
752 | pos++; | |
753 | } | |
754 | ||
755 | if (pos > 0) printf("%8.8x %s\n", size-pos, line); | |
756 | printf("\n"); | |
757 | ||
758 | } while (ReadHeader()); | |
759 | } | |
38cf12f3 | 760 | |
9fc249d9 | 761 | void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level, |
762 | Int_t code, | |
38cf12f3 | 763 | const char *message) |
764 | { | |
765 | // Add a raw data error message to the list | |
766 | // of raw-data decoding errors | |
767 | if (fEventNumber < 0) { | |
38cf12f3 | 768 | return; |
769 | } | |
3aea4e5e | 770 | Int_t ddlId = GetEquipmentId(); |
38cf12f3 | 771 | if (ddlId < 0) { |
772 | AliError("No ddl raw data have been read so far! Impossible to add a raw data error log!"); | |
773 | return; | |
774 | } | |
775 | ||
79dac785 | 776 | Int_t prevEventNumber = -1; |
777 | Int_t prevDdlId = -1; | |
778 | Int_t prevErrorCode = -1; | |
779 | AliRawDataErrorLog *prevLog = (AliRawDataErrorLog *)fErrorLogs.Last(); | |
780 | if (prevLog) { | |
781 | prevEventNumber = prevLog->GetEventNumber(); | |
782 | prevDdlId = prevLog->GetDdlID(); | |
783 | prevErrorCode = prevLog->GetErrorCode(); | |
784 | } | |
785 | ||
786 | if ((prevEventNumber != fEventNumber) || | |
787 | (prevDdlId != ddlId) || | |
788 | (prevErrorCode != code)) { | |
789 | new (fErrorLogs[fErrorLogs.GetEntriesFast()]) | |
790 | AliRawDataErrorLog(fEventNumber, | |
791 | ddlId, | |
792 | level, | |
793 | code, | |
794 | message); | |
795 | } | |
796 | else | |
797 | if (prevLog) prevLog->AddCount(); | |
798 | ||
38cf12f3 | 799 | } |
66964465 | 800 | |
801 | Bool_t AliRawReader::GotoEventWithID(Int_t event, | |
802 | UInt_t period, | |
803 | UInt_t orbitID, | |
804 | UShort_t bcID) | |
805 | { | |
806 | // Go to certain event number by | |
807 | // checking the event ID. | |
808 | // Useful in case event-selection | |
809 | // is applied and the 'event' is | |
810 | // relative | |
811 | if (!GotoEvent(event)) return kFALSE; | |
812 | ||
813 | while (GetBCID() != period || | |
814 | GetOrbitID() != orbitID || | |
815 | GetPeriod() != bcID) { | |
816 | if (!NextEvent()) return kFALSE; | |
817 | } | |
818 | ||
819 | return kTRUE; | |
820 | } | |
821 |