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 |
} |
18 |
|
19 |
void LiveTimeCollection::OnBad(PamLevel2 *event, int actNumber, unsigned int inc) { |
20 |
if((event->GetOrbitalInfo()->absTime - _currenttime > 1000.) || (_currenttime == 0)){ |
21 |
for(unsigned int j = 0; j < _sumLT.size(); j++ ) _sumLT[j] = 0; |
22 |
} |
23 |
_currenttime = event->GetOrbitalInfo()->absTime; |
24 |
unsigned int Inc = 0; |
25 |
if(inc == 0) Inc = event->GetTrigLevel2()->dltime[0]; else Inc = inc; |
26 |
for(unsigned int j = actNumber; j <= _actions.size()-1; j++) _sumLT[j] += Inc; |
27 |
} |
28 |
|
29 |
Float_t LiveTimeCollection::GetSumLiveTime(unsigned int actNumber) { |
30 |
if(actNumber >= _sum.size()) return -1; |
31 |
return _sum[actNumber] * 0.16 /1000. ; |
32 |
} |
33 |
|
34 |
int LiveTimeCollection::ApplyCut(PamLevel2 *event) { |
35 |
|
36 |
_nEv++; |
37 |
|
38 |
// Execute the actions placed before the cuts |
39 |
unsigned int iBeforeCuts = 0; |
40 |
if (_actions.size() > 0) { |
41 |
while (_actionsPositions[iBeforeCuts] == -1) { |
42 |
_actions[iBeforeCuts]->OnGood(event); |
43 |
iBeforeCuts++; |
44 |
if (iBeforeCuts == _actions.size()) |
45 |
break; |
46 |
} |
47 |
} |
48 |
|
49 |
// Apply the cuts |
50 |
if (_cuts.size() == 0) { |
51 |
_nGood++; |
52 |
OnGood(event); |
53 |
return CUTOK; |
54 |
} |
55 |
|
56 |
unsigned int firstFailed = _cuts.size(); |
57 |
for (unsigned int iCut = 0; iCut < _cuts.size(); iCut++) { |
58 |
if (_cuts[iCut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { |
59 |
firstFailed = iCut; |
60 |
break; |
61 |
} |
62 |
} |
63 |
|
64 |
Int_t actNumber = 0; |
65 |
unsigned int Inc = 0; |
66 |
|
67 |
//Do actions |
68 |
if (_actions.size() > 0) { |
69 |
Bool_t che = true; |
70 |
Int_t inc = 0; |
71 |
unsigned int lastPosition = _cuts.size(); |
72 |
for (unsigned int i = iBeforeCuts; i < _actions.size(); i++) { |
73 |
actNumber = i-1; |
74 |
if (_actionsPositions[i] < (int) firstFailed){ |
75 |
if((event->GetOrbitalInfo()->absTime - _currenttime > 1000.) || (_currenttime == 0)){ |
76 |
for(unsigned int j = 0; j < _sumLT.size(); j++ ) _sumLT[j] = 0; |
77 |
} |
78 |
if( che ){ |
79 |
inc = event->GetTrigLevel2()->dltime[0]; |
80 |
Inc = inc; |
81 |
_sum[i] += _sumLT[i]+inc; |
82 |
event->GetTrigLevel2()->dltime[0] += _sumLT[i] ; |
83 |
che = false; |
84 |
}else _sum[i] += (_sumLT[i]+inc); |
85 |
_actions[i]->OnGood(event); |
86 |
_sumLT[i] = 0; |
87 |
_currenttime = event->GetOrbitalInfo()->absTime; |
88 |
} |
89 |
else { // A cut has failed |
90 |
if (lastPosition == _cuts.size()) // Record the position of the end of the bunch |
91 |
lastPosition = _actionsPositions[i]; |
92 |
if (_actionsPositions[i] > (int) lastPosition) // Don't do actions at the end of successive bunches |
93 |
break; |
94 |
_actions[i]->OnBad(event, i); |
95 |
} |
96 |
} |
97 |
} |
98 |
|
99 |
if (firstFailed == _cuts.size()) { |
100 |
_nGood++; |
101 |
OnGood(event); |
102 |
return CUTOK; |
103 |
} |
104 |
else { |
105 |
OnBad(event, actNumber, Inc); |
106 |
return firstFailed; |
107 |
} |
108 |
} |
109 |
|
110 |
void LiveTimeCollection::Finalize() { |
111 |
ofstream livetimereport; |
112 |
livetimereport.open (_livetimereport); |
113 |
livetimereport << "Action name\t\tsum live time"<<endl; |
114 |
for (UInt_t i = 0; i < _sum.size(); i++) livetimereport << _actions[i]->GetName()<<"\t"<<GetSumLiveTime(i)<<"sec"<<endl; |
115 |
livetimereport.close(); |
116 |
} |