CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
SiStripGainFromAsciiFile Class Reference

#include <SiStripGainFromAsciiFile.h>

Inheritance diagram for SiStripGainFromAsciiFile:
ConditionDBWriter< SiStripApvGain > edm::EDAnalyzer edm::EDConsumerBase

Classes

struct  ModuleGain
 

Public Member Functions

 SiStripGainFromAsciiFile (const edm::ParameterSet &)
 
 ~SiStripGainFromAsciiFile () override
 
- Public Member Functions inherited from ConditionDBWriter< SiStripApvGain >
 ConditionDBWriter (const edm::ParameterSet &iConfig)
 
virtual ~ConditionDBWriter ()
 
- 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
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

SiStripApvGaingetNewObject () override
 

Private Attributes

std::string Asciifilename_
 
edm::FileInPath fp_
 
std::unordered_map< unsigned int, ModuleGainGainsMap
 
float referenceValue_
 

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 ConditionDBWriter< SiStripApvGain >
void setDoStore (const bool doStore)
 When set to false the payload will not be written to the db. More...
 
void storeOnDbNow ()
 
cond::Time_t timeOfLastIOV ()
 
- 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

Definition at line 12 of file SiStripGainFromAsciiFile.h.

Constructor & Destructor Documentation

SiStripGainFromAsciiFile::SiStripGainFromAsciiFile ( const edm::ParameterSet iConfig)
explicit

Definition at line 15 of file SiStripGainFromAsciiFile.cc.

References Asciifilename_, fp_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), referenceValue_, and AlCaHLTBitMon_QueryRunRegistry::string.

16 
17 
18  Asciifilename_=iConfig.getParameter<std::string>("InputFileName");
19  referenceValue_ = iConfig.getParameter<double>("referenceValue");
20  fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
21 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile ( )
override

Definition at line 24 of file SiStripGainFromAsciiFile.cc.

24  {
25  edm::LogInfo("SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile");
26 }

Member Function Documentation

SiStripApvGain * SiStripGainFromAsciiFile::getNewObject ( )
overrideprivatevirtual

Implements ConditionDBWriter< SiStripApvGain >.

Definition at line 28 of file SiStripGainFromAsciiFile.cc.

References SiStripGainFromAsciiFile::ModuleGain::apv, Asciifilename_, DetId::det(), fp_, edm::FileInPath::fullPath(), GainsMap, SiStripGainFromAsciiFile::ModuleGain::hard_reset(), geometryCSVtoXML::line, MuonAssociatorByHits_cfi::obj, SiStripApvGain::put(), matplotRender::reader, referenceValue_, and DetId::Tracker.

28  {
29 
31 
32 
33  std::stringstream ss;
34  ss.str("");
35  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Reading Ascii File\n";
36  FILE* infile = fopen (Asciifilename_.c_str(), "r");
37  char line[4096];
38  if (infile){
39  while(fgets(line, 4096, infile)!=nullptr){
40  uint32_t detid;
41  ModuleGain MG;
42  MG.apv[0] = 0.0; MG.apv[1] = 0.0; MG.apv[2] = 0.0; MG.apv[3] = 0.0; MG.apv[4] = 0.0; MG.apv[5] = 0.0;
43  char* pch=strtok(line," "); int Arg=0;
44  while (pch!=nullptr){
45  if(Arg==0){
46  sscanf(pch, "%d", &detid);
47  }else if(Arg<=6){
48  sscanf(pch, "%f", &(MG.apv[Arg-1]));
49  }else{
50  //nothing to do here
51  }
52  pch=strtok(nullptr," ");Arg++;
53  }
54  ss << detid << " " << MG.apv[0] << " " << MG.apv[1] << " " << MG.apv[2] << " " << MG.apv[3] << " " << MG.apv[4] << " " << MG.apv[5] << std::endl;
55  GainsMap.insert(std::pair<unsigned int,ModuleGain>(detid,MG));
56  }
57  fclose(infile);
58  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
59  } else {
60  edm::LogError("SiStripGainFromAsciiFile")<< " [SiStripGainFromAsciiFile::getNewObject] Error opening file " << Asciifilename_ << std::endl;
61  assert(0);
62  }
63 
64 
65 
67 
68  const std::vector<uint32_t>& DetIds = reader.getAllDetIds();
69 
70  ss.str("");
71  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Filling SiStripApvGain object";
72  short nApvPair;
73  for(std::vector<uint32_t>::const_iterator it=DetIds.begin(); it!=DetIds.end(); it++){
74  ModuleGain MG;
75  if (DetId(*it).det()!=DetId::Tracker)
76  continue;
77 
78  nApvPair=reader.getNumberOfApvsAndStripLength(*it).first/2;
79 
80  ss << "Looking at detid " << *it << " nApvPairs " << nApvPair << std::endl;
81  auto iter=GainsMap.find(*it);
82  if (iter!=GainsMap.end()){
83  MG = iter->second;
84  ss << " " << MG.apv[0] << " " << MG.apv[1] << " " << MG.apv[2] << " " << MG.apv[3] << " " << MG.apv[4] << " " << MG.apv[5] << std::endl;
85  }else {
86  ss << "Hard reset for detid " << *it << std::endl;
87  MG.hard_reset(referenceValue_);
88  }
89 
90  std::vector<float> DetGainsVector;
91 
92  if (nApvPair==2){
93  DetGainsVector.push_back(MG.apv[0]/referenceValue_);
94  DetGainsVector.push_back(MG.apv[1]/referenceValue_);
95  DetGainsVector.push_back(MG.apv[2]/referenceValue_);
96  DetGainsVector.push_back(MG.apv[3]/referenceValue_);
97  } else if (nApvPair==3){
98  DetGainsVector.push_back(MG.apv[0]/referenceValue_);
99  DetGainsVector.push_back(MG.apv[1]/referenceValue_);
100  DetGainsVector.push_back(MG.apv[2]/referenceValue_);
101  DetGainsVector.push_back(MG.apv[3]/referenceValue_);
102  DetGainsVector.push_back(MG.apv[4]/referenceValue_);
103  DetGainsVector.push_back(MG.apv[5]/referenceValue_);
104  } else {
105  edm::LogError("SiStripGainFromAsciiFile") << " SiStripGainFromAsciiFile::getNewObject] ERROR for detid " << *it << " not expected number of APV pairs " << nApvPair <<std::endl;
106  }
107 
108  SiStripApvGain::Range range(DetGainsVector.begin(),DetGainsVector.end());
109  if ( ! obj->put(*it,range) ){
110  edm::LogError("SiStripGainFromAsciiFile")<<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
111  ss <<" [SiStripGainFromAsciiFile::getNewObject] detid already exists"<<std::endl;
112  }
113  }
114  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
115 
116  return obj;
117 }
bool put(const uint32_t &detID, Range input)
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:18
std::unordered_map< unsigned int, ModuleGain > GainsMap
std::string fullPath() const
Definition: FileInPath.cc:184
Detector det() const
get the detector field from this detid
Definition: DetId.h:35

Member Data Documentation

std::string SiStripGainFromAsciiFile::Asciifilename_
private

Definition at line 33 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().

edm::FileInPath SiStripGainFromAsciiFile::fp_
private

Definition at line 35 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().

std::unordered_map< unsigned int,ModuleGain> SiStripGainFromAsciiFile::GainsMap
private

Definition at line 37 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject().

float SiStripGainFromAsciiFile::referenceValue_
private

Definition at line 34 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().