minor bugfixes (table names); get rid of warnings(Jenny)
[u/mrichter/AliRoot.git] / HLT / comp / AliHLTCompPreprocessor.cxx
CommitLineData
12ec5482 1// $Id: AliHLTCompPreprocessor.cxx 23039 2007-12-13 20:53:02Z richterm $
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//* Jenny Wagner *
9//* for The ALICE HLT Project. *
10//* *
11//* Permission to use, copy, modify and distribute this software and its *
12//* documentation strictly for non-commercial purposes is hereby granted *
13//* without fee, provided that the above copyright notice appears in all *
14//* copies and that both the copyright notice and this permission notice *
15//* appear in the supporting documentation. The authors make no claims *
16//* about the suitability of this software for any purpose. It is *
17//* provided "as is" without express or implied warranty. *
18//**************************************************************************
19
20/**
21 * @file AliHLTCompPreprocessor.cxx
22 * @author Jenny Wagner, Matthias Richter
23 * @brief Implementation of the HLT preprocessor for the AliHLTComp library
24 */
25
26#include "AliHLTCompPreprocessor.h"
27#include "AliCDBMetaData.h"
12ec5482 28#include "TObjString.h"
29#include "TString.h"
30#include "TList.h"
31#include "TFile.h"
32
33// necessary for huffman table to get information about the origin
34#include "AliHLTCOMPHuffmanData.h"
35
36ClassImp(AliHLTCompPreprocessor)
37
d83b59c6 38 AliHLTCompPreprocessor::AliHLTCompPreprocessor() :
39 fTPCactive(0),
40 fPHOSactive(0)
12ec5482 41{
42 // see header file for class documentation
43 // or
44 // refer to README to build package
45 // or
46 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
47}
48
49const char* AliHLTCompPreprocessor::fgkHuffmanFileId = "HuffmanData";
50
51AliHLTCompPreprocessor::~AliHLTCompPreprocessor()
52{
53 // see header file for function documentation
54}
55
af2ed151 56void AliHLTCompPreprocessor::Initialize(Int_t /*run*/, UInt_t /*startTime*/,
57 UInt_t /*endTime*/)
12ec5482 58{
59 // see header file for function documentation
d83b59c6 60 fTPCactive = AliHLTModulePreprocessor::GetDetectorStatus(AliHLTModulePreprocessor::DetectorBitMask("TPC"));
61 fPHOSactive = AliHLTModulePreprocessor::GetDetectorStatus(AliHLTModulePreprocessor::DetectorBitMask("PHOS"));
62
12ec5482 63}
64
65
af2ed151 66UInt_t AliHLTCompPreprocessor::Process(TMap* /*dcsAliasMap*/)
12ec5482 67{
68 // see header file for function documentation
69 UInt_t retVal = 0;
70
d83b59c6 71 // error if preprocessor states that TPC or PHOS were active but both are inactive here!
72 if( !(fTPCactive || fPHOSactive) )
73 {
74 Log("Neither TPC nor PHOS active in current run!");
75 return 0;
76 }
77
78 // else there must be Huffman tables:
12ec5482 79 if (GetHuffmanTables() != 0) {
80 // unable to fetch Huffman tables
81 retVal = 1;
12ec5482 82 }
83
84 return retVal;
85}
86
87UInt_t AliHLTCompPreprocessor::GetHuffmanTables()
88{
89 // see header file for function documentation
90
91 UInt_t retVal = 0;
92
93 // get all huffman tables stored at FXS
98697c64 94 //TList* HuffmanList = GetFileSources(AliPreprocessor::kHLT, fgkHuffmanFileId);
12ec5482 95 TList* HuffmanList = GetFileSources(AliPreprocessor::kHLT, fgkHuffmanFileId);
96 // -> list of all DDL numbers that own a huffman table
97
d83b59c6 98 // if there is no Huffman code table for a calib run, return error!
12ec5482 99 // else produce containers for each detector to be stored in the OCDB
100 if (!HuffmanList)
101 {
102 Log("No Huffman code tables for HLT");
103 return 1;
104 }
d83b59c6 105
106 TList* TPCHuffmanList;
107 TList* PHOSHuffmanList;
108
98697c64 109 TPCHuffmanList = new TList();
110
111 if(!fTPCactive)
d83b59c6 112 {
98697c64 113 delete TPCHuffmanList;
d83b59c6 114 };
115
98697c64 116 PHOSHuffmanList = new TList();
117
118 if(!fPHOSactive)
d83b59c6 119 {
98697c64 120 delete PHOSHuffmanList;
d83b59c6 121 };
d83b59c6 122
12ec5482 123 // loop over all DDL numbers and put huffman tables into special containers
124 // (one for each detector)
125 for(Int_t ii=0; ii < HuffmanList->GetEntries(); ii++)
126 {
127 // get huffman table
128 TObjString *objstr = (TObjString*) HuffmanList->At(ii);
129
130 if(objstr == 0) // should not happen?!
131 {
132 char logging[1000];
133 sprintf(logging, "Error in Huffmanlist, no DDL at position %d", ii);
134 Log(logging);
135 continue;
136 }
137
138 TString fileName = GetFile(AliPreprocessor::kHLT, "HuffmanData", objstr->GetName());
139
140 if (!(fileName.Length() > 0)) // error if local path/filename is not defined
141 {
142 Log("Local file for current Huffman table is not properly defined.");
143 return 1;
144 }
145
146 TFile* currenthuffmanfile = new TFile(fileName, "READ");
147
148 // if current huffman table file does not contain a table, return an error
98697c64 149 if ( currenthuffmanfile->Get("HuffmanData") == NULL)
12ec5482 150 {
151 char logging[1000];
152 sprintf(logging,"Local file %s does not contain a Huffman code table.", fileName.Data());
153 Log(logging);
154 //retVal = 1; // retVal must be zero to give other functions a chance to read their data
155 retVal = 0;
156 }
157
98697c64 158 TObject* huffmandata = (TObject*) currenthuffmanfile->Get("HuffmanData");
af2ed151 159 // class object not needed since container uses TObjects!
98697c64 160 AliHLTCOMPHuffmanData* currenthuffmandata = (AliHLTCOMPHuffmanData*) currenthuffmanfile->Get("HuffmanData");
12ec5482 161
162 // specifications necessary for sorting process
98697c64 163 TString detectororigin = currenthuffmandata->GetOrigin();
164 Int_t tablespec = currenthuffmandata->GetDataSpec();
12ec5482 165
166
167 // plug them into a container:
168 if(detectororigin == "PHOS") // belongs to PHOS table (one one!)
169 {
d83b59c6 170 if(!PHOSHuffmanList)
171 {
172 Log("PHOS Huffman code table retrieved although PHOS detector was not active!");
173 return 1;
174 };
175
12ec5482 176 PHOSHuffmanList->AddFirst(huffmandata);
177
178 if(PHOSHuffmanList->GetEntries() > 1)
179 {
180 Log("More than one table available for PHOS.");
181 // return: warning but go on...
182 }
183 }
184 else
185 {
186 if(detectororigin == "TPC ") // belongs to TPC tables (six)
187 {
d83b59c6 188
189 if(!TPCHuffmanList)
190 {
191 Log("TPC Huffman code table retrieved although TPC detector was not active!");
192 return 1;
193 };
194
12ec5482 195 if(tablespec < 6)
196 {
197 TPCHuffmanList->Add(huffmandata);
198
199 if(TPCHuffmanList->GetEntries() > 6)
200 {
201 Log("More than six tables available for TPC.");
202 // return warning but go on...
203 }
204 }
205 else
206 {
207 char logging[1000];
208 sprintf(logging, "Read data specification %d from Huffman table too large to belong to TPC.", tablespec);
209 Log(logging);
210 // retVal = 1; // retVal must be zero to give other functions a chance to read their data
211 retVal = 0;
212 }
213 }
214 else // error!
215 {
216 char logging[1000];
217 sprintf(logging, "Specified detector pattern %s does not define a valid detector.", detectororigin.Data());
218 Log(logging);
d83b59c6 219 retVal = 1; // retVal must be zero to give other functions a chance to read their data
220 //retVal = 0;
12ec5482 221 }
222 }
223
224
225 } // end loop over all DDLs
226
227
228 // after loop all containers are filled and can be stored in OCDB
229 AliCDBMetaData meta("Jenny Wagner");
230
d83b59c6 231 if(fTPCactive)
12ec5482 232 {
d83b59c6 233 if (!(Store("CalibTPC", "HuffmanCodeTables", (TObject*) TPCHuffmanList, &meta, 0, kTRUE)))
234 {
12ec5482 235
d83b59c6 236 Log("Storing of TPCHuffmanList (Huffman code tables for TPC) to OCDB failed.");
12ec5482 237
d83b59c6 238 if (!(StoreReferenceData("CalibTPC", "HuffmanCodeTables", (TObject*) TPCHuffmanList, &meta)))
239 {
240 Log("Storing of TPCHuffmanList (Huffman code tables for TPC) to reference storage failed.");
12ec5482 241
d83b59c6 242 retVal = 1;
243 }
12ec5482 244 }
245 }
12ec5482 246
d83b59c6 247 if(fPHOSactive)
248 {
249 if (!(Store("CalibPHOS", "HuffmanCodeTables", (TObject*) PHOSHuffmanList, &meta, 0, kTRUE)))
12ec5482 250 {
d83b59c6 251
252 Log("Storing of PHOSHuffmanList (Huffman code table for PHOS) to OCDB failed.");
12ec5482 253
d83b59c6 254 if (!(StoreReferenceData("CalibPHOS", "HuffmanCodeTables", (TObject*) PHOSHuffmanList, &meta)))
255 {
256 Log("Storing of PHOSHuffmanList (Huffman code table for PHOS) to reference storage failed.");
257
258 retVal = 1;
259 }
12ec5482 260 }
261 }
262
263 return retVal;
264}