CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
EcalPedOffset Class Reference

calculate the best DAC value to obtain a pedestal = 200 More...

#include <EcalPedOffset.h>

Inheritance diagram for EcalPedOffset:
edm::EDAnalyzer

Public Member Functions

void analyze (edm::Event const &event, edm::EventSetup const &eventSetup)
 ! Analyze More...
 
void beginRun (edm::Run const &, edm::EventSetup const &eventSetup)
 BeginRun. More...
 
 EcalPedOffset (const edm::ParameterSet &ps)
 Constructor. More...
 
void endJob (void)
 EndJob. More...
 
void makePlots ()
 create the plots of the DAC pedestal trend More...
 
void writeDb ()
 WriteDB. More...
 
void writeXMLFiles (std::string fileName)
 write the results into xml format More...
 
virtual ~EcalPedOffset ()
 Destructor. More...
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

std::string intToString (int num)
 
void readDACs (edm::Handle< EBDigiCollection > pDigis, std::map< int, int > DACvalues)
 
void readDACs (edm::Handle< EEDigiCollection > pDigis, std::map< int, int > DACvalues)
 

Private Attributes

const EcalElectronicsMappingecalElectronicsMap_
 
edm::InputTag m_barrelDigiCollection
 secondary name given to collection of digis More...
 
int m_bestPed
 
bool m_create_moniov
 
int m_DACmax
 
int m_DACmin
 
std::string m_dbHostName
 database host name More...
 
int m_dbHostPort
 database More...
 
std::string m_dbName
 database name More...
 
std::string m_dbPassword
 database user password More...
 
std::string m_dbUserName
 database user name More...
 
edm::InputTag m_endcapDigiCollection
 secondary name given to collection of digis More...
 
edm::InputTag m_headerCollection
 name of module/plugin/producer making headers More...
 
std::string m_location
 
double m_maxChi2OverNDFAllowed_
 max chi2/ndf allowed for linearity test More...
 
double m_maxSlopeAllowed_
 max slope (in magnitude) allowed for linearity test More...
 
double m_minSlopeAllowed_
 min slope (in magnitude) allowed for linearity test More...
 
std::map< int, TPedResult * > m_pedResult
 
std::map< int, TPedValues * > m_pedValues
 
std::string m_plotting
 the root file where to store the detail plots More...
 
double m_RMSmax
 
int m_run
 run number More...
 
std::string m_xmlFile
 name of the xml file to be saved More...
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

calculate the best DAC value to obtain a pedestal = 200

Date:
2008/03/02 13:52:22
Revision:
1.3
Author
P. Govoni (pietr.nosp@m.o.go.nosp@m.voni@.nosp@m.cern.nosp@m.NOSPA.nosp@m.M.ch)

Definition at line 30 of file EcalPedOffset.h.

Constructor & Destructor Documentation

EcalPedOffset::EcalPedOffset ( const edm::ParameterSet ps)

Constructor.

ctor

Definition at line 40 of file EcalPedOffset.cc.

References m_bestPed, m_DACmax, m_DACmin, and m_RMSmax.

