]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalPreprocessor.cxx
Implemented handling of StreamerInfo from the online component in the global preproce...
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalPreprocessor.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the                          * 
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   AliHLTGlobalPreprocessor.cxx
20 //  @author Matthias Richter
21 //  @date   2010-08-20
22 //  @brief  HLT Preprocessor plugin for global HLT
23 // 
24
25 #include "AliHLTGlobalPreprocessor.h"
26 #include "AliPreprocessor.h"
27 #include "AliHLTMisc.h"
28 #include "AliCDBManager.h"
29 #include "AliCDBEntry.h"
30 #include "AliGRPObject.h"
31 #include "AliCDBMetaData.h"
32 #include "AliCDBId.h"
33 #include "AliLog.h"
34 #include <cassert>
35 #include <cerrno>
36
37 #include <TObjArray.h>
38 #include <TStreamerInfo.h>
39 //#include <AliDCSValue.h>
40 //#include <TTimeStamp.h>
41
42
43 ClassImp(AliHLTGlobalPreprocessor)
44
45 AliHLTGlobalPreprocessor::AliHLTGlobalPreprocessor()
46   : AliHLTModulePreprocessor()
47 {
48   // constructor
49   // HLT preprocessor for global HLT objects
50   //
51   // Produced OCDB objects:
52   // - HLT/Calib/Streamerinfo
53   //   The streamer info object is produced by the ROOTSchemaEvolutionComponent
54   //   See ProcessStreamerInfo() for details.
55 }
56
57 const char* AliHLTGlobalPreprocessor::fgkStreamerInfoAlias="StreamerInfo";
58 const char* AliHLTGlobalPreprocessor::fgkStreamerInfoName="StreamerInfo";
59 const char* AliHLTGlobalPreprocessor::fgkStreamerInfoType="Calib";
60
61 AliHLTGlobalPreprocessor::~AliHLTGlobalPreprocessor()
62 {
63   // destructor
64 }
65
66
67 void AliHLTGlobalPreprocessor::Initialize(Int_t /*run*/, UInt_t /*startTime*/, 
68                                           UInt_t /*endTime*/)
69 {
70   // initializes AliHLTGlobalPreprocessor
71
72 }
73
74 UInt_t AliHLTGlobalPreprocessor::Process(TMap* /*dcsAliasMap*/)
75 {
76   Int_t returnValue = ProcessStreamerInfo();
77   if (returnValue < 0) {
78         AliInfo(Form("Processing for %s failed with return code %d", fgkStreamerInfoAlias, returnValue));
79   }
80   return 0; // return success
81 }
82
83 Int_t AliHLTGlobalPreprocessor::GetModuleNumber()
84 {
85   // get module number of this preprocessor, corresponds to the position
86   // in the detector bit field, or 0 if no corresponding detector existing
87   Int_t modulenumber = 0;
88   //modulenumber = AliHLTModulePreprocessor::DetectorBitMask("GRP");
89   return modulenumber;
90 }
91
92 Int_t AliHLTGlobalPreprocessor::ProcessStreamerInfo() {
93         // get file sources
94         TList* list = GetFileSources(AliPreprocessor::kHLT, fgkStreamerInfoAlias);
95         if ((!list) || (list->GetEntries() == 0)) {
96                 AliInfo(Form("No sources for %s found",fgkStreamerInfoAlias));
97                 return -1; // no sources
98         }
99         bool bStore = false;
100     TObjArray* clone = NULL;
101         // get existing object or create new one
102     AliCDBEntry* entry = GetFromOCDB(fgkStreamerInfoType, fgkStreamerInfoName);
103     if (entry && entry->GetObject()) {
104         TObject* cloneObj = entry->GetObject()->Clone();
105         if (cloneObj) clone = dynamic_cast<TObjArray*>(cloneObj);
106     } else {
107         clone = new TObjArray();
108         bStore = true;
109     }
110     if (!clone) {
111         AliError(Form("Could not clone %s, %s", fgkStreamerInfoType, fgkStreamerInfoName));
112         return -2; // no clone
113     }
114         // loop over all sources
115         TObjLink *lnk = list->FirstLink();
116         while (lnk) {
117                 TObject* obj = lnk->GetObject();
118                 TObjString* objStr = dynamic_cast<TObjString*>(obj);
119                 if (!objStr) {
120                         AliError(Form("GetFileSources returned TList with no TObjString entry?! %s", obj->ClassName()));
121                         // continue with next list entry
122                         lnk = lnk->Next();
123                         continue;
124                 }
125                 TString fileName = GetFile(AliPreprocessor::kHLT,fgkStreamerInfoAlias ,objStr->GetString().Data());
126                 if (fileName.Length() == 0) {
127                         AliError(Form("Could not get %d-%s-%s", AliPreprocessor::kHLT,fgkStreamerInfoAlias ,objStr->GetString().Data()));
128                 }
129                 // time to process the file...
130                 TFile* f = new TFile(fileName.Data(), "READ");
131                 if (!f || !f->IsOpen()) {
132                         AliError(Form("Could not open %s", objStr->GetString().Data()));
133                         return -3;
134                 }
135                 // loop over objects and create new TObjArrary to feed into merger...
136                 TObjArray* streamerinfos = new TObjArray(100);
137                 TList* keys = f->GetListOfKeys();
138                 TObjLink *lnkFile = keys->FirstLink();
139                 while (lnkFile) {
140                         // processing
141                         TObject* streamerobj = f->Get(lnkFile->GetObject()->GetName());
142                         TStreamerInfo* streamer=dynamic_cast<TStreamerInfo*>(streamerobj);
143                         if (!streamer) {
144                                 AliError(Form("StreamerInfo object has wrong class type %s, expecting TStreamerInfo", streamerobj->ClassName()));
145                         } else {
146                                 streamerinfos->Add(streamer);
147                         }
148                         lnkFile = lnkFile->Next();
149                 }
150                 if (streamerinfos->GetEntriesFast()!=0) {
151                         bStore |= AliHLTMisc::Instance().MergeStreamerInfo(clone, streamerinfos, 1)>0;
152                 }
153                 delete streamerinfos;
154                 f->Close();
155                 delete f;
156                 lnk = lnk->Next();
157         }
158         // store if necessary
159         if (bStore) {
160             AliCDBMetaData* metaData=entry?entry->GetMetaData():NULL;
161             AliCDBMetaData* newMetaData=NULL;
162             if (!metaData) {
163                 newMetaData=new AliCDBMetaData;
164                 if (newMetaData) {
165                         metaData=newMetaData;
166                         metaData->SetBeamPeriod(0);
167                         metaData->SetResponsible("ALICE HLT alice-hlt-core@cern.ch");
168                         metaData->SetComment("Streamer info for HLTOUT payload");
169                         //metaData->SetAliRootVersion(ALIROOT_SVN_BRANCH);
170                 } else {
171                         return -ENOMEM;
172                 }
173             }
174              Store(fgkStreamerInfoType, fgkStreamerInfoName, clone, metaData, GetRun(), kTRUE);
175              if (newMetaData) {
176                 delete newMetaData;
177                 newMetaData=NULL;
178                 metaData=NULL;
179              }
180         } else {
181                 if (entry) {
182               AliInfo(Form("StreamerInfo object in OCDB is already up-to-date, skipping new object"));
183               //entry->PrintId();
184                 }
185         }
186     delete clone;
187         return 0;
188 }
189
190 int AliHLTGlobalPreprocessor::ProcessStreamerInfo(TObject* object)
191 {
192   /// process the StreamerInfo object
193   int iResult=0;
194   if (!object) return -EINVAL;
195
196   TObjArray* streamerinfos=dynamic_cast<TObjArray*>(object);
197   if (!streamerinfos) {
198     AliError(Form("StreamerInfo object has wrong class type %s, expecting TObjArray", object->ClassName()));
199     return -EINVAL;
200   }
201   if (streamerinfos->GetEntriesFast()==0) return 0;
202
203   bool bStore=false;
204   AliCDBEntry* entry = GetFromOCDB(fgkStreamerInfoType, fgkStreamerInfoName);
205   TObjArray* clone=NULL;
206   if (entry && entry->GetObject()) {
207     TObject* cloneObj=entry->GetObject()->Clone();
208     if (cloneObj) clone=dynamic_cast<TObjArray*>(cloneObj);
209     bStore=AliHLTMisc::Instance().MergeStreamerInfo(clone, streamerinfos, 1)>0;
210   } else {
211     TObject* cloneObj=streamerinfos->Clone();
212     if (cloneObj) clone=dynamic_cast<TObjArray*>(cloneObj);
213     bStore=true;
214   }
215
216   if (clone) {
217     AliCDBMetaData* metaData=entry?entry->GetMetaData():NULL;
218     AliCDBMetaData* newMetaData=NULL;
219     if (!metaData) {
220       newMetaData=new AliCDBMetaData;
221       if (newMetaData) {
222         metaData=newMetaData;
223         metaData->SetBeamPeriod(0);
224         metaData->SetResponsible("ALICE HLT Matthias.Richter@cern.ch");
225         metaData->SetComment("Streamer info for HLTOUT payload");
226         //metaData->SetAliRootVersion(ALIROOT_SVN_BRANCH);
227       } else {
228         iResult=-ENOMEM;
229       }
230     }
231     if (bStore) {
232       // store new object with validity infinity (last parameter kTRUE)
233       Store(fgkStreamerInfoType, fgkStreamerInfoName, clone, metaData, GetRun(), kTRUE);
234     } else if (entry) {
235       AliInfo(Form("skipping object which is already up-to-date"));
236       entry->PrintId();
237     }
238     delete clone;
239     if (newMetaData) delete newMetaData;
240     newMetaData=NULL;
241     metaData=NULL;
242     // TODO
243     // - what to do with variable 'entry', to be deleted?
244
245   } else {
246     AliError("failed to clone streamer info object array");
247     return -ENOMEM;
248   }
249
250   return iResult;
251 }