]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/comp/AliHLTTPCDataCompressionFilterComponent.cxx
Fixing trigg.class issue
[u/mrichter/AliRoot.git] / HLT / TPCLib / comp / AliHLTTPCDataCompressionFilterComponent.cxx
1 // $Id$
2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project        * 
4 //* ALICE Experiment at CERN, All rights reserved.                         *
5 //*                                                                        *
6 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
7 //*                  for The ALICE HLT Project.                            *
8 //*                                                                        *
9 //* Permission to use, copy, modify and distribute this software and its   *
10 //* documentation strictly for non-commercial purposes is hereby granted   *
11 //* without fee, provided that the above copyright notice appears in all   *
12 //* copies and that both the copyright notice and this permission notice   *
13 //* appear in the supporting documentation. The authors make no claims     *
14 //* about the suitability of this software for any purpose. It is          *
15 //* provided "as is" without express or implied warranty.                  *
16 //**************************************************************************
17
18 /// @file   AliHLTTPCDataCompressionFilterComponent.cxx
19 /// @author Matthias Richter
20 /// @date   2011-08-08
21 /// @brief  TPC component for data compression
22 ///
23
24 #include "AliHLTTPCDataCompressionFilterComponent.h"
25 #include "AliHLTTPCDefinitions.h"
26 #include "AliHLTPluginBase.h"
27 #include "AliHLTSystem.h"
28 #include "AliHLTOUT.h"
29 #include "AliLog.h"
30
31 ClassImp(AliHLTTPCDataCompressionFilterComponent)
32
33 AliHLTTPCDataCompressionFilterComponent::AliHLTTPCDataCompressionFilterComponent()
34   : AliHLTProcessor()
35 {
36 }
37
38 AliHLTTPCDataCompressionFilterComponent::~AliHLTTPCDataCompressionFilterComponent()
39 {
40   /// destructor
41 }
42
43
44 const char* AliHLTTPCDataCompressionFilterComponent::GetComponentID()
45 {
46   /// inherited from AliHLTComponent: id of the component
47   return "TPCDataCompressorFilter";
48 }
49
50
51 void AliHLTTPCDataCompressionFilterComponent::GetInputDataTypes( AliHLTComponentDataTypeList& tgtList)
52 {
53   /// inherited from AliHLTComponent: list of data types in the vector reference
54   tgtList.clear();
55   tgtList.push_back(AliHLTTPCDefinitions::RemainingClustersCompressedDataType());
56   tgtList.push_back(AliHLTTPCDefinitions::RemainingClusterIdsDataType());
57 }
58
59 AliHLTComponentDataType AliHLTTPCDataCompressionFilterComponent::GetOutputDataType()
60 {
61   /// inherited from AliHLTComponent: output data type of the component.
62   return kAliHLTMultipleDataType;
63 }
64
65 int AliHLTTPCDataCompressionFilterComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
66 {
67   /// inherited from AliHLTComponent: multiple output data types of the component.
68   tgtList.clear();
69   tgtList.push_back(AliHLTTPCDefinitions::RemainingClustersCompressedDataType());
70   tgtList.push_back(AliHLTTPCDefinitions::RemainingClusterIdsDataType());
71   return tgtList.size();
72 }
73
74 void AliHLTTPCDataCompressionFilterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
75 {
76   /// inherited from AliHLTComponent: output data size estimator
77   constBase=0;
78   inputMultiplier=1.;  // there should not be more data than input
79 }
80
81 AliHLTComponent* AliHLTTPCDataCompressionFilterComponent::Spawn()
82 {
83   /// inherited from AliHLTComponent: spawn function.
84   return new AliHLTTPCDataCompressionFilterComponent;
85 }
86
87 int AliHLTTPCDataCompressionFilterComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, 
88                                                 AliHLTComponentTriggerData& /*trigData*/)
89 {
90   /// inherited from AliHLTProcessor: data processing
91   if (!IsDataEvent()) return 0;
92
93   if (GetFirstInputBlock(AliHLTTPCDefinitions::ClusterTracksCompressedDataType())!=NULL) {
94     // This component is only used in conjunction with an emulation chain for compressed
95     // partition cluster blocks. Blocks which are missing in HLTOUT but are existing in
96     // the data stream from the parent, are forwarded. This scheme allows to automatically
97     // create missing partitions in the compressed data from raw data (e.g. if an input
98     // link of the HLT is broken and raw data recorded), and add it to the HLTOUT to
99     // have a consistent data set. This requires individual cluster data blocks, track
100     // model compression can not be used in the emulation because the clusters can not be
101     // related to a particular partition.
102     AliFatalClass("compressed track cluster data blocks can not be mixed. aborting");
103     return -EBADF;
104   }
105
106   std::map<AliHLTUInt32_t, bool> hltoutmap;
107   bool bHaveMap=false;
108
109   for (const AliHLTComponentBlockData* pDesc=GetFirstInputBlock(AliHLTTPCDefinitions::RemainingClustersCompressedDataType());
110        pDesc!=NULL; pDesc=GetNextInputBlock()) {
111     if (!bHaveMap) {
112       InitMapFromHLTOUT(hltoutmap);
113       bHaveMap=true;
114     }
115     if (hltoutmap.find(pDesc->fSpecification)!=hltoutmap.end()) {
116       // block existing in HLTOUT
117       continue;
118     }
119     Forward(pDesc);
120     HLTInfo("inserting block 0x%08x", pDesc->fSpecification);
121   }
122
123   return 0;
124 }
125
126 int AliHLTTPCDataCompressionFilterComponent::InitMapFromHLTOUT(std::map<AliHLTUInt32_t, bool>& hltoutmap)
127 {
128   // check the HLTOUT for availability of compressed data blocks
129   AliHLTSystem* pSystem=AliHLTPluginBase::GetInstance();
130   if (!pSystem) {
131     // global system not initialized
132     return -ENODEV;
133   }
134   AliHLTOUT* pHLTOUT=pSystem->RequestHLTOUT();
135   if (!pHLTOUT) {
136     // not HLTOUT, hence not clusters
137     return 0;
138   }
139
140   for (bool bNextBlock=(pHLTOUT->SelectFirstDataBlock(AliHLTTPCDefinitions::RemainingClustersCompressedDataType())>=0);
141        bNextBlock; bNextBlock=(pHLTOUT->SelectNextDataBlock()>=0)) {
142     AliHLTComponentDataType dt=kAliHLTVoidDataType;
143     AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
144     if (pHLTOUT->GetDataBlockDescription(dt, spec)<0)
145       continue;
146
147     hltoutmap[spec]=true;
148   }
149
150   for (bool bNextBlock=(pHLTOUT->SelectFirstDataBlock(AliHLTTPCDefinitions::ClusterTracksCompressedDataType())>=0);
151        bNextBlock; bNextBlock=(pHLTOUT->SelectNextDataBlock()>=0)) {
152     // the first version of this component will not implement support for track model compression data blocks
153     // to implement it
154     // - decode data
155     // - sort into index grid
156     // - check if there is at least one cluster in a partition, that is a sufficient condition
157     //   to decide whether a partition was included or not
158     // The best would be to implement a class which supports the AliHLTTPCDataCompressionDecoder
159     // interface and stores unpacked data in AliHLTTPCRawCluster format and fills the index
160     // grid at the same time
161     AliFatalClass("this functionality needs to be implemented");
162   }
163     
164   return 0;
165 }
166
167 int AliHLTTPCDataCompressionFilterComponent::DoInit( int argc, const char** argv )
168 {
169   /// inherited from AliHLTComponent: component initialisation and argument scan.
170   int iResult=0;
171
172   // component configuration
173   //Stage 1: default initialization.
174   //No default values until now.
175
176   //Stage 2: OCDB. - disabled
177   //TString cdbPath("HLT/ConfigTPC/");
178   //cdbPath += GetComponentID();
179   //
180   //iResult = ConfigureFromCDBTObjString(cdbPath);
181   //if (iResult < 0) 
182   //  return iResult;
183
184   //Stage 3: command line arguments.
185   if (argc && (iResult = ConfigureFromArgumentString(argc, argv)) < 0)
186     return iResult;
187
188   return iResult;
189 }
190
191 int AliHLTTPCDataCompressionFilterComponent::DoDeinit()
192 {
193   /// inherited from AliHLTComponent: component cleanup
194   int iResult=0;
195
196   return iResult;
197 }
198
199 int AliHLTTPCDataCompressionFilterComponent::ScanConfigurationArgument(int argc, const char** argv)
200 {
201   /// inherited from AliHLTComponent: argument scan
202   int iResult=0;
203   if (argc<1) return 0;
204   int bMissingParam=0;
205   int i=0;
206   TString argument=argv[i];
207
208   do {
209     // -mode
210     if (argument.CompareTo("-mode")==0) {
211       if ((bMissingParam=(++i>=argc))) break;
212       TString parameter=argv[i];
213       if (parameter.IsDigit()) {
214
215         return 2;
216       } else {
217         HLTError("invalid parameter for argument %s, expecting number instead of %s", argument.Data(), parameter.Data());
218         return -EPROTO;
219       }
220     }
221
222   } while (0); // using do-while only to have break available
223
224   if (bMissingParam) {
225     HLTError("missing parameter for argument %s", argument.Data());
226     iResult=-EPROTO;
227   }
228
229   return iResult;
230 }