3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTGlobalDCSPublisherComponent.cxx
20 @author Matthias Richter
22 @brief DIM publisher component for global HLT data
25 #include "AliHLTGlobalDCSPublisherComponent.h"
26 #include "AliHLTDimServer.h"
27 #include "AliESDVertex.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTGlobalDCSPublisherComponent)
37 AliHLTGlobalDCSPublisherComponent::AliHLTGlobalDCSPublisherComponent()
43 , fEventBufferSize(1000)
48 , fDimServiceEventCount(NULL)
50 // see header file for class documentation
52 // refer to README to build package
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55 for (int i=0; i<kLastService; i++) fDimServices[i]=NULL;
58 const char* AliHLTGlobalDCSPublisherComponent::fgkServiceNames[kLastService]= {
67 AliHLTGlobalDCSPublisherComponent::~AliHLTGlobalDCSPublisherComponent()
69 // see header file for class documentation
71 // file list and file name list are owner of their objects and
72 // delete all the objects
75 const char* AliHLTGlobalDCSPublisherComponent::GetComponentID()
77 // see header file for class documentation
78 return "DCSPublisher";
81 void AliHLTGlobalDCSPublisherComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
83 // see header file for class documentation
85 list.push_back(kAliHLTAnyDataType);
88 AliHLTComponent* AliHLTGlobalDCSPublisherComponent::Spawn()
90 // see header file for class documentation
91 return new AliHLTGlobalDCSPublisherComponent;
94 int AliHLTGlobalDCSPublisherComponent::DoInit( int argc, const char** argv )
96 // see header file for class documentation
98 iResult=ConfigureFromArgumentString(argc, argv);
100 fpServer=new AliHLTDimServer(fServerName.c_str());
101 if (!fpServer) return -ENOMEM;
102 if ((iResult=fpServer->Init(fDimdns.c_str()))>=0) {
104 for (int service=0; service<kLastService; service++) {
105 fDimServices[service]=fpServer->CreateService(AliHLTDimServer::kDataTypeFloat, fgkServiceNames[service]);
107 fDimServiceEventCount=fpServer->CreateService(AliHLTDimServer::kDataTypeInt, "EventCount");
109 // now start the server
110 iResult=fpServer->Start();
114 for (int i=0; i<kDimensions; i++)
115 Reset(fEventBuffers[i], fEventBufferSize);
120 int AliHLTGlobalDCSPublisherComponent::ScanConfigurationArgument(int argc, const char** argv)
122 // see header file for class documentation
125 if (argc==0) return 0;
127 TString argument=argv[0];
128 if (argument.CompareTo("-servername")==0) {
129 if (++i>=argc) return -EPROTO;
135 if (argument.CompareTo("-dimdns")==0) {
136 if (++i>=argc) return -EPROTO;
141 // TODO: further options for tracklet cut and event buffer size
146 int AliHLTGlobalDCSPublisherComponent::DoDeinit()
148 // see header file for class documentation
151 // just wait a few seconds to get the updated services through before
152 // terminating the server
153 gSystem->Sleep(fUpdatePeriod<30?fUpdatePeriod:30);
155 if (!fpServer) return -ENODEV;
160 // TODO: proper cleanup of services objects to be synchronized with
166 int AliHLTGlobalDCSPublisherComponent::DumpEvent( const AliHLTComponentEventData& /*evtData*/,
167 AliHLTComponentTriggerData& /*trigData*/ )
169 // see header file for class documentation
170 if (!IsDataEvent()) return 0;
173 for (const TObject* pObject=GetFirstInputObject(kAliHLTDataTypeESDVertex);
175 pObject=GetNextInputObject()) {
176 const AliESDVertex* pVertex=dynamic_cast<const AliESDVertex*>(pObject);
177 if (pVertex && pVertex->GetNContributors()>=5) {
178 (fEventBuffers[kVertexX])[fPosition%fEventBuffers[kVertexX].size()]=pVertex->GetX();
179 (fEventBuffers[kVertexY])[fPosition%fEventBuffers[kVertexY].size()]=pVertex->GetY();
180 (fEventBuffers[kVertexZ])[fPosition%fEventBuffers[kVertexZ].size()]=pVertex->GetZ();
186 if ((time.Get()-fLastUpdate>fUpdatePeriod) && fPosition>0) {
187 fLastUpdate=time.Get();
193 int AliHLTGlobalDCSPublisherComponent::Publish(bool reset)
195 // publish the values to DCS
196 float mean[kDimensions];
197 float rms[kDimensions];
198 for (int dimension=0; dimension<kDimensions; dimension++) {
199 mean[dimension]= Mean(fEventBuffers[dimension], fPosition);
200 rms[dimension] = Rms(fEventBuffers[dimension], mean[dimension], fPosition);
201 ((AliHLTDimServer::AliHLTDimServiceFloat*)fDimServices[dimension])->Update(mean[dimension]);
202 ((AliHLTDimServer::AliHLTDimServiceFloat*)fDimServices[dimension+kDimensions])->Update(rms[dimension]);
204 ((AliHLTDimServer::AliHLTDimServiceInt*)fDimServiceEventCount)->Update(fPosition<fEventBufferSize?fPosition:fEventBufferSize);
206 HLTInfo("Vertex from %d samples: X:Y:Z Mean %f:%f:%f RMS %f:%f:%f",
207 fPosition<fEventBufferSize?fPosition:fEventBufferSize,
208 mean[kVertexX], mean[kVertexY], mean[kVertexZ],
209 rms[kVertexX], rms[kVertexY], rms[kVertexZ]
213 for (int i=0; i<kDimensions; i++)
214 Reset(fEventBuffers[i], fEventBufferSize);
221 void AliHLTGlobalDCSPublisherComponent::Reset(vector<float>& sample, int size) const
223 // reset the event buffer
224 if (size>0) sample.resize(size);
225 fill(sample.begin(), sample.end(), 0.0);
228 template <class T> T AliHLTGlobalDCSPublisherComponent::Mean(const vector<T>& sample, int count) const
230 // calculate mean of the event buffer
231 int samplesize=count<(int)sample.size()?count:sample.size();
232 if (samplesize==0) return 0.0;
233 T sum=std::accumulate(sample.begin(), sample.begin()+samplesize, (T)0, std::plus<T>());
234 return sum/samplesize;
237 template <class T> T AliHLTGlobalDCSPublisherComponent::Rms(const vector<T>& sample, T mean, int count) const
239 // calculate sigma of the event buffer
240 int samplesize=count<(int)sample.size()?count:sample.size();
241 if (samplesize==0) return 0.0;
242 T msd=std::accumulate(sample.begin(), sample.begin()+samplesize, (T)0, MeanSqtOp<T>(mean))/samplesize;
243 if (msd<0.00000001) return 0.0;
244 return TMath::Sqrt(msd);