40  :
41  m_barrelDigiCollection (paramSet.getParameter<edm::InputTag> ("EBdigiCollection")),
42  m_endcapDigiCollection (paramSet.getParameter<edm::InputTag> ("EEdigiCollection")),
43  m_headerCollection (paramSet.getParameter<edm::InputTag> ("headerCollection")),
44  m_xmlFile (paramSet.getParameter<std::string> ("xmlFile")),
45  m_DACmin (paramSet.getUntrackedParameter<int> ("DACmin",0)),
46  m_DACmax (paramSet.getUntrackedParameter<int> ("DACmax",256)),
47  m_RMSmax (paramSet.getUntrackedParameter<double> ("RMSmax",2)),
48  m_bestPed (paramSet.getUntrackedParameter<int> ("bestPed",200)),
49  m_dbHostName (paramSet.getUntrackedParameter<std::string> ("dbHostName","0")),
50  m_dbName (paramSet.getUntrackedParameter<std::string> ("dbName","0")),
51  m_dbUserName (paramSet.getUntrackedParameter<std::string> ("dbUserName")),
52  m_dbPassword (paramSet.getUntrackedParameter<std::string> ("dbPassword")),
53  m_dbHostPort (paramSet.getUntrackedParameter<int> ("dbHostPort",1521)),
54  m_create_moniov (paramSet.getUntrackedParameter<bool>("createMonIOV", false)),
55  m_location (paramSet.getUntrackedParameter<std::string>("location", "H4")),
56  m_run(-1),
57  m_plotting (paramSet.getParameter<std::string> ("plotting")),
58  m_maxSlopeAllowed_ (paramSet.getUntrackedParameter<double> ("maxSlopeAllowed",-29)),
59  m_minSlopeAllowed_ (paramSet.getUntrackedParameter<double> ("minSlopeAllowed",-18)),
60  m_maxChi2OverNDFAllowed_ (paramSet.getUntrackedParameter<double> ("maxChi2OverNDF",5))
61 {
62  edm::LogInfo ("EcalPedOffset") << " reading "
63  << " m_DACmin: " << m_DACmin
64  << " m_DACmax: " << m_DACmax
65  << " m_RMSmax: " << m_RMSmax
66  << " m_bestPed: " << m_bestPed ;
67 }
double m_maxChi2OverNDFAllowed_
max chi2/ndf allowed for linearity test
edm::InputTag m_barrelDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:68
std::string m_dbHostName
database host name
Definition: EcalPedOffset.h:83
std::string m_dbName
database name
Definition: EcalPedOffset.h:85
std::string m_xmlFile
name of the xml file to be saved
Definition: EcalPedOffset.h:72
double m_minSlopeAllowed_
min slope (in magnitude) allowed for linearity test
std::string m_dbPassword
database user password
Definition: EcalPedOffset.h:89
std::string m_plotting
the root file where to store the detail plots
int m_dbHostPort
database
Definition: EcalPedOffset.h:91
std::string m_dbUserName
database user name
Definition: EcalPedOffset.h:87
bool m_create_moniov
Definition: EcalPedOffset.h:94
edm::InputTag m_headerCollection
name of module/plugin/producer making headers
Definition: EcalPedOffset.h:70
int m_run
run number
Definition: EcalPedOffset.h:98
std::string m_location
Definition: EcalPedOffset.h:96
double m_maxSlopeAllowed_
max slope (in magnitude) allowed for linearity test
edm::InputTag m_endcapDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:69
EcalPedOffset::~EcalPedOffset ( )
virtual

Destructor.

dtor

Definition at line 74 of file EcalPedOffset.cc.

References m_pedResult, and m_pedValues.

75 {
76  for (std::map<int,TPedValues*>::iterator mapIt = m_pedValues.begin ();
77  mapIt != m_pedValues.end ();
78  ++mapIt)
79  delete mapIt->second ;
80  for (std::map<int,TPedResult*>::iterator mapIt = m_pedResult.begin ();
81  mapIt != m_pedResult.end ();
82  ++mapIt)
83  delete mapIt->second ;
84 }
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:74
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:75

Member Function Documentation

void EcalPedOffset::analyze ( edm::Event const &  event,
edm::EventSetup const &  eventSetup 
)
virtual

! Analyze

perform the analysis

Implements edm::EDAnalyzer.

Definition at line 106 of file EcalPedOffset.cc.

References L1Comparator_cfi::FEDid, edm::HandleBase::isValid(), LogDebug, m_barrelDigiCollection, m_endcapDigiCollection, m_headerCollection, m_run, EcalDCCHeaderBlock::EcalDCCEventSettings::ped_offset, and readDACs().

