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