Merge branch 'TPCdev' of https://git.cern.ch/reps/AliRoot into TPCdev
[u/mrichter/AliRoot.git] / TPC / Base / AliTPCPreprocessorOnline.cxx
CommitLineData
7b1c94fc 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16
17////////////////////////////////////////////////////////////////////////////////
18// //
19// Preprocessor class for HLT and DAQ //
20// Possible usage: preprocess TPC calibration data //
21// to form needed for online viewing/visualizing TPC calibration data //
22// //
23// On HLT or DAQ AliTPCPreprocessorOnline::AddComponent(...) is called, //
24// whereas ... is either an AliTPCCalPad, or an AliTPCCalROC. //
25// Their names have to be acording the naming convention for AliTPCCalPads //
26// Special for CalROCs: Add '_ROC<ROC_Number>' to the name. //
27// //
28// Internal the AliTPCCalPads are stored in a TMap, they are retrieved by //
29// their name. //
30// //
31// Once enough values are accumulated, call ::DumpToFile(fileName). //
32// A TObjArray is created out of the TMap, which is passed to //
33// AliTPCCalibViewer::MakeTree(...) and the calibratioTree is written //
34// is written to "filenName".
35//
36// The data flow is as follows:
37/*
38Begin_Html
39 <img src="../TPC/doc/dataFlowCalibViewer.png">
40End_Html
41*/
42// //
43// //
44////////////////////////////////////////////////////////////////////////////////
45
46//
47// ROOT includes
48//
49#include <TObject.h>
50#include <iostream>
51#include <TString.h>
52#include "TMap.h"
53#include "TObjArray.h"
54#include "TObjString.h"
55#include "TIterator.h"
56
57
58//
59// AliRoot includes
60//
61#include "AliTPCCalPad.h"
62#include "AliTPCCalROC.h"
63#include "AliTPCCalibViewer.h"
64#include "AliTPCPreprocessorOnline.h"
65#include <fstream>
66
67
68
69ClassImp(AliTPCPreprocessorOnline)
70
71AliTPCPreprocessorOnline::AliTPCPreprocessorOnline():TObject(), fMap(0)
72{
73 //
74 // Default constructor
75 //
76 fMap = new TMap();
77
78}
79
80//_____________________________________________________________________________
81AliTPCPreprocessorOnline::AliTPCPreprocessorOnline(const AliTPCPreprocessorOnline &c):TObject(c), fMap(0)
82{
83 //
84 // dummy AliTPCPreprocessorOnline copy constructor
85 // not yet working!!!
86 //
87 fMap = c.fMap;
88 printf("AliTPCPreprocessorOnline's copy constructor called, NOT WORKING!!!\n");
89}
90
91//_____________________________________________________________________________
92AliTPCPreprocessorOnline::AliTPCPreprocessorOnline(TMap *map):TObject(), fMap(0)
93{
94 //
95 // Constructor to "copy" the AliTPCPreprocessorOnline
96 //
97 fMap = map;
98}
99
100
101//____________________________________________________________________________
102AliTPCPreprocessorOnline & AliTPCPreprocessorOnline::operator =(const AliTPCPreprocessorOnline & param){
103 //
104 // assignment operator - dummy
105 // not yet working!!!
106 //
04420071 107 if (this == &param) return (*this);
108
7b1c94fc 109 fMap = param.fMap;
110 std::cout << "AliTPCPreprocessorOnline's assignment operator called, NOT WORKING!!!" << std::endl;
111 return (*this);
112}
113
114
115//_____________________________________________________________________________
116AliTPCPreprocessorOnline::~AliTPCPreprocessorOnline()
117{
118 //
119 // AliTPCPreprocessorOnline destructor
120 //
121 printf("AliTPCPreprocessorOnline's destructor called. \n");
122 fMap->DeleteValues();
123 delete fMap;
124}
125
126
127
128void AliTPCPreprocessorOnline::AddComponent(TObject *obj) {
129 //
130 // Add components form HLT or DAQ here
131 // The components are either AliTPCCalPads or AliTPCCalROCs
132 // other to be defined
133 //
134 // As from HLT they will come ROC wise, they have to be set together to one AliTPCCalPad here
135 // Then they are added to the Calibration Tree
136 // This calibration tree will be written by AliTPCCalibViewer::MakeTree, once you call ::DumpToFile(fileName)
137 //
138 // To distinguish, what kind of component is added, there is a Naming-Convention:
139 // The normal, already definded naming-Convention for AliTPCCalPads <PadName>
140 // <padName>_ROC<ROC_Number> for example: "CEQmean_ROC34"
141 //
142 //
143 // Get name of obj
144 // Check, if it ends with "_ROC<Int_t>" / check, if it contains "ROC"
145 // If it contains "ROC", find out, to which calibration CalPad it belongs -> Parse first part of the name
146 // Get the corsponding AliTPCCalPad / Make a new AliTPCCalPad
147 // Set "_ROC<Int_t>" to zero /? delete it -> Set the new values, out of obj
148 //
149
150
151 // printf(" ****** AliTPCPreprocessorOnline::AddComponent ****** \n");
5426880e 152 if (!obj) return;
7b1c94fc 153 TString objName = obj->GetName();
154
155 // Add a whole AliTPCCalPad to the list
156 if (TString(obj->ClassName()) == "AliTPCCalPad") {
157 // printf("AliTPCCalPad found\n");
158 AliTPCCalPad *calPad = (AliTPCCalPad*)obj;
159 TObject *listObj = fMap->GetValue(calPad->GetName());
160 if (listObj == 0) {
161 // current data not yet written to the list, write it to the list
162 fMap->Add(new TObjString(calPad->GetName()), calPad);
163 return;
164 }
165 // current data already present
166 if (TString(listObj->ClassName()) != "AliTPCCalPad")
167 Error("AddComponent", "Mismatch in internal list: '%s' is no AliTPCCalPad. \n", listObj->ClassName());
168 AliTPCCalPad *listCalPad = (AliTPCCalPad*)listObj;
169 listCalPad->Add(listCalPad, -1); // reset the current CalPad
170 listCalPad->Add(calPad);
171 return;
172 }
173
174 if (TString(obj->ClassName()) == "AliTPCCalROC") {
175 // printf("AliTPCCalROC found\n");
176 if (! objName.Contains("_ROC"))
177 Warning("AddComponent", "Uncomplete object name: '%s' is missing _ROC<ROC_number>\n", objName.Data());
178 TObjArray *stokens = objName.Tokenize("_ROC");
179 TString rocNumber("");
180 if (stokens->GetEntriesFast()>1) rocNumber = ((TObjString*)stokens->At(1))->GetString();
09d5920f 181 delete stokens;
7b1c94fc 182 Int_t iroc = -1;
183 if (rocNumber.IsAlnum()) iroc = rocNumber.Atoi();
184
185 // Extract CalPad Name:
186 TString removeString("_ROC");
187 removeString += rocNumber;
188 objName.ReplaceAll(removeString, ""); // Remove "_ROC<number>" from the end
189
190 // objName is cleaned and can now be used to extract the coresponding CalPad from the list
191 TObject *listObj = fMap->GetValue(objName.Data());
192 AliTPCCalROC *calROC = (AliTPCCalROC*)obj;
193 if (iroc == -1) iroc = calROC->GetSector();
194 if (iroc != (Int_t)calROC->GetSector())
195 Warning("AddComponent","Mismatch in ROC_number: ROC has number %i, in its name %i was specified. Treating now as %i. \n", calROC->GetSector(), iroc, iroc);
196 calROC->SetNameTitle(objName.Data(), objName.Data());
197 if (listObj == 0) {
198 // current data not yet written to the list, write it to the list
199 AliTPCCalPad *calPad = new AliTPCCalPad(objName.Data(), objName.Data());
200 calPad->SetCalROC(calROC, iroc);
201 fMap->Add(new TObjString(objName.Data()), calPad);
202 return;
203 }
204 // current data already present
205 if (TString(listObj->ClassName()) != "AliTPCCalPad")
206 Error("AddComponent", "Mismatch in internal list: '%s' is no AliTPCCalPad \n", listObj->ClassName());
207 AliTPCCalPad *listCalPad = (AliTPCCalPad*)listObj;
208 listCalPad->SetCalROC(calROC, iroc);
209 return;
210
211
212 }
213
214 Warning("AddComponent", "Unknown calibration object '%s', skipped.\n", obj->ClassName());
215
216 return;
217
218
219}
220
221
222
223void AliTPCPreprocessorOnline::DumpToFile(const char* fileName){
224 //
225 // Function to dump the tree to file
226 // A TObjArray is created out of the TMap, which is passed to
227 // AliTPCCalibViewer::MakeTree(...)
228 //
229
230 printf("AliTPCPreprocessorOnline::DumpToFile\n");
231 TObjArray *listOfCalPads = new TObjArray();
232 TIterator *iterator = fMap->MakeIterator();
233 AliTPCCalPad *calPad = 0x0;
234// while ((calibTracks = (AliTPCcalibTracks*)listIterator->Next()) ){
f3a5d03b 235 TObject * obj=0;
236 // while (( calPad = (AliTPCCalPad*)fMap->GetValue(iterator->Next()) )) {
237 while ( ( obj = iterator->Next()) ) {
238 calPad = (AliTPCCalPad*)fMap->GetValue(obj);
7b1c94fc 239 if (!calPad) continue;
240 calPad = (AliTPCCalPad*)calPad;
241 printf("adding the following element to the TObjList: %s \n", calPad->GetName());
242 printf("It's type:: %s \n", calPad->ClassName());
243 calPad->Print();
244 listOfCalPads->Add(calPad);
245 }
246 printf("writing the tree... \n");
258cd111 247 // AliTPCCalibViewer::MakeTree(fileName, listOfCalPads, "$ALICE_ROOT/TPC/Calib/MapCalibrationObjects.root");
248 AliTPCCalibViewer::MakeTree(fileName, listOfCalPads, 0);
7b1c94fc 249
250}
251