108 {
109  LogDebug ("EcalPedOffset") << "entering analyze ...";
110 
111  // get the headers
112  // (one header for each supermodule)
114  event.getByLabel(m_headerCollection, DCCHeaders);
115 
116  std::map <int,int> DACvalues;
117 
118  if(m_run==-1)
119  m_run = event.id().run();
120 
121  // loop over the headers
122  for (EcalRawDataCollection::const_iterator headerItr= DCCHeaders->begin();
123  headerItr != DCCHeaders->end ();
124  ++headerItr)
125  {
126  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
127  int FEDid = 600+headerItr->id();
128  DACvalues[FEDid] = settings.ped_offset;
129  LogDebug("EcalPedOffset") << "Found FED: " << FEDid << " in DCC header";
130  }
131 
132  bool barrelDigisFound = true;
133  bool endcapDigisFound = true;
134  // get the barrel digis
135  // (one digi for each crystal)
136  Handle<EBDigiCollection> barrelDigis;
137  event.getByLabel(m_barrelDigiCollection, barrelDigis);
138  if(!barrelDigis.isValid())
139  {
140  edm::LogError ("EcalPedOffset") << "Error! can't get the product "
141  << m_barrelDigiCollection << "; not reading barrel digis";
142  barrelDigisFound = false;
143  }
144 
145  if(barrelDigis->size()==0)
146  {
147  edm::LogInfo("EcalPedOffset") << "Size of EBDigiCollection is zero;"
148  << " not reading barrel digis";
149  barrelDigisFound = false;
150  }
151 
152  // get the endcap digis
153  // (one digi for each crystal)
154  Handle<EEDigiCollection> endcapDigis;
155  event.getByLabel(m_endcapDigiCollection, endcapDigis);
156  if(!endcapDigis.isValid())
157  {
158  edm::LogError ("EcalPedOffset") << "Error! can't get the product "
159  << m_endcapDigiCollection << "; not reading endcap digis";
160  endcapDigisFound = false;
161  }
162 
163  if(endcapDigis->size()==0)
164  {
165  edm::LogInfo("EcalPedOffset") << "Size of EEDigiCollection is zero;"
166  << " not reading endcap digis";
167  endcapDigisFound = false;
168  }
169 
170 
171  if(barrelDigisFound)
172  readDACs(barrelDigis, DACvalues);
173  if(endcapDigisFound)
174  readDACs(endcapDigis, DACvalues);
175  if(!barrelDigisFound && !endcapDigisFound)
176  edm::LogError ("EcalPedOffset") << "No digis found in the event!";
177 
178 }
#define LogDebug(id)
edm::InputTag m_barrelDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:68
std::vector< T >::const_iterator const_iterator
bool isValid() const
Definition: HandleBase.h:76
edm::InputTag m_headerCollection
name of module/plugin/producer making headers
Definition: EcalPedOffset.h:70
int m_run
run number
Definition: EcalPedOffset.h:98
edm::InputTag m_endcapDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:69
void readDACs(edm::Handle< EBDigiCollection > pDigis, std::map< int, int > DACvalues)
void EcalPedOffset::beginRun ( edm::Run const &  ,
edm::EventSetup const &  eventSetup 
)
virtual

BeginRun.

begin the run

Reimplemented from edm::EDAnalyzer.

Definition at line 91 of file EcalPedOffset.cc.

References ecalElectronicsMap_, edm::EventSetup::get(), patZpeak::handle, LogDebug, and edm::ESHandle< class >::product().

92 {
93  LogDebug ("EcalPedOffset") << "entering beginRun..." ;
94 
96  eventSetup.get< EcalMappingRcd >().get(handle);
97  ecalElectronicsMap_ = handle.product();
98 
99 }
#define LogDebug(id)
tuple handle
Definition: patZpeak.py:22
T const * product() const
Definition: ESHandle.h:62
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:62
void EcalPedOffset::endJob ( void  )
virtual

EndJob.

perform the minimization and write results

Reimplemented from edm::EDAnalyzer.

Definition at line 275 of file EcalPedOffset.cc.

References m_DACmax, m_DACmin, m_dbHostName, m_pedResult, m_pedValues, m_plotting, m_xmlFile, makePlots(), writeDb(), and writeXMLFiles().

276 {
277  for (std::map<int,TPedValues*>::const_iterator smPeds = m_pedValues.begin ();
278  smPeds != m_pedValues.end ();
279  ++smPeds)
280  {
281  m_pedResult[smPeds->first] =
282  new TPedResult ((smPeds->second)->terminate (m_DACmin, m_DACmax));
283  }
284  edm::LogInfo ("EcalPedOffset") << " results map size "
285  << m_pedResult.size ();
287 
288  if (m_plotting != '0') makePlots ();
289  if (m_dbHostName != '0') writeDb ();
290 }
std::string m_dbHostName
database host name
Definition: EcalPedOffset.h:83
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:74
std::string m_xmlFile
name of the xml file to be saved
Definition: EcalPedOffset.h:72
std::string m_plotting
the root file where to store the detail plots
void writeDb()
WriteDB.
void makePlots()
create the plots of the DAC pedestal trend
void writeXMLFiles(std::string fileName)
write the results into xml format
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:75
std::string EcalPedOffset::intToString ( int  num)
private

Definition at line 549 of file EcalPedOffset.cc.

Referenced by writeXMLFiles().

