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, Bool_t readFromGridFile) :
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)
37 Bool_t bRead = readFromGridFile;
40 FILE* fp0 = fopen(fFileName.Data(), "r");
47 if (bRead) { // open file for reading
48 fFile = TFile::Open(fFileName.Data(), "READ");
49 if (fFile==NULL) { // grid file not found, create new local default file
50 printf("ERROR: AliITSOnlineSPDscan: File %s not found! Creating 'test999.root' file instead\n",fFileName.Data());
51 // create default empty file:
52 fFileName = "test999.root";
53 fScanInfo = new AliITSOnlineSPDscanInfo();
55 fFile = new TFile(fFileName.Data(), "RECREATE");
58 else { // read from file (grid or local)
60 fFile->GetObject("AliITSOnlineSPDscanInfo", fScanInfo);
63 else { // create new local file
64 fScanInfo = new AliITSOnlineSPDscanInfo();
66 fFile = new TFile(fFileName.Data(), "RECREATE");
73 AliITSOnlineSPDscan::AliITSOnlineSPDscan(const AliITSOnlineSPDscan& /*scan*/) :
78 fInfoModified(kFALSE),
82 printf("This object should not be copied!");
85 AliITSOnlineSPDscan::~AliITSOnlineSPDscan() {
90 for (UInt_t hs=0; hs<6; hs++) {
91 if (fCurrentHitArray[hs]!=NULL) {
92 delete fCurrentHitArray[hs];
93 fCurrentHitArray[hs]=NULL;
95 if (fCurrentHitEvent[hs]!=NULL) {
96 delete fCurrentHitEvent[hs];
97 fCurrentHitEvent[hs]=NULL;
104 fFile = new TFile(fFileName.Data(), "UPDATE");
107 fFile->Delete("AliITSOnlineSPDscanInfo;*");
108 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
115 AliITSOnlineSPDscan& AliITSOnlineSPDscan::operator=(const AliITSOnlineSPDscan& scan) {
116 // assignment operator (should not be used)
117 printf("This object should not be copied!");
119 // still do nothing...
124 void AliITSOnlineSPDscan::ClearThis() {
125 // clear this scan, close file and open new
126 for (UInt_t hs=0; hs<6; hs++) {
127 if (fCurrentHitArray[hs]!=NULL) {
128 delete fCurrentHitArray[hs];
130 fCurrentHitArray[hs] = NULL;
131 if (fCurrentHitEvent[hs]!=NULL) {
132 delete fCurrentHitEvent[hs];
134 fCurrentHitEvent[hs] = NULL;
136 fScanInfo->ClearThis();
139 fFile = new TFile(fFileName.Data(), "RECREATE");
141 fFile->WriteTObject(fScanInfo, "AliITSOnlineSPDscanInfo");
145 void AliITSOnlineSPDscan::Init() {
146 // init hit arrays and hit events
147 for (UInt_t hs=0; hs<6; hs++) {
148 fCurrentHitArray[hs]=NULL;
149 fCurrentHitEvent[hs]=NULL;
154 UInt_t AliITSOnlineSPDscan::AddScanStep() {
155 // add a new scan step
157 return fScanInfo->AddScanStep();
160 void AliITSOnlineSPDscan::CreateNewStep() {
162 // save current step to file (if modified)
167 for (UInt_t hs=0; hs<6; hs++) {
168 if (fCurrentHitArray[hs]!=NULL) {
169 delete fCurrentHitArray[hs];
171 fCurrentHitArray[hs] = new AliITSOnlineSPDHitArray();
172 if (fCurrentHitEvent[hs]!=NULL) {
173 delete fCurrentHitEvent[hs];
175 fCurrentHitEvent[hs] = new AliITSOnlineSPDHitEvent();
177 fCurrentStep = fScanInfo->GetNSteps();
182 void AliITSOnlineSPDscan::SwitchToStep(UInt_t nsi) {
183 // switch to step nsi (save current step first if needed)
184 if ((Int_t)nsi!=fCurrentStep) {
188 for (UInt_t hs=0; hs<6; hs++) {
189 if (fCurrentHitArray[hs]!=NULL) {
190 delete fCurrentHitArray[hs];
191 fCurrentHitArray[hs]=NULL;
193 if (fCurrentHitEvent[hs]!=NULL) {
194 delete fCurrentHitEvent[hs];
195 fCurrentHitEvent[hs]=NULL;
198 if (nsi>=GetNSteps()) {
199 FillGap(nsi); // makes fCurrentStep = nsi
208 void AliITSOnlineSPDscan::FillGap(UInt_t nsi) {
209 //create new steps until nsi is reached
210 while (nsi>=GetNSteps()) {
211 fCurrentStep = AddScanStep();
215 void AliITSOnlineSPDscan::ReadCurrentStep() {
216 // read current step index into memory
217 for (UInt_t hs=0; hs<6; hs++) {
218 TString stepName = Form("HitArray_HS%d_Step%d",hs,fCurrentStep);
219 fFile->GetObject(stepName.Data(), fCurrentHitArray[hs]);
220 TString stepName2 = Form("HitEvent_HS%d_Step%d",hs,fCurrentStep);
221 fFile->GetObject(stepName2, fCurrentHitEvent[hs]);
225 void AliITSOnlineSPDscan::SaveCurrentStep() {
226 // save current step to file
230 fFile = new TFile(fFileName.Data(), "UPDATE");
233 for (UInt_t hs=0; hs<6; hs++) {
234 TString stepName = Form("HitArray_HS%d_Step%d",hs,fCurrentStep);
235 TString stepDelete = Form("%s;*",stepName.Data());
236 fFile->Delete(stepDelete.Data());
237 fFile->WriteTObject(fCurrentHitArray[hs], stepName.Data());
238 TString stepName2 = Form("HitEvent_HS%d_Step%d",hs,fCurrentStep);
239 TString stepDelete2 = Form("%s;*",stepName2.Data());
240 fFile->Delete(stepDelete2.Data());
241 fFile->WriteTObject(fCurrentHitEvent[hs], stepName2.Data());
246 void AliITSOnlineSPDscan::SetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi, UInt_t val) {
247 // set nr of hits for pixel
249 fCurrentHitArray[hs]->SetHits(chipi,coli,rowi,val);
252 void AliITSOnlineSPDscan::IncrementHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
253 // increment nr of hits for pixel
255 fCurrentHitArray[hs]->IncrementHits(chipi,coli,rowi);
258 void AliITSOnlineSPDscan::SetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi, Int_t val) {
259 // set nr of hit events for a chip
261 fCurrentHitEvent[hs]->SetHitEvent(chipi,val);
264 void AliITSOnlineSPDscan::SetHitEventsTot(UInt_t nsi, UInt_t hs, Int_t val) {
265 // set nr of hit events for 10 chips together
266 SetHitEvents(nsi,hs,10,val);
268 void AliITSOnlineSPDscan::IncrementHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) {
269 // increment nr of hit events for a chip
271 fCurrentHitEvent[hs]->IncrementHitEvent(chipi);
274 void AliITSOnlineSPDscan::IncrementHitEventsTot(UInt_t nsi, UInt_t hs) {
275 // increment nr of hit events for 10 chips
276 IncrementHitEvents(nsi,hs,10);
280 UInt_t AliITSOnlineSPDscan::GetHits(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
281 // get nr of hits for pixel
282 if (nsi<GetNSteps()) {
284 return fCurrentHitArray[hs]->GetHits(chipi,coli,rowi);
290 Float_t AliITSOnlineSPDscan::GetHitsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
291 // get the hit efficiency for pixel
292 UInt_t ntr = GetTriggers(nsi);
294 return ((Float_t)GetHits(nsi,hs,chipi,coli,rowi))/ntr;
300 Float_t AliITSOnlineSPDscan::GetHitsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi, UInt_t coli, UInt_t rowi) {
301 // get error in hit efficiency for pixel
302 Float_t hits = GetHits(nsi,hs,chipi,coli,rowi);
303 UInt_t ntr = GetTriggers(nsi);
304 return sqrt(hits*(ntr-hits)/ntr)/ntr;
306 UInt_t AliITSOnlineSPDscan::GetHitEvents(UInt_t nsi, UInt_t hs, UInt_t chipi) {
307 // get nr of hit events for a chip
308 if (nsi<GetNSteps()) {
310 return fCurrentHitEvent[hs]->GetHitEvent(chipi);
316 UInt_t AliITSOnlineSPDscan::GetHitEventsTot(UInt_t nsi, UInt_t hs) {
317 // get nr of hit events for 10 chips
318 return GetHitEvents(nsi,hs,10);
320 Float_t AliITSOnlineSPDscan::GetHitEventsEfficiency(UInt_t nsi, UInt_t hs, UInt_t chipi) {
321 // get the hit events efficiency for a chip
322 UInt_t ntr = GetTriggers(nsi);
324 return ((Float_t)GetHitEvents(nsi,hs,chipi))/ntr;
330 Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiency(UInt_t nsi, UInt_t hs) {
331 // get the hit events efficiency for 10 chips
332 return GetHitEventsEfficiency(nsi,hs,10);
334 Float_t AliITSOnlineSPDscan::GetHitEventsEfficiencyError(UInt_t nsi, UInt_t hs, UInt_t chipi) {
335 // get error in hit events efficiency for a chip
336 Float_t hitevents = (Float_t) GetHitEvents(nsi,hs,chipi);
337 UInt_t ntr = GetTriggers(nsi);
338 return sqrt(hitevents*(ntr-hitevents)/ntr)/ntr;
340 Float_t AliITSOnlineSPDscan::GetHitEventsTotEfficiencyError(UInt_t nsi, UInt_t hs) {
341 // get error in hit events efficiency for 10 chips
342 return GetHitEventsEfficiencyError(nsi,hs,10);
344 Float_t AliITSOnlineSPDscan::GetAverageMultiplicity(UInt_t nsi, UInt_t hs, UInt_t chipi) {
345 // get average multiplicity for a chip
347 for (UInt_t chip=0;chip<10;chip++) {
348 if (chipi==10 || chip==chipi) {
349 for (Int_t col=0; col<32; col++) {
350 for (Int_t row=0; row<256; row++) {
351 nrhits+=GetHits(nsi,hs,chip,col,row);
356 UInt_t ntr = GetTriggers(nsi);
364 Float_t AliITSOnlineSPDscan::GetAverageMultiplicityTot(UInt_t nsi, UInt_t hs) {
365 // get average multiplicity for 10 chips
366 return GetAverageMultiplicity(nsi,hs,10);
370 void AliITSOnlineSPDscan::SetType(UInt_t val) {
372 fScanInfo->SetType(val);
375 void AliITSOnlineSPDscan::SetRunNr(UInt_t val) {
377 fScanInfo->SetRunNr(val);
380 void AliITSOnlineSPDscan::SetRouterNr(UInt_t val) {
382 fScanInfo->SetRouterNr(val);
385 void AliITSOnlineSPDscan::SetHalfStaveScanned(UInt_t val, Bool_t b) {
386 // set half stave scanned
387 fScanInfo->SetHalfStaveScanned(val,b);
390 void AliITSOnlineSPDscan::SetDataFormat(UInt_t val) {
391 // set data format (0=normal 1=histogram)
392 fScanInfo->SetDataFormat(val);
395 void AliITSOnlineSPDscan::SetTriggers(UInt_t nsi, UInt_t val) {
396 // set nr of triggers
398 fScanInfo->SetTriggers(nsi,val);
401 void AliITSOnlineSPDscan::SetChipPresent(UInt_t hs, UInt_t chipi, Bool_t val){
403 fScanInfo->SetChipPresent(hs,chipi,val);
406 void AliITSOnlineSPDscan::SetRowStart(UInt_t val){
408 fScanInfo->SetRowStart(val);
411 void AliITSOnlineSPDscan::SetRowEnd(UInt_t val){
413 fScanInfo->SetRowEnd(val);
416 void AliITSOnlineSPDscan::SetDacStart(UInt_t val){
418 fScanInfo->SetDacStart(val);
421 void AliITSOnlineSPDscan::SetDacEnd(UInt_t val){
423 fScanInfo->SetDacEnd(val);
426 void AliITSOnlineSPDscan::SetDacStep(UInt_t val){
428 fScanInfo->SetDacStep(val);
431 void AliITSOnlineSPDscan::SetDCSVersion(UInt_t val){
432 // set dcs db version
433 fScanInfo->SetDCSVersion(val);
436 void AliITSOnlineSPDscan::IncrementTriggers(UInt_t nsi) {
437 // increment nr of triggers
439 fScanInfo->IncrementTriggers(nsi);
445 UInt_t AliITSOnlineSPDscan::GetNSteps() const {
446 return fScanInfo->GetNSteps();
448 UInt_t AliITSOnlineSPDscan::GetType() const {
449 return fScanInfo->GetType();
451 UInt_t AliITSOnlineSPDscan::GetRunNr() const {
452 return fScanInfo->GetRunNr();
454 UInt_t AliITSOnlineSPDscan::GetRouterNr() const {
455 return fScanInfo->GetRouterNr();
457 Bool_t AliITSOnlineSPDscan::GetHalfStaveScanned(UInt_t val) const {
458 return fScanInfo->GetHalfStaveScanned(val);
460 UInt_t AliITSOnlineSPDscan::GetDataFormat() const {
461 return fScanInfo->GetDataFormat();
463 UInt_t AliITSOnlineSPDscan::GetTriggers(UInt_t nsi) const {
464 return fScanInfo->GetTriggers(nsi);
466 Bool_t AliITSOnlineSPDscan::GetChipPresent(UInt_t hs, UInt_t chipi) const {
467 return fScanInfo->GetChipPresent(hs,chipi);
469 UInt_t AliITSOnlineSPDscan::GetRowStart() const {
470 return fScanInfo->GetRowStart();
472 UInt_t AliITSOnlineSPDscan::GetRowEnd() const {
473 return fScanInfo->GetRowEnd();
475 UInt_t AliITSOnlineSPDscan::GetDacStart() const {
476 return fScanInfo->GetDacStart();
478 UInt_t AliITSOnlineSPDscan::GetDacEnd() const {
479 return fScanInfo->GetDacEnd();
481 UInt_t AliITSOnlineSPDscan::GetDacStep() const {
482 return fScanInfo->GetDacStep();
484 UInt_t AliITSOnlineSPDscan::GetDCSVersion() const {
485 return fScanInfo->GetDCSVersion();