CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CalibrationHistosUsingDb.cc
Go to the documentation of this file.
1 // Last commit: $Id: CalibrationHistosUsingDb.cc,v 1.12 2009/11/10 14:49:02 lowette Exp $
2 
9 #include <iostream>
10 
11 using namespace sistrip;
12 
13 // -----------------------------------------------------------------------------
16 {
17  return path.substr(0,path.find(std::string(sistrip::root_) + "/")+sizeof(sistrip::root_) );
18 }
19 
20 // -----------------------------------------------------------------------------
23  DQMStore* bei,
24  SiStripConfigDb* const db,
25  const sistrip::RunType& task )
26  : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("CalibrationParameters"),
27  bei,
28  task ),
30  task ),
31  CalibrationHistograms( pset.getParameter<edm::ParameterSet>("CalibrationParameters"),
32  bei,
33  task )
34 {
36  << "[CalibrationHistosUsingDb::" << __func__ << "]"
37  << " Constructing object...";
38  // Load and dump the current ISHA/VFS values. This is used by the standalone analysis script
39  const SiStripConfigDb::DeviceDescriptionsRange & apvDescriptions = db->getDeviceDescriptions(APV25);
40  for(SiStripConfigDb::DeviceDescriptionsV::const_iterator apv = apvDescriptions.begin();apv!=apvDescriptions.end();++apv) {
41  apvDescription* desc = dynamic_cast<apvDescription*>( *apv );
42  if ( !desc ) { continue; }
43  // Retrieve device addresses from device description
44  const SiStripConfigDb::DeviceAddress& addr = db->deviceAddress(*desc);
45  std::stringstream bin;
46  bin << std::setw(1) << std::setfill('0') << addr.fecCrate_;
47  bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
48  bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
49  bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
50  bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
51  bin << "." << desc->getAddress();
52  LogTrace(mlDqmClient_) << "Present values for ISHA/VFS of APV "
53  << bin.str() << " : "
54  << static_cast<uint16_t>(desc->getIsha()) << " " << static_cast<uint16_t>(desc->getVfs());
55  }
56  // Load the histograms with the results
57  std::string pwd = bei->pwd();
58  std::string ishaPath = getBasePath(pwd);
59  ishaPath += "/ControlView/isha";
60  LogTrace(mlDqmClient_) << "Looking for " << ishaPath;
61  ishaHistogram_ = ExtractTObject<TH1F>().extract( bei->get(ishaPath) );
62  std::string vfsPath = getBasePath(pwd);
63  vfsPath += "/ControlView/vfs";
64  LogTrace(mlDqmClient_) << "Looking for " << vfsPath;
65  vfsHistogram_ = ExtractTObject<TH1F>().extract( bei->get(vfsPath) );
66 
67 }
68 
69 // -----------------------------------------------------------------------------
73  << "[CalibrationHistosUsingDb::" << __func__ << "]"
74  << " Destructing object...";
75 }
76 
77 // -----------------------------------------------------------------------------
80 
82  << "[CalibrationHistosUsingDb::" << __func__ << "]" << ishaHistogram_ << " " << vfsHistogram_;
83 
84  if(!ishaHistogram_ && !vfsHistogram_) return;
85 
86  if ( !db() ) {
88  << "[CalibrationHistosUsingDb::" << __func__ << "]"
89  << " NULL pointer to SiStripConfigDb interface!"
90  << " Aborting upload...";
91  return;
92  }
93 
94  // Update all APV device descriptions with new ISHA and VFS settings
96  update( devices );
97  if ( doUploadConf() ) {
99  << "[CalibrationHistosUsingDb::" << __func__ << "]"
100  << " Uploading ISHA/VFS settings to DB...";
103  << "[CalibrationHistosUsingDb::" << __func__ << "]"
104  << " Uploaded ISHA/VFS settings to DB!";
105  } else {
107  << "[CalibrationHistosUsingDb::" << __func__ << "]"
108  << " TEST only! No ISHA/VFS settings will be uploaded to DB...";
109  }
110 
112  << "[CalibrationHistosUsingDb::" << __func__ << "]"
113  << " Upload of ISHA/VFS settings to DB finished!";
114 
115 }
116 
117 // -----------------------------------------------------------------------------
120 
121  if(!ishaHistogram_ && !vfsHistogram_) return;
122 
123  // Iterate through devices and update device descriptions
124  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
125  for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
126 
127  // Check device type
128  if ( (*idevice)->getDeviceType() != APV25 ) { continue; }
129 
130  // Cast to retrieve appropriate description object
131  apvDescription* desc = dynamic_cast<apvDescription*>( *idevice );
132  if ( !desc ) { continue; }
133 
134  // Retrieve the device address from device description
135  const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
136 
137  // Construct the string for that address
138  std::stringstream bin;
139  bin << std::setw(1) << std::setfill('0') << addr.fecCrate_;
140  bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
141  bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
142  bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
143  bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
144  bin << "." << desc->getAddress();
145 
146  // Iterate over the histo bins and find the right one
147  for(int i = 1;i <= ishaHistogram_->GetNbinsX(); ++i) {
148  std::string label = ishaHistogram_->GetXaxis()->GetBinLabel(i);
149  if(label == bin.str()) {
150  desc->setIsha( (int)round(ishaHistogram_->GetBinContent(i)) );
151  LogDebug(mlDqmClient_) << "Setting ISHA to " << ((int)round(ishaHistogram_->GetBinContent(i))) << " for " << label;
152  }
153  }
154  for(int i = 1;i <= vfsHistogram_->GetNbinsX(); ++i) {
155  std::string label = vfsHistogram_->GetXaxis()->GetBinLabel(i);
156  if(label == bin.str()) {
157  desc->setVfs( (int)round(vfsHistogram_->GetBinContent(i)) );
158  LogDebug(mlDqmClient_) << "Setting VFS to " << ((int)round(vfsHistogram_->GetBinContent(i))) << " for " << label;
159  }
160  }
161 
162  }
163 
164 }
165 
166 // -----------------------------------------------------------------------------
169  Analysis analysis) {
170 
171  CalibrationAnalysis* anal = dynamic_cast<CalibrationAnalysis*>( analysis->second );
172  if ( !anal ) { return; }
173 
174  SiStripFecKey fec_key( anal->fecKey() );
175  SiStripFedKey fed_key( anal->fedKey() );
176 
177  std::ofstream ofile("calibrationResults.txt",ios_base::app);
178  for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
179 
180  // Create description
181  CalibrationAnalysisDescription *tmp;
182  tmp = new CalibrationAnalysisDescription(anal->amplitudeMean()[iapv],
183  anal->tailMean()[iapv],
184  anal->riseTimeMean()[iapv],
185  anal->timeConstantMean()[iapv],
186  anal->smearingMean()[iapv],
187  anal->chi2Mean()[iapv],
188  anal->deconvMode(),
189  fec_key.fecCrate(),
190  fec_key.fecSlot(),
191  fec_key.fecRing(),
192  fec_key.ccuAddr(),
193  fec_key.ccuChan(),
194  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
195  db()->dbParams().partitions().begin()->second.partitionName(),
196  db()->dbParams().partitions().begin()->second.runNumber(),
197  anal->isValid(),
198  "",
199  fed_key.fedId(),
200  fed_key.feUnit(),
201  fed_key.feChan(),
202  fed_key.fedApv(),
203  calchan_,
204  isha_,
205  vfs_ );
206 
207  // debug simplified printout in text file
208  ofile << " " << anal->amplitudeMean()[iapv]
209  << " " << anal->tailMean()[iapv]
210  << " " << anal->riseTimeMean()[iapv]
211  << " " << anal->timeConstantMean()[iapv]
212  << " " << anal->smearingMean()[iapv]
213  << " " << anal->chi2Mean()[iapv]
214  << " " << anal->deconvMode()
215  << " " << fec_key.fecCrate()
216  << " " << fec_key.fecSlot()
217  << " " << fec_key.fecRing()
218  << " " << fec_key.ccuAddr()
219  << " " << fec_key.ccuChan()
220  << " " << SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv )
221  << " " << db()->dbParams().partitions().begin()->second.partitionName()
222  << " " << db()->dbParams().partitions().begin()->second.runNumber()
223  << " " << fed_key.fedId()
224  << " " << fed_key.feUnit()
225  << " " << fed_key.feChan()
226  << " " << fed_key.fedApv()
227  << " " << calchan_
228  << " " << isha_
229  << " " << vfs_ << std::endl;
230 
231  // Add comments
232  typedef std::vector<std::string> Strings;
233  Strings errors = anal->getErrorCodes();
234  Strings::const_iterator istr = errors.begin();
235  Strings::const_iterator jstr = errors.end();
236  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
237 
238  // Store description
239  desc.push_back( tmp );
240  }
241  ofile.close();
242 
243 }
244 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
const VFloat & smearingMean() const
const uint32_t & fedKey() const
const VFloat & amplitudeMean() const
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:57
const VFloat & timeConstantMean() const
virtual bool isValid() const
std::vector< std::string > Strings
Definition: MsgTools.h:18
tuple db
Definition: EcalCondDB.py:151
static const char mlDqmClient_[]
const VFloat & riseTimeMean() const
const uint16_t & i2cAddr() const
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:46
const_iterator_range partitions() const
Analysis for calibration runs.
DeviceDescriptions::range DeviceDescriptionsRange
void create(SiStripConfigDb::AnalysisDescriptionsV &, Analysis)
An interface class to the DeviceFactory.
const uint32_t & fecKey() const
DeviceAddress deviceAddress(const deviceDescription &)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1473
#define LogTrace(id)
const VFloat & chi2Mean() const
int extract(std::vector< int > *output, const std::string &dati)
const SiStripDbParams & dbParams() const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
CalibrationHistosUsingDb(const edm::ParameterSet &pset, DQMStore *, SiStripConfigDb *const, const sistrip::RunType &task=sistrip::CALIBRATION)
std::vector< AnalysisDescription * > AnalysisDescriptionsV
static const char root_[]
void update(SiStripConfigDb::DeviceDescriptionsRange &)
const VFloat & tailMean() const
SiStripConfigDb *const db() const
DeviceDescriptionsRange getDeviceDescriptions(std::string partition="")
void uploadDeviceDescriptions(std::string partition="")
std::string getBasePath(const std::string &path)
const VString & getErrorCodes() const
const std::string & pwd(void) const
Definition: DQMStore.cc:406