]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/util/AliHLTReadoutListDumpComponent.cxx
Preparing the RootSchemaEvolutionComponent to run at 2kHz
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTReadoutListDumpComponent.cxx
CommitLineData
209986b4 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT Project. *
9//* *
10//* Permission to use, copy, modify and distribute this software and its *
11//* documentation strictly for non-commercial purposes is hereby granted *
12//* without fee, provided that the above copyright notice appears in all *
13//* copies and that both the copyright notice and this permission notice *
14//* appear in the supporting documentation. The authors make no claims *
15//* about the suitability of this software for any purpose. It is *
16//* provided "as is" without express or implied warranty. *
17//**************************************************************************
18
19/** @file AliHLTReadoutListDumpComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief Base class for writer components to store data in a ROOT file
23
24 */
25
26#include "AliHLTReadoutListDumpComponent.h"
27#include "AliHLTTriggerDecision.h"
28#include "AliHLTCTPData.h"
29#include "TH1I.h"
30#include "TH2I.h"
31#include "TString.h"
32#include "TFile.h"
33#include "TSystem.h"
34
35/** ROOT macro for the implementation of ROOT specific class methods */
36ClassImp(AliHLTReadoutListDumpComponent)
37
38AliHLTReadoutListDumpComponent::AliHLTReadoutListDumpComponent()
39 : AliHLTFileWriter()
40 , fMode(AliHLTReadoutListDumpComponent::kModeBinaryList)
41 , fBitsHisto(NULL)
42 , fBitsVsCTP(NULL)
43{
44 // see header file for class documentation
45 // or
46 // refer to README to build package
47 // or
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49}
50
51AliHLTReadoutListDumpComponent::~AliHLTReadoutListDumpComponent()
52{
53 // see header file for class documentation
54}
55
56int AliHLTReadoutListDumpComponent::InitWriter()
57{
58 // see header file for class documentation
59 int iResult=0;
60 fBitsHisto=CreateReadoutListHistogram();
61 fBitsVsCTP=CreateReadoutListVsCTPHistogram();
62 if (!fBitsHisto || !fBitsVsCTP) return -ENOMEM;
63
64 return iResult;
65}
66
67int AliHLTReadoutListDumpComponent::CloseWriter()
68{
69 // see header file for class documentation
70 TString filename=GetDirectory();
71 if (!filename.IsNull() && !filename.EndsWith("/")) filename+="/";
72 filename+=fBitsHisto->GetName();
73 filename+="_";
74 filename+=GetRunNo();
75 filename+=".root";
76
77 TFile out(filename, "RECREATE");
78 fBitsHisto->Write();
79 fBitsVsCTP->Write();
80 out.Close();
81
82 delete fBitsHisto;
83 fBitsHisto=NULL;
84 delete fBitsVsCTP;
85 fBitsVsCTP=NULL;
86 return 0;
87}
88
89int AliHLTReadoutListDumpComponent::DumpEvent( const AliHLTComponentEventData& /*evtData*/,
90 const AliHLTComponentBlockData* /*blocks*/,
91 AliHLTComponentTriggerData& trigData )
92{
93 // see header file for class documentation
94 int iResult=0;
95 if (!IsDataEvent()) return 0;
96
97 if (fMode==AliHLTReadoutListDumpComponent::kModeBinaryList) {
98 const AliHLTComponentDataType hltrdlstdt=AliHLTComponentDataTypeInitializer("HLTRDLST", "HLT ");
99 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
100 pBlock && iResult>=0;
101 pBlock=GetNextInputBlock()) {
102 if (pBlock->fDataType!=hltrdlstdt) continue;
89413559 103 if (pBlock->fSize==sizeof(AliHLTEventDDL) or pBlock->fSize==sizeof(AliHLTEventDDLV0)) {
209986b4 104 HLTDebug("Filling histograms from binary buffer");
89413559 105 AliHLTReadoutList readoutlist(*reinterpret_cast<AliHLTEventDDL*>(pBlock->fPtr));
106 FillReadoutListHistogram(fBitsHisto, &readoutlist);
107 FillReadoutListVsCTP(fBitsVsCTP, &readoutlist, &trigData);
209986b4 108 } else {
89413559 109 HLTError("HLTRDLST size missmatch: %d, expected %d or %d", pBlock->fSize, sizeof(AliHLTEventDDL), sizeof(AliHLTEventDDLV0));
209986b4 110 }
111 }
112 } else if (fMode==AliHLTReadoutListDumpComponent::kModeHLTDecision) {
113 for (const TObject* pObject=GetFirstInputObject();
114 pObject && iResult>=0;
115 pObject=GetNextInputObject()) {
116 const AliHLTTriggerDecision* pDecision=dynamic_cast<const AliHLTTriggerDecision*>(pObject);
117 if (!pDecision) continue;
118
119 AliHLTReadoutList list=pDecision->ReadoutList();
120 HLTDebug("Filling histograms from HLT decision object");
121 FillReadoutListHistogram(fBitsHisto, &list);
122 FillReadoutListVsCTP(fBitsVsCTP, &list, &trigData);
123 }
124 } else {
125 HLTError("invalid mode %d", fMode);
126 iResult=-EFAULT;
127 }
128 return iResult;
129}
130
131int AliHLTReadoutListDumpComponent::ScanArgument(int argc, const char** argv)
132{
133 // see header file for class documentation
134 int iResult=-EINVAL;
135 if (argc<=0) return 0;
136 int i=0;
137 TString argument=argv[i];
138
139 // -binary
140 if (argument.CompareTo("-binary")==0) {
141 fMode=AliHLTReadoutListDumpComponent::kModeBinaryList;
142 return 1;
143 }
144
145 // -decision
146 if (argument.CompareTo("-decision")==0) {
147 fMode=AliHLTReadoutListDumpComponent::kModeHLTDecision;
148 return 1;
149 }
150
151 return iResult;
152}
153
154TH1I* AliHLTReadoutListDumpComponent::CreateReadoutListHistogram()
155{
156 // see header file for class documentation
157 int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8;
158 TH1I* histo=new TH1I("HLTRDLST","HLT readout list", bins, 0, bins);
159 return histo;
160}
161
162TH2I* AliHLTReadoutListDumpComponent::CreateReadoutListVsCTPHistogram()
163{
164 // see header file for class documentation
165 int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8;
166 TH2I* histo=new TH2I("HLTRDLSTvsCTP","HLT readout list vs. CTP trigger", bins, 0, bins, gkNCTPTriggerClasses, 0, gkNCTPTriggerClasses);
167 return histo;
168}
169
170int AliHLTReadoutListDumpComponent::FillReadoutListHistogram(TH1I* histo, const AliHLTReadoutList* list)
171{
172 // see header file for class documentation
173 if (!histo || !list) return -EINVAL;
8fab602c 174 if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF;
89413559 175 if (list->Buffer()->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF;
209986b4 176
177 for (int word=0; word<gkAliHLTDDLListSize; word++) {
178 for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) {
89413559 179 if (list->Buffer()->fList[word]&0x1<<bit) histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit);
209986b4 180 }
181 }
89413559 182
209986b4 183 return 0;
184}
185
186int AliHLTReadoutListDumpComponent::FillReadoutListVsCTP(TH2I* histo, const AliHLTReadoutList* list, const AliHLTComponentTriggerData* trigData)
187{
188 // see header file for class documentation
189 if (!histo || !list || !trigData) return -EINVAL;
8fab602c 190 if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF;
89413559 191 if (list->Buffer()->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF;
209986b4 192
193 AliHLTUInt64_t triggerMask=AliHLTCTPData::ActiveTriggers(*trigData);
194 AliHLTUInt64_t bit0=0x1;
195 for (int word=0; word<gkAliHLTDDLListSize; word++) {
196 for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) {
89413559 197 if (list->Buffer()->fList[word]&0x1<<bit) {
209986b4 198 for (int trigger=0; trigger<gkNCTPTriggerClasses; trigger++) {
199 if ((triggerMask&(bit0<<trigger))!=0) {
200 histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit, trigger);
201 }
202 }
203 }
204 }
205 }
206
207 return 0;
208}