ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
DCSTxtToCool Class Reference
Collaboration diagram for DCSTxtToCool:

Public Member Functions

 DCSTxtToCool (const std::string &cooldb, const std::string &configfile, const std::string &datafile, const int offset)
 
int execute ()
 

Private Types

typedef std::map< std::string, DataPointInfo * > DPMap
 

Private Member Functions

void beginDataPoint (const std::string &folder)
 
void storeDataPoint (cool::ValidityKey since, float value)
 
void flushBuffer ()
 

Static Private Member Functions

static bool getCoolDB (const std::string &coolst, cool::IDatabasePtr &dbPtr)
 
static void readMap (const std::string &configfile)
 
static cool::IFolderPtr getFolder (const std::string &folder, const cool::IRecordSpecification &atrspec)
 

Private Attributes

std::string m_coolstr
 
std::string m_configfile
 
std::string m_datafile
 
int m_timeoffset
 
cool::IDatabasePtr m_coolDb
 
int m_ndata
 
std::string m_datap
 
cool::IFolderPtr m_folderp
 
DataPointInfom_dpinfo {}
 
cool::ValidityKey m_vkmin
 
cool::ValidityKey m_vkmax
 
DPMap m_dpmap {}
 
std::vector< std::string > m_folderlist {}
 
std::vector< int > m_folderchan {}
 

Detailed Description

Definition at line 33 of file DCSTxtToCool.cxx.

Member Typedef Documentation

◆ DPMap

typedef std::map<std::string, DataPointInfo*> DCSTxtToCool::DPMap
private

Definition at line 60 of file DCSTxtToCool.cxx.

Constructor & Destructor Documentation

◆ DCSTxtToCool()

DCSTxtToCool::DCSTxtToCool ( const std::string &  cooldb,
const std::string &  configfile,
const std::string &  datafile,
const int  offset 
)

Definition at line 66 of file DCSTxtToCool.cxx.

67  :
68  m_coolstr(cooldb), m_configfile(configfile), m_datafile(datafile),
70  m_ndata(0), m_datap(""), m_vkmin(cool::ValidityKeyMax), m_vkmax(0) {
71  std::cout << "Read data into COOL db: " << m_coolstr << std::endl;
72  std::cout << "Datapoint configuration file: " << m_configfile << std::endl;
73  std::cout << "Data file: " << m_datafile << std::endl;
74  std::cout << "Time offset " << m_timeoffset << " hours" << std::endl;
75 }

Member Function Documentation

◆ beginDataPoint()

void DCSTxtToCool::beginDataPoint ( const std::string &  folder)
private

Definition at line 129 of file DCSTxtToCool.cxx.

129  {
130  if (m_ndata>0) flushBuffer();
131  // strip trailing linefeeds
132  while (datap.substr(datap.size()-1,1)=="\r")
133  datap.pop_back();
134  // lookup datapoint to folder mapping
135  std::cout << "Begin processing datapoint " << datap << std::endl;
136  std::string key0=m_dpmap.begin()->first;
137  DPMap::const_iterator fitr=m_dpmap.find(datap);
138  if (fitr!=m_dpmap.end()) {
139  m_dpinfo=fitr->second;
140  m_datap=std::move(datap);
141  std::cout << "Associated datapoint to folder " << m_dpinfo->folder() <<
142  " channel " << m_dpinfo->channel() << std::endl;
143  // now get pointer to COOL folder, creating if needed
144  try {
146  }
147  catch (std::exception& e) {
148  // if folder creation fails, don't let data be stored
149  std::cout << "No valid folder to store data: " << e.what()
150  << std::endl;
151  m_dpinfo=nullptr;
152  }
153  } else {
154  std::cout << "ERROR: No mapping defined for datapoint " << datap <<
155  std::endl;
156  m_dpinfo=nullptr;
157  }
158 }

◆ execute()

int DCSTxtToCool::execute ( )

Definition at line 77 of file DCSTxtToCool.cxx.

