test
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 
8 #include <iostream>
9 
10 using namespace sistrip;
11 
12 // -----------------------------------------------------------------------------
15 {
16  return path.substr(0,path.find(std::string(sistrip::root_) + "/")+sizeof(sistrip::root_) );
17 }
18 
19 // -----------------------------------------------------------------------------
22  DQMStore* bei,
23  SiStripConfigDb* const db,
24  const sistrip::RunType& task )
25  : CommissioningHistograms( pset.getParameter<edm::ParameterSet>("CalibrationParameters"),
26  bei,
27  task ),
29  task ),
30  CalibrationHistograms( pset.getParameter<edm::ParameterSet>("CalibrationParameters"),
31  bei,
32  task )
33 {
35  << "[CalibrationHistosUsingDb::" << __func__ << "]"
36  << " Constructing object...";
37  // Load and dump the current ISHA/VFS values. This is used by the standalone analysis script
38  const SiStripConfigDb::DeviceDescriptionsRange & apvDescriptions = db->getDeviceDescriptions(APV25);
39  for(SiStripConfigDb::DeviceDescriptionsV::const_iterator apv = apvDescriptions.begin();apv!=apvDescriptions.end();++apv) {
40  apvDescription* desc = dynamic_cast<apvDescription*>( *apv );
41  if ( !desc ) { continue; }
42  // Retrieve device addresses from device description
43  const SiStripConfigDb::DeviceAddress& addr = db->deviceAddress(*desc);
44  std::stringstream bin;
45  bin << std::setw(1) << std::setfill('0') << addr.fecCrate_;
46  bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
47  bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
48  bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
49  bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
50  bin << "." << desc->getAddress();
51  LogTrace(mlDqmClient_) << "Present values for ISHA/VFS of APV "
52  << bin.str() << " : "
53  << static_cast<uint16_t>(desc->getIsha()) << " " << static_cast<uint16_t>(desc->getVfs());
54  }
55  // Load the histograms with the results
56  std::string pwd = bei->pwd();
57  std::string ishaPath = getBasePath(pwd);
58  ishaPath += "/ControlView/isha";
59  LogTrace(mlDqmClient_) << "Looking for " << ishaPath;
60  ishaHistogram_ = ExtractTObject<TH1F>().extract( bei->get(ishaPath) );
61  std::string vfsPath = getBasePath(pwd);
62  vfsPath += "/ControlView/vfs";
63  LogTrace(mlDqmClient_) << "Looking for " << vfsPath;
64  vfsHistogram_ = ExtractTObject<TH1F>().extract( bei->get(vfsPath) );
65 
66 }
67 
68 // -----------------------------------------------------------------------------
72  << "[CalibrationHistosUsingDb::" << __func__ << "]"
73  << " Destructing object...";
74 }
75 
76 // -----------------------------------------------------------------------------
79 
81  << "[CalibrationHistosUsingDb::" << __func__ << "]" << ishaHistogram_ << " " << vfsHistogram_;
82 
83  if(!ishaHistogram_ && !vfsHistogram_) return;
84 
85  if ( !db() ) {
87  << "[CalibrationHistosUsingDb::" << __func__ << "]"
88  << " NULL pointer to SiStripConfigDb interface!"
89  << " Aborting upload...";
90  return;
91  }
92 
93  // Update all APV device descriptions with new ISHA and VFS settings
95  update( devices );
96  if ( doUploadConf() ) {
98  << "[CalibrationHistosUsingDb::" << __func__ << "]"
99  << " Uploading ISHA/VFS settings to DB...";
102  << "[CalibrationHistosUsingDb::" << __func__ << "]"
103  << " Uploaded ISHA/VFS settings to DB!";
104  } else {
106  << "[CalibrationHistosUsingDb::" << __func__ << "]"
107  << " TEST only! No ISHA/VFS settings will be uploaded to DB...";
108  }
109 
111  << "[CalibrationHistosUsingDb::" << __func__ << "]"
112  << " Upload of ISHA/VFS settings to DB finished!";
113 
114 }
115 
116 // -----------------------------------------------------------------------------
119 
120  if(!ishaHistogram_ && !vfsHistogram_) return;
121 
122  // Iterate through devices and update device descriptions
123  SiStripConfigDb::DeviceDescriptionsV::const_iterator idevice;
124  for ( idevice = devices.begin(); idevice != devices.end(); idevice++ ) {
125 
126  // Check device type
127  if ( (*idevice)->getDeviceType() != APV25 ) { continue; }
128 
129  // Cast to retrieve appropriate description object
130  apvDescription* desc = dynamic_cast<apvDescription*>( *idevice );
131  if ( !desc ) { continue; }
132 
133  // Retrieve the device address from device description
134  const SiStripConfigDb::DeviceAddress& addr = db()->deviceAddress(*desc);
135 
136  // Construct the string for that address
137  std::stringstream bin;
138  bin << std::setw(1) << std::setfill('0') << addr.fecCrate_;
139  bin << "." << std::setw(2) << std::setfill('0') << addr.fecSlot_;
140  bin << "." << std::setw(1) << std::setfill('0') << addr.fecRing_;
141  bin << "." << std::setw(3) << std::setfill('0') << addr.ccuAddr_;
142  bin << "." << std::setw(2) << std::setfill('0') << addr.ccuChan_;
143  bin << "." << desc->getAddress();
144 
145  // Iterate over the histo bins and find the right one
146  for(int i = 1;i <= ishaHistogram_->GetNbinsX(); ++i) {
147  std::string label = ishaHistogram_->GetXaxis()->GetBinLabel(i);
148  if(label == bin.str()) {
149  desc->setIsha( (int)round(ishaHistogram_->GetBinContent(i)) );
150  LogDebug(mlDqmClient_) << "Setting ISHA to " << ((int)round(ishaHistogram_->GetBinContent(i))) << " for " << label;
151  }
152  }
153  for(int i = 1;i <= vfsHistogram_->GetNbinsX(); ++i) {
154  std::string label = vfsHistogram_->GetXaxis()->GetBinLabel(i);
155  if(label == bin.str()) {
156  desc->setVfs( (int)round(vfsHistogram_->GetBinContent(i)) );
157  LogDebug(mlDqmClient_) << "Setting VFS to " << ((int)round(vfsHistogram_->GetBinContent(i))) << " for " << label;
158  }
159  }
160 
161  }
162 
163 }
164 
165 // -----------------------------------------------------------------------------
168  Analysis analysis) {
169 
170  CalibrationAnalysis* anal = dynamic_cast<CalibrationAnalysis*>( analysis->second );
171  if ( !anal ) { return; }
172 
173  SiStripFecKey fec_key( anal->fecKey() );
174  SiStripFedKey fed_key( anal->fedKey() );
175 
176  std::ofstream ofile("calibrationResults.txt",ios_base::app);
177  for ( uint16_t iapv = 0; iapv < 2; ++iapv ) {
178 
179  // Create description
180  CalibrationAnalysisDescription *tmp;
181  tmp = new CalibrationAnalysisDescription(anal->amplitudeMean()[iapv],
182  anal->tailMean()[iapv],
183  anal->riseTimeMean()[iapv],
184  anal->timeConstantMean()[iapv],
185  anal->smearingMean()[iapv],
186  anal->chi2Mean()[iapv],
187  anal->deconvMode(),
188  fec_key.fecCrate(),
189  fec_key.fecSlot(),
190  fec_key.fecRing(),
191  fec_key.ccuAddr(),
192  fec_key.ccuChan(),
193  SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv ),
194  db()->dbParams().partitions().begin()->second.partitionName(),
195  db()->dbParams().partitions().begin()->second.runNumber(),
196  anal->isValid(),
197  "",
198  fed_key.fedId(),
199  fed_key.feUnit(),
200  fed_key.feChan(),
201  fed_key.fedApv(),
202  calchan_,
203  isha_,
204  vfs_ );
205 
206  // debug simplified printout in text file
207  ofile << " " << anal->amplitudeMean()[iapv]
208  << " " << anal->tailMean()[iapv]
209  << " " << anal->riseTimeMean()[iapv]
210  << " " << anal->timeConstantMean()[iapv]
211  << " " << anal->smearingMean()[iapv]
212  << " " << anal->chi2Mean()[iapv]
213  << " " << anal->deconvMode()
214  << " " << fec_key.fecCrate()
215  << " " << fec_key.fecSlot()
216  << " " << fec_key.fecRing()
217  << " " << fec_key.ccuAddr()
218  << " " << fec_key.ccuChan()
219  << " " << SiStripFecKey::i2cAddr( fec_key.lldChan(), !iapv )
220  << " " << db()->dbParams().partitions().begin()->second.partitionName()
221  << " " << db()->dbParams().partitions().begin()->second.runNumber()
222  << " " << fed_key.fedId()
223  << " " << fed_key.feUnit()
224  << " " << fed_key.feChan()
225  << " " << fed_key.fedApv()
226  << " " << calchan_
227  << " " << isha_
228  << " " << vfs_ << std::endl;
229 
230  // Add comments
231  typedef std::vector<std::string> Strings;
232  Strings errors = anal->getErrorCodes();
233  Strings::const_iterator istr = errors.begin();
234  Strings::const_iterator jstr = errors.end();
235  for ( ; istr != jstr; ++istr ) { tmp->addComments( *istr ); }
236 
237  // Store description
238  desc.push_back( tmp );
239  }
240  ofile.close();
241 
242 }
243 
#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:56
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:45
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 &)
#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