| 1 |
/* |
| 2 |
* LiveTimeCollection.cpp |
| 3 |
* |
| 4 |
* Created on: 30-marth-2010 |
| 5 |
* Author: Vitaly Malakhov |
| 6 |
*/ |
| 7 |
|
| 8 |
/*! @file LiveTimeCollection.cpp The LiveTimeCollection class implementation file */ |
| 9 |
|
| 10 |
#include "LiveTimeCollection.h" |
| 11 |
|
| 12 |
void LiveTimeCollection::AddAction(CollectionAction *action) { |
| 13 |
_actions.push_back(action); |
| 14 |
_actionsPositions.push_back(GetSize() - 1); |
| 15 |
_sumLT.push_back(0); |
| 16 |
_sum.push_back(0); |
| 17 |
_badsum.push_back(0); |
| 18 |
} |
| 19 |
|
| 20 |
void LiveTimeCollection::OnBad(PamLevel2 *event, int actNumber, unsigned int inc) { |
| 21 |
if((event->GetOrbitalInfo()->absTime - _currenttime > 1000.) || (_currenttime == 0)){ |
| 22 |
for(unsigned int j = 0; j < _sumLT.size(); j++ ){ |
| 23 |
if(_currenttime == 0) _badsum[j] = 0; else {_badsum[j] += _sumLT[j]; _gapNumb++;} |
| 24 |
_sumLT[j] = 0; |
| 25 |
} |
| 26 |
} |
| 27 |
_currenttime = event->GetOrbitalInfo()->absTime; |
| 28 |
unsigned int Inc = 0; |
| 29 |
if(inc == 0) Inc = event->GetTrigLevel2()->dltime[0]; else Inc = inc; |
| 30 |
for(unsigned int j = actNumber; j <= _actions.size()-1; j++) _sumLT[j] += Inc; |
| 31 |
} |
| 32 |
|
| 33 |
Float_t LiveTimeCollection::GetSumLiveTime(unsigned int actNumber) { |
| 34 |
if(actNumber >= _sum.size()) return -1; |
| 35 |
return _sum[actNumber] * 0.16 /1000. ; |
| 36 |
} |
| 37 |
|
| 38 |
Float_t LiveTimeCollection::GetBadsumLiveTime(unsigned int actNumber) { |
| 39 |
if(actNumber >= _sum.size()) return -1; |
| 40 |
return _badsum[actNumber] * 0.16 /1000. ; |
| 41 |
} |
| 42 |
|
| 43 |
int LiveTimeCollection::ApplyCut(PamLevel2 *event) { |
| 44 |
|
| 45 |
_nEv++; |
| 46 |
|
| 47 |
// Execute the actions placed before the cuts |
| 48 |
unsigned int iBeforeCuts = 0; |
| 49 |
if (_actions.size() > 0) { |
| 50 |
while (_actionsPositions[iBeforeCuts] == -1) { |
| 51 |
_actions[iBeforeCuts]->OnGood(event); |
| 52 |
iBeforeCuts++; |
| 53 |
if (iBeforeCuts == _actions.size()) |
| 54 |
break; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
// Apply the cuts |
| 59 |
if (_cuts.size() == 0) { |
| 60 |
_nGood++; |
| 61 |
OnGood(event); |
| 62 |
return CUTOK; |
| 63 |
} |
| 64 |
|
| 65 |
unsigned int firstFailed = _cuts.size(); |
| 66 |
for (unsigned int iCut = 0; iCut < _cuts.size(); iCut++) { |
| 67 |
if (_cuts[iCut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { |
| 68 |
firstFailed = iCut; |
| 69 |
break; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
Int_t actNumber = 0; |
| 74 |
unsigned int Inc = 0; |
| 75 |
|
| 76 |
//Do actions |
| 77 |
if (_actions.size() > 0) { |
| 78 |
Bool_t che = true; |
| 79 |
Int_t inc = 0; |
| 80 |
unsigned int lastPosition = _cuts.size(); |
| 81 |
for (unsigned int i = iBeforeCuts; i < _actions.size(); i++) { |
| 82 |
actNumber = i; |
| 83 |
if (_actionsPositions[i] < (int) firstFailed){ |
| 84 |
if((event->GetOrbitalInfo()->absTime - _currenttime > 1000.) || (_currenttime == 0)){ |
| 85 |
for(unsigned int j = 0; j < _sumLT.size(); j++ ) { |
| 86 |
if(_currenttime == 0) _badsum[j] = 0; else {_badsum[j] += _sumLT[j]; _gapNumb++;} |
| 87 |
_sumLT[j] = 0; |
| 88 |
} |
| 89 |
} |
| 90 |
if( che ){ |
| 91 |
inc = event->GetTrigLevel2()->dltime[0]; |
| 92 |
Inc = inc; |
| 93 |
} |
| 94 |
_sum[i] += (_sumLT[i]+inc); |
| 95 |
event->GetTrigLevel2()->dltime[0] += _sumLT[i] + inc; |
| 96 |
che = false; |
| 97 |
_actions[i]->OnGood(event); |
| 98 |
_sumLT[i] = 0; |
| 99 |
_currenttime = event->GetOrbitalInfo()->absTime; |
| 100 |
} |
| 101 |
else { // A cut has failed |
| 102 |
if (lastPosition == _cuts.size()) // Record the position of the end of the bunch |
| 103 |
lastPosition = _actionsPositions[i]; |
| 104 |
if (_actionsPositions[i] > (int) lastPosition) // Don't do actions at the end of successive bunches |
| 105 |
break; |
| 106 |
_actions[i]->OnBad(event, i); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
if (firstFailed == _cuts.size()) { |
| 112 |
_nGood++; |
| 113 |
OnGood(event); |
| 114 |
return CUTOK; |
| 115 |
} |
| 116 |
else { |
| 117 |
OnBad(event, actNumber, Inc); |
| 118 |
return firstFailed; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
void LiveTimeCollection::Finalize() { |
| 123 |
SmartCollection::Finalize(); |
| 124 |
ofstream livetimereport; |
| 125 |
livetimereport.open (_livetimereport); |
| 126 |
livetimereport << "Action name\t\tsum live time"<<endl; |
| 127 |
for (UInt_t i = 0; i < _sum.size(); i++) livetimereport << _actions[i]->GetName()<<"\t"<<GetSumLiveTime(i)<<"sec"<<"\t"<<GetBadsumLiveTime(i)<<"\t"<<_gapNumb<<endl; |
| 128 |
livetimereport.close(); |
| 129 |
} |