Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[91X] SiPixelAli PCL payload creation thresholds from db - CondFormats #18087

Merged
merged 8 commits into from Mar 30, 2017
6 changes: 6 additions & 0 deletions CondCore/PCLConfigPlugins/BuildFile.xml
@@ -0,0 +1,6 @@
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="CondCore/ESSources"/>
<use name="CondFormats/PCLConfig"/>
<use name="CondFormats/DataRecord"/>
<flags EDM_PLUGIN="1"/>
5 changes: 5 additions & 0 deletions CondCore/PCLConfigPlugins/src/plugin.cc
@@ -0,0 +1,5 @@
#include "CondCore/ESSources/interface/registration_macros.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"

REGISTER_PLUGIN(AlignPCLThresholdsRcd,AlignPCLThresholds);
1 change: 1 addition & 0 deletions CondCore/Utilities/BuildFile.xml
Expand Up @@ -31,6 +31,7 @@
<use name="CondFormats/Common"/>
<use name="CondFormats/BTauObjects"/>
<use name="CondFormats/MFObjects"/>
<use name="CondFormats/PCLConfig"/>
<export>
<lib name="1"/>
</export>
1 change: 1 addition & 0 deletions CondCore/Utilities/python/cond2xml.py
Expand Up @@ -99,6 +99,7 @@ def ("%(plTypeSan)s2xml", %(plTypeSan)s2xml);
<use name="CondFormats/Common"/>
<use name="CondFormats/BTauObjects"/>
<use name="CondFormats/MFObjects"/>
<use name="CondFormats/PCLConfig"/>
<export>
<lib name="1"/>
</export>
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondDBFetch.cc
Expand Up @@ -31,6 +31,7 @@ namespace cond {
FETCH_PAYLOAD_CASE( AlignmentErrorsExtended )
FETCH_PAYLOAD_CASE( AlignmentSurfaceDeformations )
FETCH_PAYLOAD_CASE( Alignments )
FETCH_PAYLOAD_CASE( AlignPCLThresholds )
FETCH_PAYLOAD_CASE( BeamSpotObjects )
FETCH_PAYLOAD_CASE( CSCBadChambers )
FETCH_PAYLOAD_CASE( CSCBadStrips )
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondDBImport.cc
Expand Up @@ -45,6 +45,7 @@ namespace cond {
IMPORT_PAYLOAD_CASE( AlignmentErrorsExtended )
IMPORT_PAYLOAD_CASE( AlignmentSurfaceDeformations )
IMPORT_PAYLOAD_CASE( Alignments )
IMPORT_PAYLOAD_CASE( AlignPCLThresholds )
IMPORT_PAYLOAD_CASE( BeamSpotObjects )
IMPORT_PAYLOAD_CASE( CSCBadChambers )
IMPORT_PAYLOAD_CASE( CSCBadStrips )
Expand Down
1 change: 1 addition & 0 deletions CondCore/Utilities/src/CondFormats.h
Expand Up @@ -249,6 +249,7 @@
#include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
#include "CondFormats/BTauObjects/interface/TrackProbabilityCalibration.h"
#include "CondFormats/MFObjects/interface/MagFieldConfig.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"

#include "CondFormats/Common/interface/BaseKeyed.h"

Expand Down
25 changes: 25 additions & 0 deletions CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h
@@ -0,0 +1,25 @@
#ifndef AlignPCLThresholdsRcd_AlignPCLThresholdsRcd_h
#define AlignPCLThresholdsRcd_AlignPCLThresholdsRcd_h
// -*- C++ -*-
//
// Package: CondFormats/DataRecord
// Class : AlignPCLThresholdsRcd
//
/**\class AlignPCLThresholdsRcd AlignPCLThresholdsRcd.h CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h

Description: [one line class summary]

Usage:
<usage>

*/
//
// Author: Marco Musich
// Created: Wed, 22 Feb 2017 10:31:30 GMT
//

#include "FWCore/Framework/interface/EventSetupRecordImplementation.h"

class AlignPCLThresholdsRcd : public edm::eventsetup::EventSetupRecordImplementation<AlignPCLThresholdsRcd> {};

#endif
15 changes: 15 additions & 0 deletions CondFormats/DataRecord/src/AlignPCLThresholdsRcd.cc
@@ -0,0 +1,15 @@
// -*- C++ -*-
//
// Package: CondFormats/DataRecord
// Class : AlignPCLThresholdsRcd
//
// Implementation:
// [Notes on implementation]
//
// Author: Marco Musich
// Created: Wed, 22 Feb 2017 10:31:30 GMT

#include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"
#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"

EVENTSETUP_RECORD_REG(AlignPCLThresholdsRcd);
15 changes: 15 additions & 0 deletions CondFormats/PCLConfig/BuildFile.xml
@@ -0,0 +1,15 @@
<flags GENREFLEX_ARGS="--"/>
<use name="CondFormats/Common"/>
<!-- // comment out
<use name="FWCore/ParameterSet"/>
<use name="FWCore/MessageLogger"/>
<use name="xerces-c"/>
<use name="rootmath"/>
-->
<use name="FWCore/Utilities"/>
<use name="CondFormats/Serialization"/>
<use name="boost_serialization"/>

<export>
<lib name="1"/>
</export>
91 changes: 91 additions & 0 deletions CondFormats/PCLConfig/interface/AlignPCLThreshold.h
@@ -0,0 +1,91 @@
#ifndef _AlignPCLThreshold_h_
#define _AlignPCLThreshold_h_

#include "CondFormats/Serialization/interface/Serializable.h"

class AlignPCLThreshold
{
public:

struct coordThresholds{
coordThresholds(){
m_Cut=5.;
m_sigCut=2.5;
m_errorCut=10.;
m_maxMoveCut=200;
m_label="default";
}
~coordThresholds(){}
void setThresholds(float theCut,float theSigCut,float theErrorCut,float theMaxMoveCut,std::string theLabel){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please replace std::string theLabel with const std::string& theLabel

m_Cut=theCut;
m_sigCut=theSigCut;
m_errorCut=theErrorCut;
m_maxMoveCut=theMaxMoveCut;
m_label=theLabel;
}

float m_Cut;
float m_sigCut;
float m_errorCut;
float m_maxMoveCut;
std::string m_label;

COND_SERIALIZABLE;

};

virtual ~AlignPCLThreshold(){}

AlignPCLThreshold(coordThresholds X=coordThresholds(),coordThresholds tX=coordThresholds(),
coordThresholds Y=coordThresholds(),coordThresholds tY=coordThresholds(),
coordThresholds Z=coordThresholds(),coordThresholds tZ=coordThresholds(),
std::vector< coordThresholds > extraDOF=std::vector< coordThresholds >()
);

float getXcut() const {return m_xCoord.m_Cut;}
float getYcut() const {return m_yCoord.m_Cut;}
float getZcut() const {return m_zCoord.m_Cut;}
float getThetaXcut() const {return m_thetaXCoord.m_Cut;}
float getThetaYcut() const {return m_thetaYCoord.m_Cut;}
float getThetaZcut() const {return m_thetaZCoord.m_Cut;}

float getSigXcut() const {return m_xCoord.m_sigCut;}
float getSigYcut() const {return m_yCoord.m_sigCut;}
float getSigZcut() const {return m_zCoord.m_sigCut;}
float getSigThetaXcut() const {return m_thetaXCoord.m_sigCut;}
float getSigThetaYcut() const {return m_thetaYCoord.m_sigCut;}
float getSigThetaZcut() const {return m_thetaZCoord.m_sigCut;}

float getErrorXcut() const {return m_xCoord.m_errorCut;}
float getErrorYcut() const {return m_yCoord.m_errorCut;}
float getErrorZcut() const {return m_zCoord.m_errorCut;}
float getErrorThetaXcut() const {return m_thetaXCoord.m_errorCut;}
float getErrorThetaYcut() const {return m_thetaYCoord.m_errorCut;}
float getErrorThetaZcut() const {return m_thetaZCoord.m_errorCut;}

float getMaxMoveXcut() const {return m_xCoord.m_maxMoveCut;}
float getMaxMoveYcut() const {return m_yCoord.m_maxMoveCut;}
float getMaxMoveZcut() const {return m_zCoord.m_maxMoveCut;}
float getMaxMoveThetaXcut() const {return m_thetaXCoord.m_maxMoveCut;}
float getMaxMoveThetaYcut() const {return m_thetaYCoord.m_maxMoveCut;}
float getMaxMoveThetaZcut() const {return m_thetaZCoord.m_maxMoveCut;}

bool hasExtraDOF() const {return (m_extraDOF.size()>0);}
unsigned int extraDOFSize() const {return m_extraDOF.size();}
std::array<float,4> getExtraDOFCuts(const unsigned int i) const;

private:

coordThresholds m_xCoord;
coordThresholds m_yCoord;
coordThresholds m_zCoord;
coordThresholds m_thetaXCoord;
coordThresholds m_thetaYCoord;
coordThresholds m_thetaZCoord;
std::vector< coordThresholds > m_extraDOF;

COND_SERIALIZABLE;

};

#endif
58 changes: 58 additions & 0 deletions CondFormats/PCLConfig/interface/AlignPCLThresholds.h
@@ -0,0 +1,58 @@
#ifndef _AlignPCLThresholds_h_
#define _AlignPCLThresholds_h_

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmusich I think this include guard should read CondFormats_PCLConfig_interface_AlignPCLThresholds_h or similar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghellwig OK, picky but probably safer.
Is it recommended in the coding rules? I see it's rather common practice troughout the CondFormats package to define guards with the name of the class alone.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it is written down somewhere explicitely, but it reduces the risk of clashes within whole CMSSW


#include "CondFormats/PCLConfig/interface/AlignPCLThreshold.h"
#include "CondFormats/Serialization/interface/Serializable.h"

#include <map>
#include <string>
#include <vector>

using namespace std;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmusich no using namespace statements in header files


class AlignPCLThresholds{
public:
typedef map<string,AlignPCLThreshold> threshold_map;
enum coordType {X, Y, Z, theta_X, theta_Y, theta_Z, extra_DOF, endOfTypes};

AlignPCLThresholds(){}
virtual ~AlignPCLThresholds(){}

void setAlignPCLThreshold(string AlignableId, const AlignPCLThreshold &Threshold);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please pass AlignableId as const std::string&
the same applies in the other methods

void setAlignPCLThresholds(const int &Nrecords,const threshold_map &Thresholds);
void setNRecords(const int &Nrecords);

const threshold_map& getThreshold_Map () const {return m_thresholds;}
const int& getNrecords() const {return m_nrecords;}

AlignPCLThreshold getAlignPCLThreshold(string AlignableId) const;
AlignPCLThreshold & getAlignPCLThreshold(string AlignableId);

float getSigCut (string AlignableId,coordType type) const;
float getCut (string AlignableId,coordType type) const;
float getMaxMoveCut (string AlignableId,coordType type) const;
float getMaxErrorCut(string AlignableId,coordType type) const;

// overloaded methods to get all the coordinates
array<float,6> getSigCut (string AlignableId) const;
array<float,6> getCut (string AlignableId) const;
array<float,6> getMaxMoveCut (string AlignableId) const;
array<float,6> getMaxErrorCut(string AlignableId) const;

array<float,4> getExtraDOFCutsForAlignable(string AlignableId,const unsigned int i) const;

double size()const {return m_thresholds.size();}
vector<string> getAlignableList() const;

void printAll() const;

private:

threshold_map m_thresholds;
int m_nrecords;

COND_SERIALIZABLE;

};

#endif
128 changes: 128 additions & 0 deletions CondFormats/PCLConfig/plugins/AlignPCLThresholdsReader.cc
@@ -0,0 +1,128 @@
#include <string>
#include <iostream>
#include <map>
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "CondFormats/PCLConfig/interface/AlignPCLThresholds.h"
#include "CondFormats/DataRecord/interface/AlignPCLThresholdsRcd.h"

namespace edmtest
{
class AlignPCLThresholdsReader : public edm::EDAnalyzer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make it an edm::one::EDAnalyzer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we'll ever need to have this run MT, but OK

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, but since it's a new class we should use the current standard

{
public:
explicit AlignPCLThresholdsReader(edm::ParameterSet const& p) :
printdebug_(p.getUntrackedParameter<bool>("printDebug",true)),
formatedOutput_(p.getUntrackedParameter<std::string>("outputFile",""))
{
edm::LogInfo("AlignPCLThresholdsReader")<<"AlignPCLThresholdsReader"<<std::endl;
}
explicit AlignPCLThresholdsReader(int i) {
edm::LogInfo("AlignPCLThresholdsReader")<<"AlignPCLThresholdsReader "<<i<<std::endl;
}
virtual ~AlignPCLThresholdsReader() {
edm::LogInfo("AlignPCLThresholdsReader")<<"~AlignPCLThresholdsReader "<<std::endl;
}
virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override;

private:
bool printdebug_;
std::string formatedOutput_;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these could be both const as is in general good practice for configuration parameters


};

void
AlignPCLThresholdsReader::analyze(const edm::Event& e, const edm::EventSetup& context){

edm::LogInfo("AlignPCLThresholdsReader") <<"### AlignPCLThresholdsReader::analyze"<<std::endl;
edm::LogInfo("AlignPCLThresholdsReader") <<" I AM IN RUN NUMBER "<<e.id().run() <<std::endl;
edm::LogInfo("AlignPCLThresholdsReader") <<" ---EVENT NUMBER "<<e.id().event() <<std::endl;

edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("AlignPCLThresholdsRcd"));

if( recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
//record not found
edm::LogInfo("AlignPCLThresholdsReader") <<"Record \"AlignPCLThresholdsRcd"<<"\" does not exist "<<std::endl;
}

//this part gets the handle of the event source and the record (i.e. the Database)
edm::ESHandle<AlignPCLThresholds> thresholdHandle;
edm::LogInfo("AlignPCLThresholdsReader") <<"got eshandle"<<std::endl;

context.get<AlignPCLThresholdsRcd>().get(thresholdHandle);
edm::LogInfo("AlignPCLThresholdsReader") <<"got context"<<std::endl;

const AlignPCLThresholds* thresholds=thresholdHandle.product();
edm::LogInfo("AlignPCLThresholdsReader") <<"got AlignPCLThresholds* "<< std::endl;
edm::LogInfo("AlignPCLThresholdsReader") << "print pointer address : " ;
edm::LogInfo("AlignPCLThresholdsReader") << thresholds << std::endl;

edm::LogInfo("AlignPCLThresholdsReader") << "Size " << thresholds->size() << std::endl;
edm::LogInfo("AlignPCLThresholdsReader") <<"Content of myThresholds "<<std::endl;
// use built-in method in the CondFormat to print the content
if(printdebug_){
thresholds->printAll();
}

FILE* pFile=NULL;
if(formatedOutput_!="")pFile=fopen(formatedOutput_.c_str(), "w");
if(pFile){

fprintf(pFile,"AlignPCLThresholds::printAll() \n");
fprintf(pFile," =================================================================================================================== \n");
fprintf(pFile,"N records cut: %i \n",thresholds->getNrecords());

AlignPCLThresholds::threshold_map m_thresholds = thresholds->getThreshold_Map();

for(auto it = m_thresholds.begin(); it != m_thresholds.end() ; ++it){
fprintf(pFile," =================================================================================================================== \n");
fprintf(pFile,"key : %s \n ",(it->first).c_str());
fprintf(pFile,"- Xcut : %8.3f um ",(it->second).getXcut() );
fprintf(pFile,"| sigXcut : %8.3f ",(it->second).getSigXcut() );
fprintf(pFile,"| maxMoveXcut : %8.3f um ",(it->second).getMaxMoveXcut() );
fprintf(pFile,"| ErrorXcut : %8.3f um\n ",(it->second).getErrorXcut() );

fprintf(pFile,"- thetaXcut : %8.3f urad ",(it->second).getThetaXcut() );
fprintf(pFile,"| sigThetaXcut : %8.3f ",(it->second).getSigThetaXcut() );
fprintf(pFile,"| maxMoveThetaXcut : %8.3f urad ",(it->second).getMaxMoveThetaXcut());
fprintf(pFile,"| ErrorThetaXcut : %8.3f urad\n ",(it->second).getErrorThetaXcut() );

fprintf(pFile,"- Ycut : %8.3f um ",(it->second).getYcut() );
fprintf(pFile,"| sigYcut : %8.3f ",(it->second).getSigXcut() );
fprintf(pFile,"| maxMoveYcut : %8.3f um ",(it->second).getMaxMoveYcut() );
fprintf(pFile,"| ErrorYcut : %8.3f um\n ",(it->second).getErrorYcut() );

fprintf(pFile,"- thetaYcut : %8.3f urad ",(it->second).getThetaYcut() );
fprintf(pFile,"| sigThetaYcut : %8.3f ",(it->second).getSigThetaYcut() );
fprintf(pFile,"| maxMoveThetaYcut : %8.3f urad ",(it->second).getMaxMoveThetaYcut());
fprintf(pFile,"| ErrorThetaYcut : %8.3f urad\n ",(it->second).getErrorThetaYcut() );

fprintf(pFile,"- Zcut : %8.3f um ",(it->second).getZcut() );
fprintf(pFile,"| sigZcut : %8.3f ",(it->second).getSigZcut() );
fprintf(pFile,"| maxMoveZcut : %8.3f um ",(it->second).getMaxMoveZcut() );
fprintf(pFile,"| ErrorZcut : %8.3f um\n ",(it->second).getErrorZcut() );

fprintf(pFile,"- thetaZcut : %8.3f urad ",(it->second).getThetaZcut() );
fprintf(pFile,"| sigThetaZcut : %8.3f ",(it->second).getSigThetaZcut() );
fprintf(pFile,"| maxMoveThetaZcut : %8.3f urad ",(it->second).getMaxMoveThetaZcut());
fprintf(pFile,"| ErrorThetaZcut : %8.3f urad\n ",(it->second).getErrorThetaZcut() );

if((it->second).hasExtraDOF()){
for (unsigned int j=0; j<(it->second).extraDOFSize(); j++){
array<float,4> extraDOFCuts = thresholds->getExtraDOFCutsForAlignable(it->first,j);
fprintf(pFile,"Extra DOF: %i \n ",j);
fprintf(pFile,"- cut : %8.3f " ,extraDOFCuts.at(0));
fprintf(pFile,"| sigCut : %8.3f " ,extraDOFCuts.at(1));
fprintf(pFile,"| maxMoveCut : %8.3f " ,extraDOFCuts.at(2));
fprintf(pFile,"| maxErrorCut : %8.3f \n " ,extraDOFCuts.at(3));
}
}
}
}

}
DEFINE_FWK_MODULE(AlignPCLThresholdsReader);
}