550 {
551 
552  // outputs the number into the string stream and then flushes
553  // the buffer (makes sure the output is put into the stream)
554  std::ostringstream myStream;
555  myStream << num << std::flush;
556  return(myStream.str()); //returns the string form of the stringstream object
557 }
long long int num
Definition: procUtils.cc:71
void EcalPedOffset::makePlots ( )

create the plots of the DAC pedestal trend

Definition at line 515 of file EcalPedOffset.cc.

References LogDebug, m_maxChi2OverNDFAllowed_, m_maxSlopeAllowed_, m_minSlopeAllowed_, m_pedValues, m_plotting, and BuildWebpage::rootFile.

Referenced by endJob().

516 {
517  LogDebug ("EcalPedOffset") << " entering makePlots ..." ;
518 
519  edm::LogInfo ("EcalPedOffset") << " map size: "
520  << m_pedValues.size();
521 
522  // create the ROOT file
523  m_plotting+=".root";
524 
525  TFile * rootFile = new TFile(m_plotting.c_str(),"RECREATE");
526 
527  // loop over the supermodules
528  for (std::map<int,TPedValues*>::const_iterator smPeds = m_pedValues.begin();
529  smPeds != m_pedValues.end();
530  ++smPeds)
531  {
532  // make a folder in the ROOT file
533  char folderName[120] ;
534  sprintf (folderName,"FED%02d",smPeds->first);
535  rootFile->mkdir(folderName);
536  smPeds->second->makePlots(rootFile,folderName,m_maxSlopeAllowed_,
538  }
539 
540  rootFile->Close();
541  delete rootFile;
542 
543  LogDebug ("EcalPedOffset") << " DONE";
544 }
#define LogDebug(id)
double m_maxChi2OverNDFAllowed_
max chi2/ndf allowed for linearity test
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:74
double m_minSlopeAllowed_
min slope (in magnitude) allowed for linearity test
std::string m_plotting
the root file where to store the detail plots
double m_maxSlopeAllowed_
max slope (in magnitude) allowed for linearity test
void EcalPedOffset::readDACs ( edm::Handle< EBDigiCollection pDigis,
std::map< int, int >  DACvalues 
)
private

Definition at line 184 of file EcalPedOffset.cc.

References ecalMGPA::adc(), ecalElectronicsMap_, L1Comparator_cfi::FEDid, ecalMGPA::gainId(), EcalElectronicsMapping::getElectronicsId(), EBDetId::ic(), LogDebug, m_bestPed, m_pedValues, m_RMSmax, and EcalDataFrame::MAXSAMPLES.

Referenced by analyze().

186 {
187 
188  // loop over the digis
189  for (EBDigiCollection::const_iterator itdigi = pDigis->begin();
190  itdigi != pDigis->end();
191  ++itdigi)
192  {
193  int gainId = ((EBDataFrame)(*itdigi)).sample(0).gainId();
194  EBDetId detId = EBDetId(itdigi->id());
196  int FEDid = 600+elecId.dccId();
197  int crystalId = detId.ic();
198 
199  //TODO: Behavior here
200  if(DACvalues.find(FEDid)==DACvalues.end())
201  {
202  edm::LogError("EcalPedOffset")
203  << "Error! EB DCCid of digi does not match any DCCid found in DCC headers" << FEDid;
204  }
205 
206  if (!m_pedValues.count(FEDid))
207  {
208  LogDebug("EcalPedOffset") << "Inserting new TPedValues object for FED:" << FEDid;
210  }
211 
212  // loop over the samples
213  for (int iSample = 0; iSample < EcalDataFrame::MAXSAMPLES; ++iSample)
214  {
215  m_pedValues[FEDid]->insert(gainId,
216  crystalId,
217  DACvalues[FEDid],
218  ((EBDataFrame)(*itdigi)).sample(iSample).adc(),
219  crystalId);
220  }
221 
222  } //end loop over digis
223 }
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
int gainId(sample_type sample)
get the gainId (2 bits)
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:74
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:94
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:62
static const int MAXSAMPLES
Definition: EcalDataFrame.h:44
void EcalPedOffset::readDACs ( edm::Handle< EEDigiCollection pDigis,
std::map< int, int >  DACvalues 
)
private

Definition at line 228 of file EcalPedOffset.cc.

References ecalMGPA::adc(), ecalElectronicsMap_, L1Comparator_cfi::FEDid, ecalMGPA::gainId(), EcalElectronicsMapping::getElectronicsId(), LogDebug, m_bestPed, m_pedValues, m_RMSmax, and EcalDataFrame::MAXSAMPLES.

230 {
231 
232  // loop over the digis
233  for (EEDigiCollection::const_iterator itdigi = pDigis->begin();
234  itdigi != pDigis->end();
235  ++itdigi)
236  {
237  int gainId = ((EEDataFrame)(*itdigi)).sample(0).gainId();
238  //int gainId = itdigi->sample(0).gainId();
239  EEDetId detId = EEDetId(itdigi->id());
241  int FEDid = 600+elecId.dccId();
242  int crystalId = 25*elecId.towerId()+5*elecId.stripId()+elecId.xtalId();
243  int endcapCrystalId = 100*elecId.towerId()+5*(elecId.stripId()-1)+elecId.xtalId();
244 
245  //TODO: Behavior here
246  if(DACvalues.find(FEDid)==DACvalues.end())
247  {
248  edm::LogError("EcalPedOffset")
249  << "Error! EE DCCid of digi does not match any DCCid found in DCC headers: " << FEDid;
250  }
251 
252  if (!m_pedValues.count(FEDid))
253  {
254  LogDebug("EcalPedOffset") << "Inserting new TPedValues object for FED:" << FEDid;
256  }
257 
258  // loop over the samples
259  for (int iSample = 0; iSample < EcalDataFrame::MAXSAMPLES; ++iSample)
260  {
261  m_pedValues[FEDid]->insert(gainId,
262  crystalId,
263  DACvalues[FEDid],
264  ((EEDataFrame)(*itdigi)).sample(iSample).adc(),
265  endcapCrystalId);
266  }
267 
268  } //end loop over digis
269 }
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
int gainId(sample_type sample)
get the gainId (2 bits)
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:74
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:62
static const int MAXSAMPLES
Definition: EcalDataFrame.h:44
void EcalPedOffset::writeDb ( )

WriteDB.

write the m_pedResult in the DB FIXME divide into sub-tasks

Definition at line 298 of file EcalPedOffset.cc.

References EcalCondDBInterface::fetchMonRunIOV(), EcalCondDBInterface::fetchRunIOV(), EcalCondDBInterface::getEcalLogicID(), RunIOV::getRunTag(), EcalCondDBInterface::insertDataSet(), LogDebug, m_create_moniov, m_dbHostName, m_dbHostPort, m_dbName, m_dbPassword, m_dbUserName, m_location, m_pedResult, m_pedValues, m_run, query::result, DTTTrigCorrFirst::run, MonPedestalOffsetsDat::setDACG1(), MonPedestalOffsetsDat::setDACG12(), MonPedestalOffsetsDat::setDACG6(), RunTag::setGeneralTag(), MonRunTag::setGeneralTag(), LocationDef::setLocation(), RunTag::setLocationDef(), MonVersionDef::setMonitoringVersion(), MonRunIOV::setMonRunTag(), MonRunTag::setMonVersionDef(), MonRunIOV::setRunIOV(), RunTypeDef::setRunType(), RunTag::setRunTypeDef(), MonRunIOV::setSubRunNumber(), MonRunIOV::setSubRunStart(), MonPedestalOffsetsDat::setTaskStatus(), and Tm::setToCurrentGMTime().

Referenced by endJob().

299 {
300  LogDebug ("EcalPedOffset") << " entering writeDb ..." ;
301 
302  // connect to the database
303  EcalCondDBInterface* DBconnection ;
304  try
305  {
306  LogInfo("EcalPedOffset") << "Opening DB connection with TNS_ADMIN ...";
308  } catch (std::runtime_error &e) {
309  LogError("EcalPedOffset") << e.what();
310  if ( m_dbHostName.size() != 0 )
311  {
312  try
313  {
314  LogInfo("EcalPedOffset") << "Opening DB connection without TNS_ADMIN ...";
315  DBconnection = new EcalCondDBInterface(m_dbHostName, m_dbName,
317  } catch (std::runtime_error &e) {
318  LogError("EcalPedOffset") << e.what();
319  return;
320  }
321  }
322  else
323  return;
324  }
325 
326  // define the query for RunIOV to get the right place in the database
327  RunTag runtag ;
328  LocationDef locdef ;
329  RunTypeDef rundef ;
330  locdef.setLocation (m_location);
331 
332  runtag.setGeneralTag ("PEDESTAL-OFFSET");
333  rundef.setRunType ("PEDESTAL-OFFSET");
334  //rundef.setRunType ("TEST");
335  //runtag.setGeneralTag ("TEST");
336 
337  runtag.setLocationDef (locdef);
338  runtag.setRunTypeDef (rundef);
339 
340 
341  run_t run = m_run ; //FIXME dal config file
342  //RunIOV runiov = DBconnection->fetchRunIOV (&runtag, run);
343  RunIOV runiov = DBconnection->fetchRunIOV(m_location, run);
344 
345  // MonRunIOV
346  MonVersionDef monverdef ;
347  monverdef.setMonitoringVersion ("test01");
348  MonRunTag montag ;
349  montag.setMonVersionDef (monverdef);
350  montag.setGeneralTag ("CMSSW");
351 
352  subrun_t subrun = 1 ; //hardcoded!
353 
354  MonRunIOV moniov ;
355 
356  try{
357  runtag = runiov.getRunTag();
358  moniov = DBconnection->fetchMonRunIOV(&runtag, &montag, run, subrun);
359  }
360  catch (std::runtime_error &e) {
361  if(m_create_moniov){
362  //if not already in the DB create a new MonRunIOV
363  Tm startSubRun;
364  startSubRun.setToCurrentGMTime();
365  // setup the MonIOV
366  moniov.setRunIOV(runiov);
367  moniov.setSubRunNumber(subrun);
368  moniov.setSubRunStart(startSubRun);
369  moniov.setMonRunTag(montag);
370  LogDebug ("EcalPedOffset") <<" creating a new MonRunIOV" ;
371  }
372  else{
373  edm::LogError ("EcalPedOffset") << " no MonRunIOV existing in the DB" ;
374  edm::LogError ("EcalPedOffset") << " the result will not be stored into the DB" ;
375  if ( DBconnection ) {delete DBconnection;}
376  return;
377  }
378  }
379 
380  // create the table to be filled and the map to be inserted
381  EcalLogicID ecid ;
382  std::map<EcalLogicID, MonPedestalOffsetsDat> DBdataset ;
383  MonPedestalOffsetsDat DBtable ;
384 
385  // fill the table
386 
387  // loop over the super-modules
388  for (std::map<int,TPedResult*>::const_iterator result = m_pedResult.begin ();
389  result != m_pedResult.end ();
390  ++result)
391  {
392  // loop over the crystals
393  for (int xtal = 0 ; xtal<1700 ; ++xtal)
394  {
395  DBtable.setDACG1 (result->second->m_DACvalue[2][xtal]);
396  DBtable.setDACG6 (result->second->m_DACvalue[1][xtal]);
397  DBtable.setDACG12 (result->second->m_DACvalue[0][xtal]);
398  DBtable.setTaskStatus (1); //FIXME to be set correctly
399 
400  // fill the table
401  if ( DBconnection )
402  {
403  try
404  {
405  int fedid = result->first;
406  int eid = m_pedValues[fedid]->getCrystalNumber(xtal);
407  // If eid is zero, that crystal was not present in digis
408  if(eid==0)
409  continue;
410 
411  if (fedid >= 601 && fedid <= 609)
412  {
413  // Add the FEDid part in for DB
414  eid = eid+10000*(fedid-600);
415  ecid = DBconnection->getEcalLogicID("EE_elec_crystal_number", eid);
416  }
417  else if (fedid >= 610 && fedid <= 627)
418  {
419  ecid = DBconnection->getEcalLogicID("EB_crystal_number", fedid-610+19,
420  eid);
421  }
422  else if (fedid >= 628 && fedid <= 645)
423  {
424  ecid = DBconnection->getEcalLogicID("EB_crystal_number", fedid-628+1,
425  eid);
426  }
427  else if (fedid >= 646 && fedid <= 654)
428  {
429  // Add the FEDid part in for DB
430  eid = eid+10000*(fedid-600);
431  ecid = DBconnection->getEcalLogicID("EE_elec_crystal_number", eid);
432  }
433  else
434  LogError("EcalPedOffset") << "FEDid is out of range 601-654";
435 
436  DBdataset[ecid] = DBtable ;
437  } catch (std::runtime_error &e) {
438  edm::LogError ("EcalPedOffset") << e.what();
439  }
440  }
441  } // loop over the crystals
442  } // loop over the super-modules
443 
444  // insert the map of tables in the database
445  if ( DBconnection ) {
446  try {
447  LogDebug ("EcalPedOffset") << "Inserting dataset ... " << std::flush;
448  if ( DBdataset.size() != 0 ) DBconnection->insertDataSet (&DBdataset, &moniov);
449  LogDebug ("EcalPedOffset") << "done." ;
450  } catch (std::runtime_error &e) {
451  edm::LogError ("EcalPedOffset") << e.what ();
452  }
453  }
454 
455  if ( DBconnection ) {delete DBconnection;}
456 }
#define LogDebug(id)
void setTaskStatus(bool status)
int run_t
Definition: CaliIOV.h:11
void setLocationDef(const LocationDef locDef)
Definition: RunTag.cc:53
std::string m_dbHostName
database host name
Definition: EcalPedOffset.h:83
Definition: RunTag.h:13
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:74
std::string m_dbName
database name
Definition: EcalPedOffset.h:85
RunIOV fetchRunIOV(RunTag *tag, run_t run)
void setToCurrentGMTime()
Definition: Tm.cc:156
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
std::string m_dbPassword
database user password
Definition: EcalPedOffset.h:89
int m_dbHostPort
database
Definition: EcalPedOffset.h:91
std::string m_dbUserName
database user name
Definition: EcalPedOffset.h:87
RunTag getRunTag() const
Definition: RunIOV.cc:96
void setRunIOV(RunIOV iov)
Definition: MonRunIOV.cc:53
void setSubRunStart(Tm start)
Definition: MonRunIOV.cc:84
void setRunTypeDef(const RunTypeDef runTypeDef)
Definition: RunTag.cc:70
tuple result
Definition: query.py:137
int subrun_t
Definition: MODRunIOV.h:11
EcalLogicID getEcalLogicID(std::string name, int id1=EcalLogicID::NULLID, int id2=EcalLogicID::NULLID, int id3=EcalLogicID::NULLID, std::string mapsTo="")
void setSubRunNumber(subrun_t subrun)
Definition: MonRunIOV.cc:67
bool m_create_moniov
Definition: EcalPedOffset.h:94
void setMonVersionDef(MonVersionDef ver)
Definition: MonRunTag.cc:49
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:75
int m_run
run number
Definition: EcalPedOffset.h:98
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
MonRunIOV fetchMonRunIOV(RunTag *runtag, MonRunTag *montag, run_t run, subrun_t monrun)
void setMonitoringVersion(std::string ver)
void setLocation(std::string loc)
Definition: LocationDef.cc:33
std::string m_location
Definition: EcalPedOffset.h:96
void insertDataSet(const std::map< EcalLogicID, DATT > *data, IOVT *iov)
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
Definition: RunIOV.h:13
Definition: Tm.h:14
void setMonRunTag(MonRunTag tag)
Definition: MonRunIOV.cc:36
void EcalPedOffset::writeXMLFiles ( std::string  fileName)

write the results into xml format

write the m_pedResults to XML files

Definition at line 463 of file EcalPedOffset.cc.

References convertXMLtoSQLite_cfg::fileName, intToString(), m_pedResult, and m_pedValues.

Referenced by endJob().

464 {
465  // loop over the super-modules
466  for (std::map<int,TPedResult*>::const_iterator smRes = m_pedResult.begin();
467  smRes != m_pedResult.end();
468  ++smRes)
469  {
470  std::string thisSMFileName = fileName;
471  // open the output stream
472  thisSMFileName+="_";
473  thisSMFileName+=intToString(smRes->first);
474  thisSMFileName+=".xml";
475  std::ofstream xml_outfile;
476  xml_outfile.open(thisSMFileName.c_str());
477 
478  // write the header file
479  xml_outfile<<"<offsets>"<<std::endl;
480  xml_outfile << "<PEDESTAL_OFFSET_RELEASE VERSION_ID = \"SM1_VER1\"> \n";
481  xml_outfile << " <RELEASE_ID>RELEASE_1</RELEASE_ID>\n";
482  xml_outfile << " <SUPERMODULE>";
483  xml_outfile << smRes->first;
484  xml_outfile << "</SUPERMODULE>\n";
485  xml_outfile << " <TIME_STAMP> 070705 </TIME_STAMP>" << std::endl;
486 
487  // loop over the crystals
488  for (int xtal = 0 ; xtal < 1700 ; ++xtal)
489  {
490  int crystalNumber = m_pedValues[smRes->first]->getCrystalNumber(xtal);
491  if(crystalNumber==0)
492  continue;
493  xml_outfile << " <PEDESTAL_OFFSET>\n";
494  xml_outfile << " <HIGH>" << ((smRes->second)->m_DACvalue)[0][xtal] << "</HIGH>\n";
495  xml_outfile << " <MED>" << ((smRes->second)->m_DACvalue)[1][xtal] << "</MED>\n";
496  xml_outfile << " <LOW>" << ((smRes->second)->m_DACvalue)[2][xtal] << "</LOW>\n";
497  xml_outfile << " <CRYSTAL> "<< crystalNumber << " </CRYSTAL>\n";
498  xml_outfile << " </PEDESTAL_OFFSET>" << std::endl;
499  }
500 
501  // close the open tags
502  xml_outfile << " </PEDESTAL_OFFSET_RELEASE>" << std::endl;
503  xml_outfile << "</offsets>" << std::endl;
504  xml_outfile.close ();
505  } // loop over the super-modules
506 
507 
508 }
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:74
std::string intToString(int num)
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:75

Member Data Documentation

const EcalElectronicsMapping* EcalPedOffset::ecalElectronicsMap_
private

Definition at line 62 of file EcalPedOffset.h.

Referenced by beginRun(), and readDACs().

edm::InputTag EcalPedOffset::m_barrelDigiCollection
private

secondary name given to collection of digis

Definition at line 68 of file EcalPedOffset.h.

Referenced by analyze().

int EcalPedOffset::m_bestPed
private

Definition at line 80 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and readDACs().

bool EcalPedOffset::m_create_moniov
private

allow the creation of a new moniov if not existing in the DB by default it is false.

Definition at line 94 of file EcalPedOffset.h.

Referenced by writeDb().

int EcalPedOffset::m_DACmax
private

Definition at line 78 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and endJob().

int EcalPedOffset::m_DACmin
private

Definition at line 77 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and endJob().

std::string EcalPedOffset::m_dbHostName
private

database host name

Definition at line 83 of file EcalPedOffset.h.

Referenced by endJob(), and writeDb().

int EcalPedOffset::m_dbHostPort
private

database

Definition at line 91 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbName
private

database name

Definition at line 85 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbPassword
private

database user password

Definition at line 89 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbUserName
private

database user name

Definition at line 87 of file EcalPedOffset.h.

Referenced by writeDb().

edm::InputTag EcalPedOffset::m_endcapDigiCollection
private

secondary name given to collection of digis

Definition at line 69 of file EcalPedOffset.h.

Referenced by analyze().

edm::InputTag EcalPedOffset::m_headerCollection
private

name of module/plugin/producer making headers

Definition at line 70 of file EcalPedOffset.h.

Referenced by analyze().

std::string EcalPedOffset::m_location
private

Definition at line 96 of file EcalPedOffset.h.

Referenced by writeDb().

double EcalPedOffset::m_maxChi2OverNDFAllowed_
private

max chi2/ndf allowed for linearity test

Definition at line 107 of file EcalPedOffset.h.

Referenced by makePlots().

double EcalPedOffset::m_maxSlopeAllowed_
private

max slope (in magnitude) allowed for linearity test

Definition at line 103 of file EcalPedOffset.h.

Referenced by makePlots().

double EcalPedOffset::m_minSlopeAllowed_
private

min slope (in magnitude) allowed for linearity test

Definition at line 105 of file EcalPedOffset.h.

Referenced by makePlots().

std::map<int,TPedResult*> EcalPedOffset::m_pedResult
private

Definition at line 75 of file EcalPedOffset.h.

Referenced by endJob(), writeDb(), writeXMLFiles(), and ~EcalPedOffset().

std::map<int,TPedValues*> EcalPedOffset::m_pedValues
private

Definition at line 74 of file EcalPedOffset.h.

Referenced by endJob(), makePlots(), readDACs(), writeDb(), writeXMLFiles(), and ~EcalPedOffset().

std::string EcalPedOffset::m_plotting
private

the root file where to store the detail plots

Definition at line 101 of file EcalPedOffset.h.

Referenced by endJob(), and makePlots().

double EcalPedOffset::m_RMSmax
private

Definition at line 79 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and readDACs().

int EcalPedOffset::m_run
private

run number

Definition at line 98 of file EcalPedOffset.h.

Referenced by analyze(), and writeDb().

std::string EcalPedOffset::m_xmlFile
private

name of the xml file to be saved

Definition at line 72 of file EcalPedOffset.h.

Referenced by endJob().