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 edm::EDConsumerBase

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
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

std::string intToString (int num)
 
void readDACs (const edm::Handle< EBDigiCollection > &pDigis, const std::map< int, int > &DACvalues)
 
void readDACs (const edm::Handle< EEDigiCollection > &pDigis, const 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
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

calculate the best DAC value to obtain a pedestal = 200

Author
P. Govoni (pietr.nosp@m.o.go.nosp@m.voni@.nosp@m.cern.nosp@m.NOSPA.nosp@m.M.ch)

Definition at line 28 of file EcalPedOffset.h.

Constructor & Destructor Documentation

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

Constructor.

ctor

Definition at line 38 of file EcalPedOffset.cc.

References m_bestPed, m_DACmax, m_DACmin, and m_RMSmax.

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

Destructor.

dtor

Definition at line 72 of file EcalPedOffset.cc.

References citk::for(), m_pedResult, and m_pedValues.

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

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 104 of file EcalPedOffset.cc.

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

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

BeginRun.

begin the run

Reimplemented from edm::EDAnalyzer.

Definition at line 89 of file EcalPedOffset.cc.

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

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

EndJob.

perform the minimization and write results

Reimplemented from edm::EDAnalyzer.

Definition at line 273 of file EcalPedOffset.cc.

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

274 {
275  for (std::map<int,TPedValues*>::const_iterator smPeds = m_pedValues.begin ();
276  smPeds != m_pedValues.end ();
277  ++smPeds)
278  {
279  m_pedResult[smPeds->first] =
280  new TPedResult ((smPeds->second)->terminate (m_DACmin, m_DACmax));
281  }
282  edm::LogInfo ("EcalPedOffset") << " results map size "
283  << m_pedResult.size ();
285 
286  if (m_plotting != '0') makePlots ();
287  if (m_dbHostName != '0') writeDb ();
288 }
std::string m_dbHostName
database host name
Definition: EcalPedOffset.h:81
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:72
std::string m_xmlFile
name of the xml file to be saved
Definition: EcalPedOffset.h:70
std::string m_plotting
the root file where to store the detail plots
Definition: EcalPedOffset.h:99
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:73
std::string EcalPedOffset::intToString ( int  num)
private

Definition at line 547 of file EcalPedOffset.cc.

Referenced by writeXMLFiles().

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

create the plots of the DAC pedestal trend

Definition at line 513 of file EcalPedOffset.cc.

References LogDebug, m_maxChi2OverNDFAllowed_, m_maxSlopeAllowed_, m_minSlopeAllowed_, m_pedValues, and m_plotting.

Referenced by endJob().

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

Definition at line 182 of file EcalPedOffset.cc.

References ecalMGPA::adc(), EcalElectronicsId::dccId(), ecalElectronicsMap_, ecalMGPA::gainId(), EcalElectronicsMapping::getElectronicsId(), EBDetId::ic(), LogDebug, m_bestPed, m_pedValues, m_RMSmax, EcalDataFrame::MAXSAMPLES, and compare_using_db::sample.

Referenced by analyze().

184 {
185  std::map<int,int> DACvalues = _DACvalues;
186  // loop over the digis
187  for (EBDigiCollection::const_iterator itdigi = pDigis->begin();
188  itdigi != pDigis->end();
189  ++itdigi)
190  {
191  int gainId = ((EBDataFrame)(*itdigi)).sample(0).gainId();
192  EBDetId detId = EBDetId(itdigi->id());
194  int FEDid = 600+elecId.dccId();
195  int crystalId = detId.ic();
196 
197  //TODO: Behavior here
198  if(DACvalues.find(FEDid)==DACvalues.end())
199  {
200  edm::LogError("EcalPedOffset")
201  << "Error! EB DCCid of digi does not match any DCCid found in DCC headers" << FEDid;
202  }
203 
204  if (!m_pedValues.count(FEDid))
205  {
206  LogDebug("EcalPedOffset") << "Inserting new TPedValues object for FED:" << FEDid;
208  }
209 
210  // loop over the samples
211  for (int iSample = 0; iSample < EcalDataFrame::MAXSAMPLES; ++iSample)
212  {
213  m_pedValues[FEDid]->insert(gainId,
214  crystalId,
215  DACvalues[FEDid],
216  ((EBDataFrame)(*itdigi)).sample(iSample).adc(),
217  crystalId);
218  }
219 
220  } //end loop over digis
221 }
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:72
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:60
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
void EcalPedOffset::readDACs ( const edm::Handle< EEDigiCollection > &  pDigis,
const std::map< int, int > &  DACvalues 
)
private

Definition at line 226 of file EcalPedOffset.cc.

References ecalMGPA::adc(), EcalElectronicsId::dccId(), ecalElectronicsMap_, ecalMGPA::gainId(), EcalElectronicsMapping::getElectronicsId(), LogDebug, m_bestPed, m_pedValues, m_RMSmax, EcalDataFrame::MAXSAMPLES, and compare_using_db::sample.

228 {
229  std::map<int,int> DACvalues = _DACvalues;
230  // loop over the digis
231  for (EEDigiCollection::const_iterator itdigi = pDigis->begin();
232  itdigi != pDigis->end();
233  ++itdigi)
234  {
235  int gainId = ((EEDataFrame)(*itdigi)).sample(0).gainId();
236  //int gainId = itdigi->sample(0).gainId();
237  EEDetId detId = EEDetId(itdigi->id());
239  int FEDid = 600+elecId.dccId();
240  int crystalId = 25*elecId.towerId()+5*elecId.stripId()+elecId.xtalId();
241  int endcapCrystalId = 100*elecId.towerId()+5*(elecId.stripId()-1)+elecId.xtalId();
242 
243  //TODO: Behavior here
244  if(DACvalues.find(FEDid)==DACvalues.end())
245  {
246  edm::LogError("EcalPedOffset")
247  << "Error! EE DCCid of digi does not match any DCCid found in DCC headers: " << FEDid;
248  }
249 
250  if (!m_pedValues.count(FEDid))
251  {
252  LogDebug("EcalPedOffset") << "Inserting new TPedValues object for FED:" << FEDid;
254  }
255 
256  // loop over the samples
257  for (int iSample = 0; iSample < EcalDataFrame::MAXSAMPLES; ++iSample)
258  {
259  m_pedValues[FEDid]->insert(gainId,
260  crystalId,
261  DACvalues[FEDid],
262  ((EEDataFrame)(*itdigi)).sample(iSample).adc(),
263  endcapCrystalId);
264  }
265 
266  } //end loop over digis
267 }
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:72
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:60
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
void EcalPedOffset::writeDb ( )

WriteDB.

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

Definition at line 296 of file EcalPedOffset.cc.

References alignCSCRings::e, 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().

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

write the results into xml format

write the m_pedResults to XML files

Definition at line 461 of file EcalPedOffset.cc.

References MillePedeFileConverter_cfg::fileName, intToString(), m_pedResult, m_pedValues, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by endJob().

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

Member Data Documentation

const EcalElectronicsMapping* EcalPedOffset::ecalElectronicsMap_
private

Definition at line 60 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 66 of file EcalPedOffset.h.

Referenced by analyze().

int EcalPedOffset::m_bestPed
private

Definition at line 78 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 92 of file EcalPedOffset.h.

Referenced by writeDb().

int EcalPedOffset::m_DACmax
private

Definition at line 76 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and endJob().

int EcalPedOffset::m_DACmin
private

Definition at line 75 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and endJob().

std::string EcalPedOffset::m_dbHostName
private

database host name

Definition at line 81 of file EcalPedOffset.h.

Referenced by endJob(), and writeDb().

int EcalPedOffset::m_dbHostPort
private

database

Definition at line 89 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbName
private

database name

Definition at line 83 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbPassword
private

database user password

Definition at line 87 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbUserName
private

database user name

Definition at line 85 of file EcalPedOffset.h.

Referenced by writeDb().

edm::InputTag EcalPedOffset::m_endcapDigiCollection
private

secondary name given to collection of digis

Definition at line 67 of file EcalPedOffset.h.

Referenced by analyze().

edm::InputTag EcalPedOffset::m_headerCollection
private

name of module/plugin/producer making headers

Definition at line 68 of file EcalPedOffset.h.

Referenced by analyze().

std::string EcalPedOffset::m_location
private

Definition at line 94 of file EcalPedOffset.h.

Referenced by writeDb().

double EcalPedOffset::m_maxChi2OverNDFAllowed_
private

max chi2/ndf allowed for linearity test

Definition at line 105 of file EcalPedOffset.h.

Referenced by makePlots().

double EcalPedOffset::m_maxSlopeAllowed_
private

max slope (in magnitude) allowed for linearity test

Definition at line 101 of file EcalPedOffset.h.

Referenced by makePlots().

double EcalPedOffset::m_minSlopeAllowed_
private

min slope (in magnitude) allowed for linearity test

Definition at line 103 of file EcalPedOffset.h.

Referenced by makePlots().

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

Definition at line 73 of file EcalPedOffset.h.

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

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

Definition at line 72 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 99 of file EcalPedOffset.h.

Referenced by endJob(), and makePlots().

double EcalPedOffset::m_RMSmax
private

Definition at line 77 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and readDACs().

int EcalPedOffset::m_run
private

run number

Definition at line 96 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 70 of file EcalPedOffset.h.

Referenced by endJob().