CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::one::EDAnalyzer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks > edm::one::EDAnalyzerBase 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)
 
 ~ConditionDBWriter () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchRuns, edm::one::WatchLuminosityBlocks >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex >
const & 
esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
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::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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 selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

std::unique_ptr< SiStripApvGaingetNewObject () override
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from ConditionDBWriter< SiStripApvGain >
static void fillPSetDescription (edm::ParameterSetDescription &desc)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 13 of file SiStripGainFromAsciiFile.h.

Constructor & Destructor Documentation

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

Definition at line 20 of file SiStripGainFromAsciiFile.cc.

20  {
21  edm::LogInfo("SiStripGainFromAsciiFile::~SiStripGainFromAsciiFile");
22 }
Log< level::Info, false > LogInfo

Member Function Documentation

std::unique_ptr< SiStripApvGain > SiStripGainFromAsciiFile::getNewObject ( )
overrideprivatevirtual

Implements ConditionDBWriter< SiStripApvGain >.

Definition at line 24 of file SiStripGainFromAsciiFile.cc.

References SiStripGainFromAsciiFile::ModuleGain::apv, Asciifilename_, cms::cuda::assert(), DetId::det(), fp_, edm::FileInPath::fullPath(), GainsMap, SiStripGainFromAsciiFile::ModuleGain::hard_reset(), timingPdfMaker::infile, geometryCSVtoXML::line, getGTfromDQMFile::obj, sistrip::SpyUtilities::range(), SiStripDetInfoFileReader::read(), referenceValue_, contentValuesCheck::ss, and DetId::Tracker.

24  {
25  auto obj = std::make_unique<SiStripApvGain>();
26 
27  std::stringstream ss;
28  ss.str("");
29  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Reading Ascii File\n";
30  FILE* infile = fopen(Asciifilename_.c_str(), "r");
31  char line[4096];
32  if (infile) {
33  while (fgets(line, 4096, infile) != nullptr) {
34  uint32_t detid;
35  ModuleGain MG;
36  MG.apv[0] = 0.0;
37  MG.apv[1] = 0.0;
38  MG.apv[2] = 0.0;
39  MG.apv[3] = 0.0;
40  MG.apv[4] = 0.0;
41  MG.apv[5] = 0.0;
42  char* saveptr;
43  char* pch = strtok_r(line, " ", &saveptr);
44  int Arg = 0;
45  while (pch != nullptr) {
46  if (Arg == 0) {
47  sscanf(pch, "%d", &detid);
48  } else if (Arg <= 6) {
49  sscanf(pch, "%f", &(MG.apv[Arg - 1]));
50  } else {
51  //nothing to do here
52  }
53  pch = strtok_r(nullptr, " ", &saveptr);
54  Arg++;
55  }
56  ss << detid << " " << MG.apv[0] << " " << MG.apv[1] << " " << MG.apv[2] << " " << MG.apv[3] << " " << MG.apv[4]
57  << " " << MG.apv[5] << std::endl;
58  GainsMap.insert(std::pair<unsigned int, ModuleGain>(detid, MG));
59  }
60  fclose(infile);
61  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
62  } else {
63  edm::LogError("SiStripGainFromAsciiFile")
64  << " [SiStripGainFromAsciiFile::getNewObject] Error opening file " << Asciifilename_ << std::endl;
65  assert(0);
66  }
67 
68  const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
69 
70  ss.str("");
71  ss << "[SiStripGainFromAsciiFile::getNewObject]\n Filling SiStripApvGain object";
72  short nApvPair;
73  for (const auto it : detInfo.getAllDetIds()) {
74  ModuleGain MG;
75  if (DetId(it).det() != DetId::Tracker)
76  continue;
77 
78  nApvPair = detInfo.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] << " "
85  << MG.apv[5] << std::endl;
86  } else {
87  ss << "Hard reset for detid " << it << std::endl;
88  MG.hard_reset(referenceValue_);
89  }
90 
91  std::vector<float> DetGainsVector;
92 
93  if (nApvPair == 2) {
94  DetGainsVector.push_back(MG.apv[0] / referenceValue_);
95  DetGainsVector.push_back(MG.apv[1] / referenceValue_);
96  DetGainsVector.push_back(MG.apv[2] / referenceValue_);
97  DetGainsVector.push_back(MG.apv[3] / referenceValue_);
98  } else if (nApvPair == 3) {
99  DetGainsVector.push_back(MG.apv[0] / referenceValue_);
100  DetGainsVector.push_back(MG.apv[1] / referenceValue_);
101  DetGainsVector.push_back(MG.apv[2] / referenceValue_);
102  DetGainsVector.push_back(MG.apv[3] / referenceValue_);
103  DetGainsVector.push_back(MG.apv[4] / referenceValue_);
104  DetGainsVector.push_back(MG.apv[5] / referenceValue_);
105  } else {
106  edm::LogError("SiStripGainFromAsciiFile") << " SiStripGainFromAsciiFile::getNewObject] ERROR for detid " << it
107  << " not expected number of APV pairs " << nApvPair << std::endl;
108  }
109 
110  SiStripApvGain::Range range(DetGainsVector.begin(), DetGainsVector.end());
111  if (!obj->put(it, range)) {
112  edm::LogError("SiStripGainFromAsciiFile")
113  << " [SiStripGainFromAsciiFile::getNewObject] detid already exists" << std::endl;
114  ss << " [SiStripGainFromAsciiFile::getNewObject] detid already exists" << std::endl;
115  }
116  }
117  edm::LogInfo("SiStripGainFromAsciiFile") << ss.str();
118 
119  return obj;
120 }
Log< level::Error, false > LogError
assert(be >=bs)
const uint16_t range(const Frame &aFrame)
std::pair< ContainerIterator, ContainerIterator > Range
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
SiStripDetInfo read(std::string filePath)
std::unordered_map< unsigned int, ModuleGain > GainsMap
Log< level::Info, false > LogInfo
Definition: DetId.h:17
std::string fullPath() const
Definition: FileInPath.cc:161
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46

Member Data Documentation

std::string SiStripGainFromAsciiFile::Asciifilename_
private

Definition at line 36 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().

edm::FileInPath SiStripGainFromAsciiFile::fp_
private

Definition at line 38 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().

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

Definition at line 40 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject().

float SiStripGainFromAsciiFile::referenceValue_
private

Definition at line 37 of file SiStripGainFromAsciiFile.h.

Referenced by getNewObject(), and SiStripGainFromAsciiFile().