00001 #include "CalibTracker/SiPixelESProducers/interface/SiPixelFakeTemplateDBObjectESSource.h" 00002 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00003 #include <fstream> 00004 00005 SiPixelFakeTemplateDBObjectESSource::SiPixelFakeTemplateDBObjectESSource(const edm::ParameterSet& conf_) : templateCalibrations_(conf_.getParameter<vstring>("siPixelTemplateCalibrations")), 00006 version_(conf_.getParameter<double>("Version")) 00007 { 00008 edm::LogInfo("SiPixelFakeTemplateDBObjectESSource::SiPixelFakeTemplateDBObjectESSource"); 00009 //the following line is needed to tell the framework what 00010 // data is being produced 00011 setWhatProduced(this); 00012 findingRecord<SiPixelTemplateDBObjectRcd>(); 00013 } 00014 00015 SiPixelFakeTemplateDBObjectESSource::~SiPixelFakeTemplateDBObjectESSource() 00016 { 00017 } 00018 00019 std::auto_ptr<SiPixelTemplateDBObject> SiPixelFakeTemplateDBObjectESSource::produce(const SiPixelTemplateDBObjectRcd & ) 00020 { 00021 using namespace edm::es; 00022 00023 //Mostly copied from CondTools/SiPixel/test/SiPixelTemplateDBObjectUploader.cc 00024 //--- Make the POOL-ORA object to store the database object 00025 SiPixelTemplateDBObject* obj = new SiPixelTemplateDBObject; 00026 00027 // Local variables 00028 const char *tempfile; 00029 int m; 00030 00031 // Set the number of templates to be passed to the dbobject 00032 obj->setNumOfTempl(templateCalibrations_.size()); 00033 00034 // Set the version of the template dbobject - this is an external parameter 00035 obj->setVersion(version_); 00036 00037 // open the template file(s) 00038 for(m=0; m< obj->numOfTempl(); ++m){ 00039 00040 edm::FileInPath file( templateCalibrations_[m].c_str() ); 00041 tempfile = (file.fullPath()).c_str(); 00042 00043 std::ifstream in_file(tempfile, std::ios::in); 00044 00045 if(in_file.is_open()){ 00046 edm::LogInfo("SiPixelFakeTemplateDBObjectESSource") << "Opened Template File: " << file.fullPath().c_str() << std::endl; 00047 00048 // Local variables 00049 char title_char[80], c; 00050 SiPixelTemplateDBObject::char2float temp; 00051 float tempstore; 00052 int iter,j; 00053 00054 // Templates contain a header char - we must be clever about storing this 00055 for (iter = 0; (c=in_file.get()) != '\n'; ++iter) { 00056 if(iter < 79) {title_char[iter] = c;} 00057 } 00058 if(iter > 78) {iter=78;} 00059 title_char[iter+1] ='\n'; 00060 00061 for(j=0; j<80; j+=4) { 00062 temp.c[0] = title_char[j]; 00063 temp.c[1] = title_char[j+1]; 00064 temp.c[2] = title_char[j+2]; 00065 temp.c[3] = title_char[j+3]; 00066 obj->push_back(temp.f); 00067 obj->setMaxIndex(obj->maxIndex()+1); 00068 } 00069 00070 // Fill the dbobject 00071 in_file >> tempstore; 00072 while(!in_file.eof()) { 00073 obj->setMaxIndex(obj->maxIndex()+1); 00074 obj->push_back(tempstore); 00075 in_file >> tempstore; 00076 } 00077 00078 in_file.close(); 00079 } 00080 else { 00081 // If file didn't open, report this 00082 edm::LogError("SiPixeFakelTemplateDBObjectESSource") << "Error opening File" << tempfile << std::endl; 00083 } 00084 } 00085 00086 //std::cout << *obj << std::endl; 00087 return std::auto_ptr<SiPixelTemplateDBObject>(obj); 00088 } 00089 00090 void SiPixelFakeTemplateDBObjectESSource::setIntervalFor( const edm::eventsetup::EventSetupRecordKey&, 00091 const edm::IOVSyncValue& iosv, 00092 edm::ValidityInterval& oValidity ) { 00093 edm::ValidityInterval infinity( iosv.beginOfTime(), iosv.endOfTime() ); 00094 oValidity = infinity; 00095 } 00096