CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
modGains.cc File Reference
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
#include "CondFormats/HcalObjects/interface/HcalGains.h"
#include "CondFormats/HcalObjects/interface/HcalRespCorrs.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"

Go to the source code of this file.

Functions

int main (int argn, char *argv[])
 

Function Documentation

int main ( int  argn,
char *  argv[] 
)

Definition at line 18 of file modGains.cc.

References HcalCondObjectContainer< Item >::addValues(), ecal_dqm_sourceclient-live_cfg::cerr, HcalDbASCIIIO::dumpObject(), HcalCondObjectContainer< Item >::exists(), HcalCondObjectContainer< Item >::getAllChannels(), HcalDbASCIIIO::getObject(), HcalRespCorr::getValue(), HcalGain::getValue(), HcalCondObjectContainer< Item >::getValues(), i, HcalTopologyMode::LHC, and AlCaHLTBitMon_QueryRunRegistry::string.

18  {
19  if (argn < 4) {
20  std::cerr << "Use: " << argv[0] << " operation <gains(.txt)> <operand> <result(.txt)>" << std::endl;
21  std::cerr << " where operation: sadd,ssub,smult,sdiv = +-*/ of a scalar value \n";
22  std::cerr << " add,sub,mult,div = +-*/ of vector values (in RespCorr-format)\n";
23  return 1;
24  }
26 
27  // get base conditions
28  std::cerr << argv[2] << std::endl;
29  std::ifstream inStream (argv[2]);
30  HcalGains gainsIn(&topo);;
31  HcalDbASCIIIO::getObject (inStream, &gainsIn);
32 
33  // where to write the result
34  std::ofstream outStream (argv[4]);
35 
36  // operation and operand
37  float val = 1.0;
38  std::string s_operation;
39  s_operation = argv[1];
40  bool vectorop = false;
41 
42  HcalRespCorrs corrsIn(&topo);;
43 
44  if ( (std::strcmp(s_operation.c_str(),"add")==0) ||
45  (std::strcmp(s_operation.c_str(),"sub")==0) ||
46  (std::strcmp(s_operation.c_str(),"mult")==0) ||
47  (std::strcmp(s_operation.c_str(),"div")==0) ) // vector operation
48  {
49  vectorop = true;
50  std::ifstream inCorr (argv[3]);
51  HcalDbASCIIIO::getObject (inCorr, &corrsIn);
52  }
53  else if ((std::strcmp(s_operation.c_str(),"sadd")==0) ||
54  (std::strcmp(s_operation.c_str(),"ssub")==0) ||
55  (std::strcmp(s_operation.c_str(),"smult")==0) ||
56  (std::strcmp(s_operation.c_str(),"sdiv")==0)) // scalar operation
57  {
58  val = atof (argv[3]);
59  std::cerr << "Scalar operation: using val=" << val << std::endl;
60  }
61  else
62  {
63  std::cerr << "Unknown operator. Stopping. \n";
64  return 1;
65  }
66 
67  HcalGains gainsOut(&topo);;
68  std::vector<DetId> channels = gainsIn.getAllChannels ();
69  std::cerr << "size = " << channels.size() << std::endl;
70  for (unsigned i = 0; i < channels.size(); i++) {
71  DetId id = channels[i];
72 
73  if (vectorop) // vector operation
74  {
75  if ((std::strcmp(s_operation.c_str(),"mult")==0)||(std::strcmp(s_operation.c_str(),"div")==0)) val = 1.0; // mult,div
76  if ((std::strcmp(s_operation.c_str(),"add")==0)||(std::strcmp(s_operation.c_str(),"sub")==0)) val = 0.0; // add,sub
77  if (corrsIn.exists(id))
78  {
79  val = corrsIn.getValues(id)->getValue();
80  }
81  if (i%100 == 0)
82  std::cerr << "Vector operation, " << i << "th channel: using val=" << val << std::endl;
83  }
84 
85  // std::cerr << "val=" << val << std::endl;
86  HcalGain* p_item = 0;
87  if ((std::strcmp(s_operation.c_str(),"add")==0) || (std::strcmp(s_operation.c_str(),"sadd")==0))
88  p_item = new HcalGain(id, gainsIn.getValues(id)->getValue(0) + val, gainsIn.getValues(id)->getValue(1) + val,
89  gainsIn.getValues(id)->getValue(2) + val, gainsIn.getValues(id)->getValue(3) + val);
90 
91  if ((std::strcmp(s_operation.c_str(),"sub")==0) || (std::strcmp(s_operation.c_str(),"ssub")==0))
92  p_item = new HcalGain(id, gainsIn.getValues(id)->getValue(0) - val, gainsIn.getValues(id)->getValue(1) - val,
93  gainsIn.getValues(id)->getValue(2) - val, gainsIn.getValues(id)->getValue(3) - val);
94 
95  if ((std::strcmp(s_operation.c_str(),"mult")==0) || (std::strcmp(s_operation.c_str(),"smult")==0))
96  p_item = new HcalGain(id, gainsIn.getValues(id)->getValue(0) * val, gainsIn.getValues(id)->getValue(1) * val,
97  gainsIn.getValues(id)->getValue(2) * val, gainsIn.getValues(id)->getValue(3) * val);
98 
99  if ((std::strcmp(s_operation.c_str(),"div")==0) || (std::strcmp(s_operation.c_str(),"sdiv")==0))
100  p_item = new HcalGain(id, gainsIn.getValues(id)->getValue(0) / val, gainsIn.getValues(id)->getValue(1) / val,
101  gainsIn.getValues(id)->getValue(2) / val, gainsIn.getValues(id)->getValue(3) / val);
102 
103 
104  // for all
105  if (p_item)
106  gainsOut.addValues(*p_item);
107  // std::cerr << i << std::endl;
108  }
109  // write out
110  HcalDbASCIIIO::dumpObject (outStream, gainsOut);
111  return 0;
112 }
int i
Definition: DBlmapReader.cc:9
Definition: DetId.h:18
bool getObject(std::istream &fInput, HcalPedestals *fObject)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)