]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerSelectiveReadoutComponent.cxx
Another try to get the last commit working...
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerSelectiveReadoutComponent.cxx
1 //-*- Mode: C++ -*-
2 // $Id$
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: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>        *
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   AliHLTTriggerSelectiveReadoutComponent.cxx
20     @author Jochen Thaeder
21     @date   
22     @brief  Component for the Selective Readout Trigger
23 */
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
30
31 #if __GNUC__ >= 3
32 using namespace std;
33 #endif
34
35 #include "AliHLTTriggerSelectiveReadoutComponent.h"
36 #include "AliHLTTPCDefinitions.h"
37
38 #include "TMath.h"
39
40 #include <cstdlib>
41 #include <cerrno>
42
43
44 // ** This is a global object used for automatic component registration, do not use this
45 AliHLTTriggerSelectiveReadoutComponent gAliHLTTriggerSelectivereadoutComponent;
46
47 ClassImp(AliHLTTriggerSelectiveReadoutComponent)
48     
49 AliHLTTriggerSelectiveReadoutComponent::AliHLTTriggerSelectiveReadoutComponent() :
50   fDetector(),
51   fEnableThresholdSize(kFALSE) {
52   // see header file for class documentation
53   // or
54   // refer to README to build package
55   // or
56   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57
58   memset( fThreshold, 0, (fkNThreshold * sizeof(AliHLTUInt32_t)) );
59 }
60
61 AliHLTTriggerSelectiveReadoutComponent::~AliHLTTriggerSelectiveReadoutComponent() {
62   // see header file for class documentation
63 }
64
65 // Public functions to implement AliHLTComponent's interface.
66 // These functions are required for the registration process
67
68 const char* AliHLTTriggerSelectiveReadoutComponent::GetComponentID() {
69   // see header file for class documentation
70   return "TriggerSelectiveReadout"; 
71 }
72
73 void AliHLTTriggerSelectiveReadoutComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) {
74   // see header file for class documentation
75
76   list.clear(); 
77   list.push_back( kAliHLTDataTypeDDLRaw );
78 }
79
80 AliHLTComponentDataType AliHLTTriggerSelectiveReadoutComponent::GetOutputDataType() {
81   // see header file for class documentation
82
83   return kAliHLTMultipleDataType;
84 }
85
86 Int_t AliHLTTriggerSelectiveReadoutComponent::GetOutputDataTypes( AliHLTComponentDataTypeList& tgtList) {
87   // see header file for class documentation
88
89   tgtList.clear(); 
90   tgtList.push_back( kAliHLTDataTypeDDLRaw );
91   tgtList.push_back( kAliHLTDataTypeDDL );
92   return tgtList.size();
93 }
94
95 void AliHLTTriggerSelectiveReadoutComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
96   // see header file for class documentation
97
98   constBase = sizeof( AliHLTEventDDL );
99   inputMultiplier = 0.0;
100 }
101
102 // Spawn function, return new instance of this class
103 AliHLTComponent* AliHLTTriggerSelectiveReadoutComponent::Spawn() {
104   // see header file for class documentation
105
106   return new AliHLTTriggerSelectiveReadoutComponent;
107 }
108
109 Int_t AliHLTTriggerSelectiveReadoutComponent::DoInit( int argc, const char** argv ) {
110   // see header file for class documentation
111     
112   Int_t iResult = 0;
113   TString argument = "";
114   TString parameter = "";
115   Int_t bMissingParam=0;
116   
117   for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
118   
119     argument = argv[ii];
120
121     if ( argument.IsNull() ) continue;
122
123     // -detector
124     if ( ! argument.CompareTo("-detector") ) {
125
126       if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
127       
128       fDetector = argv[ii];  
129       fDetector.Remove(TString::kLeading, ' ');
130       fDetector.Resize(4);
131
132       HLTInfo( "Detector has been set to '%s'.", fDetector.Data() );
133     }
134     
135     // -enableThreshold
136     else if ( ! argument.CompareTo("-enableThreshold") ) {
137
138       if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
139
140       parameter = argv[ii];  
141       parameter.Remove( TString::kLeading, ' ' );
142       
143       if ( ! parameter.CompareTo("size") ) {
144         fEnableThresholdSize = kTRUE;
145         HLTInfo( "Threshold on data 'size' has been enabled." );
146       }
147       else {
148         HLTError( "This threshold '%s' has not been implemented.", parameter.Data() );
149         iResult = -EPROTO;
150       }
151     } 
152
153     // -threshold
154     else if ( ! argument.CompareTo("-threshold") ) {
155
156       if ( ( bMissingParam=( ++ii >= argc ) ) ) break;
157
158       Int_t jj = 0;
159       
160       for ( jj = 0; ( jj < fkNThreshold ) && ( ( ii + jj ) < argc ); jj++ ) {
161         
162         parameter = argv[ii+jj];  
163         parameter.Remove( TString::kLeading, ' ' );
164
165         if ( parameter.BeginsWith( '-' ) ) break;
166     
167         if  (parameter.IsDigit() ) {
168           fThreshold[jj] = (AliHLTUInt32_t) parameter.Atoi();
169           HLTInfo( "Threshold for %d  is set to %d.", jj, fThreshold[jj] );
170         } 
171         else {
172           HLTError( "Cannot convert %d. threshold  specifier '%s'.", jj, parameter.Data() );
173           iResult = -EINVAL;
174           break;
175         }
176       } // for ( jj ; ( jj < fkNThreshold ) && ( ( ii + jj ) < argc ); jj++ ) {
177       
178       ii += --jj;
179     } 
180     
181     // - unknow parameter
182     else {
183       iResult = -EINVAL;
184       HLTError("Unknown argument '%s'", argument.Data() );
185     }
186
187   } // for ( Int_t ii=0; ii<argc && iResult>=0; ii++ ) {
188
189   if ( bMissingParam ) {
190     HLTError( "Missing parameter for argument '%s'.", argument.Data() );
191     iResult = -EPROTO;
192   }
193
194   if ( fDetector.IsNull() ) { 
195     HLTError( "No Detector has been supplied, this is mandatory." );
196     iResult = -EPROTO;
197   }
198
199   return iResult;
200 }
201     
202
203 Int_t AliHLTTriggerSelectiveReadoutComponent::DoDeinit() {
204   // see header file for class documentation
205
206   return 0;
207 }
208
209 Int_t AliHLTTriggerSelectiveReadoutComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) {
210   // see header file for class documentation
211
212   // ** No readout list for SOR and EOR event
213   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
214     return 0;
215   
216   // ** Create empty Readoutlist
217   AliHLTEventDDL readoutList;
218   memset( &readoutList, 0, sizeof(AliHLTEventDDL) );
219
220   const AliHLTComponentBlockData* iter = NULL;
221   Int_t ddlId = 0;
222   AliHLTUInt8_t patch = 0;
223
224   // ** Loop over all input blocks and specify which data format should be read - only select Raw Data
225   for ( iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|fDetector.Data()); iter != NULL; iter = GetNextInputBlock() ) {
226     
227     // ** Check if block has only the CDH Header ( 32 Bytes = gkAliHLTCommonHeaderCount *sizeof(AliHLTUInt32_t) )
228     if ( iter->fSize <= ( gkAliHLTCommonHeaderCount * sizeof(AliHLTUInt32_t) ) ) {
229       continue;
230     }
231
232     //
233     // ** Check for detector specifications
234     //
235
236     // ** Check for TPC specifc specification
237     if ( ! fDetector.CompareTo("TPC ") ) {
238       // ** Get DDL ID
239       AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
240       patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
241       if (patch < 2) ddlId = 768 + (2 * slice) + patch;
242       else ddlId = 838 + (4*slice) + patch;
243       HLTDebug ( "Input Data - TPC - Slice/Patch: %d/%d - EquipmentID : %d.", slice, patch, ddlId );
244     } // if ( ! fDetector.CompareTo("TPC ") ) {
245     
246     // ** Check for other detector specifc specification
247     else {
248       HLTError("Detector '%s' has not been implemented yet.", fDetector.Data() );
249       continue;
250     }
251
252     //
253     // ** Check if threshold should be considerd
254     //
255
256     if ( fEnableThresholdSize ) {
257       // ** Check for TPC threshold
258       if ( ! fDetector.CompareTo("TPC ") ) {
259         if ( patch < fkNThreshold ){ 
260           // ** if datablock to big, do not put it in HLT readout, enable for DAQ readout
261           if ( ( fThreshold[patch] !=0 ) && ( iter->fSize > fThreshold[patch] ) ) {
262             EnableDDLBit( readoutList, ddlId ); 
263             HLTDebug ( "DDL Id %d enabled for DAQ readout - size %d > threshold %d.", ddlId, iter->fSize, fThreshold[patch] );
264             continue;
265           }
266         }
267       } // if ( ! fDetector.CompareTo("TPC ") ) {
268       
269       // ** Check for other detector threshold
270       else
271         HLTError("Check for size threshold as not been implemented yet for Detector '%s'.", fDetector.Data() );
272       
273     } // if ( fEnableThresholdSize ) {
274  
275     //
276     // ** PushForward data block
277     //
278     
279     PushBack( iter->fPtr , iter->fSize, iter->fDataType, iter->fSpecification);
280       
281   } //  for ( iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|fDetector.Data()); iter != NULL; iter = GetNextInputBlock() ) {
282   
283   //
284   // ** PushBack readout list
285   //
286   
287   PushBack( &readoutList, sizeof(AliHLTEventDDL), kAliHLTDataTypeDDL, (AliHLTUInt32_t) 0 );
288
289   return 0;
290 }