Major update required to handle old and new AliHLTEventDDL structures within HLT...
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTRunSummaryProducerComponent.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   AliHLTRunSummaryProducerComponent.cxx
20     @author Jochen Thaeder
21     @date   
22     @brief  Produces a run summary as @see AliHLTRunSummary
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 "AliHLTRunSummaryProducerComponent.h"
36 #include "AliHLTEventSummary.h"
37 #include "AliHLTDataTypes.h"
38 #include "AliRawDataHeader.h"
39
40 #include <cerrno>
41
42 // ** This is a global object used for automatic component registration, do not use this
43 AliHLTRunSummaryProducerComponent gAliHLTRunSummaryProducerComponent;
44
45 ClassImp(AliHLTRunSummaryProducerComponent)
46     
47 // ------------------------------------------------------------------------------------------
48 AliHLTRunSummaryProducerComponent::AliHLTRunSummaryProducerComponent() : 
49   fRunSummary(NULL) {
50   // see header file for class documentation
51   // or
52   // refer to README to build package
53   // or
54   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 }
56
57 // ------------------------------------------------------------------------------------------
58 AliHLTRunSummaryProducerComponent::~AliHLTRunSummaryProducerComponent() {
59   // see header file for class documentation
60 }
61
62 // ------------------------------------------------------------------------------------------
63 const char* AliHLTRunSummaryProducerComponent::GetComponentID() {
64   // see header file for class documentation
65   return "TriggerRunSummaryProducer"; 
66 }
67
68 // ------------------------------------------------------------------------------------------
69 void AliHLTRunSummaryProducerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list) {
70   // see header file for class documentationAliHLTRunSummary
71
72   list.clear(); 
73   list.push_back( kAliHLTDataTypeEventSummary );
74   list.push_back( kAliHLTDataTypeRunStatistics );
75 }
76
77 // ------------------------------------------------------------------------------------------
78 AliHLTComponentDataType AliHLTRunSummaryProducerComponent::GetOutputDataType() {
79   // see header file for class documentation
80
81   return kAliHLTDataTypeRunSummary;
82 }
83
84 // ------------------------------------------------------------------------------------------
85 void AliHLTRunSummaryProducerComponent::GetOutputDataSize( unsigned long& constBase, 
86                                                            double& inputMultiplier ) {
87   // see header file for class documentation
88
89   constBase = sizeof( AliHLTRunSummary );
90   inputMultiplier = 0.0;
91 }
92
93 // ------------------------------------------------------------------------------------------
94 AliHLTComponent* AliHLTRunSummaryProducerComponent::Spawn() {
95   // Spawn function, return new instance of this class
96   // see header file for class documentation
97
98   return new AliHLTRunSummaryProducerComponent;
99 }
100
101
102 // ------------------------------------------------------------------------------------------
103 Int_t AliHLTRunSummaryProducerComponent::DoInit( int /*argc*/, const char** /*argv*/ ) {
104   // see header file for class documentation
105
106   Int_t iResult = 0;
107
108   if ( fRunSummary )
109     return EINPROGRESS;
110   
111   fRunSummary = new AliHLTRunSummary();
112   
113   return iResult;
114 }
115
116 // ------------------------------------------------------------------------------------------
117 Int_t AliHLTRunSummaryProducerComponent::DoDeinit() {
118   // see header file for class documentation
119
120   if ( fRunSummary )
121     delete fRunSummary;
122   fRunSummary = NULL;
123
124   return 0; 
125 }
126
127 // ------------------------------------------------------------------------------------------
128 Int_t AliHLTRunSummaryProducerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& trigData ) {
129   // see header file for class documentation
130
131   // ** Process EventSummary Block
132   AliHLTEventSummary* eventSummary = (AliHLTEventSummary*) GetFirstInputObject ( kAliHLTDataTypeEventSummary, "AliHLTEventSummary" );
133   
134   if ( eventSummary ) 
135     ProcessEventSummary ( eventSummary );   
136
137   // ** Increase Number of Events
138   fRunSummary->AddNEvents();
139
140   // ** Process CTP trigger information
141   ProcessTriggerData( trigData );
142
143   // ** Set RunType / Run Number
144   fRunSummary->SetRunNumber ( GetRunNo() );
145   fRunSummary->SetRunType   ( GetRunType() );
146
147   // ** PushBack Run Summary
148   PushBack ( (TObject*) fRunSummary, sizeof(AliHLTRunSummary), kAliHLTDataTypeRunSummary, (AliHLTUInt32_t) 0 );
149
150   return 0;
151 }
152
153 // -- **********************************************************************************************
154 // -- *******************************   Processing Functions  **************************************
155 // -- **********************************************************************************************
156
157 // -- **********************************************************************************************
158 void AliHLTRunSummaryProducerComponent::ProcessEventSummary( AliHLTEventSummary* eventSummary ) {
159   // see header file for class documentation
160   
161   // ** Check if event was accepted or rejected 
162   if ( ! eventSummary->IsAccepted() )
163     fRunSummary->AddNEventsRejected();
164 }
165
166 // -- **********************************************************************************************
167 void AliHLTRunSummaryProducerComponent::ProcessTriggerData( AliHLTComponentTriggerData& trigData ) {
168   // see header file for class documentation
169   
170   const AliRawDataHeader* cdh = NULL;
171   if (AliHLTComponent::ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true) != 0) return;
172   AliHLTUInt64_t triggerClasses = cdh->GetTriggerClasses();
173
174   for ( Int_t ndx = 0; ndx < gkNCTPTriggerClasses; ndx ++ ) {
175     
176     if ( triggerClasses & 0x1 )
177       fRunSummary->AddTriggerClass( ndx );
178     
179     triggerClasses = triggerClasses >> 1;
180   }
181
182 }
183