77  {
78  // open COOL database
80  std::cout << "COOL database opened" << std::endl;
81  } else {
82  std::cout << "Database open fails" << std::endl;
83  return 1;
84  }
85  // read datapoint mapping
87  // loop over input lines
88  std::ifstream infile;
89  int nobj=0;
90  std::vector<char> buffer(999);
91  infile.open(m_datafile.c_str());
92  while (infile.getline(&buffer[0],999,'\n')) {
93  std::string sline(buffer.begin(),buffer.begin()+strlen(&buffer[0]));
94  // parse line with assumptions
95  // if string begins with '200' (e.g. 2006) assume date, hence datapoint
96  if (sline.substr(0,3)=="200") {
97  // parse the string as three fields - date, time, value (float)
98  std::string sdate,stime;
99  float value;
100  std::istringstream sbuf(&buffer[0]);
101  sbuf >> sdate >> stime >> value;
102  int year,month,day,hour,min,sec;
103  long long frac;
104  year=atoi(sdate.substr(0,4).c_str());
105  // note -1 as month is returned by timefunctions in range 0-11
106  month=atoi(sdate.substr(5,2).c_str())-1;
107  day=atoi(sdate.substr(8,2).c_str());
108  hour=atoi(stime.substr(0,2).c_str());
109  min=atoi(stime.substr(3,2).c_str());
110  sec=atoi(stime.substr(6,2).c_str());
111  frac=atoi(stime.substr(9,3).c_str())*1E6;
112  seal::Time sincet=seal::Time(year,month,day,
113  hour,min,sec,frac,false);
114  seal::TimeSpan tofs=seal::TimeSpan(3600*m_timeoffset,0);
115  sincet=sincet+tofs;
116  storeDataPoint(sincet.ns(),value);
117  } else if (sline.size()>2) {
118  // if size >2 assume a new datapoint with this name
119  beginDataPoint(sline);
120  }
121  ++nobj;
122  }
123  // write last data
124  if (m_ndata>0) flushBuffer();
125  std::cout << "Read total of " << nobj << " lines from data file" << std::endl;
126  return 0;
127 }

◆ flushBuffer()

void DCSTxtToCool::flushBuffer ( )
private

Definition at line 174 of file DCSTxtToCool.cxx.

174  {
175  // if no data, nothing to do
176  if (m_ndata==0) return;
177  if (m_datap=="") {
178  std::cout << "Attempt to write " << m_ndata << " data points but no folder"
179  << std::endl;
180  return;
181  }
182  std::cout << "Write " << m_ndata << " values [" <<
183  seal::Time(m_vkmin).format(false,"%c") << ", " <<
184  seal::Time(m_vkmax).format(false,"%c") << "] from datapoint "
185  << m_datap << " to folder " << m_dpinfo->folder() << " channel "
186  << m_dpinfo->channel() << std::endl;
187  try {
188  m_folderp->flushStorageBuffer();
189  }
190  catch (std::exception& e ) {
191  std::cout << "Bulk insertion failed for folder " <<
192  m_dpinfo->folder() << " channel " << m_dpinfo->channel() <<
193  ", reason: " << e.what() << std::endl;
194  }
195  m_ndata=0;
196  m_vkmin=cool::ValidityKeyMax;
197  m_vkmax=0;
198 }

◆ getCoolDB()

bool DCSTxtToCool::getCoolDB ( const std::string &  coolst,
cool::IDatabasePtr &  dbPtr 
)
staticprivate

Definition at line 201 of file DCSTxtToCool.cxx.

202  {
203  std::cout << "Attempt to open COOL database with connection string: "
204  << coolstr << std::endl;
205  cool::IDatabaseSvc& dbSvc=cool::DatabaseSvcFactory::databaseService();
206  try {
207  dbPtr=dbSvc.openDatabase(coolstr,false);
208  return true;
209  }
210  catch (std::exception& e) {
211  std::cout << "COOL exception caught: " << e.what() << std::endl;
212  std::cout << "Try to create new conditions DB" << std::endl;
213  try {
214  dbPtr=dbSvc.createDatabase(coolstr);
215  std::cout << "Creation succeeded" << std::endl;
216  return true;
217  }
218  catch (std::exception& e) {
219  std::cout << "Creation failed" << std::endl;
220  return false;
221  }
222  }
223  return false;
224 }

◆ getFolder()

cool::IFolderPtr DCSTxtToCool::getFolder ( const std::string &  folder,
const cool::IRecordSpecification &  atrspec 
)
staticprivate

Definition at line 265 of file DCSTxtToCool.cxx.

266  {
267  if (m_coolDb->existsFolder(folder)) {
268  std::cout << "Folder " << folder << " already exists in database"
269  << std::endl;
270  return m_coolDb->getFolder(folder);
271  } else {
272  std::cout << "Folder " << folder << " not found - try to create it" <<
273  std::endl;
274  // create folder (single version), and create parents if needed
275  // description string is used to signal data type to Athena
276  // depends if folder is single or multichannel
277  int nchan=0;
278  for (unsigned int i=0;i<m_folderlist.size();++i)
280  std::string desc="dummy";
281  if (nchan==1) desc="<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"40774348\" /></addrHeader><typeName>AthenaAttributeList</typeName>";
282  if (nchan>1) desc="<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\" /></addrHeader><typeName>CondAttrListCollection</typeName>";
283  std::cout << "Folder description string set to: " << desc << std::endl;
284  cool::IFolderPtr folderptr=m_coolDb->createFolder(folder,cool::FolderSpecification(cool::FolderVersioning::SINGLE_VERSION,atrspec),desc,true);
285  return folderptr;
286  }
287 }

