1 ////////////////////////////////////////////////////////////
2 // Author: Henrik Tydesjo //
3 // Interface class to the containers of an online scan. //
4 // Directly connected to a TFile with all containers. //
5 // Handles reading and writing of this TFile. //
6 // Hitmaps and information on nr of events with hits //
7 // is stored in this file (AliITSOnlineSPDHitArray and //
8 // AliITSOnlineSPDHitEvent). Also some general //
9 // information is stored (AliITSOnlineSPDscanInfo). //
10 // When switching between different steps of the scan, //
11 // the previous step is automatically stored on the file. //
12 // With this scheme there is no risk of running out of //
14 ////////////////////////////////////////////////////////////
19 #include "AliITSOnlineSPDscan.h"
20 #include "AliITSOnlineSPDscanInfo.h"
21 #include "AliITSOnlineSPDHitArray.h"
22 #include "AliITSOnlineSPDHitEvent.h"
24 AliITSOnlineSPDscan::AliITSOnlineSPDscan(const Char_t *fileName) :
29 fInfoModified(kFALSE),
33 // constructor, open file for reading or writing
34 // look for a previously saved info object
35 // (if file not found create a new one and return, else read)
36 FILE* fp0 = fopen(fFileName.Data(), "r");
38 fScanInfo = new AliITSOnlineSPDscanInfo();
39 fFile = new TFile(fFileName.Data(), "RECREATE");
44 fFile = new TFile(fFileName.Data(), "READ");
46 fFile->GetObject("AliITSOnlineSPDscanInfo", fScanInfo);
51 AliITSOnlineSPDscan::AliITSOnlineSPDscan(const AliITSOnlineSPDscan& /*scan*/) :
56 fInfoModified(kFALSE),
60 printf("This object should not be copied!");
63 AliITSOnlineSPDscan::~AliITSOnlineSPDscan() {
68 for (UInt_t hs=0; hs<6; hs++) {
69 if (fCurrentHitArray[hs]!=NULL) {
70 delete fCurrentHitArray[hs];
71 fCurrentHitArray[hs]=NULL;
73 if (fCurrentHitEvent[hs]!=NULL) {
74 delete fCurrentHitEvent[hs];
75 fCurrentHitEvent[hs]=NULL;
82 fFile = new TFile(fFileName.Data(), "UPDATE");
85 fFile->Delete("AliITSOnlineSPDscanInfo;*");
86 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
92 AliITSOnlineSPDscan& AliITSOnlineSPDscan::operator=(const AliITSOnlineSPDscan& scan) {
93 // assignment operator (should not be used)
94 printf("This object should not be copied!");
96 // still do nothing...
101 void AliITSOnlineSPDscan::ClearThis() {
102 // clear this scan, close file and open new
103 for (UInt_t hs=0; hs<6; hs++) {
104 if (fCurrentHitArray[hs]!=NULL) {
105 delete fCurrentHitArray[hs];
107 fCurrentHitArray[hs] = NULL;
108 if (fCurrentHitEvent[hs]!=NULL) {
109 delete fCurrentHitEvent[hs];
111 fCurrentHitEvent[hs] = NULL;
113 fScanInfo->ClearThis();
116 fFile = new TFile(fFileName.Data(), "RECREATE");
118 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
122 void AliITSOnlineSPDscan::Init() {
123 // init hit arrays and hit events
124 for (UInt_t hs=0; hs<6; hs++) {
125 fCurrentHitArray[hs]=NULL;
126 fCurrentHitEvent[hs]=NULL;
131 UInt_t AliITSOnlineSPDscan::AddScanStep() {
132 // add a new scan step
134 return fScanInfo->AddScanStep();
137 void AliITSOnlineSPDscan::CreateNewStep() {
139 // save current step to file (if modified)
144 for (UInt_t hs=0; hs<6; hs++) {
145 if (fCurrentHitArray[hs]!=NULL) {
146 delete fCurrentHitArray[hs];
148 fCurrentHitArray[hs] = new AliITSOnlineSPDHitArray();
149 if (fCurrentHitEvent[hs]!=NULL) {
150 delete fCurrentHitEvent[hs];
152 fCurrentHitEvent[hs] = new AliITSOnlineSPDHitEvent();
154 fCurrentStep = fScanInfo->GetNSteps();
159 void AliITSOnlineSPDscan::SwitchToStep(UInt_t nsi) {
160 // switch to step nsi (save current step first if needed)
161 if ((Int_t)nsi!=fCurrentStep) {
165 for (UInt_t hs=0; hs<6; hs++) {
166 if (fCurrentHitArray[hs]!=NULL) {
167 delete fCurrentHitArray[hs];
168 fCurrentHitArray[hs]=NULL;
170 if (fCurrentHitEvent[hs]!=NULL) {
171 delete fCurrentHitEvent[hs];
172 fCurrentHitEvent[hs]=NULL;
175 if (nsi>=GetNSteps()) {
176 FillGap(nsi); // makes fCurrentStep = nsi
185 void AliITSOnlineSPDscan::FillGap(UInt_t nsi) {
186 //create new steps until nsi is reached
187 while (nsi>=GetNSteps()) {
188 fCurrentStep = AddScanStep();
192 void AliITSOnlineSPDscan::ReadCurrentStep() {
193 // read current step index into memory
194 for (UInt_t hs=0; hs<6; hs++) {
195 TString stepName = Form("HitArray_HS%d_Step%d",hs,fCurrentStep);
196 fFile->GetObject(stepName.Data(), fCurrentHitArray[hs]);
197 TString stepName2 = Form("HitEvent_HS%d_Step%d",hs,fCurrentStep);
198 fFile->GetObject(stepName2, fCurrentHitEvent[hs]);
202 void AliITSOnlineSPDscan::SaveCurrentStep() {
203 // save current step to file
207 fFile = new TFile(fFileName.Data(), "UPDATE");
210 for (UInt_t hs=0; hs<6; hs++) {
211 TString stepName = Form("HitArray_HS%d_Step%d",hs,fCurrentStep);
212 TString stepDelete = Form("%s;*",stepName.Data());
213 fFile->Delete(stepDelete.Data());
214 fFile->WriteTObject(fCurrentHitArray[hs], stepName.Data());
215 TString stepName2 = Form("HitEvent_HS%d_Step%d",hs,fCurrentStep);
216 TString stepDelete2 = Form("%s;*",stepName2.Data());
217 fFile->Delete(stepDelete2.Data());
218 fFile->WriteTObject(fCurrentHitEvent[hs], stepName2.Data());
223 void AliITSOnlineSPDscan::SetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) {
224 // set nr of hits for pixel
226 fCurrentHitArray[hs]->SetHits(chipi,coli,rowi,val);
229 void AliITSOnlineSPDscan::IncrementHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
230 // increment nr of hits for pixel
232 fCurrentHitArray[hs]->IncrementHits(chipi,coli,rowi);
235 void AliITSOnlineSPDscan::SetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi, Int_t val) {
236 // set nr of hit events for a chip
238 fCurrentHitEvent[hs]->SetHitEvent(chipi,val);
241 void AliITSOnlineSPDscan::SetHitEventsTot(UInt_t nsi, UInt_t hs, Int_t val) {
242 // set nr of hit events for 10 chips together
243 SetHitEvents(nsi,hs,10,val);
245 void AliITSOnlineSPDscan::IncrementHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) {
246 // increment nr of hit events for a chip
248 fCurrentHitEvent[hs]->IncrementHitEvent(chipi);
251 void AliITSOnlineSPDscan::IncrementHitEventsTot(UInt_t nsi, UInt_t hs) {
252 // increment nr of hit events for 10 chips
253 IncrementHitEvents(nsi,hs,10);
257 UInt_t AliITSOnlineSPDscan::GetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
258 // get nr of hits for pixel
259 if (nsi<GetNSteps()) {
261 return fCurrentHitArray[hs]->GetHits(chipi,coli,rowi);
267 Float_t AliITSOnlineSPDscan::GetHitsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
268 // get the hit efficiency for pixel
269 UInt_t ntr = GetTriggers(nsi);
271 return ((Float_t)GetHits(nsi,hs,chipi,coli,rowi))/ntr;
277 Float_t AliITSOnlineSPDscan::GetHitsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
278 // get error in hit efficiency for pixel
279 Float_t hits = GetHits(nsi,hs,chipi,coli,rowi);
280 UInt_t ntr = GetTriggers(nsi);
281 return sqrt(hits*(ntr-hits)/ntr)/ntr;
283 UInt_t AliITSOnlineSPDscan::GetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) {
284 // get nr of hit events for a chip
285 if (nsi<GetNSteps()) {
287 return fCurrentHitEvent[hs]->GetHitEvent(chipi);
293 UInt_t AliITSOnlineSPDscan::GetHitEventsTot(UInt_t nsi, UInt_t hs) {
294 // get nr of hit events for 10 chips
295 return GetHitEvents(nsi,hs,10);
297 Float_t AliITSOnlineSPDscan::GetHitEventsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi) {
298 // get the hit events efficiency for a chip
299 UInt_t ntr = GetTriggers(nsi);
301 return ((Float_t)GetHitEvents(nsi,hs,chipi))/ntr;
307 Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiency(UInt_t nsi, UInt_t hs) {
308 // get the hit events efficiency for 10 chips
309 return GetHitEventsEfficiency(nsi,hs,10);
311 Float_t AliITSOnlineSPDscan::GetHitEventsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi) {
312 // get error in hit events efficiency for a chip
313 Float_t hitevents = (Float_t) GetHitEvents(nsi,hs,chipi);
314 UInt_t ntr = GetTriggers(nsi);
315 return sqrt(hitevents*(ntr-hitevents)/ntr)/ntr;
317 Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiencyError(UInt_t nsi, UInt_t hs) {
318 // get error in hit events efficiency for 10 chips
319 return GetHitEventsEfficiencyError(nsi,hs,10);
321 Float_t AliITSOnlineSPDscan::GetAverageMultiplicity(UInt_t nsi, UInt_t hs, UInt_t chipi) {
322 // get average multiplicity for a chip
324 for (UInt_t chip=0;chip<10;chip++) {
325 if (chipi==10 || chip==chipi) {
326 for (Int_t col=0; col<32; col++) {
327 for (Int_t row=0; row<256; row++) {
328 nrhits+=GetHits(nsi,hs,chip,col,row);
333 UInt_t ntr = GetTriggers(nsi);
341 Float_t AliITSOnlineSPDscan::GetAverageMultiplicityTot(UInt_t nsi, UInt_t hs) {
342 // get average multiplicity for 10 chips
343 return GetAverageMultiplicity(nsi,hs,10);
347 void AliITSOnlineSPDscan::SetType(UInt_t val) {
349 fScanInfo->SetType(val);
352 void AliITSOnlineSPDscan::SetRunNr(UInt_t val) {
354 fScanInfo->SetRunNr(val);
357 void AliITSOnlineSPDscan::SetRouterNr(UInt_t val) {
359 fScanInfo->SetRouterNr(val);
362 void AliITSOnlineSPDscan::SetHalfStaveScanned(UInt_t val, Bool_t b) {
363 // set half stave scanned
364 fScanInfo->SetHalfStaveScanned(val,b);
367 void AliITSOnlineSPDscan::SetDataFormat(UInt_t val) {
368 // set data format (0=normal 1=histogram)
369 fScanInfo->SetDataFormat(val);
372 void AliITSOnlineSPDscan::SetTriggers(UInt_t nsi, UInt_t val) {
373 // set nr of triggers
375 fScanInfo->SetTriggers(nsi,val);
378 void AliITSOnlineSPDscan::SetChipPresent(UInt_t hs, UInt_t chipi, Bool_t val){
380 fScanInfo->SetChipPresent(hs,chipi,val);
383 void AliITSOnlineSPDscan::SetRowStart(UInt_t val){
385 fScanInfo->SetRowStart(val);
388 void AliITSOnlineSPDscan::SetRowEnd(UInt_t val){
390 fScanInfo->SetRowEnd(val);
393 void AliITSOnlineSPDscan::SetDacStart(UInt_t val){
395 fScanInfo->SetDacStart(val);
398 void AliITSOnlineSPDscan::SetDacEnd(UInt_t val){
400 fScanInfo->SetDacEnd(val);
403 void AliITSOnlineSPDscan::SetDacStep(UInt_t val){
405 fScanInfo->SetDacStep(val);
408 void AliITSOnlineSPDscan::SetDCSVersion(UInt_t val){
409 // set dcs db version
410 fScanInfo->SetDCSVersion(val);
413 void AliITSOnlineSPDscan::IncrementTriggers(UInt_t nsi) {
414 // increment nr of triggers
416 fScanInfo->IncrementTriggers(nsi);
422 UInt_t AliITSOnlineSPDscan::GetNSteps() const {
423 return fScanInfo->GetNSteps();
425 UInt_t AliITSOnlineSPDscan::GetType() const {
426 return fScanInfo->GetType();
428 UInt_t AliITSOnlineSPDscan::GetRunNr() const {
429 return fScanInfo->GetRunNr();
431 UInt_t AliITSOnlineSPDscan::GetRouterNr() const {
432 return fScanInfo->GetRouterNr();
434 Bool_t AliITSOnlineSPDscan::GetHalfStaveScanned(UInt_t val) const {
435 return fScanInfo->GetHalfStaveScanned(val);
437 UInt_t AliITSOnlineSPDscan::GetDataFormat() const {
438 return fScanInfo->GetDataFormat();
440 UInt_t AliITSOnlineSPDscan::GetTriggers(UInt_t nsi) const {
441 return fScanInfo->GetTriggers(nsi);
443 Bool_t AliITSOnlineSPDscan::GetChipPresent(UInt_t hs, UInt_t chipi) const {
444 return fScanInfo->GetChipPresent(hs,chipi);
446 UInt_t AliITSOnlineSPDscan::GetRowStart() const {
447 return fScanInfo->GetRowStart();
449 UInt_t AliITSOnlineSPDscan::GetRowEnd() const {
450 return fScanInfo->GetRowEnd();
452 UInt_t AliITSOnlineSPDscan::GetDacStart() const {
453 return fScanInfo->GetDacStart();
455 UInt_t AliITSOnlineSPDscan::GetDacEnd() const {
456 return fScanInfo->GetDacEnd();
458 UInt_t AliITSOnlineSPDscan::GetDacStep() const {
459 return fScanInfo->GetDacStep();
461 UInt_t AliITSOnlineSPDscan::GetDCSVersion() const {
462 return fScanInfo->GetDCSVersion();