Adding simple example to load default debug streamer
[u/mrichter/AliRoot.git] / TPC / 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 //
107 fMap = param.fMap;
108 std::cout << "AliTPCPreprocessorOnline's assignment operator called, NOT WORKING!!!" << std::endl;
109 return (*this);
110}
111
112
113//_____________________________________________________________________________
114AliTPCPreprocessorOnline::~AliTPCPreprocessorOnline()
115{
116 //
117 // AliTPCPreprocessorOnline destructor
118 //
119 printf("AliTPCPreprocessorOnline's destructor called. \n");
120 fMap->DeleteValues();
121 delete fMap;
122}
123
124
125
126void AliTPCPreprocessorOnline::AddComponent(TObject *obj) {
127 //
128 // Add components form HLT or DAQ here
129 // The components are either AliTPCCalPads or AliTPCCalROCs
130 // other to be defined
131 //
132 // As from HLT they will come ROC wise, they have to be set together to one AliTPCCalPad here
133 // Then they are added to the Calibration Tree
134 // This calibration tree will be written by AliTPCCalibViewer::MakeTree, once you call ::DumpToFile(fileName)
135 //
136 // To distinguish, what kind of component is added, there is a Naming-Convention:
137 // The normal, already definded naming-Convention for AliTPCCalPads <PadName>
138 // <padName>_ROC<ROC_Number> for example: "CEQmean_ROC34"
139 //
140 //
141 // Get name of obj
142 // Check, if it ends with "_ROC<Int_t>" / check, if it contains "ROC"
143 // If it contains "ROC", find out, to which calibration CalPad it belongs -> Parse first part of the name
144 // Get the corsponding AliTPCCalPad / Make a new AliTPCCalPad
145 // Set "_ROC<Int_t>" to zero /? delete it -> Set the new values, out of obj
146 //
147
148
149 // printf(" ****** AliTPCPreprocessorOnline::AddComponent ****** \n");
5426880e 150 if (!obj) return;
7b1c94fc 151 TString objName = obj->GetName();
152
153 // Add a whole AliTPCCalPad to the list
154 if (TString(obj->ClassName()) == "AliTPCCalPad") {
155 // printf("AliTPCCalPad found\n");
156 AliTPCCalPad *calPad = (AliTPCCalPad*)obj;
157 TObject *listObj = fMap->GetValue(calPad->GetName());
158 if (listObj == 0) {
159 // current data not yet written to the list, write it to the list
160 fMap->Add(new TObjString(calPad->GetName()), calPad);
161 return;
162 }
163 // current data already present
164 if (TString(listObj->ClassName()) != "AliTPCCalPad")
165 Error("AddComponent", "Mismatch in internal list: '%s' is no AliTPCCalPad. \n", listObj->ClassName());
166 AliTPCCalPad *listCalPad = (AliTPCCalPad*)listObj;
167 listCalPad->Add(listCalPad, -1); // reset the current CalPad
168 listCalPad->Add(calPad);
169 return;
170 }
171
172 if (TString(obj->ClassName()) == "AliTPCCalROC") {
173 // printf("AliTPCCalROC found\n");
174 if (! objName.Contains("_ROC"))
175 Warning("AddComponent", "Uncomplete object name: '%s' is missing _ROC<ROC_number>\n", objName.Data());
176 TObjArray *stokens = objName.Tokenize("_ROC");
177 TString rocNumber("");
178 if (stokens->GetEntriesFast()>1) rocNumber = ((TObjString*)stokens->At(1))->GetString();
179 Int_t iroc = -1;
180 if (rocNumber.IsAlnum()) iroc = rocNumber.Atoi();
181
182 // Extract CalPad Name:
183 TString removeString("_ROC");
184 removeString += rocNumber;
185 objName.ReplaceAll(removeString, ""); // Remove "_ROC<number>" from the end
186
187 // objName is cleaned and can now be used to extract the coresponding CalPad from the list
188 TObject *listObj = fMap->GetValue(objName.Data());
189 AliTPCCalROC *calROC = (AliTPCCalROC*)obj;
190 if (iroc == -1) iroc = calROC->GetSector();
191 if (iroc != (Int_t)calROC->GetSector())
192 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);
193 calROC->SetNameTitle(objName.Data(), objName.Data());
194 if (listObj == 0) {
195 // current data not yet written to the list, write it to the list
196 AliTPCCalPad *calPad = new AliTPCCalPad(objName.Data(), objName.Data());
197 calPad->SetCalROC(calROC, iroc);
198 fMap->Add(new TObjString(objName.Data()), calPad);
199 return;
200 }
201 // current data already present
202 if (TString(listObj->ClassName()) != "AliTPCCalPad")
203 Error("AddComponent", "Mismatch in internal list: '%s' is no AliTPCCalPad \n", listObj->ClassName());
204 AliTPCCalPad *listCalPad = (AliTPCCalPad*)listObj;
205 listCalPad->SetCalROC(calROC, iroc);
206 return;
207
208
209 }
210
211 Warning("AddComponent", "Unknown calibration object '%s', skipped.\n", obj->ClassName());
212
213 return;
214
215
216}
217
218
219
220void AliTPCPreprocessorOnline::DumpToFile(const char* fileName){
221 //
222 // Function to dump the tree to file
223 // A TObjArray is created out of the TMap, which is passed to
224 // AliTPCCalibViewer::MakeTree(...)
225 //
226
227 printf("AliTPCPreprocessorOnline::DumpToFile\n");
228 TObjArray *listOfCalPads = new TObjArray();
229 TIterator *iterator = fMap->MakeIterator();
230 AliTPCCalPad *calPad = 0x0;
231// while ((calibTracks = (AliTPCcalibTracks*)listIterator->Next()) ){
f3a5d03b 232 TObject * obj=0;
233 // while (( calPad = (AliTPCCalPad*)fMap->GetValue(iterator->Next()) )) {
234 while ( ( obj = iterator->Next()) ) {
235 calPad = (AliTPCCalPad*)fMap->GetValue(obj);
7b1c94fc 236 if (!calPad) continue;
237 calPad = (AliTPCCalPad*)calPad;
238 printf("adding the following element to the TObjList: %s \n", calPad->GetName());
239 printf("It's type:: %s \n", calPad->ClassName());
240 calPad->Print();
241 listOfCalPads->Add(calPad);
242 }
243 printf("writing the tree... \n");
258cd111 244 // AliTPCCalibViewer::MakeTree(fileName, listOfCalPads, "$ALICE_ROOT/TPC/Calib/MapCalibrationObjects.root");
245 AliTPCCalibViewer::MakeTree(fileName, listOfCalPads, 0);
7b1c94fc 246
247}
248