Line data Source code
1 : #include "AliMUONBusPatchEvolutionSubprocessor.h"
2 :
3 : #include "AliCDBMetaData.h"
4 : #include "AliMUONBusPatchEvolution.h"
5 : #include "AliMUONPreprocessor.h"
6 : #include "TFile.h"
7 : #include "TH1.h"
8 : #include "TObjArray.h"
9 : #include "TObjString.h"
10 : #include "TSystem.h"
11 : #include <cassert>
12 : #include <set>
13 : #include "AliMergeableCollection.h"
14 :
15 : //-----------------------------------------------------------------------------
16 : /// \class AliMUONBusPatchEvolutionSubprocessor
17 : ///
18 : /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK bus patch evolution.
19 : ///
20 : /// \author L. Aphecetche
21 : //-----------------------------------------------------------------------------
22 :
23 : /// \cond CLASSIMP
24 12 : ClassImp(AliMUONBusPatchEvolutionSubprocessor)
25 : /// \endcond
26 :
27 : namespace {
28 : const Double_t bytes2MB = 1.0 / 1024.0 / 1024.0;
29 : }
30 :
31 : //_____________________________________________________________________________
32 : AliMUONBusPatchEvolutionSubprocessor::AliMUONBusPatchEvolutionSubprocessor(AliMUONPreprocessor* master)
33 0 : : AliMUONVSubprocessor(master,"Occupancy","Upload MUON Tracker Bus Patch Evolution to OCDB"),
34 0 : fBPEVO(0x0), fProductionMode(1)
35 0 : {
36 : /// Default ctor
37 0 : }
38 :
39 : //_____________________________________________________________________________
40 : AliMUONBusPatchEvolutionSubprocessor::~AliMUONBusPatchEvolutionSubprocessor()
41 0 : {
42 : /// dtor
43 0 : delete fBPEVO;
44 0 : }
45 :
46 : //_____________________________________________________________________________
47 : Bool_t
48 : AliMUONBusPatchEvolutionSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
49 : {
50 : /// When starting a new run, reads in the occupancy ASCII files.
51 :
52 : const Int_t kSystem = AliMUONPreprocessor::kDAQ;
53 : const char* kId = "BPEVO";
54 :
55 0 : delete fBPEVO;
56 0 : fBPEVO = 0x0;
57 :
58 0 : Master()->Log(Form("Reading buspatch evolution file for Run %d startTime %u endTime %u",
59 : run,startTime,endTime));
60 :
61 0 : TList* sources = Master()->GetFileSources(kSystem,kId);
62 0 : TIter next(sources);
63 : TObjString* o(0x0);
64 : Int_t n(0);
65 :
66 0 : while ( ( o = static_cast<TObjString*>(next()) ) )
67 : {
68 0 : TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
69 0 : if (ReadFile(fileName.Data()))
70 : {
71 0 : ++n;
72 0 : }
73 0 : }
74 :
75 0 : delete sources;
76 :
77 0 : if (!n)
78 : {
79 0 : Master()->Log("Failed to read any bus patch evolution");
80 0 : delete fBPEVO;
81 0 : fBPEVO = 0;
82 :
83 : // return kFALSE; // for the moment, as this one is experimental, does not require it...
84 0 : }
85 :
86 0 : if ( fBPEVO )
87 : {
88 0 : UInt_t hsizeBefore = fBPEVO->EstimateSize(kFALSE);
89 :
90 0 : AliMUONBusPatchEvolution bpe(*fBPEVO);
91 :
92 0 : bpe.ShrinkTimeAxis();
93 :
94 0 : UInt_t hsizeAfter = fBPEVO->EstimateSize(kFALSE);
95 :
96 0 : Master()->Log(Form("Initial collection size shrinked from %7.3f to %7.3f MB",hsizeBefore*bytes2MB,hsizeAfter*bytes2MB));
97 :
98 0 : std::vector<int> timeResolutions;
99 0 : bpe.GetTimeResolutions(timeResolutions);
100 :
101 0 : if (!timeResolutions.size())
102 : {
103 0 : Master()->Log("Input mergeable collection does not seem to have time resolution histograms... Cannot work like that !");
104 : }
105 : else
106 : {
107 0 : TString msg;
108 0 : for ( std::vector<int>::size_type i = 0; i < timeResolutions.size(); ++i )
109 : {
110 0 : msg += Form("%d s ",timeResolutions[i]);
111 : }
112 0 : Master()->Log(Form("Time resolutions found : %s",msg.Data()));
113 :
114 :
115 0 : if ( !fProductionMode )
116 : {
117 0 : bpe.Augment();
118 :
119 0 : hsizeAfter = fBPEVO->EstimateSize(kFALSE);
120 0 : }
121 :
122 0 : Master()->Log(Form("Final collection size is %7.3f MB",hsizeAfter*bytes2MB));
123 0 : }
124 0 : }
125 :
126 : return kTRUE;
127 0 : }
128 :
129 : //_____________________________________________________________________________
130 : UInt_t
131 : AliMUONBusPatchEvolutionSubprocessor::Process(TMap* /*dcsAliasMap*/)
132 : {
133 : /// Store the occupancy map into the CDB
134 :
135 0 : if (!fBPEVO)
136 : {
137 : // as this one is still experimental, do not ever fail...
138 0 : return 0;
139 : }
140 :
141 0 : if ( fBPEVO->NumberOfObjects() )
142 : {
143 0 : Master()->Log("Storing buspatch evolution");
144 :
145 0 : AliCDBMetaData metaData;
146 0 : metaData.SetBeamPeriod(0);
147 0 : metaData.SetResponsible("MUON TRK");
148 0 : TString comment("Computed by AliMUONBusPatchEvolutionSubprocessor $Id$");
149 0 : comment.ReplaceAll("$","");
150 0 : metaData.SetComment(comment.Data());
151 :
152 : Bool_t validToInfinity = kFALSE;
153 0 : Bool_t result = Master()->Store("Calib", "BPEVO", fBPEVO, &metaData, 0, validToInfinity);
154 :
155 0 : return ( result != kTRUE ); // return 0 if everything is ok.
156 0 : }
157 : else
158 : {
159 0 : Master()->Log("No buspatch evolution to store");
160 0 : return 0;
161 : }
162 0 : }
163 :
164 : //_____________________________________________________________________________
165 : Bool_t
166 : AliMUONBusPatchEvolutionSubprocessor::ReadFile(const char* filename)
167 : {
168 : /// Read the occupancy from an ASCII file. \n
169 : /// Return kFALSE if reading was not successfull. \n
170 : ///
171 :
172 0 : TString sFilename(gSystem->ExpandPathName(filename));
173 :
174 0 : Master()->Log(Form("Reading %s",sFilename.Data()));
175 :
176 0 : TFile* f = TFile::Open(sFilename.Data());
177 :
178 0 : if ( !f || !f->IsOpen() )
179 : {
180 0 : Master()->Log(Form("Could not open %s",sFilename.Data()));
181 0 : return kFALSE;
182 : }
183 :
184 : AliMergeableCollection* hc(0x0);
185 :
186 0 : hc = dynamic_cast<AliMergeableCollection*>(f->Get("bpevo"));
187 :
188 0 : if (hc)
189 : {
190 0 : fBPEVO = static_cast<AliMergeableCollection*>(hc->Clone());
191 0 : }
192 : return ( hc != 0x0);
193 0 : }
194 :
195 :
196 : //_____________________________________________________________________________
197 : void
198 : AliMUONBusPatchEvolutionSubprocessor::Print(Option_t* opt) const
199 : {
200 : /// ouput to screen
201 0 : if (fBPEVO) fBPEVO->Print(opt);
202 0 : }
|