◆ readMap()

void DCSTxtToCool::readMap ( const std::string &  configfile)
staticprivate

Definition at line 226 of file DCSTxtToCool.cxx.

226  {
227  std::cout << "Read configuration from file: " << configfile << std::endl;
228  m_dpmap.clear();
229  m_folderlist.clear();
230  m_folderchan.clear();
231  std::ifstream infile;
232  infile.open(configfile.c_str());
233  std::string dpname, folder, column;
234  int channel;
235  int nobj=0;
236  while (infile >> dpname >> folder >> column >> channel) {
237  ++nobj;
238  cool::RecordSpecification atrspec;
239  atrspec.extend(column,cool::StorageType::Float);
240  DataPointInfo* dptr=new DataPointInfo(folder,column,channel,atrspec);
241  m_dpmap.insert(std::pair<std::string,DataPointInfo*>(dpname,dptr));
242 
243  // check if this folder exists already in list
244  bool found=false;
245  for (unsigned int i=0;i<m_folderlist.size();++i) {
246  if (m_folderlist[i]==folder) {
247  ++m_folderchan[i];
248  found=true;
249  }
250  }
251  if (!found) {
252  m_folderlist.push_back(folder);
253  m_folderchan.push_back(1);
254  }
255  } // end input loop
256  std::cout << "Read " << nobj << " lines from file, giving " <<
257  m_dpmap.size() << " datapoint mappings " << std::endl;
258  std::cout << "Total of " << m_folderlist.size() << " COOL folders used" <<
259  std::endl;
260  for (unsigned int i=0;i<m_folderlist.size();++i)
261  std::cout << "Folder " << m_folderlist[i] << " channel count " <<
262  m_folderchan[i] << std::endl;
263 }

◆ storeDataPoint()

void DCSTxtToCool::storeDataPoint ( cool::ValidityKey  since,
float  value 
)
private

Definition at line 160 of file DCSTxtToCool.cxx.

160  {
161  // if no valid folder mapping defined, skip storage
162  if (m_dpinfo==nullptr) return;
163  if (m_ndata==0) m_folderp->setupStorageBuffer();
164  cool::Record payload(m_dpinfo->atrspec());
165  payload[m_dpinfo->column()].setValue(value);
166  m_folderp->
167  storeObject(since,cool::ValidityKeyMax,payload,m_dpinfo->channel());
168  ++m_ndata;
169  // keep track of min/max times for printout
170  if (since<m_vkmin) m_vkmin=since;
171  if (since>m_vkmax) m_vkmax=since;
172 }

Member Data Documentation

◆ m_configfile

std::string DCSTxtToCool::m_configfile
private

Definition at line 49 of file DCSTxtToCool.cxx.

◆ m_coolDb

cool::IDatabasePtr DCSTxtToCool::m_coolDb
private

Definition at line 53 of file DCSTxtToCool.cxx.

◆ m_coolstr

std::string DCSTxtToCool::m_coolstr
private

Definition at line 48 of file DCSTxtToCool.cxx.

◆ m_datafile

std::string DCSTxtToCool::m_datafile
private

Definition at line 50 of file DCSTxtToCool.cxx.

◆ m_datap

std::string DCSTxtToCool::m_datap
private

Definition at line 55 of file DCSTxtToCool.cxx.

◆ m_dpinfo

DataPointInfo* DCSTxtToCool::m_dpinfo {}
private

Definition at line 57 of file DCSTxtToCool.cxx.

◆ m_dpmap

DPMap DCSTxtToCool::m_dpmap {}
private

Definition at line 61 of file DCSTxtToCool.cxx.

◆ m_folderchan

std::vector<int> DCSTxtToCool::m_folderchan {}
private

Definition at line 63 of file DCSTxtToCool.cxx.

◆ m_folderlist

std::vector<std::string> DCSTxtToCool::m_folderlist {}
private

Definition at line 62 of file DCSTxtToCool.cxx.

◆ m_folderp

cool::IFolderPtr DCSTxtToCool::m_folderp
private

Definition at line 56 of file DCSTxtToCool.cxx.

