]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTRootSchemaEvolutionComponent.cxx
1e628a6ac81c17f15ea6781f107e2dfaf395e10d
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTRootSchemaEvolutionComponent.cxx
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   AliHLTRootSchemaEvolutionComponent.cxx
20     @author Matthias Richter
21     @date   2009-10-18
22     @brief  Handler component for ROOT schema evolution of streamed objects
23 */
24
25 #include "AliHLTRootSchemaEvolutionComponent.h"
26 #include "AliHLTMessage.h"
27 #include "TObjArray.h"
28 #include "TStreamerInfo.h"
29 #include "TList.h"
30
31 /** ROOT macro for the implementation of ROOT specific class methods */
32 ClassImp(AliHLTRootSchemaEvolutionComponent)
33
34 AliHLTRootSchemaEvolutionComponent::AliHLTRootSchemaEvolutionComponent()
35   : AliHLTProcessor()
36   , fFlags(0)
37   , fpStreamerInfos(NULL)
38   , fFXSPrescaler(0)
39 {
40   // see header file for class documentation
41   // or
42   // refer to README to build package
43   // or
44   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
45
46 }
47 const char* AliHLTRootSchemaEvolutionComponent::fgkConfigurationObject=NULL;
48
49 AliHLTRootSchemaEvolutionComponent::~AliHLTRootSchemaEvolutionComponent()
50 {
51   // see header file for class documentation
52   if (fpStreamerInfos) {
53     fpStreamerInfos->Clear();
54     delete fpStreamerInfos;
55   }
56   fpStreamerInfos=NULL;
57 }
58
59 void AliHLTRootSchemaEvolutionComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
60 {
61   // see header file for class documentation
62   list.push_back(kAliHLTAnyDataType);
63 }
64
65 AliHLTComponentDataType AliHLTRootSchemaEvolutionComponent::GetOutputDataType()
66 {
67   // see header file for class documentation
68   return kAliHLTDataTypeStreamerInfo;
69 }
70
71 void AliHLTRootSchemaEvolutionComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
72 {
73   // see header file for class documentation
74
75   // this is nothing more than an assumption, in fact it's very difficult to predict how
76   // much output the component produces
77   constBase=100*1024;
78   inputMultiplier=3;
79 }
80
81 int AliHLTRootSchemaEvolutionComponent::DoInit(int argc, const char** argv)
82 {
83   // see header file for class documentation
84
85   int iResult=0;
86
87   // default configuration from CDB
88   if (iResult>=0 && fgkConfigurationObject!=NULL) iResult=ConfigureFromCDBTObjString(fgkConfigurationObject);
89
90   // custom configuration from command line arguments
91   if (iResult>=0 && argc>0) iResult=ConfigureFromArgumentString(argc, argv);
92
93   if (iResult>=0) {
94     fpStreamerInfos=new TObjArray();
95     if (!fpStreamerInfos) iResult=-ENOMEM;
96   }
97   return 0;
98 }
99
100 int AliHLTRootSchemaEvolutionComponent::DoDeinit()
101 {
102   // see header file for class documentation
103   if (fpStreamerInfos) {
104     fpStreamerInfos->Clear();
105     delete fpStreamerInfos;
106   }
107   fpStreamerInfos=NULL;
108
109   return 0;
110 }
111
112 int AliHLTRootSchemaEvolutionComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/,
113                                                  AliHLTComponentTriggerData& /*trigData*/ )
114 {
115   // see header file for class documentation
116   int iResult=0;
117   AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
118   if (!IsDataEvent(&eventType) && 
119       eventType==gkAliEventTypeStartOfRun) {
120     return 0;
121   }
122
123   AliHLTMessage msg(kMESS_OBJECT);
124   msg.EnableSchemaEvolution();
125   for (const TObject* pObj=GetFirstInputObject();
126        pObj && iResult>=0;
127        pObj=GetNextInputObject()) {
128     msg.WriteObject(pObj);
129     iResult=UpdateStreamerInfos(msg.GetStreamerInfos(), fpStreamerInfos);
130   }
131
132   if (iResult>=0) {
133     if ((TestBits(kHLTOUTatFirstEvent) && GetEventCount()==0) ||
134         (TestBits(kHLTOUTatAllEvents)) || 
135         (TestBits(kHLTOUTatEOR) && eventType==gkAliEventTypeEndOfRun)) {
136       PushBack(fpStreamerInfos, kAliHLTDataTypeStreamerInfo);
137     }
138
139     if (TestBits(kFXS) && eventType==gkAliEventTypeEndOfRun) {
140       // push to FXS, needs to be implemented in the base class
141     }
142   }
143
144   return iResult;
145 }
146
147 int AliHLTRootSchemaEvolutionComponent::UpdateStreamerInfos(const TList* list, TObjArray* infos) const
148 {
149   // see header file for class documentation
150   int iResult=0;
151   if (!list || !infos) {
152     return -EINVAL;
153   }
154
155   TObject* element=NULL;
156   TIter next((TList*)list);
157   while ((element = next())) {
158     TStreamerInfo* pInfo=dynamic_cast<TStreamerInfo*>(element);
159     if (!pInfo) continue;
160     TString name=pInfo->GetName();
161     int i=0;
162     for (; i<infos->GetEntriesFast(); i++) {
163       if (name.CompareTo(infos->At(i)->GetName())==0 &&
164           pInfo->GetClassVersion() == ((TStreamerInfo*)infos->At(i))->GetClassVersion()) {
165         // have it already
166         break;
167       }
168     }
169
170     // Add streamer info
171     infos->Add(pInfo);
172   }
173
174   return iResult;
175 }
176
177 int AliHLTRootSchemaEvolutionComponent::ScanConfigurationArgument(int argc, const char** argv)
178 {
179   // see header file for class documentation
180   int iResult=0;
181   if (argc<=0) return 0;
182   int i=0;
183   TString argument=argv[i];
184
185   // -hltout=[all,first,eor,off]
186   if (argument.Contains("-hltout")) {
187     argument.ReplaceAll("-hltout", "");
188     argument.ReplaceAll("=", "");
189     if (argument.IsNull() || argument.CompareTo("all")) {
190       SetBits(kHLTOUTatAllEvents);
191     } else if (argument.CompareTo("first")) {
192       SetBits(kHLTOUTatFirstEvent);
193     } else if (argument.CompareTo("eor")) {
194       SetBits(kHLTOUTatEOR);
195     } else if (argument.CompareTo("off")) {
196       ClearBits(kHLTOUTatAllEvents | kHLTOUTatFirstEvent | kHLTOUTatEOR);
197     } else {
198       HLTError("invalid parameter for argument -hltout= : %s", argument.Data());
199       return -EINVAL;
200     }
201     return 1;
202   }
203
204   // -fxs=[n,off]
205   if (argument.Contains("-fxs")) {
206     argument.ReplaceAll("-fxs", "");
207     argument.ReplaceAll("=", "");
208     if (argument.IsNull()) {
209       SetBits(kFXS);
210     } else if (argument.CompareTo("off")) {
211       ClearBits(kFXS);
212     } else if (argument.IsDigit()) {
213       fFXSPrescaler=argument.Atoi();
214     } else {
215       HLTError("invalid parameter for argument -fxs= : %s", argument.Data());
216       return -EINVAL;
217     }
218     return 1;
219   }
220   
221   return iResult;
222 }