AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONBusPatchEvolutionSubprocessor.cxx
Go to the documentation of this file.
2 
3 #include "AliCDBMetaData.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 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
22 
26 
27 namespace {
28  const Double_t bytes2MB = 1.0 / 1024.0 / 1024.0;
29 }
30 
31 //_____________________________________________________________________________
33 : AliMUONVSubprocessor(master,"Occupancy","Upload MUON Tracker Bus Patch Evolution to OCDB"),
34  fBPEVO(0x0), fProductionMode(1)
35 {
37 }
38 
39 //_____________________________________________________________________________
41 {
43  delete fBPEVO;
44 }
45 
46 //_____________________________________________________________________________
47 Bool_t
49 {
51 
52  const Int_t kSystem = AliMUONPreprocessor::kDAQ;
53  const char* kId = "BPEVO";
54 
55  delete fBPEVO;
56  fBPEVO = 0x0;
57 
58  Master()->Log(Form("Reading buspatch evolution file for Run %d startTime %u endTime %u",
59  run,startTime,endTime));
60 
61  TList* sources = Master()->GetFileSources(kSystem,kId);
62  TIter next(sources);
63  TObjString* o(0x0);
64  Int_t n(0);
65 
66  while ( ( o = static_cast<TObjString*>(next()) ) )
67  {
68  TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
69  if (ReadFile(fileName.Data()))
70  {
71  ++n;
72  }
73  }
74 
75  delete sources;
76 
77  if (!n)
78  {
79  Master()->Log("Failed to read any bus patch evolution");
80  delete fBPEVO;
81  fBPEVO = 0;
82 
83  // return kFALSE; // for the moment, as this one is experimental, does not require it...
84  }
85 
86  if ( fBPEVO )
87  {
88  UInt_t hsizeBefore = fBPEVO->EstimateSize(kFALSE);
89 
91 
92  bpe.ShrinkTimeAxis();
93 
94  UInt_t hsizeAfter = fBPEVO->EstimateSize(kFALSE);
95 
96  Master()->Log(Form("Initial collection size shrinked from %7.3f to %7.3f MB",hsizeBefore*bytes2MB,hsizeAfter*bytes2MB));
97 
98  std::vector<int> timeResolutions;
99  bpe.GetTimeResolutions(timeResolutions);
100 
101  if (!timeResolutions.size())
102  {
103  Master()->Log("Input mergeable collection does not seem to have time resolution histograms... Cannot work like that !");
104  }
105  else
106  {
107  TString msg;
108  for ( std::vector<int>::size_type i = 0; i < timeResolutions.size(); ++i )
109  {
110  msg += Form("%d s ",timeResolutions[i]);
111  }
112  Master()->Log(Form("Time resolutions found : %s",msg.Data()));
113 
114 
115  if ( !fProductionMode )
116  {
117  bpe.Augment();
118 
119  hsizeAfter = fBPEVO->EstimateSize(kFALSE);
120  }
121 
122  Master()->Log(Form("Final collection size is %7.3f MB",hsizeAfter*bytes2MB));
123  }
124  }
125 
126  return kTRUE;
127 }
128 
129 //_____________________________________________________________________________
130 UInt_t
132 {
134 
135  if (!fBPEVO)
136  {
137  // as this one is still experimental, do not ever fail...
138  return 0;
139  }
140 
141  if ( fBPEVO->NumberOfObjects() )
142  {
143  Master()->Log("Storing buspatch evolution");
144 
145  AliCDBMetaData metaData;
146  metaData.SetBeamPeriod(0);
147  metaData.SetResponsible("MUON TRK");
148  TString comment("Computed by AliMUONBusPatchEvolutionSubprocessor $Id$");
149  comment.ReplaceAll("$","");
150  metaData.SetComment(comment.Data());
151 
152  Bool_t validToInfinity = kFALSE;
153  Bool_t result = Master()->Store("Calib", "BPEVO", fBPEVO, &metaData, 0, validToInfinity);
154 
155  return ( result != kTRUE ); // return 0 if everything is ok.
156  }
157  else
158  {
159  Master()->Log("No buspatch evolution to store");
160  return 0;
161  }
162 }
163 
164 //_____________________________________________________________________________
165 Bool_t
167 {
171 
172  TString sFilename(gSystem->ExpandPathName(filename));
173 
174  Master()->Log(Form("Reading %s",sFilename.Data()));
175 
176  TFile* f = TFile::Open(sFilename.Data());
177 
178  if ( !f || !f->IsOpen() )
179  {
180  Master()->Log(Form("Could not open %s",sFilename.Data()));
181  return kFALSE;
182  }
183 
184  AliMergeableCollection* hc(0x0);
185 
186  hc = dynamic_cast<AliMergeableCollection*>(f->Get("bpevo"));
187 
188  if (hc)
189  {
190  fBPEVO = static_cast<AliMergeableCollection*>(hc->Clone());
191  }
192  return ( hc != 0x0);
193 }
194 
195 
196 //_____________________________________________________________________________
197 void
199 {
201  if (fBPEVO) fBPEVO->Print(opt);
202 }
void GetTimeResolutions(std::vector< int > &timeResolutions)
TFile * Open(const char *filename, Long64_t &nevents)
AliMUONPreprocessor * Master() const
Return the pointer to our master.
static TString comment
Definition: ConfigCosmic.C:131
TFile f("CalibObjects.root")
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Base class for a shuttle sub-task for MUON (either TRK or TRG)
TTimeStamp startTime(2009, 8, 7, 0, 0, 0)
int fProductionMode
! Whether or not we are using this one in production mode
AliMergeableCollection * fBPEVO
! Bus patch evolution
UInt_t Process(TMap *dcsAliasMap)
Process this sub-task.
void Log(const char *message)
Publish AliPreprocessor::Log function.
Bool_t Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
TList * GetFileSources(Int_t system, const char *id)
Publish AliPreprocessor::GetFileSources function.
Bool_t Store(const char *pathLevel2, const char *pathLevel3, TObject *object, AliCDBMetaData *metaData, Int_t validityStart=0, Bool_t validityInfinite=kFALSE)
Publish AliPreprocessor::Store function.
Utility class to massage the output of the MCHBPEVO DA.
Implementation of AliMUONVSubprocessor for MUON TRK bus patch evolution.
Shuttle preprocessor for MUON subsystems (TRK and TRG)