◆ m_ndata

int DCSTxtToCool::m_ndata
private

Definition at line 54 of file DCSTxtToCool.cxx.

◆ m_timeoffset

int DCSTxtToCool::m_timeoffset
private

Definition at line 51 of file DCSTxtToCool.cxx.

◆ m_vkmax

cool::ValidityKey DCSTxtToCool::m_vkmax
private

Definition at line 59 of file DCSTxtToCool.cxx.

◆ m_vkmin

cool::ValidityKey DCSTxtToCool::m_vkmin
private

Definition at line 58 of file DCSTxtToCool.cxx.


The documentation for this class was generated from the following file:
DCSTxtToCool::m_timeoffset
int m_timeoffset
Definition: DCSTxtToCool.cxx:51
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
DataPointInfo::column
const std::string & column() const
Definition: DataPointInfo.h:31
DCSTxtToCool::m_dpmap
DPMap m_dpmap
Definition: DCSTxtToCool.cxx:61
run.infile
string infile
Definition: run.py:13
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
DCSTxtToCool::m_coolDb
cool::IDatabasePtr m_coolDb
Definition: DCSTxtToCool.cxx:53
DCSTxtToCool::m_configfile
std::string m_configfile
Definition: DCSTxtToCool.cxx:49
DCSTxtToCool::m_datap
std::string m_datap
Definition: DCSTxtToCool.cxx:55
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
DataPointInfo::folder
const std::string & folder() const
Definition: DataPointInfo.h:30
DeMoUpdate.column
dictionary column
Definition: DeMoUpdate.py:1110
PlotCalibFromCool.nchan
nchan
Definition: PlotCalibFromCool.py:564
DCSTxtToCool::flushBuffer
void flushBuffer()
Definition: DCSTxtToCool.cxx:174
athena.value
value
Definition: athena.py:124
stime
std::string stime()
return the current data and time
Definition: computils.cxx:214
DataPointInfo::channel
const int channel() const
Definition: DataPointInfo.h:32
python.AtlRunQueryAMI.year
year
Definition: AtlRunQueryAMI.py:226
DCSTxtToCool::m_ndata
int m_ndata
Definition: DCSTxtToCool.cxx:54
AthExHiveOpts.Time
Time
Definition: AthExHiveOpts.py:63
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
DCSTxtToCool::m_dpinfo
DataPointInfo * m_dpinfo
Definition: DCSTxtToCool.cxx:57
DCSTxtToCool::m_coolstr
std::string m_coolstr
Definition: DCSTxtToCool.cxx:48
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
DCSTxtToCool::getCoolDB
static bool getCoolDB(const std::string &coolst, cool::IDatabasePtr &dbPtr)
Definition: DCSTxtToCool.cxx:201
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:259
calibdata.exception
exception
Definition: calibdata.py:496
DCSTxtToCool::m_datafile
std::string m_datafile
Definition: DCSTxtToCool.cxx:50
CaloNoise_fillDB.dbSvc
dbSvc
Definition: CaloNoise_fillDB.py:108
DCSTxtToCool::readMap
static void readMap(const std::string &configfile)
Definition: DCSTxtToCool.cxx:226
DCSTxtToCool::m_folderp
cool::IFolderPtr m_folderp
Definition: DCSTxtToCool.cxx:56
DataPointInfo::atrspec
const cool::IRecordSpecification & atrspec() const
Definition: DataPointInfo.h:33
DataPointInfo
Definition: DataPointInfo.h:14
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
DCSTxtToCool::getFolder
static cool::IFolderPtr getFolder(const std::string &folder, const cool::IRecordSpecification &atrspec)
Definition: DCSTxtToCool.cxx:265
CscCalibQuery.day
day
Definition: CscCalibQuery.py:312
DCSTxtToCool::storeDataPoint
void storeDataPoint(cool::ValidityKey since, float value)
Definition: DCSTxtToCool.cxx:160
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
DCSTxtToCool::m_folderlist
std::vector< std::string > m_folderlist
Definition: DCSTxtToCool.cxx:62
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
DCSTxtToCool::m_vkmin
cool::ValidityKey m_vkmin
Definition: DCSTxtToCool.cxx:58
DCSTxtToCool::m_vkmax
cool::ValidityKey m_vkmax
Definition: DCSTxtToCool.cxx:59
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
DCSTxtToCool::m_folderchan
std::vector< int > m_folderchan
Definition: DCSTxtToCool.cxx:63
DCSTxtToCool::beginDataPoint
void beginDataPoint(const std::string &folder)
Definition: DCSTxtToCool.cxx:129