]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/comp/AliHLTCompPreprocessor.cxx
72dc89d23bff3be013e9f010ff60dfc2b748ece3
[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 "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
36 ClassImp(AliHLTCompPreprocessor)
37
38   AliHLTCompPreprocessor::AliHLTCompPreprocessor() :
39     fTPCactive(0),
40     fPHOSactive(0)
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
49 const char* AliHLTCompPreprocessor::fgkHuffmanFileId = "HuffmanData";
50
51 AliHLTCompPreprocessor::~AliHLTCompPreprocessor()
52 {
53   // see header file for function documentation
54 }
55
56 void AliHLTCompPreprocessor::Initialize(Int_t /*run*/, UInt_t /*startTime*/, 
57                                         UInt_t /*endTime*/)
58 {
59   // see header file for function documentation
60   fTPCactive = AliHLTModulePreprocessor::GetDetectorStatus(AliHLTModulePreprocessor::DetectorBitMask("TPC"));
61   fPHOSactive = AliHLTModulePreprocessor::GetDetectorStatus(AliHLTModulePreprocessor::DetectorBitMask("PHOS"));
62   
63 }
64
65
66 UInt_t AliHLTCompPreprocessor::Process(TMap* /*dcsAliasMap*/)
67 {
68   // see header file for function documentation
69   UInt_t retVal = 0;
70
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:
79   if (GetHuffmanTables() != 0) {
80     // unable to fetch Huffman tables
81     retVal = 1; 
82   }
83         
84   return retVal;
85 }
86
87 UInt_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       
94   //TList* HuffmanList = GetFileSources(AliPreprocessor::kHLT, fgkHuffmanFileId);
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   TPCHuffmanList = new TList();
110
111   if(!fTPCactive)
112     {
113       delete TPCHuffmanList;
114     };
115
116   PHOSHuffmanList = new TList();
117
118   if(!fPHOSactive)
119     {
120       delete PHOSHuffmanList;
121     };
122
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           TString logging;
133           logging.Form("Error in Huffmanlist, no DDL at position %d", ii);
134           Log(logging.Data());
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
149       if ( currenthuffmanfile->Get("HuffmanData") == NULL)
150         {
151           TString logging;
152           logging.Form("Local file %s does not contain a Huffman code table.", fileName.Data());
153           Log(logging.Data());
154           //retVal = 1; // retVal must be zero to give other functions a chance to read their data
155           retVal = 0;
156         }
157             
158       TObject* huffmandata = (TObject*) currenthuffmanfile->Get("HuffmanData");
159       // class object not needed since container uses TObjects!
160       AliHLTCOMPHuffmanData* currenthuffmandata = (AliHLTCOMPHuffmanData*) currenthuffmanfile->Get("HuffmanData");
161
162       // specifications necessary for sorting process
163       TString detectororigin = currenthuffmandata->GetOrigin();
164       Int_t tablespec = currenthuffmandata->GetDataSpec();
165            
166             
167       // plug them into a container:
168       if(detectororigin == "PHOS") // belongs to PHOS table (one one!)
169         {
170           if(!PHOSHuffmanList)
171             {
172               Log("PHOS Huffman code table retrieved although PHOS detector was not active!");
173               return 1;
174             };
175
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             {
188
189               if(!TPCHuffmanList)
190                 {
191                   Log("TPC Huffman code table retrieved although TPC detector was not active!");
192                   return 1;
193                 };
194
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);
219               retVal = 1; // retVal must be zero to give other functions a chance to read their data
220               //retVal = 0;
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
231   if(fTPCactive)
232     {
233       if (!(Store("CalibTPC", "HuffmanCodeTables", (TObject*) TPCHuffmanList, &meta, 0, kTRUE))) 
234         {
235
236           Log("Storing of TPCHuffmanList (Huffman code tables for TPC) to OCDB failed.");
237
238           if (!(StoreReferenceData("CalibTPC", "HuffmanCodeTables", (TObject*) TPCHuffmanList, &meta)))
239             {
240               Log("Storing of TPCHuffmanList (Huffman code tables for TPC) to reference storage failed.");
241
242               retVal = 1;
243             }
244         }
245     }
246
247   if(fPHOSactive)
248     {
249       if (!(Store("CalibPHOS", "HuffmanCodeTables", (TObject*) PHOSHuffmanList, &meta, 0, kTRUE))) 
250         {
251       
252           Log("Storing of PHOSHuffmanList (Huffman code table for PHOS) to OCDB failed.");
253
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             }
260         }
261     }
262
263   return retVal;
264 }