3 //**************************************************************************
4 //* This file is property of and copyright by the *
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 AliHLTGlobalPreprocessor.cxx
20 // @author Matthias Richter
22 // @brief HLT Preprocessor plugin for global HLT
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"
37 #include <TObjArray.h>
38 #include <TStreamerInfo.h>
39 //#include <AliDCSValue.h>
40 //#include <TTimeStamp.h>
43 ClassImp(AliHLTGlobalPreprocessor)
45 AliHLTGlobalPreprocessor::AliHLTGlobalPreprocessor()
46 : AliHLTModulePreprocessor()
49 // HLT preprocessor for global HLT objects
51 // Produced OCDB objects:
52 // - HLT/Calib/Streamerinfo
53 // The streamer info object is produced by the ROOTSchemaEvolutionComponent
54 // See ProcessStreamerInfo() for details.
57 const char* AliHLTGlobalPreprocessor::fgkStreamerInfoAlias="StreamerInfo";
58 const char* AliHLTGlobalPreprocessor::fgkStreamerInfoName="StreamerInfo";
59 const char* AliHLTGlobalPreprocessor::fgkStreamerInfoType="Calib";
61 AliHLTGlobalPreprocessor::~AliHLTGlobalPreprocessor()
67 void AliHLTGlobalPreprocessor::Initialize(Int_t /*run*/, UInt_t /*startTime*/,
70 // initializes AliHLTGlobalPreprocessor
74 UInt_t AliHLTGlobalPreprocessor::Process(TMap* /*dcsAliasMap*/)
76 Int_t returnValue = ProcessStreamerInfo();
77 if (returnValue < 0) {
78 AliInfo(Form("Processing for %s failed with return code %d", fgkStreamerInfoAlias, returnValue));
80 return 0; // return success
83 Int_t AliHLTGlobalPreprocessor::GetModuleNumber()
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");
92 Int_t AliHLTGlobalPreprocessor::ProcessStreamerInfo() {
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
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);
107 clone = new TObjArray();
111 AliError(Form("Could not clone %s, %s", fgkStreamerInfoType, fgkStreamerInfoName));
112 return -2; // no clone
114 // loop over all sources
115 TObjLink *lnk = list->FirstLink();
117 TObject* obj = lnk->GetObject();
118 TObjString* objStr = dynamic_cast<TObjString*>(obj);
120 AliError(Form("GetFileSources returned TList with no TObjString entry?! %s", obj->ClassName()));
121 // continue with next list entry
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()));
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()));
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();
141 TObject* streamerobj = f->Get(lnkFile->GetObject()->GetName());
142 TStreamerInfo* streamer=dynamic_cast<TStreamerInfo*>(streamerobj);
144 AliError(Form("StreamerInfo object has wrong class type %s, expecting TStreamerInfo", streamerobj->ClassName()));
146 streamerinfos->Add(streamer);
148 lnkFile = lnkFile->Next();
150 if (streamerinfos->GetEntriesFast()!=0) {
151 bStore |= AliHLTMisc::Instance().MergeStreamerInfo(clone, streamerinfos, 1)>0;
153 delete streamerinfos;
158 // store if necessary
160 AliCDBMetaData* metaData=entry?entry->GetMetaData():NULL;
161 AliCDBMetaData* newMetaData=NULL;
163 newMetaData=new AliCDBMetaData;
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);
174 Store(fgkStreamerInfoType, fgkStreamerInfoName, clone, metaData, GetRun(), kTRUE);
182 AliInfo(Form("StreamerInfo object in OCDB is already up-to-date, skipping new object"));
190 int AliHLTGlobalPreprocessor::ProcessStreamerInfo(TObject* object)
192 /// process the StreamerInfo object
194 if (!object) return -EINVAL;
196 TObjArray* streamerinfos=dynamic_cast<TObjArray*>(object);
197 if (!streamerinfos) {
198 AliError(Form("StreamerInfo object has wrong class type %s, expecting TObjArray", object->ClassName()));
201 if (streamerinfos->GetEntriesFast()==0) return 0;
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;
211 TObject* cloneObj=streamerinfos->Clone();
212 if (cloneObj) clone=dynamic_cast<TObjArray*>(cloneObj);
217 AliCDBMetaData* metaData=entry?entry->GetMetaData():NULL;
218 AliCDBMetaData* newMetaData=NULL;
220 newMetaData=new AliCDBMetaData;
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);
232 // store new object with validity infinity (last parameter kTRUE)
233 Store(fgkStreamerInfoType, fgkStreamerInfoName, clone, metaData, GetRun(), kTRUE);
235 AliInfo(Form("skipping object which is already up-to-date"));
239 if (newMetaData) delete newMetaData;
243 // - what to do with variable 'entry', to be deleted?
246 AliError("failed to clone streamer info object array");